[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 17/18] aio_wait_kick: add missing memory barrier
From: |
Kevin Wolf |
Subject: |
[PULL 17/18] aio_wait_kick: add missing memory barrier |
Date: |
Thu, 9 Jun 2022 19:21:48 +0200 |
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
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>
---
include/block/aio-wait.h | 2 ++
util/aio-wait.c | 16 +++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
index b39eefb38d..54840f8622 100644
--- a/include/block/aio-wait.h
+++ b/include/block/aio-wait.h
@@ -81,6 +81,8 @@ extern AioWait global_aio_wait;
AioContext *ctx_ = (ctx); \
/* Increment wait_->num_waiters before evaluating cond. */ \
qatomic_inc(&wait_->num_waiters); \
+ /* Paired with smp_mb in aio_wait_kick(). */ \
+ smp_mb(); \
if (ctx_ && in_aio_context_home_thread(ctx_)) { \
while ((cond)) { \
aio_poll(ctx_, true); \
diff --git a/util/aio-wait.c b/util/aio-wait.c
index bdb3d3af22..98c5accd29 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);
}
--
2.35.3
- [PULL 00/18] Block layer patches, Kevin Wolf, 2022/06/09
- [PULL 09/18] linux-headers: Add vduse.h, Kevin Wolf, 2022/06/09
- [PULL 04/18] block: improve block_dirty_bitmap_merge(): don't allocate extra bitmap, Kevin Wolf, 2022/06/09
- [PULL 12/18] vduse-blk: Add vduse-blk resize support, Kevin Wolf, 2022/06/09
- [PULL 06/18] block: Support passing NULL ops to blk_set_dev_ops(), Kevin Wolf, 2022/06/09
- [PULL 17/18] aio_wait_kick: add missing memory barrier,
Kevin Wolf <=
- [PULL 05/18] block: simplify handling of try to merge different sized bitmaps, Kevin Wolf, 2022/06/09
- [PULL 11/18] vduse-blk: Implement vduse-blk export, Kevin Wolf, 2022/06/09
- [PULL 16/18] block/gluster: correctly set max_pdiscard, Kevin Wolf, 2022/06/09
- [PULL 01/18] block: drop unused bdrv_co_drain() API, Kevin Wolf, 2022/06/09
- [PULL 10/18] libvduse: Add VDUSE (vDPA Device in Userspace) library, Kevin Wolf, 2022/06/09
- [PULL 14/18] qsd: document vduse-blk exports, Kevin Wolf, 2022/06/09
- [PULL 15/18] block/rbd: report a better error when namespace does not exist, Kevin Wolf, 2022/06/09
- [PULL 08/18] block/export: Abstract out the logic of virtio-blk I/O process, Kevin Wolf, 2022/06/09
- [PULL 13/18] libvduse: Add support for reconnecting, Kevin Wolf, 2022/06/09
- [PULL 03/18] block: block_dirty_bitmap_merge(): fix error path, Kevin Wolf, 2022/06/09