Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2555938rdg; Mon, 14 Aug 2023 06:25:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUxM6FedwK0hUYMcjAVx6hlRMPrBEjDzGE9wgrOszqogNEsr88ytvdfXicUx3FwCsgMYKA X-Received: by 2002:a05:6512:3150:b0:4fb:7381:4c69 with SMTP id s16-20020a056512315000b004fb73814c69mr5331584lfi.28.1692019551734; Mon, 14 Aug 2023 06:25:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692019551; cv=none; d=google.com; s=arc-20160816; b=D7SRmhvzumyoYt3HjTx42FpvfugqnOCaHJxCm7RrtpvEULmsj+p31Eu8o8NrxY9Z/L 9tIcHYgV1xIPYaiNqeiSfXJemycTg2J7KrQZ6rIpX6FX8Z8JpJDGjzLUa5ZEdGzH56Eh P4ZS+sOMt+YkPtt6DhT1cgxV69Zup+cZyCnMn0JYdTrUspr5C3WS6ZTE9L1oDWqS1MlK QFqzPv9fyr3tniumyXnFWsQQxxlJYpl84E3UUVGY28BhTxvCABGd1M78lAn+00joX3+C vg/afhgjjaOU3myHWrsZ9WCstYSoNrgNiN/8pcZydeiEUJzDmH0Uhn5QhHwnrpqtuN+V pjfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=sJ1XfdJ8koVOpLPFh5lgGOWx8nQ+9eqY27+qcXXvzaM=; fh=hRRj5NdAV5PDe6N9BQPOEHetdzGCKd1tUr36oQQg/JA=; b=KQ6Bd/BivCzUvWZT7aPhVurHZSbzR4+YP/T0f+NT+TdVhDbxw6vgfj/A84tOhXPHz9 QwlwUOBxegKBoIW8ZPkEwe5l+vh2Ngc4pjhpvVLx4YvcMQVEHkRGcZIpCdpAFcGgUhLA 7L3x2TiAKdMtaNW/fFNyqXd7EN/EGi21LKlTQd2cLKCLpMWAsGp+WEZAGQvKJy4jMEft Myj4dQIaSJxK3s0AS2ClahYQ3kveh7XHAFmL3AKMapgweiqLrPjnnfz+InlLKSMVjQTP ItGbHV9MtKG0+3zfh6/QzhqYFFp5oWvjzm0rGcECEZpgGHwwz8LaC6hipGzy/EGyZxat mx7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=AyQtOYZ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020aa7de0b000000b0052570917661si45078edv.615.2023.08.14.06.25.27; Mon, 14 Aug 2023 06:25:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=AyQtOYZ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbjHNMhg (ORCPT + 99 others); Mon, 14 Aug 2023 08:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbjHNMhK (ORCPT ); Mon, 14 Aug 2023 08:37:10 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D41AE5B; Mon, 14 Aug 2023 05:37:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1692016627; bh=sJ1XfdJ8koVOpLPFh5lgGOWx8nQ+9eqY27+qcXXvzaM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=AyQtOYZ0fJ2oyt3zcRf92PdYESgUvJqcbG7m4mh6cpaXYGCmf5P0Wli7vr8PB3Ybw 5g8Uvmu+S0YIo2KQMSTHPdjnod3sCd3Lbs8Ao2exiIqAq7fcy3/nrvCr48CdTGqXRw qMbFT6gCgpljE4unS9Hsb4k1rhL76Qb/7Cuu3lbgE0Dz7LzfA8gWTDTXEHkolTVPSN 4HX9tj+fsr50VXJ6nAAsPLbTSAPM28CxTHpp3aC1fe5A1YxZY7CW1Xv9hToSYy386C 1fqMx1xtKpA9oAaE/nww8WtYJwEyZzDEmZsIy7Y/EPVNyANuZ2jlMumSFYoAWgM/vS DwlQminVcd0Jw== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4RPYnH5xwHz4wZJ; Mon, 14 Aug 2023 22:37:07 +1000 (AEST) From: Michael Ellerman To: Linus Walleij , Nicholas Piggin , Christophe Leroy Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Linus Walleij Subject: Re: [PATCH] powerpc: Make virt_to_pfn() a static inline In-Reply-To: <20230809-virt-to-phys-powerpc-v1-1-12e912a7d439@linaro.org> References: <20230809-virt-to-phys-powerpc-v1-1-12e912a7d439@linaro.org> Date: Mon, 14 Aug 2023 22:37:07 +1000 Message-ID: <87a5uter64.fsf@mail.lhotse> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Linus Walleij writes: > Making virt_to_pfn() a static inline taking a strongly typed > (const void *) makes the contract of a passing a pointer of that > type to the function explicit and exposes any misuse of the > macro virt_to_pfn() acting polymorphic and accepting many types > such as (void *), (unitptr_t) or (unsigned long) as arguments > without warnings. ... > diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h > index f2b6bf5687d0..9ee4b6d4a82a 100644 > --- a/arch/powerpc/include/asm/page.h > +++ b/arch/powerpc/include/asm/page.h > @@ -9,6 +9,7 @@ > #ifndef __ASSEMBLY__ > #include > #include > +#include > #else > #include > #endif > @@ -119,16 +120,6 @@ extern long long virt_phys_offset; > #define ARCH_PFN_OFFSET ((unsigned long)(MEMORY_START >> PAGE_SHIFT)) > #endif > > -#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) > -#define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr)) > -#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) > - > -#define virt_addr_valid(vaddr) ({ \ > - unsigned long _addr = (unsigned long)vaddr; \ > - _addr >= PAGE_OFFSET && _addr < (unsigned long)high_memory && \ > - pfn_valid(virt_to_pfn(_addr)); \ > -}) > - > /* > * On Book-E parts we need __va to parse the device tree and we can't > * determine MEMORY_START until then. However we can determine PHYSICAL_START > @@ -233,6 +224,25 @@ extern long long virt_phys_offset; > #endif > #endif > > +#ifndef __ASSEMBLY__ > +static inline unsigned long virt_to_pfn(const void *kaddr) > +{ > + return __pa(kaddr) >> PAGE_SHIFT; > +} > + > +static inline const void *pfn_to_kaddr(unsigned long pfn) > +{ > + return (const void *)(((unsigned long)__va(pfn)) << PAGE_SHIFT); Any reason to do it this way rather than: + return __va(pfn << PAGE_SHIFT); Seems to be equivalent and much cleaner? cheers