yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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