[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 03/28] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot()
From: |
Kevin Wolf |
Subject: |
[PULL 03/28] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot() |
Date: |
Wed, 10 May 2023 14:20:46 +0200 |
From: Stefan Hajnoczi <stefanha@redhat.com>
There is no need for the AioContext lock in aio_wait_bh_oneshot().
It's easy to remove the lock from existing callers and then switch from
AIO_WAIT_WHILE() to AIO_WAIT_WHILE_UNLOCKED() in aio_wait_bh_oneshot().
Document that the AioContext lock should not be held across
aio_wait_bh_oneshot(). Holding a lock across aio_poll() can cause
deadlock so we don't want callers to do that.
This is a step towards getting rid of the AioContext lock.
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20230404153307.458883-1-stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/aio-wait.h | 2 +-
hw/block/dataplane/virtio-blk.c | 3 ++-
hw/scsi/virtio-scsi-dataplane.c | 2 --
util/aio-wait.c | 2 +-
4 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
index 6e43e3b7bb..5449b6d742 100644
--- a/include/block/aio-wait.h
+++ b/include/block/aio-wait.h
@@ -131,7 +131,7 @@ void aio_wait_kick(void);
*
* Run a BH in @ctx and wait for it to complete.
*
- * Must be called from the main loop thread with @ctx acquired exactly once.
+ * Must be called from the main loop thread without @ctx acquired.
* Note that main loop event processing may occur.
*/
void aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index a6202997ee..af1c24c40c 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -315,9 +315,10 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)
s->stopping = true;
trace_virtio_blk_data_plane_stop(s);
- aio_context_acquire(s->ctx);
aio_wait_bh_oneshot(s->ctx, virtio_blk_data_plane_stop_bh, s);
+ aio_context_acquire(s->ctx);
+
/* Wait for virtio_blk_dma_restart_bh() and in flight I/O to complete */
blk_drain(s->conf->conf.blk);
diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c
index 20bb91766e..f3214e1c57 100644
--- a/hw/scsi/virtio-scsi-dataplane.c
+++ b/hw/scsi/virtio-scsi-dataplane.c
@@ -197,9 +197,7 @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev)
}
s->dataplane_stopping = true;
- aio_context_acquire(s->ctx);
aio_wait_bh_oneshot(s->ctx, virtio_scsi_dataplane_stop_bh, s);
- aio_context_release(s->ctx);
blk_drain_all(); /* ensure there are no in-flight requests */
diff --git a/util/aio-wait.c b/util/aio-wait.c
index 98c5accd29..b5336cf5fd 100644
--- a/util/aio-wait.c
+++ b/util/aio-wait.c
@@ -82,5 +82,5 @@ void aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb,
void *opaque)
assert(qemu_get_current_aio_context() == qemu_get_aio_context());
aio_bh_schedule_oneshot(ctx, aio_wait_bh, &data);
- AIO_WAIT_WHILE(ctx, !data.done);
+ AIO_WAIT_WHILE_UNLOCKED(NULL, !data.done);
}
--
2.40.1
- [PULL 00/28] Block layer patches, Kevin Wolf, 2023/05/10
- [PULL 01/28] block: add configure options for excluding vmdk, vhdx and vpc, Kevin Wolf, 2023/05/10
- [PULL 02/28] block: add missing coroutine_fn annotations, Kevin Wolf, 2023/05/10
- [PULL 03/28] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot(),
Kevin Wolf <=
- [PULL 07/28] qcow2: Don't call bdrv_getlength() in coroutine_fns, Kevin Wolf, 2023/05/10
- [PULL 04/28] block: Fix use after free in blockdev_mark_auto_del(), Kevin Wolf, 2023/05/10
- [PULL 05/28] iotests/nbd-reconnect-on-open: Fix NBD socket path, Kevin Wolf, 2023/05/10
- [PULL 06/28] migration: Attempt disk reactivation in more failure scenarios, Kevin Wolf, 2023/05/10
- [PULL 08/28] block: Consistently call bdrv_activate() outside coroutine, Kevin Wolf, 2023/05/10
- [PULL 12/28] test-bdrv-drain: Don't modify the graph in coroutines, Kevin Wolf, 2023/05/10
- [PULL 15/28] block: .bdrv_open is non-coroutine and unlocked, Kevin Wolf, 2023/05/10
- [PULL 10/28] block: Don't call no_coroutine_fns in qmp_block_resize(), Kevin Wolf, 2023/05/10
- [PULL 11/28] iotests: Test resizing image attached to an iothread, Kevin Wolf, 2023/05/10
- [PULL 14/28] graph-lock: Fix GRAPH_RDLOCK_GUARD*() to be reader lock, Kevin Wolf, 2023/05/10