[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 16/33] scsi: assert that callbacks run in the correct AioContext
From: |
Kevin Wolf |
Subject: |
[PULL 16/33] scsi: assert that callbacks run in the correct AioContext |
Date: |
Thu, 21 Dec 2023 22:23:21 +0100 |
From: Stefan Hajnoczi <stefanha@redhat.com>
Since the removal of AioContext locking, the correctness of the code
relies on running requests from a single AioContext at any given time.
Add assertions that verify that callbacks are invoked in the correct
AioContext.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20231205182011.1976568-3-stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/scsi/scsi-disk.c | 14 ++++++++++++++
system/dma-helpers.c | 3 +++
2 files changed, 17 insertions(+)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 2c1bbb3530..a5048e0aaf 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -273,6 +273,10 @@ static void scsi_aio_complete(void *opaque, int ret)
SCSIDiskReq *r = (SCSIDiskReq *)opaque;
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
+ /* The request must only run in the BlockBackend's AioContext */
+ assert(blk_get_aio_context(s->qdev.conf.blk) ==
+ qemu_get_current_aio_context());
+
assert(r->req.aiocb != NULL);
r->req.aiocb = NULL;
@@ -370,8 +374,13 @@ static void scsi_dma_complete(void *opaque, int ret)
static void scsi_read_complete_noio(SCSIDiskReq *r, int ret)
{
+ SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
uint32_t n;
+ /* The request must only run in the BlockBackend's AioContext */
+ assert(blk_get_aio_context(s->qdev.conf.blk) ==
+ qemu_get_current_aio_context());
+
assert(r->req.aiocb == NULL);
if (scsi_disk_req_check_error(r, ret, false)) {
goto done;
@@ -496,8 +505,13 @@ static void scsi_read_data(SCSIRequest *req)
static void scsi_write_complete_noio(SCSIDiskReq *r, int ret)
{
+ SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
uint32_t n;
+ /* The request must only run in the BlockBackend's AioContext */
+ assert(blk_get_aio_context(s->qdev.conf.blk) ==
+ qemu_get_current_aio_context());
+
assert (r->req.aiocb == NULL);
if (scsi_disk_req_check_error(r, ret, false)) {
goto done;
diff --git a/system/dma-helpers.c b/system/dma-helpers.c
index 528117f256..9b221cf94e 100644
--- a/system/dma-helpers.c
+++ b/system/dma-helpers.c
@@ -119,6 +119,9 @@ static void dma_blk_cb(void *opaque, int ret)
trace_dma_blk_cb(dbs, ret);
+ /* DMAAIOCB is not thread-safe and must be accessed only from dbs->ctx */
+ assert(ctx == qemu_get_current_aio_context());
+
dbs->acb = NULL;
dbs->offset += dbs->iov.size;
--
2.43.0
- [PULL 08/33] block: Fix crash when loading snapshot on inactive node, (continued)
- [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, 2023/12/21
- [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 <=
- [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
- [PULL 26/33] scsi: remove outdated AioContext lock comment, Kevin Wolf, 2023/12/21
- [PULL 25/33] docs: remove AioContext lock from IOThread docs, Kevin Wolf, 2023/12/21
- [PULL 27/33] job: remove outdated AioContext locking comments, Kevin Wolf, 2023/12/21