render / rpms / libvirt

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