From: Stefan Hajnoczi <stefanha@redhat.com>
To: <qemu-devel@nongnu.org>
Cc: Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [RFC v3 3/3] virtio-scsi: fix iothread deadlock on 'cont'
Date: Fri, 24 May 2019 19:36:38 +0100 [thread overview]
Message-ID: <20190524183638.20745-4-stefanha@redhat.com> (raw)
In-Reply-To: <20190524183638.20745-1-stefanha@redhat.com>
When the 'cont' command resumes guest execution the vm change state
handlers are invoked. Unfortunately there is no explicit ordering
between vm change state handlers. When two layers of code both use vm
change state handlers, we don't control which handler runs first.
virtio-scsi with iothreads hits a deadlock when a failed SCSI command is
restarted and completes before the iothread is re-initialized.
This patch makes sure that DMA restart happens after the iothread has
been started again.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/scsi/virtio-scsi.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 839f120256..236a0ee873 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -846,12 +846,28 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev,
qdev_simple_device_unplug_cb(hotplug_dev, dev, errp);
}
+static void virtio_scsi_vmstate_change(VirtIODevice *vdev, bool running)
+{
+ VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+
+ if (running) {
+ scsi_bus_dma_restart(&s->bus);
+ }
+}
+
static struct SCSIBusInfo virtio_scsi_scsi_info = {
.tcq = true,
.max_channel = VIRTIO_SCSI_MAX_CHANNEL,
.max_target = VIRTIO_SCSI_MAX_TARGET,
.max_lun = VIRTIO_SCSI_MAX_LUN,
+ /* We call scsi_bus_dma_restart() ourselves to control the ordering between
+ * ->start_ioeventfd() and DMA restart. Do it in
+ * virtio_scsi_vmstate_change(), which is called by the core virtio code
+ * after ->start_ioeventfd().
+ */
+ .custom_dma_restart = true,
+
.complete = virtio_scsi_command_complete,
.cancel = virtio_scsi_request_cancelled,
.change = virtio_scsi_change,
@@ -986,6 +1002,7 @@ static void virtio_scsi_class_init(ObjectClass *klass, void *data)
vdc->reset = virtio_scsi_reset;
vdc->start_ioeventfd = virtio_scsi_dataplane_start;
vdc->stop_ioeventfd = virtio_scsi_dataplane_stop;
+ vdc->vmstate_change = virtio_scsi_vmstate_change;
hc->plug = virtio_scsi_hotplug;
hc->unplug = virtio_scsi_hotunplug;
}
--
2.21.0
next prev parent reply other threads:[~2019-05-24 18:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-24 18:36 [Qemu-devel] [RFC v3 0/3] scsi: restart dma after vm change state handlers Stefan Hajnoczi
2019-05-24 18:36 ` [Qemu-devel] [RFC v3 1/3] virtio: add vdc->vmchange_state() callback Stefan Hajnoczi
2019-05-24 18:36 ` [Qemu-devel] [RFC v3 2/3] scsi: add scsi_bus_dma_restart() Stefan Hajnoczi
2019-05-24 18:36 ` Stefan Hajnoczi [this message]
2019-05-24 18:47 ` [Qemu-devel] [RFC v3 0/3] scsi: restart dma after vm change state handlers Paolo Bonzini
2019-05-24 19:08 ` Michael S. Tsirkin
2019-05-29 22:10 ` Kevin Wolf
2019-05-30 8:27 ` Paolo Bonzini
2019-05-30 8:52 ` Kevin Wolf
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=20190524183638.20745-4-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mst@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).