OSDN Git Service

arm64/mm: Validate CONFIG_PGTABLE_LEVELS
authorAnshuman Khandual <anshuman.khandual@arm.com>
Mon, 10 May 2021 12:22:06 +0000 (17:52 +0530)
committerWill Deacon <will@kernel.org>
Tue, 25 May 2021 17:54:39 +0000 (18:54 +0100)
CONFIG_PGTABLE_LEVELS has been statically defined in (arch/arm64/Kconfig)
depending on the page size and requested virtual address range. In order to
validate this page table levels selection this adds a BUILD_BUG_ON() as per
the existing formula ARM64_HW_PGTABLE_LEVELS(). This would help protect any
inadvertent changes to CONFIG_PGTABLE_LEVELS selection.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Link: https://lore.kernel.org/r/1620649326-24115-1-git-send-email-anshuman.khandual@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/mm/init.c

index e55409c..6e1ca04 100644 (file)
@@ -499,6 +499,13 @@ void __init mem_init(void)
        BUILD_BUG_ON(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);
+
        if (PAGE_SIZE >= 16384 && get_num_physpages() <= 128) {
                extern int sysctl_overcommit_memory;
                /*