diff mbox series

[RFC,v2,20/21] riscv: mm: Adjust address space layout and init page table for 64K Page

Message ID 20241205103729.14798-21-luxu.kernel@bytedance.com (mailing list archive)
State New
Headers show
Series riscv: Introduce 64K base page | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR fail PR summary
conchuod/patch-20-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh took 211.42s
conchuod/patch-20-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh took 2595.20s
conchuod/patch-20-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh took 2991.39s
conchuod/patch-20-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh took 80.35s
conchuod/patch-20-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh took 82.39s
conchuod/patch-20-test-6 warning .github/scripts/patches/tests/checkpatch.sh took 0.97s
conchuod/patch-20-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh took 48.82s
conchuod/patch-20-test-8 success .github/scripts/patches/tests/header_inline.sh took 0.01s
conchuod/patch-20-test-9 success .github/scripts/patches/tests/kdoc.sh took 0.65s
conchuod/patch-20-test-10 success .github/scripts/patches/tests/module_param.sh took 0.02s
conchuod/patch-20-test-11 success .github/scripts/patches/tests/verify_fixes.sh took 0.00s
conchuod/patch-20-test-12 success .github/scripts/patches/tests/verify_signedoff.sh took 0.04s
conchuod/vmtest-fixes-PR fail merge-conflict

Commit Message

Xu Lu Dec. 5, 2024, 10:37 a.m. UTC
Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
---
 arch/riscv/include/asm/page.h    |  6 +++++-
 arch/riscv/include/asm/pgtable.h | 12 +++++++++++
 arch/riscv/mm/init.c             | 36 +++++++++++++++++++++++---------
 3 files changed, 43 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
index 9bc908d94c7a..236b0106a1c9 100644
--- a/arch/riscv/include/asm/page.h
+++ b/arch/riscv/include/asm/page.h
@@ -40,8 +40,12 @@ 
  * By default, CONFIG_PAGE_OFFSET value corresponds to SV57 address space so
  * define the PAGE_OFFSET value for SV48 and SV39.
  */
+#ifdef CONFIG_RISCV_64K_PAGES
+#define PAGE_OFFSET_L4		_AC(0xffffa80000000000, UL)
+#else
 #define PAGE_OFFSET_L4		_AC(0xffffaf8000000000, UL)
-#define PAGE_OFFSET_L3		_AC(0xffffffd600000000, UL)
+#endif /* CONFIG_RISCV_64K_PAGES */
+#define PAGE_OFFSET_L3		_AC(0xffffffd800000000, UL)
 #else
 #define PAGE_OFFSET		_AC(CONFIG_PAGE_OFFSET, UL)
 #endif /* CONFIG_64BIT */
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 9f347e5eefeb..fbc397c4e1c8 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -147,6 +147,18 @@  static inline unsigned long __page_val_to_pfn(unsigned long val);
 #include <asm/pgtable-32.h>
 #endif /* CONFIG_64BIT */
 
+#define __PMD_SHIFT	(PMD_SHIFT - (PAGE_SHIFT - HW_PAGE_SHIFT))
+#define __PMD_SIZE	(_AC(1, UL) << __PMD_SHIFT)
+
+#define __PUD_SHIFT	(PUD_SHIFT - (PAGE_SHIFT - HW_PAGE_SHIFT))
+#define __PUD_SIZE	(_AC(1, UL) << __PUD_SHIFT)
+
+#define __P4D_SHIFT	(P4D_SHIFT - (PAGE_SHIFT - HW_PAGE_SHIFT))
+#define __P4D_SIZE	(_AC(1, UL) << __P4D_SHIFT)
+
+#define __PGD_SHIFT	(PGD_SHIFT - (PAGE_SHIFT - HW_PAGE_SHIFT))
+#define __PGD_SIZE	(_AC(1, UL) << __PGD_SHIFT)
+
 #include <linux/page_table_check.h>
 
 #ifdef CONFIG_XIP_KERNEL
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 678b892b4ed8..2c6b7ea33009 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -695,15 +695,15 @@  static uintptr_t __meminit best_map_size(phys_addr_t pa, uintptr_t va, phys_addr
 		return PAGE_SIZE;
 
 	if (pgtable_l5_enabled &&
-	    !(pa & (P4D_SIZE - 1)) && !(va & (P4D_SIZE - 1)) && size >= P4D_SIZE)
+	    !(pa & (__P4D_SIZE - 1)) && !(va & (P4D_SIZE - 1)) && size >= P4D_SIZE)
 		return P4D_SIZE;
 
 	if (pgtable_l4_enabled &&
-	    !(pa & (PUD_SIZE - 1)) && !(va & (PUD_SIZE - 1)) && size >= PUD_SIZE)
+	    !(pa & (__PUD_SIZE - 1)) && !(va & (PUD_SIZE - 1)) && size >= PUD_SIZE)
 		return PUD_SIZE;
 
 	if (IS_ENABLED(CONFIG_64BIT) &&
-	    !(pa & (PMD_SIZE - 1)) && !(va & (PMD_SIZE - 1)) && size >= PMD_SIZE)
+	    !(pa & (__PMD_SIZE - 1)) && !(va & (PMD_SIZE - 1)) && size >= PMD_SIZE)
 		return PMD_SIZE;
 
 	return PAGE_SIZE;
@@ -937,17 +937,33 @@  static void __init create_kernel_page_table(pgd_t *pgdir,
 				   PMD_SIZE, PAGE_KERNEL);
 }
 #else
+
+#ifdef CONFIG_RISCV_64K_PAGES
+/* TODO: better implementation */
+#define KERNEL_MAP_STEP			PAGE_SIZE
+#else
+#define KERNEL_MAP_STEP			PMD_SIZE
+#endif
+
 static void __init create_kernel_page_table(pgd_t *pgdir, bool early)
 {
 	uintptr_t va, end_va;
 
 	end_va = kernel_map.virt_addr + kernel_map.size;
-	for (va = kernel_map.virt_addr; va < end_va; va += PMD_SIZE)
-		create_pgd_mapping(pgdir, va,
-				   kernel_map.phys_addr + (va - kernel_map.virt_addr),
-				   PMD_SIZE,
-				   early ?
-					PAGE_KERNEL_EXEC : pgprot_from_va(va));
+	if (early)
+		for (va = kernel_map.virt_addr; va < end_va; va += PMD_SIZE)
+			create_pgd_mapping(pgdir, va,
+					   kernel_map.phys_addr + (va - kernel_map.virt_addr),
+					   PMD_SIZE,
+					   early ?
+						PAGE_KERNEL_EXEC : pgprot_from_va(va));
+	else
+		for (va = kernel_map.virt_addr; va < end_va; va += KERNEL_MAP_STEP)
+			create_pgd_mapping(pgdir, va,
+					   kernel_map.phys_addr + (va - kernel_map.virt_addr),
+					   KERNEL_MAP_STEP,
+					   early ?
+						PAGE_KERNEL_EXEC : pgprot_from_va(va));
 }
 #endif
 
@@ -1138,7 +1154,7 @@  asmlinkage void __init setup_vm(uintptr_t dtb_pa)
 
 	/* Sanity check alignment and size */
 	BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
-	BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0);
+	BUG_ON((kernel_map.phys_addr % __PMD_SIZE) != 0);
 
 #ifdef CONFIG_64BIT
 	/*