From 351bb3a04c1eb6de11efad54f809a6f3e3a868c8 Mon Sep 17 00:00:00 2001 Message-Id: <351bb3a04c1eb6de11efad54f809a6f3e3a868c8@dist-git> From: Laine Stump Date: Sun, 26 Apr 2020 13:17:01 -0400 Subject: [PATCH] qemu/conf: set HOTPLUGGABLE connect flag during PCI address set init virDomainPCIAddressBusSetModel() is called for each PCI controller when building an address set prior to assiging PCI addresses to devices. This patch adds a new argument, allowHotplug, to that function that can be set to false if we know for certain that a particular controller won't support hotplug The most interesting case is in qemuDomainPCIAddressSetCreate(), where the config of each existing controller is available while building the address set, so we can appropriately set allowHotplug = false when the user has "hotplug='off'" in the config of a controller that normally would support hotplug. In all other cases, it is set to true or false in accordance with the capability of the controller model. So far we aren't doing anything with this bus flag in the address set. Signed-off-by: Laine Stump Reviewed-by: Michal Privoznik (cherry picked from commit aa15e9259f1f246e69fb9742581ced720c88695d) https://bugzilla.redhat.com/1802592 Signed-off-by: Laine Stump Message-Id: <20200426171703.18808-1-laine@redhat.com> Reviewed-by: Michal Privoznik --- src/conf/domain_addr.c | 31 +++++++++++++++++++++---------- src/conf/domain_addr.h | 3 ++- src/qemu/qemu_domain_address.c | 10 +++++++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 05f036e3e6..cc45a0bbf1 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -495,31 +495,40 @@ virDomainPCIAddressValidate(virDomainPCIAddressSetPtr addrs, int virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus, - virDomainControllerModelPCI model) + virDomainControllerModelPCI model, + bool allowHotplug) { /* set flags for what can be connected *downstream* from each * bus. */ + virDomainPCIConnectFlags hotplugFlag = 0; + + if (allowHotplug) + hotplugFlag = VIR_PCI_CONNECT_HOTPLUGGABLE; + switch (model) { case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT: bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN | VIR_PCI_CONNECT_TYPE_PCI_DEVICE | VIR_PCI_CONNECT_TYPE_PCI_BRIDGE | - VIR_PCI_CONNECT_TYPE_PCI_EXPANDER_BUS); + VIR_PCI_CONNECT_TYPE_PCI_EXPANDER_BUS | + hotplugFlag); bus->minSlot = 1; bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST; break; case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE: bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN | VIR_PCI_CONNECT_TYPE_PCI_DEVICE | - VIR_PCI_CONNECT_TYPE_PCI_BRIDGE); + VIR_PCI_CONNECT_TYPE_PCI_BRIDGE | + hotplugFlag); bus->minSlot = 1; bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST; break; case VIR_DOMAIN_CONTROLLER_MODEL_PCI_EXPANDER_BUS: bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN | VIR_PCI_CONNECT_TYPE_PCI_DEVICE | - VIR_PCI_CONNECT_TYPE_PCI_BRIDGE); + VIR_PCI_CONNECT_TYPE_PCI_BRIDGE | + hotplugFlag); bus->minSlot = 0; bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST; break; @@ -550,7 +559,8 @@ virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus, * the first of which is not usable because of the SHPC */ bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN | VIR_PCI_CONNECT_TYPE_PCI_DEVICE | - VIR_PCI_CONNECT_TYPE_PCI_BRIDGE); + VIR_PCI_CONNECT_TYPE_PCI_BRIDGE | + hotplugFlag); bus->minSlot = 1; bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST; break; @@ -562,7 +572,8 @@ virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus, bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN | VIR_PCI_CONNECT_TYPE_PCIE_DEVICE | VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_UPSTREAM_PORT | - VIR_PCI_CONNECT_TYPE_PCIE_TO_PCI_BRIDGE); + VIR_PCI_CONNECT_TYPE_PCIE_TO_PCI_BRIDGE | + hotplugFlag); bus->minSlot = 0; bus->maxSlot = 0; break; @@ -759,7 +770,7 @@ virDomainPCIAddressSetGrow(virDomainPCIAddressSetPtr addrs, * rest are of the requested type */ if (virDomainPCIAddressBusSetModel(&addrs->buses[i++], - VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE) < 0) { + VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE, false) < 0) { return -1; } } @@ -776,20 +787,20 @@ virDomainPCIAddressSetGrow(virDomainPCIAddressSetPtr addrs, * will be allocated for the dummy PCIe device later on. */ if (virDomainPCIAddressBusSetModel(&addrs->buses[i], - VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT) < 0) { + VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT, true) < 0) { return -1; } addrs->buses[i].flags = VIR_PCI_CONNECT_TYPE_PCIE_TO_PCI_BRIDGE; i++; if (virDomainPCIAddressBusSetModel(&addrs->buses[i++], - VIR_DOMAIN_CONTROLLER_MODEL_PCIE_TO_PCI_BRIDGE) < 0) { + VIR_DOMAIN_CONTROLLER_MODEL_PCIE_TO_PCI_BRIDGE, true) < 0) { return -1; } } for (; i < addrs->nbuses; i++) { - if (virDomainPCIAddressBusSetModel(&addrs->buses[i], model) < 0) + if (virDomainPCIAddressBusSetModel(&addrs->buses[i], model, true) < 0) return -1; } diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 40738ddb72..c1363c1490 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -148,7 +148,8 @@ bool virDomainPCIAddressValidate(virDomainPCIAddressSetPtr addrs, int virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus, - virDomainControllerModelPCI model) + virDomainControllerModelPCI model, + bool allowHotplug) ATTRIBUTE_NONNULL(1); bool virDomainPCIAddressBusIsFullyReserved(virDomainPCIAddressBusPtr bus) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index e81585bc6c..2ae1724696 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1645,6 +1645,7 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def, for (i = 0; i < def->ncontrollers; i++) { virDomainControllerDefPtr cont = def->controllers[i]; size_t idx = cont->idx; + bool allowHotplug = false; if (cont->type != VIR_DOMAIN_CONTROLLER_TYPE_PCI) continue; @@ -1656,7 +1657,10 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def, goto error; } - if (virDomainPCIAddressBusSetModel(&addrs->buses[idx], cont->model) < 0) + if (cont->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_OFF) + allowHotplug = true; + + if (virDomainPCIAddressBusSetModel(&addrs->buses[idx], cont->model, allowHotplug) < 0) goto error; /* Forward the information about isolation groups */ @@ -1674,7 +1678,7 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def, * assigning addresses to devices. */ if (virDomainPCIAddressBusSetModel(&addrs->buses[0], - VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 0) + VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT, true) < 0) goto error; } @@ -1696,7 +1700,7 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def, if (addrs->buses[i].model) continue; - if (virDomainPCIAddressBusSetModel(&addrs->buses[i], defaultModel) < 0) + if (virDomainPCIAddressBusSetModel(&addrs->buses[i], defaultModel, true) < 0) goto error; VIR_DEBUG("Auto-adding ", -- 2.26.2