All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks
@ 2018-11-05 10:20 David Hildenbrand
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks David Hildenbrand
                   ` (9 more replies)
  0 siblings, 10 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, 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.

>From my POV 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())

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 (10):
  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/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 | 29 ++++++++++++++------
 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/pcie.h           | 12 ++++++---
 include/hw/pci/shpc.h           | 10 ++++---
 12 files changed, 201 insertions(+), 94 deletions(-)

-- 
2.17.2

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

* [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-06  6:03   ` David Gibson
  2018-11-19 15:43   ` Igor Mammedov
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 02/10] pci/shpc: " David Hildenbrand
                   ` (8 subsequent siblings)
  9 siblings, 2 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, 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_check_common().

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] 35+ messages in thread

* [Qemu-devel] [PATCH v2 02/10] pci/shpc: rename hotplug handler callbacks
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-06  8:14   ` David Gibson
  2018-11-19 15:56   ` Igor Mammedov
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 03/10] s390x/pci: " David Hildenbrand
                   ` (7 subsequent siblings)
  9 siblings, 2 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, 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().

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] 35+ messages in thread

* [Qemu-devel] [PATCH v2 03/10] s390x/pci: rename hotplug handler callbacks
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks David Hildenbrand
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 02/10] pci/shpc: " David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-06  8:14   ` David Gibson
                     ` (2 more replies)
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 04/10] pci/pcie: stop plug/unplug if the slot is locked David Hildenbrand
                   ` (6 subsequent siblings)
  9 siblings, 3 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, David Hildenbrand

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

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 e42e1b80d6..e1b14b131b 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -813,8 +813,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;
@@ -923,8 +923,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;
@@ -1032,8 +1032,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] 35+ messages in thread

* [Qemu-devel] [PATCH v2 04/10] pci/pcie: stop plug/unplug if the slot is locked
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
                   ` (2 preceding siblings ...)
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 03/10] s390x/pci: " David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-06 23:10   ` David Gibson
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 05/10] pci/pcihp: perform check for bus capability in pre_plug handler David Hildenbrand
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, David Hildenbrand

We better stop right away. While at it, properly move the check
to the pre_plug handler.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
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] 35+ messages in thread

* [Qemu-devel] [PATCH v2 05/10] pci/pcihp: perform check for bus capability in pre_plug handler
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
                   ` (3 preceding siblings ...)
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 04/10] pci/pcie: stop plug/unplug if the slot is locked David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 06/10] pci/pcihp: overwrite hotplug handler recursively from the start David Hildenbrand
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, 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] 35+ messages in thread

* [Qemu-devel] [PATCH v2 06/10] pci/pcihp: overwrite hotplug handler recursively from the start
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
                   ` (4 preceding siblings ...)
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 05/10] pci/pcihp: perform check for bus capability in pre_plug handler David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-19 16:31   ` Igor Mammedov
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 07/10] pci/pcihp: perform unplug via the hotplug handler David Hildenbrand
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, 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).

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] 35+ messages in thread

* [Qemu-devel] [PATCH v2 07/10] pci/pcihp: perform unplug via the hotplug handler
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
                   ` (5 preceding siblings ...)
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 06/10] pci/pcihp: overwrite hotplug handler recursively from the start David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-19 16:36   ` Igor Mammedov
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 08/10] pci/pcie: " David Hildenbrand
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, 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".

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] 35+ messages in thread

* [Qemu-devel] [PATCH v2 08/10] pci/pcie: perform unplug via the hotplug handler
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
                   ` (6 preceding siblings ...)
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 07/10] pci/pcihp: perform unplug via the hotplug handler David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-07  0:55   ` David Gibson
  2018-11-19 16:46   ` Igor Mammedov
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 09/10] pci/shpc: " David Hildenbrand
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 10/10] spapr_pci: " David Hildenbrand
  9 siblings, 2 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, 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".

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] 35+ messages in thread

* [Qemu-devel] [PATCH v2 09/10] pci/shpc: perform unplug via the hotplug handler
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
                   ` (7 preceding siblings ...)
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 08/10] pci/pcie: " David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-07  0:59   ` David Gibson
  2018-11-19 17:09   ` Igor Mammedov
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 10/10] spapr_pci: " David Hildenbrand
  9 siblings, 2 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, 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".

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/pci-bridge/pci_bridge_dev.c  | 14 ++++++++++++++
 hw/pci-bridge/pcie_pci_bridge.c | 14 ++++++++++++++
 hw/pci/shpc.c                   | 11 ++++++++++-
 include/hw/pci/shpc.h           |  2 ++
 4 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
index e1df9a52ac..91415f114c 100644
--- a/hw/pci-bridge/pci_bridge_dev.c
+++ b/hw/pci-bridge/pci_bridge_dev.c
@@ -219,6 +219,19 @@ static void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev,
     shpc_device_plug_cb(hotplug_dev, dev, errp);
 }
 
+static void pci_bridge_dev_unplug_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);
+        return;
+    }
+    shpc_device_unplug_cb(hotplug_dev, dev, errp);
+}
+
 static void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
                                              DeviceState *dev, Error **errp)
 {
@@ -251,6 +264,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 c634353b06..7c667bc97c 100644
--- a/hw/pci-bridge/pcie_pci_bridge.c
+++ b/hw/pci-bridge/pcie_pci_bridge.c
@@ -150,6 +150,19 @@ static void pcie_pci_bridge_plug_cb(HotplugHandler *hotplug_dev,
     shpc_device_plug_cb(hotplug_dev, dev, errp);
 }
 
+static void pcie_pci_bridge_unplug_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_cb(hotplug_dev, dev, errp);
+}
+
 static void pcie_pci_bridge_unplug_request_cb(HotplugHandler *hotplug_dev,
                                               DeviceState *dev, Error **errp)
 {
@@ -180,6 +193,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 = pcie_pci_bridge_plug_cb;
+    hc->unplug = pcie_pci_bridge_unplug_cb;
     hc->unplug_request = pcie_pci_bridge_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/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] 35+ messages in thread

* [Qemu-devel] [PATCH v2 10/10] spapr_pci: perform unplug via the hotplug handler
  2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
                   ` (8 preceding siblings ...)
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 09/10] pci/shpc: " David Hildenbrand
@ 2018-11-05 10:20 ` David Hildenbrand
  2018-11-05 10:31   ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
                     ` (2 more replies)
  9 siblings, 3 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x, 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".

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 58afa46204..64b8591023 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] 35+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 10/10] spapr_pci: perform unplug via the hotplug handler
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 10/10] spapr_pci: " David Hildenbrand
@ 2018-11-05 10:31   ` Greg Kurz
  2018-11-05 10:33     ` David Hildenbrand
  2018-11-07  4:22   ` [Qemu-devel] " David Gibson
  2018-11-19 17:13   ` [Qemu-devel] [PATCH v2 10/10] spapr_pci: perform unplug via the hotplug handler Igor Mammedov
  2 siblings, 1 reply; 35+ messages in thread
From: Greg Kurz @ 2018-11-05 10:31 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Eduardo Habkost, Michael S . Tsirkin, Cornelia Huck,
	Dr . David Alan Gilbert, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Marcel Apfelbaum, Igor Mammedov, Richard Henderson,
	David Gibson

On Mon,  5 Nov 2018 11:20:44 +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".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

>  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 58afa46204..64b8591023 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;
>  }
>  

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

* Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 10/10] spapr_pci: perform unplug via the hotplug handler
  2018-11-05 10:31   ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
@ 2018-11-05 10:33     ` David Hildenbrand
  0 siblings, 0 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-05 10:33 UTC (permalink / raw)
  To: Greg Kurz
  Cc: qemu-devel, Eduardo Habkost, Michael S . Tsirkin, Cornelia Huck,
	Dr . David Alan Gilbert, Christian Borntraeger, qemu-s390x,
	qemu-ppc, Marcel Apfelbaum, Igor Mammedov, Richard Henderson,
	David Gibson

On 05.11.18 11:31, Greg Kurz wrote:
> On Mon,  5 Nov 2018 11:20:44 +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".
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
> 
> Reviewed-by: Greg Kurz <groug@kaod.org>

BTW, sorry for dropping you RB! (realized it just now)

-- 

Thanks,

David / dhildenb

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

* Re: [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks David Hildenbrand
@ 2018-11-06  6:03   ` David Gibson
  2018-11-06  8:43     ` David Hildenbrand
  2018-11-19 15:43   ` Igor Mammedov
  1 sibling, 1 reply; 35+ messages in thread
From: David Gibson @ 2018-11-06  6:03 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, Eduardo Habkost, Dr . David Alan Gilbert,
	Cornelia Huck, Christian Borntraeger, Richard Henderson,
	qemu-ppc, qemu-s390x

[-- Attachment #1: Type: text/plain, Size: 4931 bytes --]

On Mon, Nov 05, 2018 at 11:20:35AM +0100, David Hildenbrand wrote:
> 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_check_common().

Uh.. this part of the message doesn't appear to be accurate any more.

> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Apart from that,

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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 */

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [Qemu-devel] [PATCH v2 02/10] pci/shpc: rename hotplug handler callbacks
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 02/10] pci/shpc: " David Hildenbrand
@ 2018-11-06  8:14   ` David Gibson
  2018-11-19 15:56   ` Igor Mammedov
  1 sibling, 0 replies; 35+ messages in thread
From: David Gibson @ 2018-11-06  8:14 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, Eduardo Habkost, Dr . David Alan Gilbert,
	Cornelia Huck, Christian Borntraeger, Richard Henderson,
	qemu-ppc, qemu-s390x

[-- Attachment #1: Type: text/plain, Size: 8895 bytes --]

On Mon, Nov 05, 2018 at 11:20:36AM +0100, David Hildenbrand wrote:
> 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().
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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) \

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [Qemu-devel] [PATCH v2 03/10] s390x/pci: rename hotplug handler callbacks
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 03/10] s390x/pci: " David Hildenbrand
@ 2018-11-06  8:14   ` David Gibson
  2018-11-08 12:38   ` Cornelia Huck
  2018-11-19 15:59   ` Igor Mammedov
  2 siblings, 0 replies; 35+ messages in thread
From: David Gibson @ 2018-11-06  8:14 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, Eduardo Habkost, Dr . David Alan Gilbert,
	Cornelia Huck, Christian Borntraeger, Richard Henderson,
	qemu-ppc, qemu-s390x

[-- Attachment #1: Type: text/plain, Size: 2107 bytes --]

On Mon, Nov 05, 2018 at 11:20:37AM +0100, David Hildenbrand wrote:
> The callbacks are also called for cold plugged devices. Drop the "hot"
> to better match the actual callback names.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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 e42e1b80d6..e1b14b131b 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -813,8 +813,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;
> @@ -923,8 +923,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;
> @@ -1032,8 +1032,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;
>  }
>  

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks
  2018-11-06  6:03   ` David Gibson
@ 2018-11-06  8:43     ` David Hildenbrand
  0 siblings, 0 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-06  8:43 UTC (permalink / raw)
  To: David Gibson
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, Eduardo Habkost, Dr . David Alan Gilbert,
	Cornelia Huck, Christian Borntraeger, Richard Henderson,
	qemu-ppc, qemu-s390x

On 06.11.18 07:03, David Gibson wrote:
> On Mon, Nov 05, 2018 at 11:20:35AM +0100, David Hildenbrand wrote:
>> 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_check_common().
> 
> Uh.. this part of the message doesn't appear to be accurate any more.
> 

Indeed, after renaming it 10 times I think I forgot to update the
description :)

Thanks!

>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
> 
> Apart from that,
> 
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> 


-- 

Thanks,

David / dhildenb

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

* Re: [Qemu-devel] [PATCH v2 04/10] pci/pcie: stop plug/unplug if the slot is locked
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 04/10] pci/pcie: stop plug/unplug if the slot is locked David Hildenbrand
@ 2018-11-06 23:10   ` David Gibson
  2018-11-07  9:03     ` David Hildenbrand
  0 siblings, 1 reply; 35+ messages in thread
From: David Gibson @ 2018-11-06 23:10 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, Eduardo Habkost, Dr . David Alan Gilbert,
	Cornelia Huck, Christian Borntraeger, Richard Henderson,
	qemu-ppc, qemu-s390x

[-- Attachment #1: Type: text/plain, Size: 4709 bytes --]

On Mon, Nov 05, 2018 at 11:20:38AM +0100, David Hildenbrand wrote:
> We better stop right away. While at it, properly move the check
> to the pre_plug handler.
> 
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

Although I'm not sure the commit message gives a terribly clear
picture of what's going on here.

> ---
>  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,

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [Qemu-devel] [PATCH v2 08/10] pci/pcie: perform unplug via the hotplug handler
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 08/10] pci/pcie: " David Hildenbrand
@ 2018-11-07  0:55   ` David Gibson
  2018-11-19 16:46   ` Igor Mammedov
  1 sibling, 0 replies; 35+ messages in thread
From: David Gibson @ 2018-11-07  0:55 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, Eduardo Habkost, Dr . David Alan Gilbert,
	Cornelia Huck, Christian Borntraeger, Richard Henderson,
	qemu-ppc, qemu-s390x

[-- Attachment #1: Type: text/plain, Size: 3155 bytes --]

On Mon, Nov 05, 2018 at 11:20:42AM +0100, David Hildenbrand 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".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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 */

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [Qemu-devel] [PATCH v2 09/10] pci/shpc: perform unplug via the hotplug handler
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 09/10] pci/shpc: " David Hildenbrand
@ 2018-11-07  0:59   ` David Gibson
  2018-11-19 17:09   ` Igor Mammedov
  1 sibling, 0 replies; 35+ messages in thread
From: David Gibson @ 2018-11-07  0:59 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, Eduardo Habkost, Dr . David Alan Gilbert,
	Cornelia Huck, Christian Borntraeger, Richard Henderson,
	qemu-ppc, qemu-s390x

[-- Attachment #1: Type: text/plain, Size: 5956 bytes --]

On Mon, Nov 05, 2018 at 11:20:43AM +0100, David Hildenbrand 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".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  hw/pci-bridge/pci_bridge_dev.c  | 14 ++++++++++++++
>  hw/pci-bridge/pcie_pci_bridge.c | 14 ++++++++++++++
>  hw/pci/shpc.c                   | 11 ++++++++++-
>  include/hw/pci/shpc.h           |  2 ++
>  4 files changed, 40 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
> index e1df9a52ac..91415f114c 100644
> --- a/hw/pci-bridge/pci_bridge_dev.c
> +++ b/hw/pci-bridge/pci_bridge_dev.c
> @@ -219,6 +219,19 @@ static void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev,
>      shpc_device_plug_cb(hotplug_dev, dev, errp);
>  }
>  
> +static void pci_bridge_dev_unplug_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);
> +        return;
> +    }
> +    shpc_device_unplug_cb(hotplug_dev, dev, errp);
> +}
> +
>  static void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
>                                               DeviceState *dev, Error **errp)
>  {
> @@ -251,6 +264,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 c634353b06..7c667bc97c 100644
> --- a/hw/pci-bridge/pcie_pci_bridge.c
> +++ b/hw/pci-bridge/pcie_pci_bridge.c
> @@ -150,6 +150,19 @@ static void pcie_pci_bridge_plug_cb(HotplugHandler *hotplug_dev,
>      shpc_device_plug_cb(hotplug_dev, dev, errp);
>  }
>  
> +static void pcie_pci_bridge_unplug_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_cb(hotplug_dev, dev, errp);
> +}
> +
>  static void pcie_pci_bridge_unplug_request_cb(HotplugHandler *hotplug_dev,
>                                                DeviceState *dev, Error **errp)
>  {
> @@ -180,6 +193,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 = pcie_pci_bridge_plug_cb;
> +    hc->unplug = pcie_pci_bridge_unplug_cb;
>      hc->unplug_request = pcie_pci_bridge_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/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);
>  

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [Qemu-devel] [PATCH v2 10/10] spapr_pci: perform unplug via the hotplug handler
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 10/10] spapr_pci: " David Hildenbrand
  2018-11-05 10:31   ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
@ 2018-11-07  4:22   ` David Gibson
  2018-11-08  3:08     ` [Qemu-devel] QEMU bootup hang in tcg model using mainline QEMU code gengdongjiu
  2018-11-19 17:13   ` [Qemu-devel] [PATCH v2 10/10] spapr_pci: perform unplug via the hotplug handler Igor Mammedov
  2 siblings, 1 reply; 35+ messages in thread
From: David Gibson @ 2018-11-07  4:22 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, Eduardo Habkost, Dr . David Alan Gilbert,
	Cornelia Huck, Christian Borntraeger, Richard Henderson,
	qemu-ppc, qemu-s390x

[-- Attachment #1: Type: text/plain, Size: 3720 bytes --]

On Mon, Nov 05, 2018 at 11:20:44AM +0100, David Hildenbrand 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".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  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 58afa46204..64b8591023 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;
>  }
>  

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [Qemu-devel] [PATCH v2 04/10] pci/pcie: stop plug/unplug if the slot is locked
  2018-11-06 23:10   ` David Gibson
@ 2018-11-07  9:03     ` David Hildenbrand
  0 siblings, 0 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-07  9:03 UTC (permalink / raw)
  To: David Gibson
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, Eduardo Habkost, Dr . David Alan Gilbert,
	Cornelia Huck, Christian Borntraeger, Richard Henderson,
	qemu-ppc, qemu-s390x

On 07.11.18 00:10, David Gibson wrote:
> On Mon, Nov 05, 2018 at 11:20:38AM +0100, David Hildenbrand wrote:
>> We better stop right away. While at it, properly move the check
>> to the pre_plug handler.
>>
>> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
> 
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> 
> Although I'm not sure the commit message gives a terribly clear
> picture of what's going on here.

Thanks, I'll change it to

"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."

-- 

Thanks,

David / dhildenb

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

* [Qemu-devel] QEMU bootup hang in tcg model using mainline QEMU code
  2018-11-07  4:22   ` [Qemu-devel] " David Gibson
@ 2018-11-08  3:08     ` gengdongjiu
  0 siblings, 0 replies; 35+ messages in thread
From: gengdongjiu @ 2018-11-08  3:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell

Hi All
  using mainline QEMU code and below boot up commands, the QEMU will be hang when do bootup, if I add the "-enable-kvm" parameter, it can boot up successfully,  do you know the reason about it?
I also try the "remotes/origin/stable-2.12" branch code using below same boot up commands, it does not have this hang issue. it seems the mainline code has some issue.


./qemu-system-aarch64  -m 1024 -cpu cortex-a57 -machine virt,gic-version=3 \
  -smp 4 -nographic -kernel Image -append "root=/dev/sda1 console=ttyAMA0 sched_debug ignore_loglevel" \
  -device virtio-scsi-device,id=scsi -drive file=./linaro.img,id=rootimg,cache=unsafe,if=none -device scsi-hd,drive=rootimg

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

* Re: [Qemu-devel] [PATCH v2 03/10] s390x/pci: rename hotplug handler callbacks
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 03/10] s390x/pci: " David Hildenbrand
  2018-11-06  8:14   ` David Gibson
@ 2018-11-08 12:38   ` Cornelia Huck
  2018-11-19 15:59   ` Igor Mammedov
  2 siblings, 0 replies; 35+ messages in thread
From: Cornelia Huck @ 2018-11-08 12:38 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Igor Mammedov, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x

On Mon,  5 Nov 2018 11:20:37 +0100
David Hildenbrand <david@redhat.com> wrote:

> The callbacks are also called for cold plugged devices. Drop the "hot"
> to better match the actual callback names.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  hw/s390x/s390-pci-bus.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

[I assume this series will go through the pci tree?]

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

* Re: [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks David Hildenbrand
  2018-11-06  6:03   ` David Gibson
@ 2018-11-19 15:43   ` Igor Mammedov
  1 sibling, 0 replies; 35+ messages in thread
From: Igor Mammedov @ 2018-11-19 15:43 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Eduardo Habkost, Michael S . Tsirkin, Cornelia Huck,
	Alexander Graf, Dr . David Alan Gilbert, Christian Borntraeger,
	qemu-s390x, qemu-ppc, Richard Henderson, David Gibson

On Mon,  5 Nov 2018 11:20:35 +0100
David Hildenbrand <david@redhat.com> wrote:

> 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_check_common().
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
With commit message amended per David's suggestion

Reviewed-by: Igor Mammedov <imammedo@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 */

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

* Re: [Qemu-devel] [PATCH v2 02/10] pci/shpc: rename hotplug handler callbacks
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 02/10] pci/shpc: " David Hildenbrand
  2018-11-06  8:14   ` David Gibson
@ 2018-11-19 15:56   ` Igor Mammedov
  1 sibling, 0 replies; 35+ messages in thread
From: Igor Mammedov @ 2018-11-19 15:56 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Eduardo Habkost, Michael S . Tsirkin, Cornelia Huck,
	Alexander Graf, Dr . David Alan Gilbert, Christian Borntraeger,
	qemu-s390x, qemu-ppc, Richard Henderson, David Gibson

On Mon,  5 Nov 2018 11:20:36 +0100
David Hildenbrand <david@redhat.com> wrote:

> 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().
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@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) \

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

* Re: [Qemu-devel] [PATCH v2 03/10] s390x/pci: rename hotplug handler callbacks
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 03/10] s390x/pci: " David Hildenbrand
  2018-11-06  8:14   ` David Gibson
  2018-11-08 12:38   ` Cornelia Huck
@ 2018-11-19 15:59   ` Igor Mammedov
  2 siblings, 0 replies; 35+ messages in thread
From: Igor Mammedov @ 2018-11-19 15:59 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Eduardo Habkost, Michael S . Tsirkin, Cornelia Huck,
	Alexander Graf, Dr . David Alan Gilbert, Christian Borntraeger,
	qemu-s390x, qemu-ppc, Richard Henderson, David Gibson

On Mon,  5 Nov 2018 11:20:37 +0100
David Hildenbrand <david@redhat.com> wrote:

> The callbacks are also called for cold plugged devices. Drop the "hot"
> to better match the actual callback names.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@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 e42e1b80d6..e1b14b131b 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -813,8 +813,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;
> @@ -923,8 +923,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;
> @@ -1032,8 +1032,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;
>  }
>  

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

* Re: [Qemu-devel] [PATCH v2 06/10] pci/pcihp: overwrite hotplug handler recursively from the start
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 06/10] pci/pcihp: overwrite hotplug handler recursively from the start David Hildenbrand
@ 2018-11-19 16:31   ` Igor Mammedov
  0 siblings, 0 replies; 35+ messages in thread
From: Igor Mammedov @ 2018-11-19 16:31 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x

On Mon,  5 Nov 2018 11:20:40 +0100
David Hildenbrand <david@redhat.com> wrote:

> 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).
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@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);
>  }

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

* Re: [Qemu-devel] [PATCH v2 07/10] pci/pcihp: perform unplug via the hotplug handler
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 07/10] pci/pcihp: perform unplug via the hotplug handler David Hildenbrand
@ 2018-11-19 16:36   ` Igor Mammedov
  0 siblings, 0 replies; 35+ messages in thread
From: Igor Mammedov @ 2018-11-19 16:36 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x

On Mon,  5 Nov 2018 11:20:41 +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".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@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);

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

* Re: [Qemu-devel] [PATCH v2 08/10] pci/pcie: perform unplug via the hotplug handler
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 08/10] pci/pcie: " David Hildenbrand
  2018-11-07  0:55   ` David Gibson
@ 2018-11-19 16:46   ` Igor Mammedov
  1 sibling, 0 replies; 35+ messages in thread
From: Igor Mammedov @ 2018-11-19 16:46 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x

On Mon,  5 Nov 2018 11:20:42 +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".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@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 */

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

* Re: [Qemu-devel] [PATCH v2 09/10] pci/shpc: perform unplug via the hotplug handler
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 09/10] pci/shpc: " David Hildenbrand
  2018-11-07  0:59   ` David Gibson
@ 2018-11-19 17:09   ` Igor Mammedov
  2018-11-20 10:11     ` David Hildenbrand
  1 sibling, 1 reply; 35+ messages in thread
From: Igor Mammedov @ 2018-11-19 17:09 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x

On Mon,  5 Nov 2018 11:20:43 +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".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  hw/pci-bridge/pci_bridge_dev.c  | 14 ++++++++++++++
>  hw/pci-bridge/pcie_pci_bridge.c | 14 ++++++++++++++
>  hw/pci/shpc.c                   | 11 ++++++++++-
>  include/hw/pci/shpc.h           |  2 ++
>  4 files changed, 40 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
> index e1df9a52ac..91415f114c 100644
> --- a/hw/pci-bridge/pci_bridge_dev.c
> +++ b/hw/pci-bridge/pci_bridge_dev.c
> @@ -219,6 +219,19 @@ static void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev,
>      shpc_device_plug_cb(hotplug_dev, dev, errp);
>  }
>  
> +static void pci_bridge_dev_unplug_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);
> +        return;
> +    }
> +    shpc_device_unplug_cb(hotplug_dev, dev, errp);
> +}
> +
>  static void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev,
>                                               DeviceState *dev, Error **errp)
>  {
> @@ -251,6 +264,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 c634353b06..7c667bc97c 100644
> --- a/hw/pci-bridge/pcie_pci_bridge.c
> +++ b/hw/pci-bridge/pcie_pci_bridge.c
> @@ -150,6 +150,19 @@ static void pcie_pci_bridge_plug_cb(HotplugHandler *hotplug_dev,
>      shpc_device_plug_cb(hotplug_dev, dev, errp);
>  }
>  
> +static void pcie_pci_bridge_unplug_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);
Is it possible to reach here at all?

> +        return;
> +    }
> +    shpc_device_unplug_cb(hotplug_dev, dev, errp);
> +}

you probably can share this function impl. with pci_bridge_dev_unplug_cb()
if you use object_get_typename().



> +
>  static void pcie_pci_bridge_unplug_request_cb(HotplugHandler *hotplug_dev,
>                                                DeviceState *dev, Error **errp)
>  {
> @@ -180,6 +193,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 = pcie_pci_bridge_plug_cb;
> +    hc->unplug = pcie_pci_bridge_unplug_cb;
>      hc->unplug_request = pcie_pci_bridge_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/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] 35+ messages in thread

* Re: [Qemu-devel] [PATCH v2 10/10] spapr_pci: perform unplug via the hotplug handler
  2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 10/10] spapr_pci: " David Hildenbrand
  2018-11-05 10:31   ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
  2018-11-07  4:22   ` [Qemu-devel] " David Gibson
@ 2018-11-19 17:13   ` Igor Mammedov
  2 siblings, 0 replies; 35+ messages in thread
From: Igor Mammedov @ 2018-11-19 17:13 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x

On Mon,  5 Nov 2018 11:20:44 +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".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@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 58afa46204..64b8591023 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;
>  }
>  

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

* Re: [Qemu-devel] [PATCH v2 09/10] pci/shpc: perform unplug via the hotplug handler
  2018-11-19 17:09   ` Igor Mammedov
@ 2018-11-20 10:11     ` David Hildenbrand
  2018-11-20 14:13       ` Igor Mammedov
  0 siblings, 1 reply; 35+ messages in thread
From: David Hildenbrand @ 2018-11-20 10:11 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: qemu-devel, Michael S . Tsirkin, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x

>> diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridge.c
>> index c634353b06..7c667bc97c 100644
>> --- a/hw/pci-bridge/pcie_pci_bridge.c
>> +++ b/hw/pci-bridge/pcie_pci_bridge.c
>> @@ -150,6 +150,19 @@ static void pcie_pci_bridge_plug_cb(HotplugHandler *hotplug_dev,
>>      shpc_device_plug_cb(hotplug_dev, dev, errp);
>>  }
>>  
>> +static void pcie_pci_bridge_unplug_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);
> Is it possible to reach here at all?

Right, this should right now not be possible. I'll turn this into an

g_assert(shpc_present(pci_hotplug_dev));

(if we every support surprise removal, we'll have to rethink either way)

> 
>> +        return;
>> +    }
>> +    shpc_device_unplug_cb(hotplug_dev, dev, errp);
>> +}
> 
> you probably can share this function impl. with pci_bridge_dev_unplug_cb()
> if you use object_get_typename().

The same holds for all three functions (+ later pre_plug), however can
we be sure there won't be differences in the near future?

If we don't expect these functions to differ, I can add a patch to
factor the existing two functions (plug/unplug) out.

-- 

Thanks,

David / dhildenb

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

* Re: [Qemu-devel] [PATCH v2 09/10] pci/shpc: perform unplug via the hotplug handler
  2018-11-20 10:11     ` David Hildenbrand
@ 2018-11-20 14:13       ` Igor Mammedov
  2018-11-20 14:34         ` David Hildenbrand
  0 siblings, 1 reply; 35+ messages in thread
From: Igor Mammedov @ 2018-11-20 14:13 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, Michael S . Tsirkin, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x

On Tue, 20 Nov 2018 11:11:46 +0100
David Hildenbrand <david@redhat.com> wrote:

> >> diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridge.c
> >> index c634353b06..7c667bc97c 100644
> >> --- a/hw/pci-bridge/pcie_pci_bridge.c
> >> +++ b/hw/pci-bridge/pcie_pci_bridge.c
> >> @@ -150,6 +150,19 @@ static void pcie_pci_bridge_plug_cb(HotplugHandler *hotplug_dev,
> >>      shpc_device_plug_cb(hotplug_dev, dev, errp);
> >>  }
> >>  
> >> +static void pcie_pci_bridge_unplug_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);  
> > Is it possible to reach here at all?  
> 
> Right, this should right now not be possible. I'll turn this into an
> 
> g_assert(shpc_present(pci_hotplug_dev));
> 
> (if we every support surprise removal, we'll have to rethink either way)
> 
> >   
> >> +        return;
> >> +    }
> >> +    shpc_device_unplug_cb(hotplug_dev, dev, errp);
> >> +}  
> > 
> > you probably can share this function impl. with pci_bridge_dev_unplug_cb()
> > if you use object_get_typename().  
> 
> The same holds for all three functions (+ later pre_plug), however can
> we be sure there won't be differences in the near future?
> 
> If we don't expect these functions to differ, I can add a patch to
> factor the existing two functions (plug/unplug) out.
I'm not sure if they will differ or not in future,
but right now it looks as premature splitting.
It might be better to have a single function now and split it later
when it is necessary.

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

* Re: [Qemu-devel] [PATCH v2 09/10] pci/shpc: perform unplug via the hotplug handler
  2018-11-20 14:13       ` Igor Mammedov
@ 2018-11-20 14:34         ` David Hildenbrand
  0 siblings, 0 replies; 35+ messages in thread
From: David Hildenbrand @ 2018-11-20 14:34 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: qemu-devel, Michael S . Tsirkin, Marcel Apfelbaum,
	Alexander Graf, David Gibson, Eduardo Habkost,
	Dr . David Alan Gilbert, Cornelia Huck, Christian Borntraeger,
	Richard Henderson, qemu-ppc, qemu-s390x

On 20.11.18 15:13, Igor Mammedov wrote:
> On Tue, 20 Nov 2018 11:11:46 +0100
> David Hildenbrand <david@redhat.com> wrote:
> 
>>>> diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridge.c
>>>> index c634353b06..7c667bc97c 100644
>>>> --- a/hw/pci-bridge/pcie_pci_bridge.c
>>>> +++ b/hw/pci-bridge/pcie_pci_bridge.c
>>>> @@ -150,6 +150,19 @@ static void pcie_pci_bridge_plug_cb(HotplugHandler *hotplug_dev,
>>>>      shpc_device_plug_cb(hotplug_dev, dev, errp);
>>>>  }
>>>>  
>>>> +static void pcie_pci_bridge_unplug_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);  
>>> Is it possible to reach here at all?  
>>
>> Right, this should right now not be possible. I'll turn this into an
>>
>> g_assert(shpc_present(pci_hotplug_dev));
>>
>> (if we every support surprise removal, we'll have to rethink either way)
>>
>>>   
>>>> +        return;
>>>> +    }
>>>> +    shpc_device_unplug_cb(hotplug_dev, dev, errp);
>>>> +}  
>>>
>>> you probably can share this function impl. with pci_bridge_dev_unplug_cb()
>>> if you use object_get_typename().  
>>
>> The same holds for all three functions (+ later pre_plug), however can
>> we be sure there won't be differences in the near future?
>>
>> If we don't expect these functions to differ, I can add a patch to
>> factor the existing two functions (plug/unplug) out.
> I'm not sure if they will differ or not in future,
> but right now it looks as premature splitting.
> It might be better to have a single function now and split it later
> when it is necessary.
> 

Indeed, I already went ahead and sent a new version including the
suggested re-factoring.

Thanks!

-- 

Thanks,

David / dhildenb

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

end of thread, other threads:[~2018-11-20 14:34 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-05 10:20 [Qemu-devel] [PATCH v2 00/10] pci: hotplug handler reworks David Hildenbrand
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 01/10] pci/pcie: rename hotplug handler callbacks David Hildenbrand
2018-11-06  6:03   ` David Gibson
2018-11-06  8:43     ` David Hildenbrand
2018-11-19 15:43   ` Igor Mammedov
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 02/10] pci/shpc: " David Hildenbrand
2018-11-06  8:14   ` David Gibson
2018-11-19 15:56   ` Igor Mammedov
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 03/10] s390x/pci: " David Hildenbrand
2018-11-06  8:14   ` David Gibson
2018-11-08 12:38   ` Cornelia Huck
2018-11-19 15:59   ` Igor Mammedov
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 04/10] pci/pcie: stop plug/unplug if the slot is locked David Hildenbrand
2018-11-06 23:10   ` David Gibson
2018-11-07  9:03     ` David Hildenbrand
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 05/10] pci/pcihp: perform check for bus capability in pre_plug handler David Hildenbrand
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 06/10] pci/pcihp: overwrite hotplug handler recursively from the start David Hildenbrand
2018-11-19 16:31   ` Igor Mammedov
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 07/10] pci/pcihp: perform unplug via the hotplug handler David Hildenbrand
2018-11-19 16:36   ` Igor Mammedov
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 08/10] pci/pcie: " David Hildenbrand
2018-11-07  0:55   ` David Gibson
2018-11-19 16:46   ` Igor Mammedov
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 09/10] pci/shpc: " David Hildenbrand
2018-11-07  0:59   ` David Gibson
2018-11-19 17:09   ` Igor Mammedov
2018-11-20 10:11     ` David Hildenbrand
2018-11-20 14:13       ` Igor Mammedov
2018-11-20 14:34         ` David Hildenbrand
2018-11-05 10:20 ` [Qemu-devel] [PATCH v2 10/10] spapr_pci: " David Hildenbrand
2018-11-05 10:31   ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2018-11-05 10:33     ` David Hildenbrand
2018-11-07  4:22   ` [Qemu-devel] " David Gibson
2018-11-08  3:08     ` [Qemu-devel] QEMU bootup hang in tcg model using mainline QEMU code gengdongjiu
2018-11-19 17:13   ` [Qemu-devel] [PATCH v2 10/10] spapr_pci: perform unplug via the hotplug handler Igor Mammedov

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.