Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
scsi: assert that callbacks run in the correct AioContext
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>
  • Loading branch information
Stefan Hajnoczi authored and Kevin Wolf committed Dec 21, 2023
1 parent 85d8802 commit d69fadd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions hw/scsi/scsi-disk.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions system/dma-helpers.c
Expand Up @@ -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;

Expand Down

0 comments on commit d69fadd

Please sign in to comment.