[RFC PATCH v2 27/43] arm64: mm: Make page size dependent BUILD_BUG_ON() checks runtime

Eric Curtin ericcurtin17 at gmail.com
Mon Nov 30 17:51:59 PST 2026


From: Ryan Roberts <ryan.roberts at arm.com>

Some BUILD_BUG_ON() checks test values that depend on the page size,
which are not compile-time constants with boot-time page size selection,
so they no longer compile.

Convert the check that the page table levels derived from
CONFIG_ARM64_VA_BITS match CONFIG_PGTABLE_LEVELS in arch_mm_preinit() to
VM_BUG_ON(). Convert the TASK_SIZE_32 check in arch_mm_preinit(), the
pgd_index() check in map_mem() and the PGD_SIZE alignment check in
pgtable_cache_init() to BUILD_BUG_ON_FIXED_PAGE_SIZE(), which stays a
build-time check for a fixed page size and becomes a VM_BUG_ON() for a
boot-time one.

Signed-off-by: Ryan Roberts <ryan.roberts at arm.com>
Signed-off-by: Eric Curtin <eric.curtin at docker.com>
(cherry picked from commit 945351892e8d81903147f4adab6a29e7e5f24115)
---
 arch/arm64/mm/init.c | 6 +++---
 arch/arm64/mm/mmu.c  | 6 ++++--
 arch/arm64/mm/pgd.c  | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 70393e4d2d82..f3229c921d9c 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -355,15 +355,15 @@ void __init arch_mm_preinit(void)
 	 * detected at build time already.
 	 */
 #ifdef CONFIG_COMPAT
-	BUILD_BUG_ON(TASK_SIZE_32 > DEFAULT_MAP_WINDOW_64);
+	BUILD_BUG_ON_FIXED_PAGE_SIZE(TASK_SIZE_32 > DEFAULT_MAP_WINDOW_64);
 #endif
 
 	/*
 	 * Selected page table levels should match when derived from
 	 * scratch using the virtual address range and page size.
 	 */
-	BUILD_BUG_ON(ARM64_HW_PGTABLE_LEVELS(CONFIG_ARM64_VA_BITS) !=
-		     CONFIG_PGTABLE_LEVELS);
+	VM_BUG_ON(ARM64_HW_PGTABLE_LEVELS(CONFIG_ARM64_VA_BITS) !=
+		  CONFIG_PGTABLE_LEVELS);
 
 	if (PAGE_SIZE >= 16384 && get_num_physpages() <= 128) {
 		extern int sysctl_overcommit_memory;
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 96fc6d843d34..9bc4c0b4b4d5 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1198,8 +1198,10 @@ static void __init map_mem(void)
 	 * entire reduced VA space is covered by a single pgd_t which will have
 	 * been populated without the PXNTable attribute by the time we get here.)
 	 */
-	BUILD_BUG_ON(pgd_index(direct_map_end - 1) == pgd_index(direct_map_end) &&
-		     pgd_index(_PAGE_OFFSET(VA_BITS_MIN)) != PTRS_PER_PGD - 1);
+	BUILD_BUG_ON_FIXED_PAGE_SIZE(pgd_index(direct_map_end - 1) ==
+				     pgd_index(direct_map_end) &&
+				     pgd_index(_PAGE_OFFSET(VA_BITS_MIN)) !=
+				     PTRS_PER_PGD - 1);
 
 	arm64_kfence_map_pool();
 
diff --git a/arch/arm64/mm/pgd.c b/arch/arm64/mm/pgd.c
index bf5110b91e2f..5d40ce1eab3f 100644
--- a/arch/arm64/mm/pgd.c
+++ b/arch/arm64/mm/pgd.c
@@ -56,7 +56,7 @@ void __init pgtable_cache_init(void)
 	 * With 52-bit physical addresses, the architecture requires the
 	 * top-level table to be aligned to at least 64 bytes.
 	 */
-	BUILD_BUG_ON(!IS_ALIGNED(PGD_SIZE, 64));
+	BUILD_BUG_ON_FIXED_PAGE_SIZE(!IS_ALIGNED(PGD_SIZE, 64));
 #endif
 
 	/*



More information about the linux-arm-kernel mailing list