[PATCH 2/4] KVM: Use smp_store_release() to mark dirty ring entries as dirtied
From: James Houghton
Date: Tue Nov 17 2026 - 16:29:43 EST
Publish dirty ring entries to userspace with smp_store_release() in
kvm_dirty_gfn_set_dirtied(), instead of an smp_wmb() in
kvm_dirty_ring_push() followed by a plain store in the helper.
Setting the DIRTY flag is the first half of a handshake with userspace:
userspace load-acquires the DIRTY flag, harvests the entry, and
store-releases the RESET flag, which KVM then load-acquires in
kvm_dirty_gfn_harvested(). Commit 8929bc965964 ("KVM: Use acquire/release
semantics when accessing dirty ring GFN state") converted KVM's side of
the RESET flag to acquire/release, but left the DIRTY side split between
a barrier in the caller and a plain store in the helper. As a result, the
helper doesn't convey that its store must be ordered, and the store isn't
marked even though userspace can access the flags concurrently.
Now that kvm_dirty_ring_reset() relies on this handshake to observe an
up-to-date dirty_index, make the ordering explicit and self-contained in
the helper, so that all three flag accessors use matching acquire/release
semantics.
No functional change intended.
Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>
---
virt/kvm/dirty_ring.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
index 8fab75dace76..d0693ef6e479 100644
--- a/virt/kvm/dirty_ring.c
+++ b/virt/kvm/dirty_ring.c
@@ -95,7 +95,7 @@ static inline void kvm_dirty_gfn_set_invalid(struct kvm_dirty_gfn *gfn)
static inline void kvm_dirty_gfn_set_dirtied(struct kvm_dirty_gfn *gfn)
{
- gfn->flags = KVM_DIRTY_GFN_F_DIRTY;
+ smp_store_release(&gfn->flags, KVM_DIRTY_GFN_F_DIRTY);
}
static inline bool kvm_dirty_gfn_harvested(struct kvm_dirty_gfn *gfn)
@@ -245,7 +245,6 @@ void kvm_dirty_ring_push(struct kvm_vcpu *vcpu, u32 slot, u64 offset)
* the entry to userspace.
*/
WRITE_ONCE(ring->dirty_index, ring->dirty_index + 1);
- smp_wmb();
kvm_dirty_gfn_set_dirtied(entry);
trace_kvm_dirty_ring_push(ring, slot, offset);
--
2.56.1.708.g77570a6a1d-goog