From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
Stefano Stabellini <sstabellini@kernel.org>,
"open list:virtio-blk" <qemu-block@nongnu.org>,
Sergio Lopez <slp@redhat.com>, Paul Durrant <paul@xen.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
Max Reitz <mreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
"open list:X86 Xen CPUs" <xen-devel@lists.xenproject.org>,
Anthony Perard <anthony.perard@citrix.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [PULL 03/13] block: Honor blk_set_aio_context() context requirements
Date: Wed, 20 Jan 2021 20:36:47 -0600 [thread overview]
Message-ID: <20210121023657.1186241-4-eblake@redhat.com> (raw)
In-Reply-To: <20210121023657.1186241-1-eblake@redhat.com>
From: Sergio Lopez <slp@redhat.com>
The documentation for bdrv_set_aio_context_ignore() states this:
* The caller must own the AioContext lock for the old AioContext of bs, but it
* must not own the AioContext lock for new_context (unless new_context is the
* same as the current context of bs).
As blk_set_aio_context() makes use of this function, this rule also
applies to it.
Fix all occurrences where this rule wasn't honored.
Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Sergio Lopez <slp@redhat.com>
Message-Id: <20201214170519.223781-2-slp@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
hw/block/dataplane/virtio-blk.c | 4 ++++
hw/block/dataplane/xen-block.c | 7 ++++++-
hw/scsi/virtio-scsi.c | 6 ++++--
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 37499c556482..e9050c8987e7 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -172,6 +172,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
VirtIOBlockDataPlane *s = vblk->dataplane;
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vblk)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+ AioContext *old_context;
unsigned i;
unsigned nvqs = s->conf->num_queues;
Error *local_err = NULL;
@@ -214,7 +215,10 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
vblk->dataplane_started = true;
trace_virtio_blk_data_plane_start(s);
+ old_context = blk_get_aio_context(s->conf->conf.blk);
+ aio_context_acquire(old_context);
r = blk_set_aio_context(s->conf->conf.blk, s->ctx, &local_err);
+ aio_context_release(old_context);
if (r < 0) {
error_report_err(local_err);
goto fail_guest_notifiers;
diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c
index 71c337c7b7e7..3675f8deaf9d 100644
--- a/hw/block/dataplane/xen-block.c
+++ b/hw/block/dataplane/xen-block.c
@@ -725,6 +725,7 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
{
ERRP_GUARD();
XenDevice *xendev = dataplane->xendev;
+ AioContext *old_context;
unsigned int ring_size;
unsigned int i;
@@ -808,10 +809,14 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
goto stop;
}
- aio_context_acquire(dataplane->ctx);
+ old_context = blk_get_aio_context(dataplane->blk);
+ aio_context_acquire(old_context);
/* If other users keep the BlockBackend in the iothread, that's ok */
blk_set_aio_context(dataplane->blk, dataplane->ctx, NULL);
+ aio_context_release(old_context);
+
/* Only reason for failure is a NULL channel */
+ aio_context_acquire(dataplane->ctx);
xen_device_set_event_channel_context(xendev, dataplane->event_channel,
dataplane->ctx, &error_abort);
aio_context_release(dataplane->ctx);
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 9690bc63c860..99ff261cead1 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -849,15 +849,17 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,
VirtIODevice *vdev = VIRTIO_DEVICE(hotplug_dev);
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
SCSIDevice *sd = SCSI_DEVICE(dev);
+ AioContext *old_context;
int ret;
if (s->ctx && !s->dataplane_fenced) {
if (blk_op_is_blocked(sd->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) {
return;
}
- virtio_scsi_acquire(s);
+ old_context = blk_get_aio_context(sd->conf.blk);
+ aio_context_acquire(old_context);
ret = blk_set_aio_context(sd->conf.blk, s->ctx, errp);
- virtio_scsi_release(s);
+ aio_context_release(old_context);
if (ret < 0) {
return;
}
--
2.30.0
next prev parent reply other threads:[~2021-01-21 2:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-21 2:36 [PULL 00/13] NBD patches through 2021-01-20 Eric Blake
2021-01-21 2:36 ` [PULL 01/13] qemu-nbd: Fix a memleak in qemu_nbd_client_list() Eric Blake
2021-01-21 2:36 ` [PULL 02/13] qemu-nbd: Fix a memleak in nbd_client_thread() Eric Blake
2021-01-21 2:36 ` Eric Blake [this message]
2021-01-21 2:36 ` [PULL 04/13] nbd/server: Quiesce coroutines on context switch Eric Blake
2021-01-21 2:36 ` [PULL 05/13] iotests/277: use dot slash for nbd-fault-injector.py running Eric Blake
2021-01-21 2:36 ` [PULL 06/13] iotests/303: use dot slash for qcow2.py running Eric Blake
2021-01-21 2:36 ` [PULL 07/13] iotests: fix some whitespaces in test output files Eric Blake
2021-01-21 2:36 ` [PULL 08/13] iotests: make tests executable Eric Blake
2021-01-21 2:36 ` [PULL 09/13] iotests/294: add shebang line Eric Blake
2021-01-21 2:36 ` [PULL 10/13] iotests: define group in each iotest Eric Blake
2021-01-21 9:19 ` Vladimir Sementsov-Ogievskiy
2021-01-21 2:36 ` [PULL 11/13] iotests/264: fix style Eric Blake
2021-01-21 2:36 ` [PULL 12/13] iotests.py: fix qemu_tool_pipe_and_status() Eric Blake
2021-01-21 2:36 ` [PULL 13/13] iotests.py: qemu_io(): reuse qemu_tool_pipe_and_status() Eric Blake
2021-01-21 11:35 ` [PULL 00/13] NBD patches through 2021-01-20 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210121023657.1186241-4-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=anthony.perard@citrix.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=slp@redhat.com \
--cc=sstabellini@kernel.org \
--cc=stefanha@redhat.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).