Skip to contentSkip to conversation

KVM: dirty ring: Add memory barrier when marking pfn collected

PATCH In review Peter Xu 3 participants 4 messages Sep 22, 2022 – Oct 14, 2022

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 KVM: dirty ring: Add memory barrier when marking pfn collected

Following commit 4802bf910eee9, add the other missing barrier when marking the PFN as collected. This will also be required just like 4802bf910eee9 on weak ordering architectures like aarch64.

Cc Marc Zyngier <[email protected]>
Cc Gavin Shan <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 accel/kvm/kvm-all.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
accel/kvm/kvm-all.c +5 -1
index 136c8eaed3..60a044048e 100644
@@ -728,7 +728,11 @@ static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
 
 static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
 {
-    gfn->flags = KVM_DIRTY_GFN_F_RESET;
+    /*
+     * Write the flags after reading the entry.  Should pair with another
+     * smp_load_acquire() in KVM when reset dirty rings.
+     */
+    qatomic_store_release(&gfn->flags, KVM_DIRTY_GFN_F_RESET);
 }
 
 /*
Signature · 1 line
2.32.0
Reviewed-by Philippe Mathieu-Daudé on v1 1/1
#1 lore raw
Quoted 19 lines · Peter Xu

Following commit 4802bf910eee9, add the other missing barrier when marking the PFN as collected. This will also be required just like 4802bf910eee9 on weak ordering architectures like aarch64.

Cc Marc Zyngier <[email protected]>
Cc Gavin Shan <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
  accel/kvm/kvm-all.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
accel/kvm/kvm-all.c +0 -0
index 136c8eaed3..60a044048e 100644
@@ -728,7 +728,11 @@ static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
 
  static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)

accel/kvm/kvm-all.c static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn) · line 738

Quoted 10 lines
accel/kvm/kvm-all.c +5 -1
  {
-    gfn->flags = KVM_DIRTY_GFN_F_RESET;
+    /*
+     * Write the flags after reading the entry.  Should pair with another
+     * smp_load_acquire() in KVM when reset dirty rings.
+     */
+    qatomic_store_release(&gfn->flags, KVM_DIRTY_GFN_F_RESET);
  }
 
  /*
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Xu
Quoted 4 lines · Peter Xu

Following commit 4802bf910eee9, add the other missing barrier when marking the PFN as collected. This will also be required just like 4802bf910eee9 on weak ordering architectures like aarch64.

Quoted 8 lines
Cc Marc Zyngier <[email protected]>
Cc Gavin Shan <[email protected]>
Cc 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
index 136c8eaed3..60a044048e 100644
@@ -728,7 +728,11 @@ static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn)
 
  static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn)
  {
-    gfn->flags = KVM_DIRTY_GFN_F_RESET;
+    /*
+     * Write the flags after reading the entry.  Should pair with another
+     * smp_load_acquire() in KVM when reset dirty rings.
+     */
+    qatomic_store_release(&gfn->flags, KVM_DIRTY_GFN_F_RESET);
  }
 
  /*