KVM: dirty ring: add missing memory barrier
PATCH v2 1/1 KVM: dirty ring: add missing memory barrier
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.
--- accel/kvm/kvm-all.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
accel/kvm/kvm-all.c +5 -1
@@ -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)
Signature · 1 line
2.37.1
Quoted 18 lines · Paolo Bonzini
The
KVM_DIRTY_GFN_F_DIRTYflag 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 Peter Xu <[email protected]>Cc Gavin Shan <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- accel/kvm/kvm-all.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)accel/kvm/kvm-all.c +0
-0@@ -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)
accel/kvm/kvm-all.c static void kvm_dirty_ring_mark_page(KVMState *s, uint32_t as_id, · line 729
Quoted 10 lines
accel/kvm/kvm-all.c +5
-1{ -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)
Quoted 7 lines · Paolo Bonzini
The
KVM_DIRTY_GFN_F_DIRTYflag 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 Peter Xu <[email protected]>Cc Gavin Shan <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>
Thanks!
Signature · 1 line
Peter Xu
Quoted 11 lines · Paolo Bonzini
The
KVM_DIRTY_GFN_F_DIRTYflag 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 Peter Xu <[email protected]>Cc Gavin Shan <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- accel/kvm/kvm-all.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 18 lines
accel/kvm/kvm-all.c +5
-1@@ -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)