[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 14/33] dma-helpers: don't lock AioContext in dma_blk_cb()
From: |
Kevin Wolf |
Subject: |
[PULL 14/33] dma-helpers: don't lock AioContext in dma_blk_cb() |
Date: |
Thu, 21 Dec 2023 22:23:19 +0100 |
From: Stefan Hajnoczi <stefanha@redhat.com>
Commit abfcd2760b3e ("dma-helpers: prevent dma_blk_cb() vs
dma_aio_cancel() race") acquired the AioContext lock inside dma_blk_cb()
to avoid a race with scsi_device_purge_requests() running in the main
loop thread.
The SCSI code no longer calls dma_aio_cancel() from the main loop thread
while I/O is running in the IOThread AioContext. Therefore it is no
longer necessary to take this lock to protect DMAAIOCB fields. The
->cb() function also does not require the lock because blk_aio_*() and
friends do not need the AioContext lock.
Both hw/ide/core.c and hw/ide/macio.c also call dma_blk_io() but don't
rely on it taking the AioContext lock, so this change is safe.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20231204164259.1515217-5-stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
system/dma-helpers.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/system/dma-helpers.c b/system/dma-helpers.c
index 36211acc7e..528117f256 100644
--- a/system/dma-helpers.c
+++ b/system/dma-helpers.c
@@ -119,13 +119,12 @@ static void dma_blk_cb(void *opaque, int ret)
trace_dma_blk_cb(dbs, ret);
- aio_context_acquire(ctx);
dbs->acb = NULL;
dbs->offset += dbs->iov.size;
if (dbs->sg_cur_index == dbs->sg->nsg || ret < 0) {
dma_complete(dbs, ret);
- goto out;
+ return;
}
dma_blk_unmap(dbs);
@@ -168,7 +167,7 @@ static void dma_blk_cb(void *opaque, int ret)
trace_dma_map_wait(dbs);
dbs->bh = aio_bh_new(ctx, reschedule_dma, dbs);
cpu_register_map_client(dbs->bh);
- goto out;
+ return;
}
if (!QEMU_IS_ALIGNED(dbs->iov.size, dbs->align)) {
@@ -179,8 +178,6 @@ static void dma_blk_cb(void *opaque, int ret)
dbs->acb = dbs->io_func(dbs->offset, &dbs->iov,
dma_blk_cb, dbs, dbs->io_func_opaque);
assert(dbs->acb);
-out:
- aio_context_release(ctx);
}
static void dma_aio_cancel(BlockAIOCB *acb)
--
2.43.0
- [PULL 03/33] nbd/server: introduce NBDClient->lock to protect fields, (continued)
- [PULL 03/33] nbd/server: introduce NBDClient->lock to protect fields, Kevin Wolf, 2023/12/21
- [PULL 04/33] block/file-posix: set up Linux AIO and io_uring in the current thread, Kevin Wolf, 2023/12/21
- [PULL 05/33] virtio-blk: add lock to protect s->rq, Kevin Wolf, 2023/12/21
- [PULL 08/33] block: Fix crash when loading snapshot on inactive node, Kevin Wolf, 2023/12/21
- [PULL 06/33] virtio-blk: don't lock AioContext in the completion code path, Kevin Wolf, 2023/12/21
- [PULL 07/33] virtio-blk: don't lock AioContext in the submission code path, Kevin Wolf, 2023/12/21
- [PULL 09/33] vl: Improve error message for conflicting -incoming and -loadvm, Kevin Wolf, 2023/12/21
- [PULL 10/33] iotests: Basic tests for internal snapshots, Kevin Wolf, 2023/12/21
- [PULL 12/33] virtio-scsi: don't lock AioContext around virtio_queue_aio_attach_host_notifier(), Kevin Wolf, 2023/12/21
- [PULL 11/33] scsi: only access SCSIDevice->requests from one thread, Kevin Wolf, 2023/12/21
- [PULL 14/33] dma-helpers: don't lock AioContext in dma_blk_cb(),
Kevin Wolf <=
- [PULL 13/33] scsi: don't lock AioContext in I/O code path, Kevin Wolf, 2023/12/21
- [PULL 15/33] virtio-scsi: replace AioContext lock with tmf_bh_lock, Kevin Wolf, 2023/12/21
- [PULL 16/33] scsi: assert that callbacks run in the correct AioContext, Kevin Wolf, 2023/12/21
- [PULL 17/33] tests: remove aio_context_acquire() tests, Kevin Wolf, 2023/12/21
- [PULL 18/33] aio: make aio_context_acquire()/aio_context_release() a no-op, Kevin Wolf, 2023/12/21
- [PULL 19/33] graph-lock: remove AioContext locking, Kevin Wolf, 2023/12/21
- [PULL 20/33] block: remove AioContext locking, Kevin Wolf, 2023/12/21
- [PULL 22/33] scsi: remove AioContext locking, Kevin Wolf, 2023/12/21
- [PULL 21/33] block: remove bdrv_co_lock(), Kevin Wolf, 2023/12/21
- [PULL 24/33] aio: remove aio_context_acquire()/aio_context_release() API, Kevin Wolf, 2023/12/21