From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fam Zheng <fam@euphon.net>, Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [RFC] scsi: restart dma after vm change state handlers
Date: Tue, 21 May 2019 11:36:50 +0100 [thread overview]
Message-ID: <20190521103650.18479-1-stefanha@redhat.com> (raw)
Various components register vm change state handlers to restart device
emulation when the guest is unpaused. These handlers run in an
arbitrary order since there is no way to specific explicit dependencies
or priorities.
Each SCSIDevice has a vm change state handler to restart failed I/O
requests when the guest is unpaused. It schedules a BH in the
AioContext of the BlockBackend.
When virtio-scsi is used with an iothread, the BH may execute in the
iothread while the main loop thread is invoking the remaining vm change
state handlers. In this case virtio-scsi iothread may not be fully
started yet, leading to problems.
One symptom is that I/O request completion is processed in the iothread
before virtio-scsi iothread is fully started and the MSI notify code
path takes the BQL. This violates QEMU's lock order and causes a
deadlock.
This patch defers restarting SCSIDevice requests until after all vm
change state handlers have completed. It's an ugly fix because we're
taking advantage of side-effects instead of explicitly introducing
dependencies that are visible in the source code, but I haven't found a
cleaner solution that isn't also complex and hard to understand.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
This is RFC because I am waiting for a test result on the system where
the bug was originally discovered. I'm also open to nicer solutions!
hw/scsi/scsi-bus.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index c480553083..13b3823752 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -134,13 +134,10 @@ void scsi_req_retry(SCSIRequest *req)
req->retry = true;
}
-static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
+static void scsi_device_retry_reqs_bh(void *opaque)
{
SCSIDevice *s = opaque;
- if (!running) {
- return;
- }
if (!s->bh) {
AioContext *ctx = blk_get_aio_context(s->conf.blk);
s->bh = aio_bh_new(ctx, scsi_dma_restart_bh, s);
@@ -148,6 +145,22 @@ static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
}
}
+static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
+{
+ SCSIDevice *s = opaque;
+
+ if (!running) {
+ return;
+ }
+
+ /* Defer to a main loop BH since other vm change state handlers may need to
+ * run before the bus is ready for I/O activity (e.g. virtio-scsi's
+ * iothread setup).
+ */
+ aio_bh_schedule_oneshot(qemu_get_aio_context(),
+ scsi_device_retry_reqs_bh, s);
+}
+
static void scsi_qdev_realize(DeviceState *qdev, Error **errp)
{
SCSIDevice *dev = SCSI_DEVICE(qdev);
--
2.21.0
next reply other threads:[~2019-05-21 10:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-21 10:36 Stefan Hajnoczi [this message]
2019-05-21 11:04 ` [Qemu-devel] [RFC] scsi: restart dma after vm change state handlers Paolo Bonzini
2019-05-21 11:30 ` Kevin Wolf
2019-05-22 10:48 ` Stefan Hajnoczi
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=20190521103650.18479-1-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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).