Skip to content

Commit 8246601

Browse files
xhackerustcpalmer-dabbelt
authored andcommitted
riscv: tlb: fix __p*d_free_tlb()
If non-leaf PTEs I.E pmd, pud or p4d is modified, a sfence.vma is a must for safe, imagine if an implementation caches the non-leaf translation in TLB, although I didn't meet this HW so far, but it's possible in theory. Signed-off-by: Jisheng Zhang <[email protected]> Fixes: c5e9b2c ("riscv: Improve tlb_flush()") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent b85ea95 commit 8246601

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

arch/riscv/include/asm/pgalloc.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ static inline void pud_free(struct mm_struct *mm, pud_t *pud)
9595
__pud_free(mm, pud);
9696
}
9797

98-
#define __pud_free_tlb(tlb, pud, addr) pud_free((tlb)->mm, pud)
98+
#define __pud_free_tlb(tlb, pud, addr) \
99+
do { \
100+
if (pgtable_l4_enabled) { \
101+
pagetable_pud_dtor(virt_to_ptdesc(pud)); \
102+
tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pud)); \
103+
} \
104+
} while (0)
99105

100106
#define p4d_alloc_one p4d_alloc_one
101107
static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr)
@@ -124,7 +130,11 @@ static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
124130
__p4d_free(mm, p4d);
125131
}
126132

127-
#define __p4d_free_tlb(tlb, p4d, addr) p4d_free((tlb)->mm, p4d)
133+
#define __p4d_free_tlb(tlb, p4d, addr) \
134+
do { \
135+
if (pgtable_l5_enabled) \
136+
tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(p4d)); \
137+
} while (0)
128138
#endif /* __PAGETABLE_PMD_FOLDED */
129139

130140
static inline void sync_kernel_mappings(pgd_t *pgd)
@@ -149,7 +159,11 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
149159

150160
#ifndef __PAGETABLE_PMD_FOLDED
151161

152-
#define __pmd_free_tlb(tlb, pmd, addr) pmd_free((tlb)->mm, pmd)
162+
#define __pmd_free_tlb(tlb, pmd, addr) \
163+
do { \
164+
pagetable_pmd_dtor(virt_to_ptdesc(pmd)); \
165+
tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pmd)); \
166+
} while (0)
153167

154168
#endif /* __PAGETABLE_PMD_FOLDED */
155169

0 commit comments

Comments
 (0)