[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 17/17] s390x/pci: make hot-unplug handler smoother
From: |
Cornelia Huck |
Subject: |
[Qemu-devel] [PATCH 17/17] s390x/pci: make hot-unplug handler smoother |
Date: |
Fri, 24 Jun 2016 15:29:06 +0200 |
From: Yi Min Zhao <address@hidden>
The current implementation of hot-unplug handler is abrupt. Any pci
operation will be just rejected if pci device is unconfigured. Thus a
pci device can not be reset or destroyed in a right, smooth and safe
way.
Improve this as follows:
- Notify the guest via a HP_EVENT_DECONFIGURE_REQUEST(0x303) event in
the unplug handler, giving it a chance to deconfigure the device via
sclp and allowing us to continue hot-unplug afterwards.
- Set up a timer that will generate the HP_EVENT_CONFIGURE_TO_STBRES
(0x304) event as before if the guest did not react after an adequate
time.
Signed-off-by: Yi Min Zhao <address@hidden>
Reviewed-by: Pierre Morel <address@hidden>
Signed-off-by: Cornelia Huck <address@hidden>
---
hw/s390x/s390-pci-bus.c | 35 ++++++++++++++++++++++++++++++++++-
hw/s390x/s390-pci-bus.h | 3 +++
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 630a826..640a4ea 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -192,6 +192,10 @@ void s390_pci_sclp_deconfigure(SCCB *sccb)
}
pbdev->state = ZPCI_FS_STANDBY;
rc = SCLP_RC_NORMAL_COMPLETION;
+
+ if (pbdev->release_timer) {
+ qdev_unplug(DEVICE(pbdev->pdev), NULL);
+ }
}
out:
psccb->header.response_code = cpu_to_be16(rc);
@@ -679,6 +683,23 @@ static void s390_pcihost_hot_plug(HotplugHandler
*hotplug_dev,
}
}
+static void s390_pcihost_timer_cb(void *opaque)
+{
+ S390PCIBusDevice *pbdev = opaque;
+
+ if (pbdev->summary_ind) {
+ pci_dereg_irqs(pbdev);
+ }
+ if (pbdev->iommu_enabled) {
+ pci_dereg_ioat(pbdev);
+ }
+
+ pbdev->state = ZPCI_FS_STANDBY;
+ s390_pci_generate_plug_event(HP_EVENT_CONFIGURED_TO_STBRES,
+ pbdev->fh, pbdev->fid);
+ qdev_unplug(DEVICE(pbdev), NULL);
+}
+
static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
{
@@ -712,8 +733,20 @@ static void s390_pcihost_hot_unplug(HotplugHandler
*hotplug_dev,
case ZPCI_FS_STANDBY:
break;
default:
- s390_pci_generate_plug_event(HP_EVENT_CONFIGURED_TO_STBRES,
+ s390_pci_generate_plug_event(HP_EVENT_DECONFIGURE_REQUEST,
pbdev->fh, pbdev->fid);
+ pbdev->release_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
+ s390_pcihost_timer_cb,
+ pbdev);
+ timer_mod(pbdev->release_timer,
+ qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + HOT_UNPLUG_TIMEOUT);
+ return;
+ }
+
+ if (pbdev->release_timer && timer_pending(pbdev->release_timer)) {
+ timer_del(pbdev->release_timer);
+ timer_free(pbdev->release_timer);
+ pbdev->release_timer = NULL;
}
s390_pci_generate_plug_event(HP_EVENT_STANDBY_TO_RESERVED,
diff --git a/hw/s390x/s390-pci-bus.h b/hw/s390x/s390-pci-bus.h
index 71cdd7a..f1fbd3c 100644
--- a/hw/s390x/s390-pci-bus.h
+++ b/hw/s390x/s390-pci-bus.h
@@ -34,6 +34,7 @@
#define ZPCI_MAX_UID 0xffff
#define UID_UNDEFINED 0
#define UID_CHECKING_ENABLED 0x01
+#define HOT_UNPLUG_TIMEOUT (NANOSECONDS_PER_SECOND * 60 * 5)
#define S390_PCI_HOST_BRIDGE(obj) \
OBJECT_CHECK(S390pciState, (obj), TYPE_S390_PCI_HOST_BRIDGE)
@@ -44,6 +45,7 @@
#define HP_EVENT_TO_CONFIGURED 0x0301
#define HP_EVENT_RESERVED_TO_STANDBY 0x0302
+#define HP_EVENT_DECONFIGURE_REQUEST 0x0303
#define HP_EVENT_CONFIGURED_TO_STBRES 0x0304
#define HP_EVENT_STANDBY_TO_RESERVED 0x0308
@@ -283,6 +285,7 @@ typedef struct S390PCIBusDevice {
MemoryRegion iommu_mr;
IndAddr *summary_ind;
IndAddr *indicator;
+ QEMUTimer *release_timer;
} S390PCIBusDevice;
typedef struct S390PCIBus {
--
2.9.0
- [Qemu-devel] [PATCH 00/17] s390x: the big pci update, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 05/17] s390x/pci: refactor s390_pci_find_dev_by_fh, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 16/17] s390x/pci: replace fid with idx in msg data of msix, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 17/17] s390x/pci: make hot-unplug handler smoother,
Cornelia Huck <=
- [Qemu-devel] [PATCH 08/17] s390x/pci: introduce S390PCIIOMMU, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 15/17] s390x/pci: fix stpcifc_service_call, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 04/17] s390x/pci: unify FH_ macros, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 03/17] s390x/pci: write fid in CLP_QUERY_PCI_FN, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 10/17] s390x/pci: enable uid-checking, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 12/17] s390x/pci: add checkings in CLP_SET_PCI_FN, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 06/17] s390x/pci: enforce zPCI state checking, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 01/17] s390x/pci: fix failures of dma map/unmap, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 02/17] s390x/pci: acceleration for getting S390pciState, Cornelia Huck, 2016/06/24
- [Qemu-devel] [PATCH 09/17] s390x/pci: introduce S390PCIBusDevice qdev, Cornelia Huck, 2016/06/24