aio-wait: avoid AioContext lock in aio_wait_bh_oneshot()
PATCH 1/1 aio-wait: avoid AioContext lock in aio_wait_bh_oneshot()
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.
--- 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(-)
include/block/aio-wait.h +1 -1
@@ -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);
hw/block/dataplane/virtio-blk.c +2 -1
@@ -314,9 +314,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);
hw/scsi/virtio-scsi-dataplane.c +0 -2
@@ -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 */
util/aio-wait.c +1 -1
@@ -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); }
Signature · 1 line
2.39.2
Quoted 9 lines · Stefan Hajnoczi
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 fromAIO_WAIT_WHILE()toAIO_WAIT_WHILE_UNLOCKED()inaio_wait_bh_oneshot().Document that the AioContext lock should not be held across
aio_wait_bh_oneshot(). Holding a lock acrossaio_poll()can cause deadlock so we don't want callers to do that.This is a step towards getting rid of the AioContext lock.
Paolo
Am 04/04/2023 um 17:33 schrieb Stefan Hajnoczi:
Quoted 4 lines
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 fromAIO_WAIT_WHILE()toAIO_WAIT_WHILE_UNLOCKED()inaio_wait_bh_oneshot().
Quoted 9 lines
Document that the AioContext lock should not be held across
aio_wait_bh_oneshot(). Holding a lock acrossaio_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 <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>
Kevin Wolf
AppliedAm 04.04.2023 um 17:33 hat Stefan Hajnoczi geschrieben:
Quoted 4 lines
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 fromAIO_WAIT_WHILE()toAIO_WAIT_WHILE_UNLOCKED()inaio_wait_bh_oneshot().
Quoted 8 lines
Document that the AioContext lock should not be held across
aio_wait_bh_oneshot(). Holding a lock acrossaio_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 <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>
Thanks, applied to the block branch.
Kevin