[kvm-unit-tests PATCH v2 7/7] riscv: mmu: Ensure order of PTE update and sfence
Andrew Jones
andrew.jones at linux.dev
Mon Aug 12 06:44:59 PDT 2024
Use WRITE_ONCE to ensure the compiler won't order the page table
write after the TLB flush.
Signed-off-by: Andrew Jones <andrew.jones at linux.dev>
---
lib/riscv/mmu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/riscv/mmu.c b/lib/riscv/mmu.c
index ce49e67be84b..577c66aa77ba 100644
--- a/lib/riscv/mmu.c
+++ b/lib/riscv/mmu.c
@@ -64,7 +64,8 @@ static pteval_t *__install_page(pgd_t *pgtable, phys_addr_t paddr,
assert(!(ppn & ~PTE_PPN));
ptep = get_pte(pgtable, vaddr);
- *ptep = __pte(pte | pgprot_val(prot) | _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_DIRTY);
+ pte |= pgprot_val(prot) | _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_DIRTY;
+ WRITE_ONCE(*ptep, __pte(pte));
if (flush)
local_flush_tlb_page(vaddr);
--
2.45.2
More information about the kvm-riscv
mailing list