All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks
@ 2018-11-20 11:04 David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 01/11] pci/pcie: rename hotplug handler callbacks David Hildenbrand
                   ` (11 more replies)
  0 siblings, 12 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

This series reworks some pci hotplug handlers (except for s390, that will
require more work but is not required for now).

1. Route all unplug calls via the hotplug handler when called from the
   unplug_request handler. This will be required to get multi-stage
   hotplug handlers running, but also makes sense on its own (just like we
   already did for some CPU/memory hotplug handlers).

2. Introduce some pre_plug handlers where it makes sense already.

3. Call the plug/pre_plug handler also for coldplugged devices. Especially
   pcihp is special as it overwrites hotplug handlers.

This series will not yet factor out pre_plug/plug/unplug from pci device
realize/unrealize functions, this will require more work but this
series is also required first to get it running.

In my opinion what needs to be done in the future:
1. Introduce pre_plug/plug/unplug_request/unplug handlers for all PCI
   buses
2. Move pci realize/unrealize parts to pre_plug/pkug/unplug functions like
   pci_pre_plug() ...
3. Call the pci pre_plug/plug/unplug handlers from the PCI bus hotplug
   handler at the right spots
4. Factor more checks from existing plug() handlers out into pre_plug()
   (e.g. after the call to pci_pre_plug())

v2 -> v3:
- Added "pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge"
-- Use one handler callback for pcie and !pcie
- "pci/shpc: perform unplug via the hotplug handler"
-- Use one handler callback for pcie and !pcie
-- Replace error check by an assertion
- Minor description changes.
- Added Rbs

v1 -> v2:
- Added "pci/pcie: rename hotplug handler callbacks"
- Added "pci/shpc: rename hotplug handler callbacks"
- Added "s390x/pci: rename hotplug handler callbacks"
- Dropped "pci/shpc: move hotplug checks to preplug handler"
-- We will have to factor out stuff into pre_plug() first as described
   above
- Renamed and added more details to the "perform unplug via the hotplug
  handler" patches
- "pci/pcihp: overwrite hotplug handler recursively from the start"
-- Perform the overwrite only for cold plugged bridges, to keep the
   existing behavior

David Hildenbrand (11):
  pci/pcie: rename hotplug handler callbacks
  pci/shpc: rename hotplug handler callbacks
  s390x/pci: rename hotplug handler callbacks
  pci/pcie: stop plug/unplug if the slot is locked
  pci/pcihp: perform check for bus capability in pre_plug handler
  pci/pcihp: overwrite hotplug handler recursively from the start
  pci/pcihp: perform unplug via the hotplug handler
  pci/pcie: perform unplug via the hotplug handler
  pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge
  pci/shpc: perform unplug via the hotplug handler
  spapr_pci: perform unplug via the hotplug handler

 hw/acpi/pcihp.c                 | 47 ++++++++++++++++++++++++++++-----
 hw/acpi/piix4.c                 | 39 ++++++++++++++-------------
 hw/pci-bridge/pci_bridge_dev.c  | 31 ++++++++++++++--------
 hw/pci-bridge/pcie_pci_bridge.c | 32 +++-------------------
 hw/pci/pcie.c                   | 46 +++++++++++++++++++++-----------
 hw/pci/pcie_port.c              |  6 +++--
 hw/pci/shpc.c                   | 25 ++++++++++++------
 hw/ppc/spapr_pci.c              | 33 ++++++++++++++---------
 hw/s390x/s390-pci-bus.c         | 12 ++++-----
 include/hw/acpi/pcihp.h         |  5 ++++
 include/hw/pci/pci_bridge.h     |  6 +++++
 include/hw/pci/pcie.h           | 12 ++++++---
 include/hw/pci/shpc.h           | 10 ++++---
 13 files changed, 187 insertions(+), 117 deletions(-)

-- 
2.17.2

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 01/11] pci/pcie: rename hotplug handler callbacks
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 02/11] pci/shpc: " David Hildenbrand
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

The callbacks are also called for cold plugged devices. Drop the "hot"
to better match the actual callback names.

While at it, also rename  pcie_cap_slot_hotplug_common() to
pcie_cap_slot_plug_common().

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/pci/pcie.c         | 17 ++++++++---------
 hw/pci/pcie_port.c    |  4 ++--
 include/hw/pci/pcie.h |  8 ++++----
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 6c91bd44a0..44737cc1cd 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -315,9 +315,8 @@ static void pcie_cap_slot_event(PCIDevice *dev, PCIExpressHotPlugEvent event)
     hotplug_event_notify(dev);
 }
 
-static void pcie_cap_slot_hotplug_common(PCIDevice *hotplug_dev,
-                                         DeviceState *dev,
-                                         uint8_t **exp_cap, Error **errp)
+static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev,
+                                      uint8_t **exp_cap, Error **errp)
 {
     *exp_cap = hotplug_dev->config + hotplug_dev->exp.exp_cap;
     uint16_t sltsta = pci_get_word(*exp_cap + PCI_EXP_SLTSTA);
@@ -331,13 +330,13 @@ static void pcie_cap_slot_hotplug_common(PCIDevice *hotplug_dev,
     }
 }
 
-void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
-                              Error **errp)
+void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                           Error **errp)
 {
     uint8_t *exp_cap;
     PCIDevice *pci_dev = PCI_DEVICE(dev);
 
-    pcie_cap_slot_hotplug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
+    pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
 
     /* Don't send event when device is enabled during qemu machine creation:
      * it is present on boot, no hotplug event is necessary. We do send an
@@ -365,14 +364,14 @@ static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque)
     object_unparent(OBJECT(dev));
 }
 
-void pcie_cap_slot_hot_unplug_request_cb(HotplugHandler *hotplug_dev,
-                                         DeviceState *dev, Error **errp)
+void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                     DeviceState *dev, Error **errp)
 {
     uint8_t *exp_cap;
     PCIDevice *pci_dev = PCI_DEVICE(dev);
     PCIBus *bus = pci_get_bus(pci_dev);
 
-    pcie_cap_slot_hotplug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
+    pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
 
     /* In case user cancel the operation of multi-function hot-add,
      * remove the function that is unexposed to guest individually,
diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c
index 6432b9ac1f..73e81e5847 100644
--- a/hw/pci/pcie_port.c
+++ b/hw/pci/pcie_port.c
@@ -154,8 +154,8 @@ static void pcie_slot_class_init(ObjectClass *oc, void *data)
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
 
     dc->props = pcie_slot_props;
-    hc->plug = pcie_cap_slot_hotplug_cb;
-    hc->unplug_request = pcie_cap_slot_hot_unplug_request_cb;
+    hc->plug = pcie_cap_slot_plug_cb;
+    hc->unplug_request = pcie_cap_slot_unplug_request_cb;
 }
 
 static const TypeInfo pcie_slot_type_info = {
diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
index b71e369703..735f8e8154 100644
--- a/include/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
@@ -131,8 +131,8 @@ void pcie_ari_init(PCIDevice *dev, uint16_t offset, uint16_t nextfn);
 void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num);
 void pcie_ats_init(PCIDevice *dev, uint16_t offset);
 
-void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
-                              Error **errp);
-void pcie_cap_slot_hot_unplug_request_cb(HotplugHandler *hotplug_dev,
-                                         DeviceState *dev, Error **errp);
+void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                           Error **errp);
+void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                     DeviceState *dev, Error **errp);
 #endif /* QEMU_PCIE_H */
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 02/11] pci/shpc: rename hotplug handler callbacks
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 01/11] pci/pcie: rename hotplug handler callbacks David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 03/11] s390x/pci: " David Hildenbrand
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

The callbacks are also called for cold plugged devices. Drop the "hot"
to better match the actual callback names.

While at it, also rename shpc_device_hotplug_common() to
shpc_device_plug_common().

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/pci-bridge/pci_bridge_dev.c  | 17 ++++++++---------
 hw/pci-bridge/pcie_pci_bridge.c | 17 ++++++++---------
 hw/pci/shpc.c                   | 14 +++++++-------
 include/hw/pci/shpc.h           |  8 ++++----
 4 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
index 97a8e8b6a4..e1df9a52ac 100644
--- a/hw/pci-bridge/pci_bridge_dev.c
+++ b/hw/pci-bridge/pci_bridge_dev.c
@@ -206,8 +206,8 @@ static const VMStateDescription pci_bridge_dev_vmstate = {
     }
 };
 
-static void pci_bridge_dev_hotplug_cb(HotplugHandler *hotplug_dev,
-                                      DeviceState *dev, Error **errp)
+static void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev,
+                                   DeviceState *dev, Error **errp)
 {
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
 
@@ -216,12 +216,11 @@ static void pci_bridge_dev_hotplug_cb(HotplugHandler *hotplug_dev,
                    "this %s", TYPE_PCI_BRIDGE_DEV);
         return;
     }
-    shpc_device_hotplug_cb(hotplug_dev, dev, errp);
+    shpc_device_plug_cb(hotplug_dev, dev, errp);
 }
 
-static void pci_bridge_dev_hot_unplug_request_cb(HotplugHandler *hotplug_dev,
-                                                 DeviceState *dev,
-                                                 Error **errp)
+static void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                             DeviceState *dev, Error **errp)
 {
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
 
@@ -230,7 +229,7 @@ static void pci_bridge_dev_hot_unplug_request_cb(HotplugHandler *hotplug_dev,
                    "this %s", TYPE_PCI_BRIDGE_DEV);
         return;
     }
-    shpc_device_hot_unplug_request_cb(hotplug_dev, dev, errp);
+    shpc_device_unplug_request_cb(hotplug_dev, dev, errp);
 }
 
 static void pci_bridge_dev_class_init(ObjectClass *klass, void *data)
@@ -251,8 +250,8 @@ static void pci_bridge_dev_class_init(ObjectClass *klass, void *data)
     dc->props = pci_bridge_dev_properties;
     dc->vmsd = &pci_bridge_dev_vmstate;
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
-    hc->plug = pci_bridge_dev_hotplug_cb;
-    hc->unplug_request = pci_bridge_dev_hot_unplug_request_cb;
+    hc->plug = pci_bridge_dev_plug_cb;
+    hc->unplug_request = pci_bridge_dev_unplug_request_cb;
 }
 
 static const TypeInfo pci_bridge_dev_info = {
diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridge.c
index 04cf5a6a92..c634353b06 100644
--- a/hw/pci-bridge/pcie_pci_bridge.c
+++ b/hw/pci-bridge/pcie_pci_bridge.c
@@ -137,8 +137,8 @@ static const VMStateDescription pcie_pci_bridge_dev_vmstate = {
         }
 };
 
-static void pcie_pci_bridge_hotplug_cb(HotplugHandler *hotplug_dev,
-                                      DeviceState *dev, Error **errp)
+static void pcie_pci_bridge_plug_cb(HotplugHandler *hotplug_dev,
+                                    DeviceState *dev, Error **errp)
 {
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
 
@@ -147,12 +147,11 @@ static void pcie_pci_bridge_hotplug_cb(HotplugHandler *hotplug_dev,
                    "this %s", TYPE_PCIE_PCI_BRIDGE_DEV);
         return;
     }
-    shpc_device_hotplug_cb(hotplug_dev, dev, errp);
+    shpc_device_plug_cb(hotplug_dev, dev, errp);
 }
 
-static void pcie_pci_bridge_hot_unplug_request_cb(HotplugHandler *hotplug_dev,
-                                                 DeviceState *dev,
-                                                 Error **errp)
+static void pcie_pci_bridge_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                              DeviceState *dev, Error **errp)
 {
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
 
@@ -161,7 +160,7 @@ static void pcie_pci_bridge_hot_unplug_request_cb(HotplugHandler *hotplug_dev,
                    "this %s", TYPE_PCIE_PCI_BRIDGE_DEV);
         return;
     }
-    shpc_device_hot_unplug_request_cb(hotplug_dev, dev, errp);
+    shpc_device_unplug_request_cb(hotplug_dev, dev, errp);
 }
 
 static void pcie_pci_bridge_class_init(ObjectClass *klass, void *data)
@@ -180,8 +179,8 @@ static void pcie_pci_bridge_class_init(ObjectClass *klass, void *data)
     dc->props = pcie_pci_bridge_dev_properties;
     dc->reset = &pcie_pci_bridge_reset;
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
-    hc->plug = pcie_pci_bridge_hotplug_cb;
-    hc->unplug_request = pcie_pci_bridge_hot_unplug_request_cb;
+    hc->plug = pcie_pci_bridge_plug_cb;
+    hc->unplug_request = pcie_pci_bridge_unplug_request_cb;
 }
 
 static const TypeInfo pcie_pci_bridge_info = {
diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index a8462d48bb..098ffaef1d 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -482,8 +482,8 @@ static const MemoryRegionOps shpc_mmio_ops = {
         .max_access_size = 4,
     },
 };
-static void shpc_device_hotplug_common(PCIDevice *affected_dev, int *slot,
-                                       SHPCDevice *shpc, Error **errp)
+static void shpc_device_plug_common(PCIDevice *affected_dev, int *slot,
+                                    SHPCDevice *shpc, Error **errp)
 {
     int pci_slot = PCI_SLOT(affected_dev->devfn);
     *slot = SHPC_PCI_TO_IDX(pci_slot);
@@ -497,7 +497,7 @@ static void shpc_device_hotplug_common(PCIDevice *affected_dev, int *slot,
     }
 }
 
-void shpc_device_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                             Error **errp)
 {
     Error *local_err = NULL;
@@ -505,7 +505,7 @@ void shpc_device_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
     SHPCDevice *shpc = pci_hotplug_dev->shpc;
     int slot;
 
-    shpc_device_hotplug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
+    shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         return;
@@ -540,8 +540,8 @@ void shpc_device_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
     shpc_interrupt_update(pci_hotplug_dev);
 }
 
-void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev,
-                                       DeviceState *dev, Error **errp)
+void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                   DeviceState *dev, Error **errp)
 {
     Error *local_err = NULL;
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
@@ -550,7 +550,7 @@ void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev,
     uint8_t led;
     int slot;
 
-    shpc_device_hotplug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
+    shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         return;
diff --git a/include/hw/pci/shpc.h b/include/hw/pci/shpc.h
index ee19fecf61..71293aca58 100644
--- a/include/hw/pci/shpc.h
+++ b/include/hw/pci/shpc.h
@@ -45,10 +45,10 @@ void shpc_free(PCIDevice *dev);
 void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int len);
 
 
-void shpc_device_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
-                            Error **errp);
-void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev,
-                                       DeviceState *dev, Error **errp);
+void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                         Error **errp);
+void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                   DeviceState *dev, Error **errp);
 
 extern VMStateInfo shpc_vmstate_info;
 #define SHPC_VMSTATE(_field, _type,  _test) \
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 03/11] s390x/pci: rename hotplug handler callbacks
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 01/11] pci/pcie: rename hotplug handler callbacks David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 02/11] pci/shpc: " David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-23 15:07   ` Pierre Morel
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 04/11] pci/pcie: stop plug/unplug if the slot is locked David Hildenbrand
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

The callbacks are also called for cold plugged devices. Drop the "hot"
to better match the actual callback names.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/s390x/s390-pci-bus.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 060ff062bc..9abd49a9dc 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -827,8 +827,8 @@ static bool s390_pci_alloc_idx(S390pciState *s, S390PCIBusDevice *pbdev)
     return true;
 }
 
-static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
-                                  DeviceState *dev, Error **errp)
+static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
+                              Error **errp)
 {
     PCIDevice *pdev = NULL;
     S390PCIBusDevice *pbdev = NULL;
@@ -936,8 +936,8 @@ static void s390_pcihost_timer_cb(void *opaque)
     qdev_unplug(DEVICE(pbdev), NULL);
 }
 
-static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev,
-                                    DeviceState *dev, Error **errp)
+static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
+                                Error **errp)
 {
     PCIDevice *pci_dev = NULL;
     PCIBus *bus;
@@ -1045,8 +1045,8 @@ static void s390_pcihost_class_init(ObjectClass *klass, void *data)
 
     dc->reset = s390_pcihost_reset;
     dc->realize = s390_pcihost_realize;
-    hc->plug = s390_pcihost_hot_plug;
-    hc->unplug = s390_pcihost_hot_unplug;
+    hc->plug = s390_pcihost_plug;
+    hc->unplug = s390_pcihost_unplug;
     msi_nonbroken = true;
 }
 
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 04/11] pci/pcie: stop plug/unplug if the slot is locked
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
                   ` (2 preceding siblings ...)
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 03/11] s390x/pci: " David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 05/11] pci/pcihp: perform check for bus capability in pre_plug handler David Hildenbrand
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

We better stop right away. For now, errors would be partially ignored
(so the guest might get informed or the device might get unplugged),
although actual plug/unplug will be reported as failed to the user.

While at it, properly move the check to the pre_plug handler for the plug
case, as we can test the slot state before the device will be realized.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/pci/pcie.c         | 25 +++++++++++++++++--------
 hw/pci/pcie_port.c    |  1 +
 include/hw/pci/pcie.h |  2 ++
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 44737cc1cd..ccba29269e 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -316,10 +316,10 @@ static void pcie_cap_slot_event(PCIDevice *dev, PCIExpressHotPlugEvent event)
 }
 
 static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev,
-                                      uint8_t **exp_cap, Error **errp)
+                                      Error **errp)
 {
-    *exp_cap = hotplug_dev->config + hotplug_dev->exp.exp_cap;
-    uint16_t sltsta = pci_get_word(*exp_cap + PCI_EXP_SLTSTA);
+    uint8_t *exp_cap = hotplug_dev->config + hotplug_dev->exp.exp_cap;
+    uint16_t sltsta = pci_get_word(exp_cap + PCI_EXP_SLTSTA);
 
     PCIE_DEV_PRINTF(PCI_DEVICE(dev), "hotplug state: 0x%x\n", sltsta);
     if (sltsta & PCI_EXP_SLTSTA_EIS) {
@@ -330,14 +330,19 @@ static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev,
     }
 }
 
+void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                               Error **errp)
+{
+    pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, errp);
+}
+
 void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                            Error **errp)
 {
-    uint8_t *exp_cap;
+    PCIDevice *hotplug_pdev = PCI_DEVICE(hotplug_dev);
+    uint8_t *exp_cap = hotplug_pdev->config + hotplug_pdev->exp.exp_cap;
     PCIDevice *pci_dev = PCI_DEVICE(dev);
 
-    pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
-
     /* Don't send event when device is enabled during qemu machine creation:
      * it is present on boot, no hotplug event is necessary. We do send an
      * event when the device is disabled later. */
@@ -367,11 +372,15 @@ static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque)
 void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
                                      DeviceState *dev, Error **errp)
 {
-    uint8_t *exp_cap;
+    Error *local_err = NULL;
     PCIDevice *pci_dev = PCI_DEVICE(dev);
     PCIBus *bus = pci_get_bus(pci_dev);
 
-    pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp);
+    pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
 
     /* In case user cancel the operation of multi-function hot-add,
      * remove the function that is unexposed to guest individually,
diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c
index 73e81e5847..7982a87880 100644
--- a/hw/pci/pcie_port.c
+++ b/hw/pci/pcie_port.c
@@ -154,6 +154,7 @@ static void pcie_slot_class_init(ObjectClass *oc, void *data)
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
 
     dc->props = pcie_slot_props;
+    hc->pre_plug = pcie_cap_slot_pre_plug_cb;
     hc->plug = pcie_cap_slot_plug_cb;
     hc->unplug_request = pcie_cap_slot_unplug_request_cb;
 }
diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
index 735f8e8154..d9fbcf4a4a 100644
--- a/include/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
@@ -131,6 +131,8 @@ void pcie_ari_init(PCIDevice *dev, uint16_t offset, uint16_t nextfn);
 void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num);
 void pcie_ats_init(PCIDevice *dev, uint16_t offset);
 
+void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                               Error **errp);
 void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                            Error **errp);
 void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 05/11] pci/pcihp: perform check for bus capability in pre_plug handler
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
                   ` (3 preceding siblings ...)
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 04/11] pci/pcie: stop plug/unplug if the slot is locked David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 06/11] pci/pcihp: overwrite hotplug handler recursively from the start David Hildenbrand
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

Perform the check in the pre_plug handler. In addition, we need the
capability only if the device is actually hotplugged (and not created
during machine initialization). This is a preparation for coldplugging
pci devices via that hotplug handler.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/acpi/pcihp.c         | 21 +++++++++++++++------
 hw/acpi/piix4.c         | 16 ++++++++++++++--
 include/hw/acpi/pcihp.h |  2 ++
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 80d42e12ff..5e7cef173c 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -217,17 +217,24 @@ void acpi_pcihp_reset(AcpiPciHpState *s)
     acpi_pcihp_update(s);
 }
 
-void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
-                               DeviceState *dev, Error **errp)
+void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev,
+                                   DeviceState *dev, Error **errp)
 {
-    PCIDevice *pdev = PCI_DEVICE(dev);
-    int slot = PCI_SLOT(pdev->devfn);
-    int bsel = acpi_pcihp_get_bsel(pci_get_bus(pdev));
-    if (bsel < 0) {
+    /* Only hotplugged devices need the hotplug capability. */
+    if (dev->hotplugged &&
+        acpi_pcihp_get_bsel(pci_get_bus(PCI_DEVICE(dev))) < 0) {
         error_setg(errp, "Unsupported bus. Bus doesn't have property '"
                    ACPI_PCIHP_PROP_BSEL "' set");
         return;
     }
+}
+
+void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
+                               DeviceState *dev, Error **errp)
+{
+    PCIDevice *pdev = PCI_DEVICE(dev);
+    int slot = PCI_SLOT(pdev->devfn);
+    int bsel;
 
     /* Don't send event when device is enabled during qemu machine creation:
      * it is present on boot, no hotplug event is necessary. We do send an
@@ -236,6 +243,8 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
         return;
     }
 
+    bsel = acpi_pcihp_get_bsel(pci_get_bus(pdev));
+    g_assert(bsel >= 0);
     s->acpi_pcihp_pci_status[bsel].up |= (1U << slot);
     acpi_send_event(DEVICE(hotplug_dev), ACPI_PCI_HOTPLUG_STATUS);
 }
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index e330f24c71..e586cfdc53 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -370,6 +370,18 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque)
     acpi_pm1_evt_power_down(&s->ar);
 }
 
+static void piix4_device_pre_plug_cb(HotplugHandler *hotplug_dev,
+                                    DeviceState *dev, Error **errp)
+{
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+        acpi_pcihp_device_pre_plug_cb(hotplug_dev, dev, errp);
+    } else if (!object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) &&
+               !object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+        error_setg(errp, "acpi: device pre plug request for not supported"
+                   " device type: %s", object_get_typename(OBJECT(dev)));
+    }
+}
+
 static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
                                  DeviceState *dev, Error **errp)
 {
@@ -392,8 +404,7 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
             acpi_cpu_plug_cb(hotplug_dev, &s->cpuhp_state, dev, errp);
         }
     } else {
-        error_setg(errp, "acpi: device plug request for not supported device"
-                   " type: %s", object_get_typename(OBJECT(dev)));
+        g_assert_not_reached();
     }
 }
 
@@ -702,6 +713,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
      */
     dc->user_creatable = false;
     dc->hotpluggable = false;
+    hc->pre_plug = piix4_device_pre_plug_cb;
     hc->plug = piix4_device_plug_cb;
     hc->unplug_request = piix4_device_unplug_request_cb;
     hc->unplug = piix4_device_unplug_cb;
diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h
index 8a65f99fc8..ce31625850 100644
--- a/include/hw/acpi/pcihp.h
+++ b/include/hw/acpi/pcihp.h
@@ -56,6 +56,8 @@ typedef struct AcpiPciHpState {
 void acpi_pcihp_init(Object *owner, AcpiPciHpState *, PCIBus *root,
                      MemoryRegion *address_space_io, bool bridges_enabled);
 
+void acpi_pcihp_device_pre_plug_cb(HotplugHandler *hotplug_dev,
+                                   DeviceState *dev, Error **errp);
 void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
                                DeviceState *dev, Error **errp);
 void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 06/11] pci/pcihp: overwrite hotplug handler recursively from the start
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
                   ` (4 preceding siblings ...)
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 05/11] pci/pcihp: perform check for bus capability in pre_plug handler David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 07/11] pci/pcihp: perform unplug via the hotplug handler David Hildenbrand
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

For now, the hotplug handler is not called for devices that are
being cold plugged. The hotplug handler is setup when the machine
initialization is fully done. Only bridges that were cold plugged are
considered.

Set the hotplug handler for the root piix bus directly when realizing.
Overwrite the hotplug handler of bridges when coldplugging them.

This will now make sure that the ACPI PCI hotplug handler is also called
for cold plugged devices (also on bridges) but not for bridges that were
hotplugged (keeping the current behavior).

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/acpi/pcihp.c | 15 +++++++++++++++
 hw/acpi/piix4.c | 16 +---------------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 5e7cef173c..05e3f8d11e 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -30,6 +30,7 @@
 #include "hw/hw.h"
 #include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bridge.h"
 #include "hw/acpi/acpi.h"
 #include "sysemu/sysemu.h"
 #include "exec/address-spaces.h"
@@ -240,6 +241,20 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
      * it is present on boot, no hotplug event is necessary. We do send an
      * event when the device is disabled later. */
     if (!dev->hotplugged) {
+        /*
+         * Overwrite the default hotplug handler with the ACPI PCI one
+         * for cold plugged bridges only.
+         */
+        if (!s->legacy_piix &&
+            object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)) {
+            PCIBus *sec = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
+
+            qbus_set_hotplug_handler(BUS(sec), DEVICE(hotplug_dev),
+                                     &error_abort);
+            /* We don't have to overwrite any other hotplug handler yet */
+            assert(QLIST_EMPTY(&sec->child));
+        }
+
         return;
     }
 
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index e586cfdc53..160f727a5e 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -446,15 +446,6 @@ static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
     }
 }
 
-static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
-{
-    PIIX4PMState *s = opaque;
-
-    /* pci_bus cannot outlive PIIX4PMState, because /machine keeps it alive
-     * and it's not hot-unpluggable */
-    qbus_set_hotplug_handler(BUS(pci_bus), DEVICE(s), &error_abort);
-}
-
 static void piix4_pm_machine_ready(Notifier *n, void *opaque)
 {
     PIIX4PMState *s = container_of(n, PIIX4PMState, machine_ready);
@@ -468,12 +459,6 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque)
     pci_conf[0x63] = 0x60;
     pci_conf[0x67] = (memory_region_present(io_as, 0x3f8) ? 0x08 : 0) |
         (memory_region_present(io_as, 0x2f8) ? 0x90 : 0);
-
-    if (s->use_acpi_pci_hotplug) {
-        pci_for_each_bus(pci_get_bus(d), piix4_update_bus_hotplug, s);
-    } else {
-        piix4_update_bus_hotplug(pci_get_bus(d), s);
-    }
 }
 
 static void piix4_pm_add_propeties(PIIX4PMState *s)
@@ -547,6 +532,7 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)
 
     piix4_acpi_system_hot_add_init(pci_address_space_io(dev),
                                    pci_get_bus(dev), s);
+    qbus_set_hotplug_handler(BUS(pci_get_bus(dev)), DEVICE(s), &error_abort);
 
     piix4_pm_add_propeties(s);
 }
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 07/11] pci/pcihp: perform unplug via the hotplug handler
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
                   ` (5 preceding siblings ...)
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 06/11] pci/pcihp: overwrite hotplug handler recursively from the start David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 08/11] pci/pcie: " David Hildenbrand
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

Introduce and use the "unplug" callback.

This is a preparation for multi-stage hotplug handlers, whereby the bus
hotplug handler is overwritten by the machine hotplug handler. This handler
will then pass control to the bus hotplug handler. So to get this running
cleanly, we also have to make sure to go via the hotplug handler chain when
actually unplugging a device after an unplug request. Lookup the hotplug
handler and call "unplug".

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/acpi/pcihp.c         | 11 ++++++++++-
 hw/acpi/piix4.c         |  7 +++++--
 include/hw/acpi/pcihp.h |  3 +++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index 05e3f8d11e..7bc7a72340 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -154,6 +154,7 @@ static bool acpi_pcihp_pc_no_hotplug(AcpiPciHpState *s, PCIDevice *dev)
 
 static void acpi_pcihp_eject_slot(AcpiPciHpState *s, unsigned bsel, unsigned slots)
 {
+    HotplugHandler *hotplug_ctrl;
     BusChild *kid, *next;
     int slot = ctz32(slots);
     PCIBus *bus = acpi_pcihp_find_hotplug_bus(s, bsel);
@@ -171,7 +172,8 @@ static void acpi_pcihp_eject_slot(AcpiPciHpState *s, unsigned bsel, unsigned slo
         PCIDevice *dev = PCI_DEVICE(qdev);
         if (PCI_SLOT(dev->devfn) == slot) {
             if (!acpi_pcihp_pc_no_hotplug(s, dev)) {
-                object_unparent(OBJECT(qdev));
+                hotplug_ctrl = qdev_get_hotplug_handler(qdev);
+                hotplug_handler_unplug(hotplug_ctrl, qdev, &error_abort);
             }
         }
     }
@@ -266,6 +268,13 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
 
 void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
                                  DeviceState *dev, Error **errp)
+{
+    object_unparent(OBJECT(dev));
+}
+
+void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                         AcpiPciHpState *s, DeviceState *dev,
+                                         Error **errp)
 {
     PCIDevice *pdev = PCI_DEVICE(dev);
     int slot = PCI_SLOT(pdev->devfn);
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 160f727a5e..54a12a36f5 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -418,8 +418,8 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,
         acpi_memory_unplug_request_cb(hotplug_dev, &s->acpi_memory_hotplug,
                                       dev, errp);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
-        acpi_pcihp_device_unplug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev,
-                                    errp);
+        acpi_pcihp_device_unplug_request_cb(hotplug_dev, &s->acpi_pci_hotplug,
+                                            dev, errp);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) &&
                !s->cpu_hotplug_legacy) {
         acpi_cpu_unplug_request_cb(hotplug_dev, &s->cpuhp_state, dev, errp);
@@ -437,6 +437,9 @@ static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
     if (s->acpi_memory_hotplug.is_enabled &&
         object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         acpi_memory_unplug_cb(&s->acpi_memory_hotplug, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+        acpi_pcihp_device_unplug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev,
+                                    errp);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) &&
                !s->cpu_hotplug_legacy) {
         acpi_cpu_unplug_cb(&s->cpuhp_state, dev, errp);
diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h
index ce31625850..8bc4a4c01d 100644
--- a/include/hw/acpi/pcihp.h
+++ b/include/hw/acpi/pcihp.h
@@ -62,6 +62,9 @@ void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
                                DeviceState *dev, Error **errp);
 void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
                                  DeviceState *dev, Error **errp);
+void acpi_pcihp_device_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                         AcpiPciHpState *s, DeviceState *dev,
+                                         Error **errp);
 
 /* Called on reset */
 void acpi_pcihp_reset(AcpiPciHpState *s);
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 08/11] pci/pcie: perform unplug via the hotplug handler
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
                   ` (6 preceding siblings ...)
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 07/11] pci/pcihp: perform unplug via the hotplug handler David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 09/11] pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge David Hildenbrand
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

Introduce and use the "unplug" callback.

This is a preparation for multi-stage hotplug handlers, whereby the bus
hotplug handler is overwritten by the machine hotplug handler. This handler
will then pass control to the bus hotplug handler. So to get this running
cleanly, we also have to make sure to go via the hotplug handler chain when
actually unplugging a device after an unplug request. Lookup the hotplug
handler and call "unplug".

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/pci/pcie.c         | 10 +++++++++-
 hw/pci/pcie_port.c    |  1 +
 include/hw/pci/pcie.h |  2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index ccba29269e..ba3ea925e9 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -364,11 +364,19 @@ void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
     }
 }
 
-static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque)
+void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                             Error **errp)
 {
     object_unparent(OBJECT(dev));
 }
 
+static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque)
+{
+    HotplugHandler *hotplug_ctrl = qdev_get_hotplug_handler(DEVICE(dev));
+
+    hotplug_handler_unplug(hotplug_ctrl, DEVICE(dev), &error_abort);
+}
+
 void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
                                      DeviceState *dev, Error **errp)
 {
diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c
index 7982a87880..a30291ef54 100644
--- a/hw/pci/pcie_port.c
+++ b/hw/pci/pcie_port.c
@@ -156,6 +156,7 @@ static void pcie_slot_class_init(ObjectClass *oc, void *data)
     dc->props = pcie_slot_props;
     hc->pre_plug = pcie_cap_slot_pre_plug_cb;
     hc->plug = pcie_cap_slot_plug_cb;
+    hc->unplug = pcie_cap_slot_unplug_cb;
     hc->unplug_request = pcie_cap_slot_unplug_request_cb;
 }
 
diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
index d9fbcf4a4a..9ae6482658 100644
--- a/include/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
@@ -135,6 +135,8 @@ void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                                Error **errp);
 void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                            Error **errp);
+void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                             Error **errp);
 void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
                                      DeviceState *dev, Error **errp);
 #endif /* QEMU_PCIE_H */
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 09/11] pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
                   ` (7 preceding siblings ...)
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 08/11] pci/pcie: " David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-20 15:15   ` Igor Mammedov
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 10/11] pci/shpc: perform unplug via the hotplug handler David Hildenbrand
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

These functions are essentially the same, we only have to use
object_get_typename() for reporting errors. So let's share the
implementation of hotplug handler callbacks.

Suggested-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/pci-bridge/pci_bridge_dev.c  | 12 ++++++------
 hw/pci-bridge/pcie_pci_bridge.c | 30 ++----------------------------
 include/hw/pci/pci_bridge.h     |  4 ++++
 3 files changed, 12 insertions(+), 34 deletions(-)

diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
index e1df9a52ac..fa0be13ac4 100644
--- a/hw/pci-bridge/pci_bridge_dev.c
+++ b/hw/pci-bridge/pci_bridge_dev.c
@@ -206,27 +206,27 @@ static const VMStateDescription pci_bridge_dev_vmstate = {
     }
 };
 
-static void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev,
-                                   DeviceState *dev, Error **errp)
+void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                            Error **errp)
 {
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
 
     if (!shpc_present(pci_hotplug_dev)) {
         error_setg(errp, "standard hotplug controller has been disabled for "
-                   "this %s", TYPE_PCI_BRIDGE_DEV);
+                   "this %s", object_get_typename(OBJECT(hotplug_dev)));
         return;
     }
     shpc_device_plug_cb(hotplug_dev, dev, errp);
 }
 
-static void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
-                                             DeviceState *dev, Error **errp)
+void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                      DeviceState *dev, Error **errp)
 {
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
 
     if (!shpc_present(pci_hotplug_dev)) {
         error_setg(errp, "standard hotplug controller has been disabled for "
-                   "this %s", TYPE_PCI_BRIDGE_DEV);
+                   "this %s", object_get_typename(OBJECT(hotplug_dev)));
         return;
     }
     shpc_device_unplug_request_cb(hotplug_dev, dev, errp);
diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridge.c
index c634353b06..0ffea680d5 100644
--- a/hw/pci-bridge/pcie_pci_bridge.c
+++ b/hw/pci-bridge/pcie_pci_bridge.c
@@ -137,32 +137,6 @@ static const VMStateDescription pcie_pci_bridge_dev_vmstate = {
         }
 };
 
-static void pcie_pci_bridge_plug_cb(HotplugHandler *hotplug_dev,
-                                    DeviceState *dev, Error **errp)
-{
-    PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
-
-    if (!shpc_present(pci_hotplug_dev)) {
-        error_setg(errp, "standard hotplug controller has been disabled for "
-                   "this %s", TYPE_PCIE_PCI_BRIDGE_DEV);
-        return;
-    }
-    shpc_device_plug_cb(hotplug_dev, dev, errp);
-}
-
-static void pcie_pci_bridge_unplug_request_cb(HotplugHandler *hotplug_dev,
-                                              DeviceState *dev, Error **errp)
-{
-    PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
-
-    if (!shpc_present(pci_hotplug_dev)) {
-        error_setg(errp, "standard hotplug controller has been disabled for "
-                   "this %s", TYPE_PCIE_PCI_BRIDGE_DEV);
-        return;
-    }
-    shpc_device_unplug_request_cb(hotplug_dev, dev, errp);
-}
-
 static void pcie_pci_bridge_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -179,8 +153,8 @@ static void pcie_pci_bridge_class_init(ObjectClass *klass, void *data)
     dc->props = pcie_pci_bridge_dev_properties;
     dc->reset = &pcie_pci_bridge_reset;
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
-    hc->plug = pcie_pci_bridge_plug_cb;
-    hc->unplug_request = pcie_pci_bridge_unplug_request_cb;
+    hc->plug = pci_bridge_dev_plug_cb;
+    hc->unplug_request = pci_bridge_dev_unplug_request_cb;
 }
 
 static const TypeInfo pcie_pci_bridge_info = {
diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h
index cdff7edfd1..6e37c7551a 100644
--- a/include/hw/pci/pci_bridge.h
+++ b/include/hw/pci/pci_bridge.h
@@ -99,6 +99,10 @@ void pci_bridge_reset(DeviceState *qdev);
 void pci_bridge_initfn(PCIDevice *pci_dev, const char *typename);
 void pci_bridge_exitfn(PCIDevice *pci_dev);
 
+void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                            Error **errp);
+void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                      DeviceState *dev, Error **errp);
 
 /*
  * before qdev initialization(qdev_init()), this function sets bus_name and
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 10/11] pci/shpc: perform unplug via the hotplug handler
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
                   ` (8 preceding siblings ...)
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 09/11] pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-20 15:19   ` Igor Mammedov
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 11/11] spapr_pci: " David Hildenbrand
  2018-11-21 12:43 ` [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
  11 siblings, 1 reply; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

Introduce and use the "unplug" callback.

This is a preparation for multi-stage hotplug handlers, whereby the bus
hotplug handler is overwritten by the machine hotplug handler. This handler
will then pass control to the bus hotplug handler. So to get this running
cleanly, we also have to make sure to go via the hotplug handler chain when
actually unplugging a device after an unplug request. Lookup the hotplug
handler and call "unplug".

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/pci-bridge/pci_bridge_dev.c  | 10 ++++++++++
 hw/pci-bridge/pcie_pci_bridge.c |  1 +
 hw/pci/shpc.c                   | 11 ++++++++++-
 include/hw/pci/pci_bridge.h     |  2 ++
 include/hw/pci/shpc.h           |  2 ++
 5 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
index fa0be13ac4..ff6b8323da 100644
--- a/hw/pci-bridge/pci_bridge_dev.c
+++ b/hw/pci-bridge/pci_bridge_dev.c
@@ -219,6 +219,15 @@ void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
     shpc_device_plug_cb(hotplug_dev, dev, errp);
 }
 
+void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                              Error **errp)
+{
+    PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
+
+    g_assert(shpc_present(pci_hotplug_dev));
+    shpc_device_unplug_cb(hotplug_dev, dev, errp);
+}
+
 void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
                                       DeviceState *dev, Error **errp)
 {
@@ -251,6 +260,7 @@ static void pci_bridge_dev_class_init(ObjectClass *klass, void *data)
     dc->vmsd = &pci_bridge_dev_vmstate;
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     hc->plug = pci_bridge_dev_plug_cb;
+    hc->unplug = pci_bridge_dev_unplug_cb;
     hc->unplug_request = pci_bridge_dev_unplug_request_cb;
 }
 
diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridge.c
index 0ffea680d5..d491b40d04 100644
--- a/hw/pci-bridge/pcie_pci_bridge.c
+++ b/hw/pci-bridge/pcie_pci_bridge.c
@@ -154,6 +154,7 @@ static void pcie_pci_bridge_class_init(ObjectClass *klass, void *data)
     dc->reset = &pcie_pci_bridge_reset;
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     hc->plug = pci_bridge_dev_plug_cb;
+    hc->unplug = pci_bridge_dev_unplug_cb;
     hc->unplug_request = pci_bridge_dev_unplug_request_cb;
 }
 
diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index 098ffaef1d..5de905cb56 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -238,6 +238,7 @@ static void shpc_invalid_command(SHPCDevice *shpc)
 
 static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
 {
+    HotplugHandler *hotplug_ctrl;
     int devfn;
     int pci_slot = SHPC_IDX_TO_PCI(slot);
     for (devfn = PCI_DEVFN(pci_slot, 0);
@@ -245,7 +246,9 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
          ++devfn) {
         PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
         if (affected_dev) {
-            object_unparent(OBJECT(affected_dev));
+            hotplug_ctrl = qdev_get_hotplug_handler(DEVICE(affected_dev));
+            hotplug_handler_unplug(hotplug_ctrl, DEVICE(affected_dev),
+                                   &error_abort);
         }
     }
 }
@@ -540,6 +543,12 @@ void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
     shpc_interrupt_update(pci_hotplug_dev);
 }
 
+void shpc_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                           Error **errp)
+{
+    object_unparent(OBJECT(dev));
+}
+
 void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
                                    DeviceState *dev, Error **errp)
 {
diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h
index 6e37c7551a..ba488818d2 100644
--- a/include/hw/pci/pci_bridge.h
+++ b/include/hw/pci/pci_bridge.h
@@ -101,6 +101,8 @@ void pci_bridge_exitfn(PCIDevice *pci_dev);
 
 void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                             Error **errp);
+void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                              Error **errp);
 void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
                                       DeviceState *dev, Error **errp);
 
diff --git a/include/hw/pci/shpc.h b/include/hw/pci/shpc.h
index 71293aca58..18f6ec1cd5 100644
--- a/include/hw/pci/shpc.h
+++ b/include/hw/pci/shpc.h
@@ -47,6 +47,8 @@ void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int len);
 
 void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                          Error **errp);
+void shpc_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
+                           Error **errp);
 void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
                                    DeviceState *dev, Error **errp);
 
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3 11/11] spapr_pci: perform unplug via the hotplug handler
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
                   ` (9 preceding siblings ...)
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 10/11] pci/shpc: perform unplug via the hotplug handler David Hildenbrand
@ 2018-11-20 11:04 ` David Hildenbrand
  2018-11-21 12:43 ` [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
  11 siblings, 0 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-20 11:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc, David Hildenbrand

Introduce and use the "unplug" callback.

This is a preparation for multi-stage hotplug handlers, whereby the bus
hotplug handler is overwritten by the machine hotplug handler. This handler
will then pass control to the bus hotplug handler. So to get this running
cleanly, we also have to make sure to go via the hotplug handler chain when
actually unplugging a device after an unplug request. Lookup the hotplug
handler and call "unplug".

Reviewed-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/ppc/spapr_pci.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 2374d55fc1..bfb02ee96b 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -1370,18 +1370,9 @@ static int spapr_create_pci_child_dt(sPAPRPHBState *phb, PCIDevice *dev,
 /* Callback to be called during DRC release. */
 void spapr_phb_remove_pci_device_cb(DeviceState *dev)
 {
-    /* some version guests do not wait for completion of a device
-     * cleanup (generally done asynchronously by the kernel) before
-     * signaling to QEMU that the device is safe, but instead sleep
-     * for some 'safe' period of time. unfortunately on a busy host
-     * this sleep isn't guaranteed to be long enough, resulting in
-     * bad things like IRQ lines being left asserted during final
-     * device removal. to deal with this we call reset just prior
-     * to finalizing the device, which will put the device back into
-     * an 'idle' state, as the device cleanup code expects.
-     */
-    pci_device_reset(PCI_DEVICE(dev));
-    object_unparent(OBJECT(dev));
+    HotplugHandler *hotplug_ctrl = qdev_get_hotplug_handler(dev);
+
+    hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort);
 }
 
 static sPAPRDRConnector *spapr_phb_get_pci_func_drc(sPAPRPHBState *phb,
@@ -1490,6 +1481,23 @@ out:
     }
 }
 
+static void spapr_pci_unplug(HotplugHandler *plug_handler,
+                             DeviceState *plugged_dev, Error **errp)
+{
+    /* some version guests do not wait for completion of a device
+     * cleanup (generally done asynchronously by the kernel) before
+     * signaling to QEMU that the device is safe, but instead sleep
+     * for some 'safe' period of time. unfortunately on a busy host
+     * this sleep isn't guaranteed to be long enough, resulting in
+     * bad things like IRQ lines being left asserted during final
+     * device removal. to deal with this we call reset just prior
+     * to finalizing the device, which will put the device back into
+     * an 'idle' state, as the device cleanup code expects.
+     */
+    pci_device_reset(PCI_DEVICE(plugged_dev));
+    object_unparent(OBJECT(plugged_dev));
+}
+
 static void spapr_pci_unplug_request(HotplugHandler *plug_handler,
                                      DeviceState *plugged_dev, Error **errp)
 {
@@ -1965,6 +1973,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data)
     dc->user_creatable = true;
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     hp->plug = spapr_pci_plug;
+    hp->unplug = spapr_pci_unplug;
     hp->unplug_request = spapr_pci_unplug_request;
 }
 
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v3 09/11] pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 09/11] pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge David Hildenbrand
@ 2018-11-20 15:15   ` Igor Mammedov
  0 siblings, 0 replies; 18+ messages in thread
From: Igor Mammedov @ 2018-11-20 15:15 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, David Gibson, Greg Kurz,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc

On Tue, 20 Nov 2018 12:04:25 +0100
David Hildenbrand <david@redhat.com> wrote:

> These functions are essentially the same, we only have to use
> object_get_typename() for reporting errors. So let's share the
> implementation of hotplug handler callbacks.
> 
> Suggested-by: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  hw/pci-bridge/pci_bridge_dev.c  | 12 ++++++------
>  hw/pci-bridge/pcie_pci_bridge.c | 30 ++----------------------------
>  include/hw/pci/pci_bridge.h     |  4 ++++
>  3 files changed, 12 insertions(+), 34 deletions(-)
> 
> diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
> index e1df9a52ac..fa0be13ac4 100644
> --- a/hw/pci-bridge/pci_bridge_dev.c
> +++ b/hw/pci-bridge/pci_bridge_dev.c
> @@ -206,27 +206,27 @@ static const VMStateDescription pci_bridge_dev_vmstate = {
>      }
>  };
>  
> -static void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev,
> -                                   DeviceState *dev, Error **errp)
> +void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
> +                            Error **errp)
>  {
>      PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
>  
>      if (!shpc_present(pci_hotplug_dev)) {
>          error_setg(errp, "standard hotplug controller has been disabled for "
> -                   "this %s", TYPE_PCI_BRIDGE_DEV);
> +                   "this %s", object_get_typename(OBJECT(hotplug_dev)));
>          return;
>      }
>      shpc_device_plug_cb(hotplug_dev, dev, errp);
>  }
>  
> -static void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
> -                                             DeviceState *dev, Error **errp)
> +void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
> +                                      DeviceState *dev, Error **errp)
>  {
>      PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
>  
>      if (!shpc_present(pci_hotplug_dev)) {
>          error_setg(errp, "standard hotplug controller has been disabled for "
> -                   "this %s", TYPE_PCI_BRIDGE_DEV);
> +                   "this %s", object_get_typename(OBJECT(hotplug_dev)));
>          return;
>      }
>      shpc_device_unplug_request_cb(hotplug_dev, dev, errp);
> diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridge.c
> index c634353b06..0ffea680d5 100644
> --- a/hw/pci-bridge/pcie_pci_bridge.c
> +++ b/hw/pci-bridge/pcie_pci_bridge.c
> @@ -137,32 +137,6 @@ static const VMStateDescription pcie_pci_bridge_dev_vmstate = {
>          }
>  };
>  
> -static void pcie_pci_bridge_plug_cb(HotplugHandler *hotplug_dev,
> -                                    DeviceState *dev, Error **errp)
> -{
> -    PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
> -
> -    if (!shpc_present(pci_hotplug_dev)) {
> -        error_setg(errp, "standard hotplug controller has been disabled for "
> -                   "this %s", TYPE_PCIE_PCI_BRIDGE_DEV);
> -        return;
> -    }
> -    shpc_device_plug_cb(hotplug_dev, dev, errp);
> -}
> -
> -static void pcie_pci_bridge_unplug_request_cb(HotplugHandler *hotplug_dev,
> -                                              DeviceState *dev, Error **errp)
> -{
> -    PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
> -
> -    if (!shpc_present(pci_hotplug_dev)) {
> -        error_setg(errp, "standard hotplug controller has been disabled for "
> -                   "this %s", TYPE_PCIE_PCI_BRIDGE_DEV);
> -        return;
> -    }
> -    shpc_device_unplug_request_cb(hotplug_dev, dev, errp);
> -}
> -
>  static void pcie_pci_bridge_class_init(ObjectClass *klass, void *data)
>  {
>      PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
> @@ -179,8 +153,8 @@ static void pcie_pci_bridge_class_init(ObjectClass *klass, void *data)
>      dc->props = pcie_pci_bridge_dev_properties;
>      dc->reset = &pcie_pci_bridge_reset;
>      set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
> -    hc->plug = pcie_pci_bridge_plug_cb;
> -    hc->unplug_request = pcie_pci_bridge_unplug_request_cb;
> +    hc->plug = pci_bridge_dev_plug_cb;
> +    hc->unplug_request = pci_bridge_dev_unplug_request_cb;
>  }
>  
>  static const TypeInfo pcie_pci_bridge_info = {
> diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h
> index cdff7edfd1..6e37c7551a 100644
> --- a/include/hw/pci/pci_bridge.h
> +++ b/include/hw/pci/pci_bridge.h
> @@ -99,6 +99,10 @@ void pci_bridge_reset(DeviceState *qdev);
>  void pci_bridge_initfn(PCIDevice *pci_dev, const char *typename);
>  void pci_bridge_exitfn(PCIDevice *pci_dev);
>  
> +void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
> +                            Error **errp);
> +void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
> +                                      DeviceState *dev, Error **errp);
>  
>  /*
>   * before qdev initialization(qdev_init()), this function sets bus_name and

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v3 10/11] pci/shpc: perform unplug via the hotplug handler
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 10/11] pci/shpc: perform unplug via the hotplug handler David Hildenbrand
@ 2018-11-20 15:19   ` Igor Mammedov
  0 siblings, 0 replies; 18+ messages in thread
From: Igor Mammedov @ 2018-11-20 15:19 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, David Gibson, Greg Kurz,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc

On Tue, 20 Nov 2018 12:04:26 +0100
David Hildenbrand <david@redhat.com> wrote:

> Introduce and use the "unplug" callback.
> 
> This is a preparation for multi-stage hotplug handlers, whereby the bus
> hotplug handler is overwritten by the machine hotplug handler. This handler
> will then pass control to the bus hotplug handler. So to get this running
> cleanly, we also have to make sure to go via the hotplug handler chain when
> actually unplugging a device after an unplug request. Lookup the hotplug
> handler and call "unplug".
> 
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  hw/pci-bridge/pci_bridge_dev.c  | 10 ++++++++++
>  hw/pci-bridge/pcie_pci_bridge.c |  1 +
>  hw/pci/shpc.c                   | 11 ++++++++++-
>  include/hw/pci/pci_bridge.h     |  2 ++
>  include/hw/pci/shpc.h           |  2 ++
>  5 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
> index fa0be13ac4..ff6b8323da 100644
> --- a/hw/pci-bridge/pci_bridge_dev.c
> +++ b/hw/pci-bridge/pci_bridge_dev.c
> @@ -219,6 +219,15 @@ void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
>      shpc_device_plug_cb(hotplug_dev, dev, errp);
>  }
>  
> +void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
> +                              Error **errp)
> +{
> +    PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
> +
> +    g_assert(shpc_present(pci_hotplug_dev));
> +    shpc_device_unplug_cb(hotplug_dev, dev, errp);
> +}
> +
>  void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
>                                        DeviceState *dev, Error **errp)
>  {
> @@ -251,6 +260,7 @@ static void pci_bridge_dev_class_init(ObjectClass *klass, void *data)
>      dc->vmsd = &pci_bridge_dev_vmstate;
>      set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
>      hc->plug = pci_bridge_dev_plug_cb;
> +    hc->unplug = pci_bridge_dev_unplug_cb;
>      hc->unplug_request = pci_bridge_dev_unplug_request_cb;
>  }
>  
> diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridge.c
> index 0ffea680d5..d491b40d04 100644
> --- a/hw/pci-bridge/pcie_pci_bridge.c
> +++ b/hw/pci-bridge/pcie_pci_bridge.c
> @@ -154,6 +154,7 @@ static void pcie_pci_bridge_class_init(ObjectClass *klass, void *data)
>      dc->reset = &pcie_pci_bridge_reset;
>      set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
>      hc->plug = pci_bridge_dev_plug_cb;
> +    hc->unplug = pci_bridge_dev_unplug_cb;
>      hc->unplug_request = pci_bridge_dev_unplug_request_cb;
>  }
>  
> diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
> index 098ffaef1d..5de905cb56 100644
> --- a/hw/pci/shpc.c
> +++ b/hw/pci/shpc.c
> @@ -238,6 +238,7 @@ static void shpc_invalid_command(SHPCDevice *shpc)
>  
>  static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
>  {
> +    HotplugHandler *hotplug_ctrl;
>      int devfn;
>      int pci_slot = SHPC_IDX_TO_PCI(slot);
>      for (devfn = PCI_DEVFN(pci_slot, 0);
> @@ -245,7 +246,9 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
>           ++devfn) {
>          PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
>          if (affected_dev) {
> -            object_unparent(OBJECT(affected_dev));
> +            hotplug_ctrl = qdev_get_hotplug_handler(DEVICE(affected_dev));
> +            hotplug_handler_unplug(hotplug_ctrl, DEVICE(affected_dev),
> +                                   &error_abort);
>          }
>      }
>  }
> @@ -540,6 +543,12 @@ void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
>      shpc_interrupt_update(pci_hotplug_dev);
>  }
>  
> +void shpc_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
> +                           Error **errp)
> +{
> +    object_unparent(OBJECT(dev));
> +}
> +
>  void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
>                                     DeviceState *dev, Error **errp)
>  {
> diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h
> index 6e37c7551a..ba488818d2 100644
> --- a/include/hw/pci/pci_bridge.h
> +++ b/include/hw/pci/pci_bridge.h
> @@ -101,6 +101,8 @@ void pci_bridge_exitfn(PCIDevice *pci_dev);
>  
>  void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
>                              Error **errp);
> +void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
> +                              Error **errp);
>  void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
>                                        DeviceState *dev, Error **errp);
>  
> diff --git a/include/hw/pci/shpc.h b/include/hw/pci/shpc.h
> index 71293aca58..18f6ec1cd5 100644
> --- a/include/hw/pci/shpc.h
> +++ b/include/hw/pci/shpc.h
> @@ -47,6 +47,8 @@ void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int len);
>  
>  void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
>                           Error **errp);
> +void shpc_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
> +                           Error **errp);
>  void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
>                                     DeviceState *dev, Error **errp);
>  

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks
  2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
                   ` (10 preceding siblings ...)
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 11/11] spapr_pci: " David Hildenbrand
@ 2018-11-21 12:43 ` David Hildenbrand
  2018-11-21 13:28   ` Michael S. Tsirkin
  11 siblings, 1 reply; 18+ messages in thread
From: David Hildenbrand @ 2018-11-21 12:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc

On 20.11.18 12:04, David Hildenbrand wrote:
> This series reworks some pci hotplug handlers (except for s390, that will
> require more work but is not required for now).
> 
> 1. Route all unplug calls via the hotplug handler when called from the
>    unplug_request handler. This will be required to get multi-stage
>    hotplug handlers running, but also makes sense on its own (just like we
>    already did for some CPU/memory hotplug handlers).
> 
> 2. Introduce some pre_plug handlers where it makes sense already.
> 
> 3. Call the plug/pre_plug handler also for coldplugged devices. Especially
>    pcihp is special as it overwrites hotplug handlers.
> 
> This series will not yet factor out pre_plug/plug/unplug from pci device
> realize/unrealize functions, this will require more work but this
> series is also required first to get it running.
> 
> In my opinion what needs to be done in the future:
> 1. Introduce pre_plug/plug/unplug_request/unplug handlers for all PCI
>    buses
> 2. Move pci realize/unrealize parts to pre_plug/pkug/unplug functions like
>    pci_pre_plug() ...
> 3. Call the pci pre_plug/plug/unplug handlers from the PCI bus hotplug
>    handler at the right spots
> 4. Factor more checks from existing plug() handlers out into pre_plug()
>    (e.g. after the call to pci_pre_plug())
> 
> v2 -> v3:
> - Added "pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge"
> -- Use one handler callback for pcie and !pcie
> - "pci/shpc: perform unplug via the hotplug handler"
> -- Use one handler callback for pcie and !pcie
> -- Replace error check by an assertion
> - Minor description changes.
> - Added Rbs
> 
> v1 -> v2:
> - Added "pci/pcie: rename hotplug handler callbacks"
> - Added "pci/shpc: rename hotplug handler callbacks"
> - Added "s390x/pci: rename hotplug handler callbacks"
> - Dropped "pci/shpc: move hotplug checks to preplug handler"
> -- We will have to factor out stuff into pre_plug() first as described
>    above
> - Renamed and added more details to the "perform unplug via the hotplug
>   handler" patches
> - "pci/pcihp: overwrite hotplug handler recursively from the start"
> -- Perform the overwrite only for cold plugged bridges, to keep the
>    existing behavior
> 
> David Hildenbrand (11):
>   pci/pcie: rename hotplug handler callbacks
>   pci/shpc: rename hotplug handler callbacks
>   s390x/pci: rename hotplug handler callbacks
>   pci/pcie: stop plug/unplug if the slot is locked
>   pci/pcihp: perform check for bus capability in pre_plug handler
>   pci/pcihp: overwrite hotplug handler recursively from the start
>   pci/pcihp: perform unplug via the hotplug handler
>   pci/pcie: perform unplug via the hotplug handler
>   pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge
>   pci/shpc: perform unplug via the hotplug handler
>   spapr_pci: perform unplug via the hotplug handler
> 
>  hw/acpi/pcihp.c                 | 47 ++++++++++++++++++++++++++++-----
>  hw/acpi/piix4.c                 | 39 ++++++++++++++-------------
>  hw/pci-bridge/pci_bridge_dev.c  | 31 ++++++++++++++--------
>  hw/pci-bridge/pcie_pci_bridge.c | 32 +++-------------------
>  hw/pci/pcie.c                   | 46 +++++++++++++++++++++-----------
>  hw/pci/pcie_port.c              |  6 +++--
>  hw/pci/shpc.c                   | 25 ++++++++++++------
>  hw/ppc/spapr_pci.c              | 33 ++++++++++++++---------
>  hw/s390x/s390-pci-bus.c         | 12 ++++-----
>  include/hw/acpi/pcihp.h         |  5 ++++
>  include/hw/pci/pci_bridge.h     |  6 +++++
>  include/hw/pci/pcie.h           | 12 ++++++---
>  include/hw/pci/shpc.h           | 10 ++++---
>  13 files changed, 187 insertions(+), 117 deletions(-)
> 

Seems like everything is reviewed and this is good to go. Anybody fancy
queuing this? (@mst?) Thanks!

-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks
  2018-11-21 12:43 ` [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
@ 2018-11-21 13:28   ` Michael S. Tsirkin
  2018-11-21 16:26     ` David Hildenbrand
  0 siblings, 1 reply; 18+ messages in thread
From: Michael S. Tsirkin @ 2018-11-21 13:28 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc

On Wed, Nov 21, 2018 at 01:43:05PM +0100, David Hildenbrand wrote:
> On 20.11.18 12:04, David Hildenbrand wrote:
> > This series reworks some pci hotplug handlers (except for s390, that will
> > require more work but is not required for now).
> > 
> > 1. Route all unplug calls via the hotplug handler when called from the
> >    unplug_request handler. This will be required to get multi-stage
> >    hotplug handlers running, but also makes sense on its own (just like we
> >    already did for some CPU/memory hotplug handlers).
> > 
> > 2. Introduce some pre_plug handlers where it makes sense already.
> > 
> > 3. Call the plug/pre_plug handler also for coldplugged devices. Especially
> >    pcihp is special as it overwrites hotplug handlers.
> > 
> > This series will not yet factor out pre_plug/plug/unplug from pci device
> > realize/unrealize functions, this will require more work but this
> > series is also required first to get it running.
> > 
> > In my opinion what needs to be done in the future:
> > 1. Introduce pre_plug/plug/unplug_request/unplug handlers for all PCI
> >    buses
> > 2. Move pci realize/unrealize parts to pre_plug/pkug/unplug functions like
> >    pci_pre_plug() ...
> > 3. Call the pci pre_plug/plug/unplug handlers from the PCI bus hotplug
> >    handler at the right spots
> > 4. Factor more checks from existing plug() handlers out into pre_plug()
> >    (e.g. after the call to pci_pre_plug())
> > 
> > v2 -> v3:
> > - Added "pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge"
> > -- Use one handler callback for pcie and !pcie
> > - "pci/shpc: perform unplug via the hotplug handler"
> > -- Use one handler callback for pcie and !pcie
> > -- Replace error check by an assertion
> > - Minor description changes.
> > - Added Rbs
> > 
> > v1 -> v2:
> > - Added "pci/pcie: rename hotplug handler callbacks"
> > - Added "pci/shpc: rename hotplug handler callbacks"
> > - Added "s390x/pci: rename hotplug handler callbacks"
> > - Dropped "pci/shpc: move hotplug checks to preplug handler"
> > -- We will have to factor out stuff into pre_plug() first as described
> >    above
> > - Renamed and added more details to the "perform unplug via the hotplug
> >   handler" patches
> > - "pci/pcihp: overwrite hotplug handler recursively from the start"
> > -- Perform the overwrite only for cold plugged bridges, to keep the
> >    existing behavior
> > 
> > David Hildenbrand (11):
> >   pci/pcie: rename hotplug handler callbacks
> >   pci/shpc: rename hotplug handler callbacks
> >   s390x/pci: rename hotplug handler callbacks
> >   pci/pcie: stop plug/unplug if the slot is locked
> >   pci/pcihp: perform check for bus capability in pre_plug handler
> >   pci/pcihp: overwrite hotplug handler recursively from the start
> >   pci/pcihp: perform unplug via the hotplug handler
> >   pci/pcie: perform unplug via the hotplug handler
> >   pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge
> >   pci/shpc: perform unplug via the hotplug handler
> >   spapr_pci: perform unplug via the hotplug handler
> > 
> >  hw/acpi/pcihp.c                 | 47 ++++++++++++++++++++++++++++-----
> >  hw/acpi/piix4.c                 | 39 ++++++++++++++-------------
> >  hw/pci-bridge/pci_bridge_dev.c  | 31 ++++++++++++++--------
> >  hw/pci-bridge/pcie_pci_bridge.c | 32 +++-------------------
> >  hw/pci/pcie.c                   | 46 +++++++++++++++++++++-----------
> >  hw/pci/pcie_port.c              |  6 +++--
> >  hw/pci/shpc.c                   | 25 ++++++++++++------
> >  hw/ppc/spapr_pci.c              | 33 ++++++++++++++---------
> >  hw/s390x/s390-pci-bus.c         | 12 ++++-----
> >  include/hw/acpi/pcihp.h         |  5 ++++
> >  include/hw/pci/pci_bridge.h     |  6 +++++
> >  include/hw/pci/pcie.h           | 12 ++++++---
> >  include/hw/pci/shpc.h           | 10 ++++---
> >  13 files changed, 187 insertions(+), 117 deletions(-)
> > 
> 
> Seems like everything is reviewed and this is good to go. Anybody fancy
> queuing this? (@mst?) Thanks!

Yes, thanks! But we are in freeze so please repost after the release and I will queue.

> -- 
> 
> Thanks,
> 
> David / dhildenb

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks
  2018-11-21 13:28   ` Michael S. Tsirkin
@ 2018-11-21 16:26     ` David Hildenbrand
  0 siblings, 0 replies; 18+ messages in thread
From: David Hildenbrand @ 2018-11-21 16:26 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: qemu-devel, David Gibson, Greg Kurz, Igor Mammedov,
	Marcel Apfelbaum, Cornelia Huck, Christian Borntraeger,
	qemu-s390x, Richard Henderson, Collin Walling, Thomas Huth,
	qemu-ppc

On 21.11.18 14:28, Michael S. Tsirkin wrote:
> On Wed, Nov 21, 2018 at 01:43:05PM +0100, David Hildenbrand wrote:
>> On 20.11.18 12:04, David Hildenbrand wrote:
>>> This series reworks some pci hotplug handlers (except for s390, that will
>>> require more work but is not required for now).
>>>
>>> 1. Route all unplug calls via the hotplug handler when called from the
>>>    unplug_request handler. This will be required to get multi-stage
>>>    hotplug handlers running, but also makes sense on its own (just like we
>>>    already did for some CPU/memory hotplug handlers).
>>>
>>> 2. Introduce some pre_plug handlers where it makes sense already.
>>>
>>> 3. Call the plug/pre_plug handler also for coldplugged devices. Especially
>>>    pcihp is special as it overwrites hotplug handlers.
>>>
>>> This series will not yet factor out pre_plug/plug/unplug from pci device
>>> realize/unrealize functions, this will require more work but this
>>> series is also required first to get it running.
>>>
>>> In my opinion what needs to be done in the future:
>>> 1. Introduce pre_plug/plug/unplug_request/unplug handlers for all PCI
>>>    buses
>>> 2. Move pci realize/unrealize parts to pre_plug/pkug/unplug functions like
>>>    pci_pre_plug() ...
>>> 3. Call the pci pre_plug/plug/unplug handlers from the PCI bus hotplug
>>>    handler at the right spots
>>> 4. Factor more checks from existing plug() handlers out into pre_plug()
>>>    (e.g. after the call to pci_pre_plug())
>>>
>>> v2 -> v3:
>>> - Added "pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge"
>>> -- Use one handler callback for pcie and !pcie
>>> - "pci/shpc: perform unplug via the hotplug handler"
>>> -- Use one handler callback for pcie and !pcie
>>> -- Replace error check by an assertion
>>> - Minor description changes.
>>> - Added Rbs
>>>
>>> v1 -> v2:
>>> - Added "pci/pcie: rename hotplug handler callbacks"
>>> - Added "pci/shpc: rename hotplug handler callbacks"
>>> - Added "s390x/pci: rename hotplug handler callbacks"
>>> - Dropped "pci/shpc: move hotplug checks to preplug handler"
>>> -- We will have to factor out stuff into pre_plug() first as described
>>>    above
>>> - Renamed and added more details to the "perform unplug via the hotplug
>>>   handler" patches
>>> - "pci/pcihp: overwrite hotplug handler recursively from the start"
>>> -- Perform the overwrite only for cold plugged bridges, to keep the
>>>    existing behavior
>>>
>>> David Hildenbrand (11):
>>>   pci/pcie: rename hotplug handler callbacks
>>>   pci/shpc: rename hotplug handler callbacks
>>>   s390x/pci: rename hotplug handler callbacks
>>>   pci/pcie: stop plug/unplug if the slot is locked
>>>   pci/pcihp: perform check for bus capability in pre_plug handler
>>>   pci/pcihp: overwrite hotplug handler recursively from the start
>>>   pci/pcihp: perform unplug via the hotplug handler
>>>   pci/pcie: perform unplug via the hotplug handler
>>>   pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge
>>>   pci/shpc: perform unplug via the hotplug handler
>>>   spapr_pci: perform unplug via the hotplug handler
>>>
>>>  hw/acpi/pcihp.c                 | 47 ++++++++++++++++++++++++++++-----
>>>  hw/acpi/piix4.c                 | 39 ++++++++++++++-------------
>>>  hw/pci-bridge/pci_bridge_dev.c  | 31 ++++++++++++++--------
>>>  hw/pci-bridge/pcie_pci_bridge.c | 32 +++-------------------
>>>  hw/pci/pcie.c                   | 46 +++++++++++++++++++++-----------
>>>  hw/pci/pcie_port.c              |  6 +++--
>>>  hw/pci/shpc.c                   | 25 ++++++++++++------
>>>  hw/ppc/spapr_pci.c              | 33 ++++++++++++++---------
>>>  hw/s390x/s390-pci-bus.c         | 12 ++++-----
>>>  include/hw/acpi/pcihp.h         |  5 ++++
>>>  include/hw/pci/pci_bridge.h     |  6 +++++
>>>  include/hw/pci/pcie.h           | 12 ++++++---
>>>  include/hw/pci/shpc.h           | 10 ++++---
>>>  13 files changed, 187 insertions(+), 117 deletions(-)
>>>
>>
>> Seems like everything is reviewed and this is good to go. Anybody fancy
>> queuing this? (@mst?) Thanks!
> 
> Yes, thanks! But we are in freeze so please repost after the release and I will queue.

I know about the freeze, however some maintainers seem to be queue
patches already during the freeze. I can resend once we're working on
4.0 :) Thanks!

-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v3 03/11] s390x/pci: rename hotplug handler callbacks
  2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 03/11] s390x/pci: " David Hildenbrand
@ 2018-11-23 15:07   ` Pierre Morel
  0 siblings, 0 replies; 18+ messages in thread
From: Pierre Morel @ 2018-11-23 15:07 UTC (permalink / raw)
  To: David Hildenbrand, qemu-devel
  Cc: Collin Walling, Michael S . Tsirkin, Cornelia Huck, Greg Kurz,
	Christian Borntraeger, qemu-s390x, qemu-ppc, Thomas Huth,
	Igor Mammedov, Richard Henderson, David Gibson

On 20/11/2018 12:04, David Hildenbrand wrote:
> The callbacks are also called for cold plugged devices. Drop the "hot"
> to better match the actual callback names.
> 
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>   hw/s390x/s390-pci-bus.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index 060ff062bc..9abd49a9dc 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -827,8 +827,8 @@ static bool s390_pci_alloc_idx(S390pciState *s, S390PCIBusDevice *pbdev)
>       return true;
>   }
> 
> -static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev,
> -                                  DeviceState *dev, Error **errp)
> +static void s390_pcihost_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
> +                              Error **errp)
>   {
>       PCIDevice *pdev = NULL;
>       S390PCIBusDevice *pbdev = NULL;
> @@ -936,8 +936,8 @@ static void s390_pcihost_timer_cb(void *opaque)
>       qdev_unplug(DEVICE(pbdev), NULL);
>   }
> 
> -static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev,
> -                                    DeviceState *dev, Error **errp)
> +static void s390_pcihost_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
> +                                Error **errp)
>   {
>       PCIDevice *pci_dev = NULL;
>       PCIBus *bus;
> @@ -1045,8 +1045,8 @@ static void s390_pcihost_class_init(ObjectClass *klass, void *data)
> 
>       dc->reset = s390_pcihost_reset;
>       dc->realize = s390_pcihost_realize;
> -    hc->plug = s390_pcihost_hot_plug;
> -    hc->unplug = s390_pcihost_hot_unplug;
> +    hc->plug = s390_pcihost_plug;
> +    hc->unplug = s390_pcihost_unplug;
>       msi_nonbroken = true;
>   }
> 

LBTM (does that exist? Look Better To Me)

Reviewed-by: Pierre Morel<pmorel@linux.ibm.com>

-- 
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2018-11-23 15:07 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-20 11:04 [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 01/11] pci/pcie: rename hotplug handler callbacks David Hildenbrand
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 02/11] pci/shpc: " David Hildenbrand
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 03/11] s390x/pci: " David Hildenbrand
2018-11-23 15:07   ` Pierre Morel
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 04/11] pci/pcie: stop plug/unplug if the slot is locked David Hildenbrand
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 05/11] pci/pcihp: perform check for bus capability in pre_plug handler David Hildenbrand
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 06/11] pci/pcihp: overwrite hotplug handler recursively from the start David Hildenbrand
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 07/11] pci/pcihp: perform unplug via the hotplug handler David Hildenbrand
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 08/11] pci/pcie: " David Hildenbrand
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 09/11] pci: Reuse pci-bridge hotplug handler handlers for pcie-pci-bridge David Hildenbrand
2018-11-20 15:15   ` Igor Mammedov
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 10/11] pci/shpc: perform unplug via the hotplug handler David Hildenbrand
2018-11-20 15:19   ` Igor Mammedov
2018-11-20 11:04 ` [Qemu-devel] [PATCH v3 11/11] spapr_pci: " David Hildenbrand
2018-11-21 12:43 ` [Qemu-devel] [PATCH v3 00/11] pci: hotplug handler reworks David Hildenbrand
2018-11-21 13:28   ` Michael S. Tsirkin
2018-11-21 16:26     ` David Hildenbrand

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.