diff mbox series

[RFC,v2,17/21] riscv: mm: Apply Svnapot for base page mapping if possible

Message ID 20241205103729.14798-18-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-17-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh took 208.62s
conchuod/patch-17-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh took 2588.00s
conchuod/patch-17-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh took 2985.13s
conchuod/patch-17-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh took 79.47s
conchuod/patch-17-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh took 81.37s
conchuod/patch-17-test-6 success .github/scripts/patches/tests/checkpatch.sh took 0.71s
conchuod/patch-17-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh took 48.37s
conchuod/patch-17-test-8 success .github/scripts/patches/tests/header_inline.sh took 0.01s
conchuod/patch-17-test-9 success .github/scripts/patches/tests/kdoc.sh took 0.62s
conchuod/patch-17-test-10 success .github/scripts/patches/tests/module_param.sh took 0.02s
conchuod/patch-17-test-11 success .github/scripts/patches/tests/verify_fixes.sh took 0.00s
conchuod/patch-17-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
All hardware pages in the same software page point to the same contiguous
memory region (the region size is equal to the software page size) and
has same prots. Thus this commit uses Svnapot extension to optimize the
mapping to software page to reduce tlb pressure.

Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
---
 arch/riscv/include/asm/pgtable.h | 16 +++++++++++++++-
 arch/riscv/mm/pgtable.c          |  6 ++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 5b2ca92ad833..9f347e5eefeb 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -483,13 +483,27 @@  static inline unsigned long __pte_mknapot(unsigned long pteval,
 	return pteval;
 }
 
+static inline unsigned long __pte_denapot(unsigned long pteval)
+{
+	unsigned long prot_mask = ~(_PAGE_HW_PFN_MASK | _PAGE_NAPOT);
+	unsigned long res;
+
+	if (!__pte_napot(pteval))
+		return pteval;
+	res = __page_val_to_hwpfn(pteval);
+	res = res & (res - 1UL);
+	pteval = (res << _PAGE_HWPFN_SHIFT) | (pteval & prot_mask);
+
+	return pteval;
+}
+
 #ifdef CONFIG_RISCV_USE_SW_PAGE
 static inline pte_t pte_mknapot(pte_t pte, unsigned int order)
 {
 	unsigned long pteval = pte_val(pte);
 	unsigned int i;
 
-	pteval = __pte_mknapot(pteval, order);
+	pteval = __pte_denapot(pteval);
 	for (i = 0; i < HW_PAGES_PER_PAGE; i++)
 		pte.ptes[i] = pteval;
 
diff --git a/arch/riscv/mm/pgtable.c b/arch/riscv/mm/pgtable.c
index 150aea8e2d7a..0bcaffe798d5 100644
--- a/arch/riscv/mm/pgtable.c
+++ b/arch/riscv/mm/pgtable.c
@@ -11,6 +11,12 @@  pte_t __pte(unsigned long pteval)
 {
 	pte_t pte;
 	unsigned int i;
+	unsigned int order;
+
+	if (has_svnapot() && __pte_present(pteval) && !__pte_napot(pteval))
+		for_each_napot_order(order)
+			if (napot_cont_shift(order) == PAGE_SHIFT)
+				pteval = __pte_mknapot(pteval, order);
 
 	for (i = 0; i < HW_PAGES_PER_PAGE; i++) {
 		pte.ptes[i] = pteval;