arch/arm64/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+)
Add a fallback stub for pgd_page_paddr() when (PGTBALE_LEVELS <= 4) which
helps in intercepting any unintended usage and which is also in line with
existing stubs for similar [pud|p4d]_page_paddr() helpers.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
arch/arm64/include/asm/pgtable.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index aa89c2e67ebc..fb34df92d159 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -1212,6 +1212,8 @@ static inline p4d_t *p4d_offset_kimg(pgd_t *pgdp, u64 addr)
static inline bool pgtable_l5_enabled(void) { return false; }
+#define pgd_page_paddr(pgd) ({ BUILD_BUG(); 0; })
+
#define p4d_index(addr) (((addr) >> P4D_SHIFT) & (PTRS_PER_P4D - 1))
/* Match p4d_offset folding in <asm/generic/pgtable-nop4d.h> */
--
2.30.2
On Tue, Oct 14, 2025 at 12:06:33PM +0100, Anshuman Khandual wrote: > Add a fallback stub for pgd_page_paddr() when (PGTBALE_LEVELS <= 4) which typo > helps in intercepting any unintended usage and which is also in line with > existing stubs for similar [pud|p4d]_page_paddr() helpers. Are you saying the kernel compiles in this case without your patch? Which definition of pgd_page_paddr() does it end up using? Will
On 04/11/25 8:01 PM, Will Deacon wrote: > On Tue, Oct 14, 2025 at 12:06:33PM +0100, Anshuman Khandual wrote: >> Add a fallback stub for pgd_page_paddr() when (PGTBALE_LEVELS <= 4) which > > typo Sure will change - s/Add/Adds > >> helps in intercepting any unintended usage and which is also in line with >> existing stubs for similar [pud|p4d]_page_paddr() helpers. > > Are you saying the kernel compiles in this case without your patch? Which > definition of pgd_page_paddr() does it end up using? Kernel compiles for PGTBALE_LEVELS <= 4 just fine without this patch as both its current users p4d_offset_phys() and p4d_offset_lockless() are wrapped in with PGTBALE_LEVELS > 4.
On Wed, Nov 05, 2025 at 08:24:40AM +0530, Anshuman Khandual wrote: > On 04/11/25 8:01 PM, Will Deacon wrote: > > On Tue, Oct 14, 2025 at 12:06:33PM +0100, Anshuman Khandual wrote: > >> Add a fallback stub for pgd_page_paddr() when (PGTBALE_LEVELS <= 4) which > > > > typo > > Sure will change - s/Add/Adds > > > >> helps in intercepting any unintended usage and which is also in line with > >> existing stubs for similar [pud|p4d]_page_paddr() helpers. > > > > Are you saying the kernel compiles in this case without your patch? Which > > definition of pgd_page_paddr() does it end up using? > > Kernel compiles for PGTBALE_LEVELS <= 4 just fine without this patch as both > its current users p4d_offset_phys() and p4d_offset_lockless() are wrapped in > with PGTBALE_LEVELS > 4. Ok, but your patch is trying to catch broken users of the macro, right? So my question is, would such a user compile today? If not, then your patch is pointless. Will
On 05/11/25 10:33 PM, Will Deacon wrote: > On Wed, Nov 05, 2025 at 08:24:40AM +0530, Anshuman Khandual wrote: >> On 04/11/25 8:01 PM, Will Deacon wrote: >>> On Tue, Oct 14, 2025 at 12:06:33PM +0100, Anshuman Khandual wrote: >>>> Add a fallback stub for pgd_page_paddr() when (PGTBALE_LEVELS <= 4) which >>> >>> typo >> >> Sure will change - s/Add/Adds >>> >>>> helps in intercepting any unintended usage and which is also in line with >>>> existing stubs for similar [pud|p4d]_page_paddr() helpers. >>> >>> Are you saying the kernel compiles in this case without your patch? Which >>> definition of pgd_page_paddr() does it end up using? >> >> Kernel compiles for PGTBALE_LEVELS <= 4 just fine without this patch as both >> its current users p4d_offset_phys() and p4d_offset_lockless() are wrapped in >> with PGTBALE_LEVELS > 4. > > Ok, but your patch is trying to catch broken users of the macro, right? Right but there are no broken users at present because all the users are wrapped inside #ifdef PGTBALE_LEVELS > 4. > So my question is, would such a user compile today? If not, then your > patch is pointless. The point is this macro is not visible outside #ifdef PGTBALE_LEVELS > 4 where as similar ones such as p4d_page_paddr() and pud_page_paddr() are always visible via their respective fallback stubs, when PGTABLE_LEVELS are lower.
On Thu, Nov 06, 2025 at 07:29:55AM +0530, Anshuman Khandual wrote: > On 05/11/25 10:33 PM, Will Deacon wrote: > > So my question is, would such a user compile today? If not, then your > > patch is pointless. > > The point is this macro is not visible outside #ifdef PGTBALE_LEVELS > 4 > where as similar ones such as p4d_page_paddr() and pud_page_paddr() are > always visible via their respective fallback stubs, when PGTABLE_LEVELS > are lower. Yes but we needed the p4d/pud fallbacks to be able to use them in functions like early_fixmap_init_pud() without #ifdefs. We don't have such a case for pgd_page_paddr(), so I don't think this patch makes sense on its own. -- Catalin
© 2016 - 2025 Red Hat, Inc.