c480ed
From 9aef6ea4b1d8a79e353bb34ab5559c698cad1eb1 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <9aef6ea4b1d8a79e353bb34ab5559c698cad1eb1@dist-git>
c480ed
From: Yi Min Zhao <zyimin@linux.ibm.com>
c480ed
Date: Mon, 8 Apr 2019 10:57:26 +0200
c480ed
Subject: [PATCH] qemu: Add zPCI address definition check
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
We should ensure that QEMU supports zPCI when a zPCI address is defined
c480ed
in XML and otherwise report an error. This patch introduces a generic
c480ed
validation function qemuDomainDeviceDefValidateAddress() which calls
c480ed
qemuDomainDeviceDefValidateZPCIAddress() if address type is PCI address.
c480ed
c480ed
Signed-off-by: Yi Min Zhao <zyimin@linux.ibm.com>
c480ed
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
c480ed
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
c480ed
c480ed
(cherry picked from commit e6565d54db3d52ae38b5934877be4d004c2d5f35)
c480ed
c480ed
https://bugzilla.redhat.com/show_bug.cgi?id=1508149
c480ed
c480ed
Conflicts:
c480ed
c480ed
  * src/qemu/qemu_domain.c
c480ed
    + context
c480ed
      - missing 709f57c25be8
c480ed
c480ed
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c480ed
Message-Id: <20190408085732.28684-10-abologna@redhat.com>
c480ed
Reviewed-by: Laine Stump <laine@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/qemu/qemu_domain.c                        | 36 +++++++++++++++++++
c480ed
 .../hostdev-vfio-zpci-wrong-arch.xml          | 34 ++++++++++++++++++
c480ed
 tests/qemuxml2argvtest.c                      |  2 ++
c480ed
 3 files changed, 72 insertions(+)
c480ed
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml
c480ed
c480ed
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
c480ed
index da961f0de9..8604385aa2 100644
c480ed
--- a/src/qemu/qemu_domain.c
c480ed
+++ b/src/qemu/qemu_domain.c
c480ed
@@ -5681,6 +5681,38 @@ qemuDomainDeviceDefValidateGraphics(const virDomainGraphicsDef *graphics,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+qemuDomainDeviceDefValidateZPCIAddress(virDomainDeviceInfoPtr info,
c480ed
+                                       virQEMUCapsPtr qemuCaps)
c480ed
+{
c480ed
+    if (!virZPCIDeviceAddressIsEmpty(&info->addr.pci.zpci) &&
c480ed
+        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ZPCI)) {
c480ed
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c480ed
+                       "%s",
c480ed
+                       _("This QEMU binary doesn't support zPCI"));
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
+static int
c480ed
+qemuDomainDeviceDefValidateAddress(const virDomainDeviceDef *dev,
c480ed
+                                   virQEMUCapsPtr qemuCaps)
c480ed
+{
c480ed
+    virDomainDeviceInfoPtr info;
c480ed
+
c480ed
+    if (!(info = virDomainDeviceGetInfo((virDomainDeviceDef *)dev)))
c480ed
+        return 0;
c480ed
+
c480ed
+    if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI)
c480ed
+        return qemuDomainDeviceDefValidateZPCIAddress(info, qemuCaps);
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 static int
c480ed
 qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
c480ed
                             const virDomainDef *def,
c480ed
@@ -5694,6 +5726,9 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
c480ed
                                             def->emulator)))
c480ed
         return -1;
c480ed
 
c480ed
+    if ((ret = qemuDomainDeviceDefValidateAddress(dev, qemuCaps)) < 0)
c480ed
+        goto cleanup;
c480ed
+
c480ed
     switch ((virDomainDeviceType)dev->type) {
c480ed
     case VIR_DOMAIN_DEVICE_NET:
c480ed
         ret = qemuDomainDeviceDefValidateNetwork(dev->data.net);
c480ed
@@ -5769,6 +5804,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
c480ed
         break;
c480ed
     }
c480ed
 
c480ed
+ cleanup:
c480ed
     virObjectUnref(qemuCaps);
c480ed
     return ret;
c480ed
 }
c480ed
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml b/tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml
c480ed
new file mode 100644
c480ed
index 0000000000..bfb2f83a3b
c480ed
--- /dev/null
c480ed
+++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci-wrong-arch.xml
c480ed
@@ -0,0 +1,34 @@
c480ed
+<domain type='qemu'>
c480ed
+  <name>QEMUGuest2</name>
c480ed
+  <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid>
c480ed
+  <memory unit='KiB'>219100</memory>
c480ed
+  <currentMemory unit='KiB'>219100</currentMemory>
c480ed
+  <vcpu placement='static'>1</vcpu>
c480ed
+  <os>
c480ed
+    <type arch='i686' machine='pc'>hvm</type>
c480ed
+    <boot dev='hd'/>
c480ed
+  </os>
c480ed
+  <clock offset='utc'/>
c480ed
+  <on_poweroff>destroy</on_poweroff>
c480ed
+  <on_reboot>restart</on_reboot>
c480ed
+  <on_crash>destroy</on_crash>
c480ed
+  <devices>
c480ed
+    <emulator>/usr/bin/qemu-system-i686</emulator>
c480ed
+    <disk type='block' device='disk'>
c480ed
+      <source dev='/dev/HostVG/QEMUGuest2'/>
c480ed
+      <target dev='hda' bus='ide'/>
c480ed
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
c480ed
+    </disk>
c480ed
+    <controller type='pci' index='0' model='pci-root'/>
c480ed
+    <hostdev mode='subsystem' type='pci' managed='yes'>
c480ed
+      <driver name='vfio'/>
c480ed
+      <source>
c480ed
+        <address domain='0x0001' bus='00' slot='00' function='0'/>
c480ed
+      </source>
c480ed
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'>
c480ed
+        <zpci uid='0x0019' fid='0x0000001f'/>
c480ed
+      </address>
c480ed
+    </hostdev>
c480ed
+    <memballoon model='virtio'/>
c480ed
+  </devices>
c480ed
+</domain>
c480ed
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
c480ed
index 2eb2505971..1066de8bc4 100644
c480ed
--- a/tests/qemuxml2argvtest.c
c480ed
+++ b/tests/qemuxml2argvtest.c
c480ed
@@ -1632,6 +1632,8 @@ mymain(void)
c480ed
     DO_TEST_PARSE_ERROR("hostdev-mdev-display-missing-graphics",
c480ed
             QEMU_CAPS_DEVICE_VFIO_PCI,
c480ed
             QEMU_CAPS_VFIO_PCI_DISPLAY);
c480ed
+    DO_TEST_PARSE_ERROR("hostdev-vfio-zpci-wrong-arch",
c480ed
+                        QEMU_CAPS_DEVICE_VFIO_PCI);
c480ed
     DO_TEST("hostdev-vfio-zpci",
c480ed
             QEMU_CAPS_DEVICE_VFIO_PCI,
c480ed
             QEMU_CAPS_DEVICE_ZPCI);
c480ed
-- 
c480ed
2.22.0
c480ed