aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorEmanuele Giuseppe Esposito <eesposit@redhat.com>2022-05-24 13:30:54 -0400
committerKevin Wolf <kwolf@redhat.com>2022-06-24 17:07:06 +0200
commit7455ff1aa01564cc175db5b2373e610503ad4411 (patch)
tree5a10d1498410ecbd582c7423d305188967600fc2 /util
parent9b38fc56c054c7de65fa3bf7cdd82b32654f6b7d (diff)
downloadqemu-7455ff1aa01564cc175db5b2373e610503ad4411.zip
qemu-7455ff1aa01564cc175db5b2373e610503ad4411.tar.gz
qemu-7455ff1aa01564cc175db5b2373e610503ad4411.tar.bz2
aio_wait_kick: add missing memory barrier
It seems that aio_wait_kick always required a memory barrier or atomic operation in the caller, but nobody actually took care of doing it. Let's put the barrier in the function instead, and pair it with another one in AIO_WAIT_WHILE. Read aio_wait_kick() comment for further explanation. Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Message-Id: <20220524173054.12651-1-eesposit@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/aio-wait.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/util/aio-wait.c b/util/aio-wait.c
index bdb3d3a..98c5acc 100644
--- a/util/aio-wait.c
+++ b/util/aio-wait.c
@@ -35,7 +35,21 @@ static void dummy_bh_cb(void *opaque)
void aio_wait_kick(void)
{
- /* The barrier (or an atomic op) is in the caller. */
+ /*
+ * Paired with smp_mb in AIO_WAIT_WHILE. Here we have:
+ * write(condition);
+ * aio_wait_kick() {
+ * smp_mb();
+ * read(num_waiters);
+ * }
+ *
+ * And in AIO_WAIT_WHILE:
+ * write(num_waiters);
+ * smp_mb();
+ * read(condition);
+ */
+ smp_mb();
+
if (qatomic_read(&global_aio_wait.num_waiters)) {
aio_bh_schedule_oneshot(qemu_get_aio_context(), dummy_bh_cb, NULL);
}