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

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