[PATCH] RISC-V: KVM: Add missing write barrier when linking G-stage page tables
Tan Chi
tanchi25 at mails.ucas.ac.cn
Wed Nov 25 06:18:40 PST 2026
kvm_riscv_gstage_set_pte() links a newly allocated page table
to its parent PTE without a write memory barrier.
A concurrent hardware page table walker may observe the parent
PTE before the child page table is fully initialized, potentially
interpreting stale contents as valid PTEs.
Add an smp_wmb() before linking the child page table, as is
already done in kvm_riscv_gstage_split_huge().
Sashiko reported this pre-existing issue while reviewing my
G-stage page table accounting patch. LLM assistance was used
to analyze the issue and prepare the changelog.
Fixes: 9d05c1fee837 ("RISC-V: KVM: Implement stage2 page table programming")
Link: https://sashiko.dev/#/bug/linux-9339e577-5f31-42a2-a5ea-9844d30b43f8
Signed-off-by: Tan Chi <tanchi25 at mails.ucas.ac.cn>
---
arch/riscv/kvm/gstage.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/riscv/kvm/gstage.c b/arch/riscv/kvm/gstage.c
index 0aace3215d3e..61ab60adb616 100644
--- a/arch/riscv/kvm/gstage.c
+++ b/arch/riscv/kvm/gstage.c
@@ -160,6 +160,13 @@ int kvm_riscv_gstage_set_pte(struct kvm_gstage *gstage,
next_ptep = kvm_mmu_memory_cache_alloc(pcache);
if (!next_ptep)
return -ENOMEM;
+
+ /*
+ * Ensure the initialization of the new page table is visible
+ * before linking it to the parent PTE.
+ */
+ smp_wmb();
+
set_pte(ptep, pfn_pte(PFN_DOWN(__pa(next_ptep)),
__pgprot(_PAGE_TABLE)));
} else {
--
2.53.0
More information about the kvm-riscv
mailing list