diff mbox series

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

Message ID 20210531084540.78546-4-kernelfans@gmail.com (mailing list archive)
State New, archived
Headers show
Series use __create_pgd_mapping() to implement idmap and unify codes | expand

Commit Message

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

Patch

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