|
|
ae23c9 |
From b872baa52f5e8e8c84b3a19bb6cf5b6e92106fb9 Mon Sep 17 00:00:00 2001
|
|
|
ae23c9 |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ae23c9 |
Date: Tue, 24 Jul 2018 15:13:08 +0200
|
|
|
ae23c9 |
Subject: [PATCH 264/268] virtio-scsi: fix hotplug ->reset() vs event race
|
|
|
ae23c9 |
|
|
|
ae23c9 |
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ae23c9 |
Message-id: <20180724151308.20500-3-stefanha@redhat.com>
|
|
|
ae23c9 |
Patchwork-id: 81486
|
|
|
ae23c9 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 2/2] virtio-scsi: fix hotplug ->reset() vs event race
|
|
|
ae23c9 |
Bugzilla: 1607891
|
|
|
ae23c9 |
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Pankaj Gupta <pagupta@redhat.com>
|
|
|
ae23c9 |
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
|
|
|
ae23c9 |
|
|
|
ae23c9 |
There is a race condition during hotplug when iothread is used. It
|
|
|
ae23c9 |
occurs because virtio-scsi may be processing command queues in the
|
|
|
ae23c9 |
iothread while the monitor performs SCSI device hotplug.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
When a SCSI device is hotplugged the HotplugHandler->plug() callback is
|
|
|
ae23c9 |
invoked and virtio-scsi emits a rescan event to the guest.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
If the guest submits a SCSI command at this point then it may be
|
|
|
ae23c9 |
cancelled before hotplug completes. This happens because ->reset() is
|
|
|
ae23c9 |
called by hw/core/qdev.c:device_set_realized() after
|
|
|
ae23c9 |
HotplugHandler->plug() has been called and
|
|
|
ae23c9 |
hw/scsi/scsi-disk.c:scsi_disk_reset() purges all requests.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
This patch uses the new HotplugHandler->post_plug() callback to emit the
|
|
|
ae23c9 |
rescan event after ->reset(). This eliminates the race conditions where
|
|
|
ae23c9 |
requests could be cancelled.
|
|
|
ae23c9 |
|
|
|
ae23c9 |
Reported-by: l00284672 <lizhengui@huawei.com>
|
|
|
ae23c9 |
Cc: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
ae23c9 |
Cc: Fam Zheng <famz@redhat.com>
|
|
|
ae23c9 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ae23c9 |
Message-Id: <20180716083732.3347-3-stefanha@redhat.com>
|
|
|
ae23c9 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
ae23c9 |
(cherry picked from commit 8449bcf94986156a1476d6647c75ec1ce3db64d0)
|
|
|
ae23c9 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
ae23c9 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ae23c9 |
---
|
|
|
ae23c9 |
hw/scsi/virtio-scsi.c | 11 ++++++++++-
|
|
|
ae23c9 |
1 file changed, 10 insertions(+), 1 deletion(-)
|
|
|
ae23c9 |
|
|
|
ae23c9 |
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
|
|
|
ae23c9 |
index 9f754c4..52a3c1d 100644
|
|
|
ae23c9 |
--- a/hw/scsi/virtio-scsi.c
|
|
|
ae23c9 |
+++ b/hw/scsi/virtio-scsi.c
|
|
|
ae23c9 |
@@ -806,8 +806,16 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,
|
|
|
ae23c9 |
virtio_scsi_acquire(s);
|
|
|
ae23c9 |
blk_set_aio_context(sd->conf.blk, s->ctx);
|
|
|
ae23c9 |
virtio_scsi_release(s);
|
|
|
ae23c9 |
-
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
+}
|
|
|
ae23c9 |
+
|
|
|
ae23c9 |
+/* Announce the new device after it has been plugged */
|
|
|
ae23c9 |
+static void virtio_scsi_post_hotplug(HotplugHandler *hotplug_dev,
|
|
|
ae23c9 |
+ DeviceState *dev)
|
|
|
ae23c9 |
+{
|
|
|
ae23c9 |
+ VirtIODevice *vdev = VIRTIO_DEVICE(hotplug_dev);
|
|
|
ae23c9 |
+ VirtIOSCSI *s = VIRTIO_SCSI(vdev);
|
|
|
ae23c9 |
+ SCSIDevice *sd = SCSI_DEVICE(dev);
|
|
|
ae23c9 |
|
|
|
ae23c9 |
if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) {
|
|
|
ae23c9 |
virtio_scsi_acquire(s);
|
|
|
ae23c9 |
@@ -977,6 +985,7 @@ static void virtio_scsi_class_init(ObjectClass *klass, void *data)
|
|
|
ae23c9 |
vdc->start_ioeventfd = virtio_scsi_dataplane_start;
|
|
|
ae23c9 |
vdc->stop_ioeventfd = virtio_scsi_dataplane_stop;
|
|
|
ae23c9 |
hc->plug = virtio_scsi_hotplug;
|
|
|
ae23c9 |
+ hc->post_plug = virtio_scsi_post_hotplug;
|
|
|
ae23c9 |
hc->unplug = virtio_scsi_hotunplug;
|
|
|
ae23c9 |
}
|
|
|
ae23c9 |
|
|
|
ae23c9 |
--
|
|
|
ae23c9 |
1.8.3.1
|
|
|
ae23c9 |
|