Skip to content

Commit 835e5ac

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Fix huge_ptep_set_wrprotect when PTE is a NAPOT
We need to avoid inconsistencies across the PTEs that form a NAPOT region, so when we write protect such a region, we should clear and flush all the PTEs to make sure that any of those PTEs is not cached which would result in such inconsistencies (arm64 does the same). Fixes: 82a1a1f ("riscv: mm: support Svnapot in hugetlb page") Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 9a7e8ec commit 835e5ac

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/riscv/mm/hugetlbpage.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm,
218218
{
219219
pte_t pte = ptep_get(ptep);
220220
unsigned long order;
221+
pte_t orig_pte;
221222
int i, pte_num;
222223

223224
if (!pte_napot(pte)) {
@@ -228,9 +229,12 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm,
228229
order = napot_cont_order(pte);
229230
pte_num = napot_pte_num(order);
230231
ptep = huge_pte_offset(mm, addr, napot_cont_size(order));
232+
orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num);
233+
234+
orig_pte = pte_wrprotect(orig_pte);
231235

232236
for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
233-
ptep_set_wrprotect(mm, addr, ptep);
237+
set_pte_at(mm, addr, ptep, orig_pte);
234238
}
235239

236240
pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,

0 commit comments

Comments
 (0)