thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 6 months ago
Clone
97168e
From d7eae0ff4c7f7f7bf10f10272adf7c6971c0db9b Mon Sep 17 00:00:00 2001
97168e
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
Date: Thu, 9 Mar 2023 09:26:35 -0500
97168e
Subject: [PATCH 01/13] aio_wait_kick: add missing memory barrier
97168e
97168e
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
RH-MergeRequest: 263: qatomic: add smp_mb__before/after_rmw()
97168e
RH-Bugzilla: 2168472
97168e
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
97168e
RH-Acked-by: Eric Auger <eric.auger@redhat.com>
97168e
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
97168e
RH-Acked-by: David Hildenbrand <david@redhat.com>
97168e
RH-Commit: [1/10] eb774aee79864052e14e706d931e52e7bd1162c8
97168e
97168e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168472
97168e
97168e
commit 7455ff1aa01564cc175db5b2373e610503ad4411
97168e
Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
Date:   Tue May 24 13:30:54 2022 -0400
97168e
97168e
    aio_wait_kick: add missing memory barrier
97168e
97168e
    It seems that aio_wait_kick always required a memory barrier
97168e
    or atomic operation in the caller, but nobody actually
97168e
    took care of doing it.
97168e
97168e
    Let's put the barrier in the function instead, and pair it
97168e
    with another one in AIO_WAIT_WHILE. Read aio_wait_kick()
97168e
    comment for further explanation.
97168e
97168e
    Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
97168e
    Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
    Message-Id: <20220524173054.12651-1-eesposit@redhat.com>
97168e
    Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
97168e
    Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
97168e
    Signed-off-by: Kevin Wolf <kwolf@redhat.com>
97168e
97168e
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
---
97168e
 include/block/aio-wait.h |  2 ++
97168e
 util/aio-wait.c          | 16 +++++++++++++++-
97168e
 2 files changed, 17 insertions(+), 1 deletion(-)
97168e
97168e
diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
97168e
index b39eefb38d..54840f8622 100644
97168e
--- a/include/block/aio-wait.h
97168e
+++ b/include/block/aio-wait.h
97168e
@@ -81,6 +81,8 @@ extern AioWait global_aio_wait;
97168e
     AioContext *ctx_ = (ctx);                                      \
97168e
     /* Increment wait_->num_waiters before evaluating cond. */     \
97168e
     qatomic_inc(&wait_->num_waiters);                              \
97168e
+    /* Paired with smp_mb in aio_wait_kick(). */                   \
97168e
+    smp_mb();                                                      \
97168e
     if (ctx_ && in_aio_context_home_thread(ctx_)) {                \
97168e
         while ((cond)) {                                           \
97168e
             aio_poll(ctx_, true);                                  \
97168e
diff --git a/util/aio-wait.c b/util/aio-wait.c
97168e
index bdb3d3af22..98c5accd29 100644
97168e
--- a/util/aio-wait.c
97168e
+++ b/util/aio-wait.c
97168e
@@ -35,7 +35,21 @@ static void dummy_bh_cb(void *opaque)
97168e
 
97168e
 void aio_wait_kick(void)
97168e
 {
97168e
-    /* The barrier (or an atomic op) is in the caller.  */
97168e
+    /*
97168e
+     * Paired with smp_mb in AIO_WAIT_WHILE. Here we have:
97168e
+     * write(condition);
97168e
+     * aio_wait_kick() {
97168e
+     *      smp_mb();
97168e
+     *      read(num_waiters);
97168e
+     * }
97168e
+     *
97168e
+     * And in AIO_WAIT_WHILE:
97168e
+     * write(num_waiters);
97168e
+     * smp_mb();
97168e
+     * read(condition);
97168e
+     */
97168e
+    smp_mb();
97168e
+
97168e
     if (qatomic_read(&global_aio_wait.num_waiters)) {
97168e
         aio_bh_schedule_oneshot(qemu_get_aio_context(), dummy_bh_cb, NULL);
97168e
     }
97168e
-- 
97168e
2.37.3
97168e