Blame SOURCES/kvm-virtio-scsi-fix-hotplug-reset-vs-event-race.patch

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