[PATCHv3 3/5] arm64/mm: unconditionally set IDMAP_PGTABLE_LEVELS to max pgtable level

Pingfan Liu kernelfans at gmail.com
Mon May 31 01:45:38 PDT 2021


After commit 5dfe9d7d23c2 ("arm64: reduce ID map to a single page"),
idmap only costs a page. While with 4K page, the current code enforces
section mapping (2MB) on it due to the prot SWAPPER_MM_MMUFLAGS.

But if switching to __create_pgd_mapping() to create pgtable, the code
will decide the proper mapping level by itself, as the code snippet in
init_pmd():
    if (((addr | next | phys) & ~SECTION_MASK) == 0 &&
    		    (flags & NO_BLOCK_MAPPINGS) == 0)
    	pmd_set_huge(pmdp, phys, prot);

As the case of .idmap.text, it requires pgtable up to pte level. Hence
IDMAP_PGTABLE_LEVELS should be large enough to assure the capacity of
IDMAP_DIR_SIZE.

Signed-off-by: Pingfan Liu <kernelfans at gmail.com>
Cc: Catalin Marinas <catalin.marinas at arm.com>
Cc: Will Deacon <will at kernel.org>
Cc: Ard Biesheuvel <ardb at kernel.org>
Cc: Marc Zyngier <maz at kernel.org>
Cc: Kristina Martsenko <kristina.martsenko at arm.com>
Cc: James Morse <james.morse at arm.com>
Cc: Steven Price <steven.price at arm.com>
Cc: Jonathan Cameron <Jonathan.Cameron at huawei.com>
Cc: Pavel Tatashin <pasha.tatashin at soleen.com>
Cc: Anshuman Khandual <anshuman.khandual at arm.com>
Cc: Atish Patra <atish.patra at wdc.com>
Cc: Mike Rapoport <rppt at kernel.org>
Cc: Logan Gunthorpe <logang at deltatee.com>
Cc: Mark Brown <broonie at kernel.org>
To: linux-arm-kernel at lists.infradead.org
---
 arch/arm64/include/asm/kernel-pgtable.h | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
index d44df9d62fc9..249ab132fced 100644
--- a/arch/arm64/include/asm/kernel-pgtable.h
+++ b/arch/arm64/include/asm/kernel-pgtable.h
@@ -24,23 +24,26 @@
 #endif
 
 /*
- * The idmap and swapper page tables need some space reserved in the kernel
- * image. Both require pgd, pud (4 levels only) and pmd tables to (section)
- * map the kernel. With the 64K page configuration, swapper and idmap need to
+ * The swapper page table needs some space reserved in the kernel
+ * image. It require pgd, pud (4 levels only) and pmd tables to (section)
+ * map the kernel. With the 64K page configuration, swapper needs to
  * map to pte level. The swapper also maps the FDT (see __create_page_tables
- * for more information). Note that the number of ID map translation levels
- * could be increased on the fly if system RAM is out of reach for the default
- * VA range, so pages required to map highest possible PA are reserved in all
- * cases.
+ * for more information).
  */
 #if ARM64_SWAPPER_USES_SECTION_MAPS
 #define SWAPPER_PGTABLE_LEVELS	(CONFIG_PGTABLE_LEVELS - 1)
-#define IDMAP_PGTABLE_LEVELS	(ARM64_HW_PGTABLE_LEVELS(PHYS_MASK_SHIFT) - 1)
 #else
 #define SWAPPER_PGTABLE_LEVELS	(CONFIG_PGTABLE_LEVELS)
-#define IDMAP_PGTABLE_LEVELS	(ARM64_HW_PGTABLE_LEVELS(PHYS_MASK_SHIFT))
 #endif
 
+/*
+ * idmap also needs some space reserved in the kernel image. Since ".idmap.text"
+ * only occupies less than a page, idmap needs to map to pte level.
+ * Note that the number of ID map translation levels could be increased on the fly
+ * if system RAM is out of reach for the default VA range, so pages required to
+ * map highest possible PA are reserved in all cases.
+ */
+#define IDMAP_PGTABLE_LEVELS	(ARM64_HW_PGTABLE_LEVELS(PHYS_MASK_SHIFT))
 
 /*
  * If KASLR is enabled, then an offset K is added to the kernel address
-- 
2.29.2




More information about the linux-arm-kernel mailing list