Blame SOURCES/kvm-s390x-pci-Drop-release-timer-and-replace-it-with-a-f.patch

b38b0f
From d1ce5b3af38aa7d4eb9d3a2dd90a7572a69f7d41 Mon Sep 17 00:00:00 2001
b38b0f
From: Cornelia Huck <cohuck@redhat.com>
b38b0f
Date: Wed, 17 Apr 2019 13:57:34 +0100
b38b0f
Subject: [PATCH 17/24] s390x/pci: Drop release timer and replace it with a
b38b0f
 flag
b38b0f
b38b0f
RH-Author: Cornelia Huck <cohuck@redhat.com>
b38b0f
Message-id: <20190417135741.25297-18-cohuck@redhat.com>
b38b0f
Patchwork-id: 85798
b38b0f
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v2 17/24] s390x/pci: Drop release timer and replace it with a flag
b38b0f
Bugzilla: 1699070
b38b0f
RH-Acked-by: David Hildenbrand <david@redhat.com>
b38b0f
RH-Acked-by: Thomas Huth <thuth@redhat.com>
b38b0f
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
b38b0f
b38b0f
From: David Hildenbrand <david@redhat.com>
b38b0f
b38b0f
Let's handle it similar to x86 ACPI PCI code and don't use a timer.
b38b0f
Instead, remember if an unplug request is pending and keep it pending
b38b0f
for eternity. (a follow up patch will process the request on
b38b0f
reboot).
b38b0f
b38b0f
We expect that a guest that is up and running, will process the unplug
b38b0f
request and trigger the unplug. This is normal operation, no timer needed.
b38b0f
b38b0f
If the guest does not react, this usually means something in the guest
b38b0f
is going wrong. Simply removing the device after 30 seconds does not
b38b0f
really sound like a good idea. It might sometimes be wanted, but I
b38b0f
consider this rather an "opt-in" decision as it might harm a guest not
b38b0f
prepared for it.
b38b0f
b38b0f
If we ever actually want a "forced/surprise removal", we will have to
b38b0f
implement something on top of the existing "device_del" framework. E.g.
b38b0f
also x86 might want to do a forced/surprise removal of PCI devices under
b38b0f
some conditions. "device_del X, forced=true" could be an option and will
b38b0f
require changes to the hotplug handler infrastructure.
b38b0f
b38b0f
This will then move the responsibility on when to do a forced removal
b38b0f
to a higher level. Doing a forced removal right now over-complicates
b38b0f
things and doesn't really seem to be required.
b38b0f
b38b0f
Let's allow to send multiple requests.
b38b0f
b38b0f
Signed-off-by: David Hildenbrand <david@redhat.com>
b38b0f
Message-Id: <20190130155733.32742-6-david@redhat.com>
b38b0f
Reviewed-by: Collin Walling <walling@linux.ibm.com>
b38b0f
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
b38b0f
(cherry picked from commit 9f2a46b11139cd21c41f4d97c0416af6f9e76f7b)
b38b0f
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
b38b0f
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
b38b0f
---
b38b0f
 hw/s390x/s390-pci-bus.c | 38 +++++++-------------------------------
b38b0f
 hw/s390x/s390-pci-bus.h |  3 +--
b38b0f
 2 files changed, 8 insertions(+), 33 deletions(-)
b38b0f
b38b0f
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
b38b0f
index 21419df..97d3eb8 100644
b38b0f
--- a/hw/s390x/s390-pci-bus.c
b38b0f
+++ b/hw/s390x/s390-pci-bus.c
b38b0f
@@ -194,7 +194,7 @@ void s390_pci_sclp_deconfigure(SCCB *sccb)
b38b0f
         pbdev->state = ZPCI_FS_STANDBY;
b38b0f
         rc = SCLP_RC_NORMAL_COMPLETION;
b38b0f
 
b38b0f
-        if (pbdev->release_timer) {
b38b0f
+        if (pbdev->unplug_requested) {
b38b0f
             s390_pci_perform_unplug(pbdev);
b38b0f
         }
b38b0f
     }
b38b0f
@@ -963,23 +963,6 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
b38b0f
     }
b38b0f
 }
b38b0f
 
b38b0f
-static void s390_pcihost_timer_cb(void *opaque)
b38b0f
-{
b38b0f
-    S390PCIBusDevice *pbdev = opaque;
b38b0f
-
b38b0f
-    if (pbdev->summary_ind) {
b38b0f
-        pci_dereg_irqs(pbdev);
b38b0f
-    }
b38b0f
-    if (pbdev->iommu->enabled) {
b38b0f
-        pci_dereg_ioat(pbdev->iommu);
b38b0f
-    }
b38b0f
-
b38b0f
-    pbdev->state = ZPCI_FS_STANDBY;
b38b0f
-    s390_pci_generate_plug_event(HP_EVENT_CONFIGURED_TO_STBRES,
b38b0f
-                                 pbdev->fh, pbdev->fid);
b38b0f
-    s390_pci_perform_unplug(pbdev);
b38b0f
-}
b38b0f
-
b38b0f
 static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
b38b0f
                                 Error **errp)
b38b0f
 {
b38b0f
@@ -1006,12 +989,6 @@ static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
b38b0f
         pbdev->state = ZPCI_FS_RESERVED;
b38b0f
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_S390_PCI_DEVICE)) {
b38b0f
         pbdev = S390_PCI_DEVICE(dev);
b38b0f
-
b38b0f
-        if (pbdev->release_timer) {
b38b0f
-            timer_del(pbdev->release_timer);
b38b0f
-            timer_free(pbdev->release_timer);
b38b0f
-            pbdev->release_timer = NULL;
b38b0f
-        }
b38b0f
         pbdev->fid = 0;
b38b0f
         QTAILQ_REMOVE(&s->zpci_devs, pbdev, link);
b38b0f
         g_hash_table_remove(s->zpci_table, &pbdev->idx);
b38b0f
@@ -1058,15 +1035,14 @@ static void s390_pcihost_unplug_request(HotplugHandler *hotplug_dev,
b38b0f
             s390_pci_perform_unplug(pbdev);
b38b0f
             break;
b38b0f
         default:
b38b0f
-            if (pbdev->release_timer) {
b38b0f
-                return;
b38b0f
-            }
b38b0f
+            /*
b38b0f
+             * Allow to send multiple requests, e.g. if the guest crashed
b38b0f
+             * before releasing the device, we would not be able to send
b38b0f
+             * another request to the same VM (e.g. fresh OS).
b38b0f
+             */
b38b0f
+            pbdev->unplug_requested = true;
b38b0f
             s390_pci_generate_plug_event(HP_EVENT_DECONFIGURE_REQUEST,
b38b0f
                                          pbdev->fh, pbdev->fid);
b38b0f
-            pbdev->release_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
b38b0f
-                                                s390_pcihost_timer_cb, pbdev);
b38b0f
-            timer_mod(pbdev->release_timer,
b38b0f
-                    qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + HOT_UNPLUG_TIMEOUT);
b38b0f
         }
b38b0f
     } else {
b38b0f
         g_assert_not_reached();
b38b0f
diff --git a/hw/s390x/s390-pci-bus.h b/hw/s390x/s390-pci-bus.h
b38b0f
index 7684658..3eae782 100644
b38b0f
--- a/hw/s390x/s390-pci-bus.h
b38b0f
+++ b/hw/s390x/s390-pci-bus.h
b38b0f
@@ -35,7 +35,6 @@
b38b0f
 #define ZPCI_MAX_UID 0xffff
b38b0f
 #define UID_UNDEFINED 0
b38b0f
 #define UID_CHECKING_ENABLED 0x01
b38b0f
-#define HOT_UNPLUG_TIMEOUT (NANOSECONDS_PER_SECOND * 60 * 5)
b38b0f
 
b38b0f
 #define S390_PCI_HOST_BRIDGE(obj) \
b38b0f
     OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE)
b38b0f
@@ -307,8 +306,8 @@ struct S390PCIBusDevice {
b38b0f
     MemoryRegion msix_notify_mr;
b38b0f
     IndAddr *summary_ind;
b38b0f
     IndAddr *indicator;
b38b0f
-    QEMUTimer *release_timer;
b38b0f
     bool pci_unplug_request_processed;
b38b0f
+    bool unplug_requested;
b38b0f
     QTAILQ_ENTRY(S390PCIBusDevice) link;
b38b0f
 };
b38b0f
 
b38b0f
-- 
b38b0f
1.8.3.1
b38b0f