KVM: dirty ring: add missing memory barrier
PATCH 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/kvm/kvm-all.c +1 -1
@@ -719,7 +719,7 @@ 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 ; +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
Hi Paolo,
Quoted 16 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/kvm/kvm-all.c +0
-0
accel/kvm/kvm-all.c static void kvm_dirty_ring_mark_page(KVMState *s, · line 724
Quoted 7 lines
accel/kvm/kvm-all.c +1
-1@@ -719,7 +719,7 @@ 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; + return qatomic_load_acquire(&gfn->flags, KVM_DIRTY_GFN_F_DIRTY);
Is this patch based on another which changes the qatomic_load_acquire() prototype?
Quoted 8 lines
accel/kvm/kvm-all.c +0
-0}static void
dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
--
2.37.1
Yikes no, the patch is obviously bogus.
Paolo
Il ven 26 ago 2022, 17:59 Philippe Mathieu-Daudé <[email protected]> ha scritto:
Quoted 40 lines
Hi Paolo,
Quoted 16 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/kvm/kvm-all.c +0
-0accel/kvm/kvm-all.c static void kvm_dirty_ring_mark_page(KVMState *s, · line 724
Quoted 7 lines
accel/kvm/kvm-all.c +1
-1@@ -719,7 +719,7 @@ 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; + return qatomic_load_acquire(&gfn->flags, KVM_DIRTY_GFN_F_DIRTY);Is this patch based on another which changes the
qatomic_load_acquire()prototype?Quoted 8 lines
accel/kvm/kvm-all.c +0
-0}static void
dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
--
2.37.1