All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot()
@ 2023-04-04 15:33 Stefan Hajnoczi
  2023-04-04 16:51 ` Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2023-04-04 15:33 UTC (permalink / raw)
  To: qemu-devel
  Cc: Stefan Hajnoczi, Kevin Wolf, Hanna Reitz, Paolo Bonzini,
	qemu-block, Fam Zheng, Michael S. Tsirkin, eesposit

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>
---
 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 da13357bb8..fdd14294ec 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 b28d81737e..e0111efd6d 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -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);
 
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.39.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot()
  2023-04-04 15:33 [PATCH] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot() Stefan Hajnoczi
@ 2023-04-04 16:51 ` Paolo Bonzini
  2023-04-05  8:23 ` Emanuele Giuseppe Esposito
  2023-04-27 12:39 ` Kevin Wolf
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2023-04-04 16:51 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Kevin Wolf, Hanna Reitz, qemu-block, Fam Zheng,
	Michael S. Tsirkin, eesposit

On 4/4/23 17:33, Stefan Hajnoczi wrote:
> 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.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot()
  2023-04-04 15:33 [PATCH] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot() Stefan Hajnoczi
  2023-04-04 16:51 ` Paolo Bonzini
@ 2023-04-05  8:23 ` Emanuele Giuseppe Esposito
  2023-04-27 12:39 ` Kevin Wolf
  2 siblings, 0 replies; 4+ messages in thread
From: Emanuele Giuseppe Esposito @ 2023-04-05  8:23 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Kevin Wolf, Hanna Reitz, Paolo Bonzini, qemu-block, Fam Zheng,
	Michael S. Tsirkin



Am 04/04/2023 um 17:33 schrieb 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 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>
> 
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot()
  2023-04-04 15:33 [PATCH] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot() Stefan Hajnoczi
  2023-04-04 16:51 ` Paolo Bonzini
  2023-04-05  8:23 ` Emanuele Giuseppe Esposito
@ 2023-04-27 12:39 ` Kevin Wolf
  2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2023-04-27 12:39 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: qemu-devel, Hanna Reitz, Paolo Bonzini, qemu-block, Fam Zheng,
	Michael S. Tsirkin, eesposit

Am 04.04.2023 um 17:33 hat Stefan Hajnoczi geschrieben:
> 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>

Thanks, applied to the block branch.

Kevin



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-27 12:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-04 15:33 [PATCH] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot() Stefan Hajnoczi
2023-04-04 16:51 ` Paolo Bonzini
2023-04-05  8:23 ` Emanuele Giuseppe Esposito
2023-04-27 12:39 ` Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.