Skip to contentSkip to conversation

KVM: dirty ring: add missing memory barrier

PATCH Superseded Paolo Bonzini 2 participants 3 messages Aug 26, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index 8d81ab74de..f49643cd24 100644
@@ -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
#1 lore raw

Hi Paolo,

Quoted 16 lines · Paolo Bonzini

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 +0 -0
index 8d81ab74de..f49643cd24 100644

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

#2 lore raw

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_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 +0 -0
index 8d81ab74de..f49643cd24 100644

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