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

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