[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/13] virtio-scsi: fix hotplug ->reset() vs event ra
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 09/13] virtio-scsi: fix hotplug ->reset() vs event race |
Date: |
Tue, 17 Jul 2018 17:06:51 +0200 |
From: Stefan Hajnoczi <address@hidden>
There is a race condition during hotplug when iothread is used. It
occurs because virtio-scsi may be processing command queues in the
iothread while the monitor performs SCSI device hotplug.
When a SCSI device is hotplugged the HotplugHandler->plug() callback is
invoked and virtio-scsi emits a rescan event to the guest.
If the guest submits a SCSI command at this point then it may be
cancelled before hotplug completes. This happens because ->reset() is
called by hw/core/qdev.c:device_set_realized() after
HotplugHandler->plug() has been called and
hw/scsi/scsi-disk.c:scsi_disk_reset() purges all requests.
This patch uses the new HotplugHandler->post_plug() callback to emit the
rescan event after ->reset(). This eliminates the race conditions where
requests could be cancelled.
Reported-by: l00284672 <address@hidden>
Cc: Paolo Bonzini <address@hidden>
Cc: Fam Zheng <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/scsi/virtio-scsi.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 3aa9971..5a3057d 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -797,8 +797,16 @@ static void virtio_scsi_hotplug(HotplugHandler
*hotplug_dev, DeviceState *dev,
virtio_scsi_acquire(s);
blk_set_aio_context(sd->conf.blk, s->ctx);
virtio_scsi_release(s);
-
}
+}
+
+/* Announce the new device after it has been plugged */
+static void virtio_scsi_post_hotplug(HotplugHandler *hotplug_dev,
+ DeviceState *dev)
+{
+ VirtIODevice *vdev = VIRTIO_DEVICE(hotplug_dev);
+ VirtIOSCSI *s = VIRTIO_SCSI(vdev);
+ SCSIDevice *sd = SCSI_DEVICE(dev);
if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
virtio_scsi_acquire(s);
@@ -968,6 +976,7 @@ static void virtio_scsi_class_init(ObjectClass *klass, void
*data)
vdc->start_ioeventfd = virtio_scsi_dataplane_start;
vdc->stop_ioeventfd = virtio_scsi_dataplane_stop;
hc->plug = virtio_scsi_hotplug;
+ hc->post_plug = virtio_scsi_post_hotplug;
hc->unplug = virtio_scsi_hotunplug;
}
--
1.8.3.1
- [Qemu-devel] [PULL 00/13] Misc fixes for QEMU 3.0.0-rc1, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 01/13] dump: add kernel_gs_base to QEMU CPU state, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 03/13] hyperv: rename vcpu_id to vp_index, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 02/13] accel: Fix typo and grammar in comment, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 06/13] PC Chipset: Improve serial divisor calculation, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 05/13] vhost-user-test: added proper TestServer *dest initialization in test_migrate(), Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 04/13] hyperv: ensure VP index equal to QEMU cpu_index, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 07/13] hw/char/serial: retry write if EAGAIN, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 09/13] virtio-scsi: fix hotplug ->reset() vs event race,
Paolo Bonzini <=
- [Qemu-devel] [PULL 12/13] opts: remove redundant check for NULL parameter, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 08/13] qdev: add HotplugHandler->post_plug() callback, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 10/13] i386: fix regression parsing multiboot initrd modules, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 11/13] i386: only parse the initrd_filename once for multiboot modules, Paolo Bonzini, 2018/07/17
- [Qemu-devel] [PULL 13/13] Document command line options with single dash, Paolo Bonzini, 2018/07/17
- Re: [Qemu-devel] [PULL 00/13] Misc fixes for QEMU 3.0.0-rc1, Peter Maydell, 2018/07/17