[PATCH v2 07/15] riscv/mm: preserve Svnapot leaf-size semantics for page-table consumers
Yunhui Cui <[email protected]> Thu, 16 Jul 2026 20:41:42 +0800
| Newsgroups | org.kernel.vger.linux-efi,org.infradead.lists.kvm-riscv,org.infradead.lists.linux-arm-kernel,org.infradead.lists.linux-riscv,org.kernel.vger.kvm,org.kernel.vger.linux-arch,org.kernel.vger.linux-kernel,org.kernel.vger.linux-perf-users,org.kvack.linux-mm |
|---|---|
| Message-ID | <180084b20de76f7ad61641e9b7abe6d103caf5f3.1784201104.git.cuiyunhui@bytedance.com> |
Svnapot keeps a folded 64KB mapping encoded in the page table, while the public PTE helpers may expose a logical per-page sub-PTE view to generic MM users. That logical view is suitable for leaf-style PTE consumers, but it must not change the effective leaf size reported for the mapping. Use the original page-table entry for leaf-size queries, so page-table consumers continue to observe the Svnapot leaf size instead of incorrectly treating a folded mapping as PAGE_SIZE entries. Signed-off-by: Yunhui Cui <[email protected]> --- arch/riscv/include/asm/pgtable.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index da7ffea0dcd98..e4b9c05014c00 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -580,6 +580,17 @@ static inline pte_t pte_swp_clear_soft_dirty(pte_t pte) napot_cont_size(napot_cont_order(pte)) :\ PAGE_SIZE) +#define __ptep_leaf_size __ptep_leaf_size +static inline unsigned long __ptep_leaf_size(pmd_t pmd, pte_t *ptep, pte_t pte) +{ + pte_t raw_pte = READ_ONCE(*ptep); + + if (pte_present_napot(raw_pte)) + return pte_leaf_size(raw_pte); + + return PAGE_SIZE; +} + void __napotpte_try_fold(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); void __napotpte_try_unfold(struct mm_struct *mm, unsigned long addr, -- 2.39.5