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