qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] KVM: dirty ring: add missing memory barrier


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v2] KVM: dirty ring: add missing memory barrier
Date: Tue, 30 Aug 2022 14:07:55 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.0

On 27/8/22 10:22, Paolo Bonzini wrote:
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: Peter Xu <peterx@redhat.com>
Cc: Gavin Shan <gshan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
  accel/kvm/kvm-all.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 8d81ab74de..136c8eaed3 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -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)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]