From 4e81f870fc9f235df004fe33f668217f34c5d210 Mon Sep 17 00:00:00 2001 Message-Id: <4e81f870fc9f235df004fe33f668217f34c5d210@dist-git> From: Laine Stump Date: Wed, 10 Aug 2016 11:00:13 -0400 Subject: [PATCH] conf: restrict where dmi-to-pci-bridge can be connected libvirt had allowed a dmi-to-pci-bridge to be plugged in anywhere a normal PCIe endpoint can be connected, but this is wrong - it will only work if it's plugged into pcie-root (the PCIe root complex) or a pcie-expander-bus (the qemu device pxb-pcie). This patch adjusts the connection flags accordingly. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1363648 (cherry picked from commit b70e3d0123fcb6e22e99d1b272239e03a84262cb) --- src/conf/domain_addr.c | 26 ++++++++++----- src/conf/domain_addr.h | 4 ++- .../qemuxml2argv-q35-dmi-bad-address1.xml | 31 +++++++++++++++++ .../qemuxml2argv-q35-dmi-bad-address2.xml | 39 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 8 +++++ 5 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-q35-dmi-bad-address1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-q35-dmi-bad-address2.xml diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index c22329d..ea641a5 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -58,15 +58,17 @@ virDomainPCIControllerModelToConnectType(virDomainControllerModelPCI model) */ return VIR_PCI_CONNECT_TYPE_PCI_DEVICE; - case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE: case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS: - /* dmi-to-pci-bridge and pcie-expander-bus are treated like - * PCIe devices (the part of pcie-expander-bus that is plugged - * in isn't the expander bus itself, but a companion device - * used for setting it up). + /* pcie-expander-bus is treated like a standard PCIe endpoint + * device (the part of pcie-expander-bus that is plugged in + * isn't the expander bus itself, but a companion device used + * for setting it up). */ return VIR_PCI_CONNECT_TYPE_PCIE_DEVICE; + case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE: + return VIR_PCI_CONNECT_TYPE_DMI_TO_PCI_BRIDGE; + case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT: return VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT; @@ -133,6 +135,8 @@ virDomainPCIAddressFlagsCompatible(virPCIDeviceAddressPtr addr, connectStr = "pci-switch-upstream-port"; } else if (devFlags & VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_DOWNSTREAM_PORT) { connectStr = "pci-switch-downstream-port"; + } else if (devFlags & VIR_PCI_CONNECT_TYPE_DMI_TO_PCI_BRIDGE) { + connectStr = "dmi-to-pci-bridge"; } else { /* this should never happen. If it does, there is a * bug in the code that sets the flag bits for devices. @@ -259,8 +263,9 @@ virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus, * user config *and* the particular device being attached also * allows it. */ - bus->flags = (VIR_PCI_CONNECT_TYPE_PCIE_DEVICE - | VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT); + bus->flags = (VIR_PCI_CONNECT_TYPE_PCIE_DEVICE | + VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT | + VIR_PCI_CONNECT_TYPE_DMI_TO_PCI_BRIDGE); bus->minSlot = 1; bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST; break; @@ -291,8 +296,11 @@ virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus, bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST; break; case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS: - /* single slot, no hotplug, only accepts pcie-root-port */ - bus->flags = VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT; + /* single slot, no hotplug, only accepts pcie-root-port or + * dmi-to-pci-bridge + */ + bus->flags = (VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT | + VIR_PCI_CONNECT_TYPE_DMI_TO_PCI_BRIDGE); bus->minSlot = 0; bus->maxSlot = 0; break; diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index ce94981..2d55c46 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -40,6 +40,7 @@ typedef enum { VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT = 1 << 3, VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_UPSTREAM_PORT = 1 << 4, VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_DOWNSTREAM_PORT = 1 << 5, + VIR_PCI_CONNECT_TYPE_DMI_TO_PCI_BRIDGE = 1 << 6, } virDomainPCIConnectFlags; /* a combination of all bits that describe the type of connections @@ -49,7 +50,8 @@ typedef enum { (VIR_PCI_CONNECT_TYPE_PCI_DEVICE | VIR_PCI_CONNECT_TYPE_PCIE_DEVICE | \ VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_UPSTREAM_PORT | \ VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_DOWNSTREAM_PORT | \ - VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT) + VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT | \ + VIR_PCI_CONNECT_TYPE_DMI_TO_PCI_BRIDGE) /* combination of all bits that could be used to connect a normal * endpoint device (i.e. excluding the connection possible between an diff --git a/tests/qemuxml2argvdata/qemuxml2argv-q35-dmi-bad-address1.xml b/tests/qemuxml2argvdata/qemuxml2argv-q35-dmi-bad-address1.xml new file mode 100644 index 0000000..e23c874 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-q35-dmi-bad-address1.xml @@ -0,0 +1,31 @@ + + q35-test + 11dbdcdd-4c3b-482b-8903-9bdb8c0a2774 + 2097152 + 2097152 + 2 + + hvm + + + + destroy + restart + destroy + + /usr/libexec/qemu-kvm + + + + + + + + + + +
+ + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-q35-dmi-bad-address2.xml b/tests/qemuxml2argvdata/qemuxml2argv-q35-dmi-bad-address2.xml new file mode 100644 index 0000000..c3c1b6a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-q35-dmi-bad-address2.xml @@ -0,0 +1,39 @@ + + q35-test + 11dbdcdd-4c3b-482b-8903-9bdb8c0a2774 + 2097152 + 2097152 + 2 + + hvm + + + + destroy + restart + destroy + + /usr/libexec/qemu-kvm + + + +
+ + + + + + + + + + + +
+ + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 927728e..c7c0ff2 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1631,6 +1631,14 @@ mymain(void) QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_ICH9_USB_EHCI1, QEMU_CAPS_DEVICE_VIDEO_PRIMARY, QEMU_CAPS_VGA_QXL, QEMU_CAPS_DEVICE_QXL); + DO_TEST_PARSE_ERROR("q35-dmi-bad-address1", + QEMU_CAPS_DEVICE_PCI_BRIDGE, + QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, + QEMU_CAPS_DEVICE_IOH3420); + DO_TEST_PARSE_ERROR("q35-dmi-bad-address2", + QEMU_CAPS_DEVICE_PCI_BRIDGE, + QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, + QEMU_CAPS_DEVICE_IOH3420); DO_TEST("q35-pm-disable", QEMU_CAPS_DEVICE_PCI_BRIDGE, QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, QEMU_CAPS_ICH9_AHCI, -- 2.9.2