]> Git Repo - qemu.git/commitdiff
KVM: dirty ring: add missing memory barrier
authorPaolo Bonzini <[email protected]>
Fri, 26 Aug 2022 11:00:00 +0000 (13:00 +0200)
committerPaolo Bonzini <[email protected]>
Thu, 1 Sep 2022 06:37:04 +0000 (08:37 +0200)
The KVM_DIRTY_GFN_F_DIRTY flag ensures that the entry is valid.  If
the read of the fields are not ordered after the read of the flag,
QEMU might see stale values.

Cc: Gavin Shan <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Peter Xu <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
accel/kvm/kvm-all.c

index 8d81ab74deb1d4c2fc338e4734e457829c5fbbf7..136c8eaed30ee418b21c91ff19ad999fa75de630 100644 (file)
@@ -719,7 +719,11 @@ static void kvm_dirty_ring_mark_page(KVMState *s, uint32_t as_id,
 
 static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
 {
-    return gfn->flags == KVM_DIRTY_GFN_F_DIRTY;
+    /*
+     * Read the flags before the value.  Pairs with barrier in
+     * KVM's kvm_dirty_ring_push() function.
+     */
+    return qatomic_load_acquire(&gfn->flags) == KVM_DIRTY_GFN_F_DIRTY;
 }
 
 static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
This page took 0.038739 seconds and 4 git commands to generate.