Skip to content

Commit

Permalink
aio-wait: avoid AioContext lock in aio_wait_bh_oneshot()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stefanhaRH authored and kevmw committed May 10, 2023
1 parent 17ac39c commit 3edf660
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion hw/block/dataplane/virtio-blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions hw/scsi/virtio-scsi-dataplane.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
2 changes: 1 addition & 1 deletion include/block/aio-wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion util/aio-wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 3edf660

Please sign in to comment.