All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com, berrange@redhat.com
Subject: [PATCH v2 12/34] pci: fix 'hotplugglable' property behavior
Date: Thu,  2 Mar 2023 17:15:21 +0100	[thread overview]
Message-ID: <20230302161543.286002-13-imammedo@redhat.com> (raw)
In-Reply-To: <20230302161543.286002-1-imammedo@redhat.com>

Currently the property may flip its state
during VM bring up or just doesn't work as
the name implies.

In particular with PCIE root port that has
'hotplug={on|off}' property, and when it's
turned off, one would expect
  'hotpluggable' == false
for any devices attached to it.
Which is not the case since qbus_is_hotpluggable()
used by the property just checks for presence
of any hotplug_handler set on bus.

The problem is that name BusState::hotplug_handler
from its inception is misnomer, as it handles
not only hotplug but also in many cases coldplug
as well (i.e. generic wiring interface), and
it's fine to have hotplug_handler set on bus
while it doesn't support hotplug (ex. pcie-slot
with hotplug=off).

Another case of root port flipping 'hotpluggable'
state when ACPI PCI hotplug is enabled in this
case root port with 'hotplug=off' starts as
hotpluggable and then later on, pcihp
hotplug_handler clears hotplug_handler
explicitly after checking root port's 'hotplug'
property.

So root-port hotpluggablity check sort of works
if pcihp is enabled but is broken if pcihp is
disabled.

One way to deal with the issue is to ask
hotplug_handler if bus it controls is hotpluggable
or not. To do that add is_hotpluggable_bus()
hook to HotplugHandler interface and use it in
'hotpluggable' property + teach pcie-slot to
actually look into 'hotplug' property state
before deciding if bus is hotpluggable.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 include/hw/hotplug.h   |  2 ++
 include/hw/qdev-core.h | 13 ++++++++++++-
 hw/pci/pcie_port.c     |  8 ++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h
index e15f59c8b3..a9840ed485 100644
--- a/include/hw/hotplug.h
+++ b/include/hw/hotplug.h
@@ -48,6 +48,7 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler,
  * @unplug: unplug callback.
  *          Used for device removal with devices that implement
  *          asynchronous and synchronous (surprise) removal.
+ * @is_hotpluggable_bus: called to check if bus/its parent allow hotplug on bus
  */
 struct HotplugHandlerClass {
     /* <private> */
@@ -58,6 +59,7 @@ struct HotplugHandlerClass {
     hotplug_fn plug;
     hotplug_fn unplug_request;
     hotplug_fn unplug;
+    bool (*is_hotpluggable_bus)(HotplugHandler *plug_handler, BusState *bus);
 };
 
 /**
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index f5b3b2f89a..bd50ad5ee1 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -812,7 +812,18 @@ void qbus_set_bus_hotplug_handler(BusState *bus);
 
 static inline bool qbus_is_hotpluggable(BusState *bus)
 {
-   return bus->hotplug_handler;
+    HotplugHandler *plug_handler = bus->hotplug_handler;
+    bool ret = !!plug_handler;
+
+    if (plug_handler) {
+        HotplugHandlerClass *hdc;
+
+        hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler);
+        if (hdc->is_hotpluggable_bus) {
+            ret = hdc->is_hotpluggable_bus(plug_handler, bus);
+        }
+    }
+    return ret;
 }
 
 /**
diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c
index 65a397ad23..000633fec1 100644
--- a/hw/pci/pcie_port.c
+++ b/hw/pci/pcie_port.c
@@ -161,6 +161,13 @@ PCIDevice *pcie_find_port_by_pn(PCIBus *bus, uint8_t pn)
     return NULL;
 }
 
+static bool pcie_slot_is_hotpluggbale_bus(HotplugHandler *plug_handler,
+                                          BusState *bus)
+{
+    PCIESlot *s = PCIE_SLOT(bus->parent);
+    return s->hotplug;
+}
+
 static const TypeInfo pcie_port_type_info = {
     .name = TYPE_PCIE_PORT,
     .parent = TYPE_PCI_BRIDGE,
@@ -188,6 +195,7 @@ static void pcie_slot_class_init(ObjectClass *oc, void *data)
     hc->plug = pcie_cap_slot_plug_cb;
     hc->unplug = pcie_cap_slot_unplug_cb;
     hc->unplug_request = pcie_cap_slot_unplug_request_cb;
+    hc->is_hotpluggable_bus = pcie_slot_is_hotpluggbale_bus;
 }
 
 static const TypeInfo pcie_slot_type_info = {
-- 
2.39.1



  parent reply	other threads:[~2023-03-02 16:17 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 16:15 [PATCH v2 00/34] pci(pc/q35): acpi-index support on non-hotpluggable slots Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 01/34] Revert "tests/qtest: Check for devices in bios-tables-test" Igor Mammedov
2023-03-02 16:46   ` Fabiano Rosas
2023-03-02 16:15 ` [PATCH v2 02/34] tests: acpi: whitelist new q35.noacpihp test and pc.hpbrroot Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 03/34] tests: acpi: add test_acpi_q35_tcg_no_acpi_hotplug test and extend test_acpi_piix4_no_acpi_pci_hotplug Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 04/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 05/34] tests: acpi: whitelist q35/DSDT.multi-bridge before extending testcase Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 06/34] tests: acpi: extend multi-bridge case with case 'root-port, id=HOHP, hotplug=off root-port, bus=NOHP' Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 07/34] x86: pcihp: fix missing PCNT callchain when intermediate root-port has 'hotplug=off' set Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 08/34] tests: acpi: whitelist pc/DSDT.hpbrroot and pc/DSDT.hpbridge tests Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 09/34] x86: pcihp: fix missing bridge AML when intermediate root-port has 'hotplug=off' set Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 10/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 11/34] pcihp: piix4: do not redirect hotplug controller to piix4 when ACPI hotplug is disabled Igor Mammedov
2023-03-02 16:15 ` Igor Mammedov [this message]
2023-03-02 16:15 ` [PATCH v2 13/34] tests: acpi: whitelist DSDT blobs before isolating PCI _DSM func 0 prolog Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 14/34] pcihp: move PCI _DSM function 0 prolog into separate function Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 15/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 16/34] tests: acpi: whitelist DSDT before adding EDSM method Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 17/34] acpi: pci: add EDSM method to DSDT Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 18/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 19/34] tests: acpi: whitelist DSDT before adding device with acpi-index to testcases Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 20/34] tests: acpi: add device with acpi-index on non-hotpluggble bus Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 21/34] acpi: pci: support acpi-index for non-hotpluggable devices Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 22/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 23/34] tests: acpi: whitelist DSDT before exposing non zero functions Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 24/34] acpi: pci: describe all functions on populated slots Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 25/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 26/34] tests: acpi: whitelist DSDT before adding non-0 function device with acpi-index to testcases Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 27/34] tests: acpi: add non zero function device with acpi-index on non-hotpluggble bus Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 28/34] tests: acpi: update expected blobs Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 29/34] pci: move acpi-index uniqueness check to generic PCI device code Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 30/34] acpi: pci: drop BSEL usage when deciding that device isn't hotpluggable Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 31/34] acpi: pci: move BSEL into build_append_pcihp_slots() Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 32/34] acpi: pci: move out ACPI PCI hotplug generator from generic slot generator build_append_pci_bus_devices() Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 33/34] pcihp: move fields enabling hotplug into AcpiPciHpState Igor Mammedov
2023-03-02 16:15 ` [PATCH v2 34/34] pcihp: add ACPI PCI hotplug specific is_hotpluggable_bus() callback Igor Mammedov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230302161543.286002-13-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=berrange@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.