c313de
From 37f8c26d43550986a8c6467aef4bf9d1ebe3a683 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <37f8c26d43550986a8c6467aef4bf9d1ebe3a683@dist-git>
c313de
From: Yi Min Zhao <zyimin@linux.ibm.com>
c313de
Date: Mon, 8 Apr 2019 10:57:28 +0200
c313de
Subject: [PATCH] qemu: Generate and use zPCI device in QEMU command line
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
Add new functions to generate zPCI command string and append it to
c313de
QEMU command line. And the related tests are added.
c313de
c313de
Signed-off-by: Yi Min Zhao <zyimin@linux.ibm.com>
c313de
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
c313de
Reviewed-by: Stefan Zimmermann <stzi@linux.ibm.com>
c313de
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
c313de
c313de
(cherry picked from commit 9d6be3ff79b4ce7588e2842d4a6c3e713a97a7ec)
c313de
c313de
https://bugzilla.redhat.com/show_bug.cgi?id=1508149
c313de
c313de
Conflicts:
c313de
c313de
  * src/qemu/qemu_command.c
c313de
    + context in qemuBuildInterfaceCommandLine()
c313de
      - missing 4de4e4bc9911
c313de
    + context in qemuBuildDiskCommandLine()
c313de
      - missing b8936d265518
c313de
c313de
  * tests/qemuxml2argvdata/hostdev-vfio-zpci.args
c313de
    + no -boot in output
c313de
      - missing caccbba64aa9
c313de
c313de
Changes
c313de
c313de
  * tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.args
c313de
    tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.args
c313de
    tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.args
c313de
    + no -boot in output
c313de
      - missing caccbba64aa9
c313de
c313de
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c313de
Message-Id: <20190408085732.28684-12-abologna@redhat.com>
c313de
Reviewed-by: Laine Stump <laine@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/qemu/qemu_command.c                       | 104 ++++++++++++++++++
c313de
 src/qemu/qemu_command.h                       |   2 +
c313de
 .../disk-virtio-s390-zpci.args                |   1 +
c313de
 .../hostdev-vfio-zpci-autogenerate.args       |  26 +++++
c313de
 .../hostdev-vfio-zpci-autogenerate.xml        |  18 +++
c313de
 .../hostdev-vfio-zpci-boundaries.args         |  30 +++++
c313de
 .../hostdev-vfio-zpci-boundaries.xml          |  30 +++++
c313de
 .../hostdev-vfio-zpci-multidomain-many.args   |  40 +++++++
c313de
 .../hostdev-vfio-zpci-multidomain-many.xml    |  79 +++++++++++++
c313de
 tests/qemuxml2argvdata/hostdev-vfio-zpci.args |   2 +
c313de
 tests/qemuxml2argvtest.c                      |  13 +++
c313de
 .../hostdev-vfio-zpci-autogenerate.xml        |  34 ++++++
c313de
 .../hostdev-vfio-zpci-boundaries.xml          |  48 ++++++++
c313de
 .../hostdev-vfio-zpci-multidomain-many.xml    |  97 ++++++++++++++++
c313de
 tests/qemuxml2xmltest.c                       |  11 ++
c313de
 15 files changed, 535 insertions(+)
c313de
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.args
c313de
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.xml
c313de
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.args
c313de
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.xml
c313de
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.args
c313de
 create mode 100644 tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.xml
c313de
 create mode 100644 tests/qemuxml2xmloutdata/hostdev-vfio-zpci-autogenerate.xml
c313de
 create mode 100644 tests/qemuxml2xmloutdata/hostdev-vfio-zpci-boundaries.xml
c313de
 create mode 100644 tests/qemuxml2xmloutdata/hostdev-vfio-zpci-multidomain-many.xml
c313de
c313de
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c313de
index a8c832bad8..c06f396b44 100644
c313de
--- a/src/qemu/qemu_command.c
c313de
+++ b/src/qemu/qemu_command.c
c313de
@@ -2147,6 +2147,57 @@ qemuBuildDriveDevStr(const virDomainDef *def,
c313de
     return NULL;
c313de
 }
c313de
 
c313de
+char *
c313de
+qemuBuildZPCIDevStr(virDomainDeviceInfoPtr dev)
c313de
+{
c313de
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
c313de
+
c313de
+    virBufferAsprintf(&buf,
c313de
+                      "zpci,uid=%u,fid=%u,target=%s,id=zpci%u",
c313de
+                      dev->addr.pci.zpci.uid,
c313de
+                      dev->addr.pci.zpci.fid,
c313de
+                      dev->alias,
c313de
+                      dev->addr.pci.zpci.uid);
c313de
+
c313de
+    if (virBufferCheckError(&buf) < 0) {
c313de
+        virBufferFreeAndReset(&buf;;
c313de
+        return NULL;
c313de
+    }
c313de
+
c313de
+    return virBufferContentAndReset(&buf;;
c313de
+}
c313de
+
c313de
+static int
c313de
+qemuCommandAddZPCIDevice(virCommandPtr cmd,
c313de
+                         virDomainDeviceInfoPtr dev)
c313de
+{
c313de
+    char *devstr = NULL;
c313de
+
c313de
+    virCommandAddArg(cmd, "-device");
c313de
+
c313de
+    if (!(devstr = qemuBuildZPCIDevStr(dev)))
c313de
+        return -1;
c313de
+
c313de
+    virCommandAddArg(cmd, devstr);
c313de
+
c313de
+    VIR_FREE(devstr);
c313de
+    return 0;
c313de
+}
c313de
+
c313de
+static int
c313de
+qemuCommandAddExtDevice(virCommandPtr cmd,
c313de
+                        virDomainDeviceInfoPtr dev)
c313de
+{
c313de
+    if (dev->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI ||
c313de
+        dev->addr.pci.extFlags == VIR_PCI_ADDRESS_EXTENSION_NONE) {
c313de
+        return 0;
c313de
+    }
c313de
+
c313de
+    if (dev->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI)
c313de
+        return qemuCommandAddZPCIDevice(cmd, dev);
c313de
+
c313de
+    return 0;
c313de
+}
c313de
 
c313de
 static int
c313de
 qemuBulildFloppyCommandLineOptions(virCommandPtr cmd,
c313de
@@ -2267,6 +2318,9 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
c313de
                                                    bootindex) < 0)
c313de
                 return -1;
c313de
         } else {
c313de
+            if (qemuCommandAddExtDevice(cmd, &disk->info) < 0)
c313de
+                return -1;
c313de
+
c313de
             virCommandAddArg(cmd, "-device");
c313de
 
c313de
             if (!(optstr = qemuBuildDriveDevStr(def, disk, bootindex,
c313de
@@ -2466,6 +2520,9 @@ qemuBuildFSDevCommandLine(virCommandPtr cmd,
c313de
         virCommandAddArg(cmd, optstr);
c313de
         VIR_FREE(optstr);
c313de
 
c313de
+        if (qemuCommandAddExtDevice(cmd, &fs->info) < 0)
c313de
+            return -1;
c313de
+
c313de
         virCommandAddArg(cmd, "-device");
c313de
         if (!(optstr = qemuBuildFSDevStr(def, fs, qemuCaps)))
c313de
             return -1;
c313de
@@ -2950,6 +3007,11 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd,
c313de
                 goto cleanup;
c313de
 
c313de
             if (devstr) {
c313de
+                if (qemuCommandAddExtDevice(cmd, &cont->info) < 0) {
c313de
+                    VIR_FREE(devstr);
c313de
+                    goto cleanup;
c313de
+                }
c313de
+
c313de
                 virCommandAddArg(cmd, "-device");
c313de
                 virCommandAddArg(cmd, devstr);
c313de
                 VIR_FREE(devstr);
c313de
@@ -3753,6 +3815,9 @@ qemuBuildWatchdogCommandLine(virCommandPtr cmd,
c313de
     if (!def->watchdog)
c313de
         return 0;
c313de
 
c313de
+    if (qemuCommandAddExtDevice(cmd, &def->watchdog->info) < 0)
c313de
+        return -1;
c313de
+
c313de
     virCommandAddArg(cmd, "-device");
c313de
 
c313de
     optstr = qemuBuildWatchdogDevStr(def, watchdog, qemuCaps);
c313de
@@ -3837,6 +3902,9 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd,
c313de
     if (qemuBuildVirtioOptionsStr(&buf, def->memballoon->virtio, qemuCaps) < 0)
c313de
         goto error;
c313de
 
c313de
+    if (qemuCommandAddExtDevice(cmd, &def->memballoon->info) < 0)
c313de
+        goto error;
c313de
+
c313de
     virCommandAddArg(cmd, "-device");
c313de
     virCommandAddArgBuffer(cmd, &buf;;
c313de
     return 0;
c313de
@@ -4059,6 +4127,9 @@ qemuBuildInputCommandLine(virCommandPtr cmd,
c313de
         virDomainInputDefPtr input = def->inputs[i];
c313de
         char *devstr = NULL;
c313de
 
c313de
+        if (qemuCommandAddExtDevice(cmd, &input->info) < 0)
c313de
+            return -1;
c313de
+
c313de
         if (qemuBuildInputDevStr(&devstr, def, input, qemuCaps) < 0)
c313de
             return -1;
c313de
 
c313de
@@ -4200,6 +4271,9 @@ qemuBuildSoundCommandLine(virCommandPtr cmd,
c313de
         if (sound->model == VIR_DOMAIN_SOUND_MODEL_PCSPK) {
c313de
             virCommandAddArgList(cmd, "-soundhw", "pcspk", NULL);
c313de
         } else {
c313de
+            if (qemuCommandAddExtDevice(cmd, &sound->info) < 0)
c313de
+                return -1;
c313de
+
c313de
             virCommandAddArg(cmd, "-device");
c313de
             if (!(str = qemuBuildSoundDevStr(def, sound, qemuCaps)))
c313de
                 return -1;
c313de
@@ -4439,6 +4513,10 @@ qemuBuildVideoCommandLine(virCommandPtr cmd,
c313de
         if (video->primary) {
c313de
             if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY)) {
c313de
 
c313de
+                if (qemuCommandAddExtDevice(cmd,
c313de
+                                            &def->videos[i]->info) < 0)
c313de
+                    return -1;
c313de
+
c313de
                 virCommandAddArg(cmd, "-device");
c313de
 
c313de
                 if (!(str = qemuBuildDeviceVideoStr(def, video, qemuCaps)))
c313de
@@ -4451,6 +4529,9 @@ qemuBuildVideoCommandLine(virCommandPtr cmd,
c313de
                     return -1;
c313de
             }
c313de
         } else {
c313de
+            if (qemuCommandAddExtDevice(cmd, &def->videos[i]->info) < 0)
c313de
+                return -1;
c313de
+
c313de
             virCommandAddArg(cmd, "-device");
c313de
 
c313de
             if (!(str = qemuBuildDeviceVideoStr(def, video, qemuCaps)))
c313de
@@ -5328,6 +5409,10 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
c313de
                                      VIR_COMMAND_PASS_FD_CLOSE_PARENT);
c313de
                 }
c313de
             }
c313de
+
c313de
+            if (qemuCommandAddExtDevice(cmd, hostdev->info) < 0)
c313de
+                return -1;
c313de
+
c313de
             virCommandAddArg(cmd, "-device");
c313de
             devstr = qemuBuildPCIHostdevDevStr(def, hostdev, bootIndex,
c313de
                                                configfd_name, qemuCaps);
c313de
@@ -5802,6 +5887,9 @@ qemuBuildRNGCommandLine(virLogManagerPtr logManager,
c313de
         virCommandAddArgBuffer(cmd, &buf;;
c313de
 
c313de
         /* add the device */
c313de
+        if (qemuCommandAddExtDevice(cmd, &rng->info) < 0)
c313de
+            return -1;
c313de
+
c313de
         if (!(tmp = qemuBuildRNGDevStr(def, rng, qemuCaps)))
c313de
             return -1;
c313de
         virCommandAddArgList(cmd, "-device", tmp, NULL);
c313de
@@ -8654,11 +8742,17 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
c313de
      *   New way: -netdev type=tap,id=netdev1 -device e1000,id=netdev1
c313de
      */
c313de
     if (qemuDomainSupportsNicdev(def, net)) {
c313de
+        if (qemuCommandAddExtDevice(cmd, &net->info) < 0)
c313de
+            goto cleanup;
c313de
+
c313de
         if (!(nic = qemuBuildNicDevStr(def, net, bootindex,
c313de
                                        vhostfdSize, qemuCaps)))
c313de
             goto cleanup;
c313de
         virCommandAddArgList(cmd, "-device", nic, NULL);
c313de
     } else {
c313de
+        if (qemuCommandAddExtDevice(cmd, &net->info) < 0)
c313de
+            goto cleanup;
c313de
+
c313de
         if (!(nic = qemuBuildLegacyNicStr(net)))
c313de
             goto cleanup;
c313de
         virCommandAddArgList(cmd, "-net", nic, NULL);
c313de
@@ -9105,6 +9199,12 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
c313de
 
c313de
     if (!devstr)
c313de
         return -1;
c313de
+
c313de
+    if (qemuCommandAddExtDevice(cmd, &shmem->info) < 0) {
c313de
+        VIR_FREE(devstr);
c313de
+        return -1;
c313de
+    }
c313de
+
c313de
     virCommandAddArgList(cmd, "-device", devstr, NULL);
c313de
     VIR_FREE(devstr);
c313de
 
c313de
@@ -10259,6 +10359,10 @@ qemuBuildVsockCommandLine(virCommandPtr cmd,
c313de
 
c313de
     virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
c313de
     priv->vhostfd = -1;
c313de
+
c313de
+    if (qemuCommandAddExtDevice(cmd, &vsock->info) < 0)
c313de
+        goto cleanup;
c313de
+
c313de
     virCommandAddArgList(cmd, "-device", devstr, NULL);
c313de
 
c313de
     ret = 0;
c313de
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
c313de
index 4f1b360130..e8cd8ed04e 100644
c313de
--- a/src/qemu/qemu_command.h
c313de
+++ b/src/qemu/qemu_command.h
c313de
@@ -174,6 +174,8 @@ char *qemuBuildRedirdevDevStr(const virDomainDef *def,
c313de
                               virDomainRedirdevDefPtr dev,
c313de
                               virQEMUCapsPtr qemuCaps);
c313de
 
c313de
+char *qemuBuildZPCIDevStr(virDomainDeviceInfoPtr dev);
c313de
+
c313de
 int qemuNetworkPrepareDevices(virDomainDefPtr def);
c313de
 
c313de
 int qemuGetDriveSourceString(virStorageSourcePtr src,
c313de
diff --git a/tests/qemuxml2argvdata/disk-virtio-s390-zpci.args b/tests/qemuxml2argvdata/disk-virtio-s390-zpci.args
c313de
index 20e63a15b5..ffb5d1597e 100644
c313de
--- a/tests/qemuxml2argvdata/disk-virtio-s390-zpci.args
c313de
+++ b/tests/qemuxml2argvdata/disk-virtio-s390-zpci.args
c313de
@@ -21,6 +21,7 @@ server,nowait \
c313de
 -no-shutdown \
c313de
 -boot c \
c313de
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-virtio-disk0 \
c313de
+-device zpci,uid=25,fid=31,target=virtio-disk0,id=zpci25 \
c313de
 -device virtio-blk-pci,bus=pci.0,addr=0x8,drive=drive-virtio-disk0,\
c313de
 id=virtio-disk0 \
c313de
 -device virtio-balloon-ccw,id=balloon0,devno=fe.0.0000
c313de
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.args b/tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.args
c313de
new file mode 100644
c313de
index 0000000000..e5987e1053
c313de
--- /dev/null
c313de
+++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.args
c313de
@@ -0,0 +1,26 @@
c313de
+LC_ALL=C \
c313de
+PATH=/bin \
c313de
+HOME=/home/test \
c313de
+USER=test \
c313de
+LOGNAME=test \
c313de
+QEMU_AUDIO_DRV=none \
c313de
+/usr/bin/qemu-system-s390x \
c313de
+-name QEMUGuest1 \
c313de
+-S \
c313de
+-machine s390-ccw-virtio,accel=tcg,usb=off,dump-guest-core=off \
c313de
+-m 214 \
c313de
+-smp 1,sockets=1,cores=1,threads=1 \
c313de
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
c313de
+-display none \
c313de
+-no-user-config \
c313de
+-nodefaults \
c313de
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
c313de
+server,nowait \
c313de
+-mon chardev=charmonitor,id=monitor,mode=control \
c313de
+-rtc base=utc \
c313de
+-no-shutdown \
c313de
+-boot c \
c313de
+-device zpci,uid=1,fid=0,target=hostdev0,id=zpci1 \
c313de
+-device vfio-pci,host=00:00.0,id=hostdev0,bus=pci.0,addr=0x1 \
c313de
+-device zpci,uid=2,fid=1,target=balloon0,id=zpci2 \
c313de
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2
c313de
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.xml b/tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.xml
c313de
new file mode 100644
c313de
index 0000000000..36161006ab
c313de
--- /dev/null
c313de
+++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci-autogenerate.xml
c313de
@@ -0,0 +1,18 @@
c313de
+<domain type='qemu'>
c313de
+  <name>QEMUGuest1</name>
c313de
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c313de
+  <memory>219100</memory>
c313de
+  <os>
c313de
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
c313de
+  </os>
c313de
+  <devices>
c313de
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0000' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci'/>
c313de
+    </hostdev>
c313de
+  </devices>
c313de
+</domain>
c313de
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.args b/tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.args
c313de
new file mode 100644
c313de
index 0000000000..dcbb179a7d
c313de
--- /dev/null
c313de
+++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.args
c313de
@@ -0,0 +1,30 @@
c313de
+LC_ALL=C \
c313de
+PATH=/bin \
c313de
+HOME=/home/test \
c313de
+USER=test \
c313de
+LOGNAME=test \
c313de
+QEMU_AUDIO_DRV=none \
c313de
+/usr/bin/qemu-system-s390x \
c313de
+-name QEMUGuest1 \
c313de
+-S \
c313de
+-machine s390-ccw-virtio,accel=tcg,usb=off,dump-guest-core=off \
c313de
+-m 214 \
c313de
+-smp 1,sockets=1,cores=1,threads=1 \
c313de
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
c313de
+-display none \
c313de
+-no-user-config \
c313de
+-nodefaults \
c313de
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
c313de
+server,nowait \
c313de
+-mon chardev=charmonitor,id=monitor,mode=control \
c313de
+-rtc base=utc \
c313de
+-no-shutdown \
c313de
+-boot c \
c313de
+-device zpci,uid=3,fid=2,target=pci.1,id=zpci3 \
c313de
+-device pci-bridge,chassis_nr=1,id=pci.1,bus=pci.0,addr=0x1 \
c313de
+-device zpci,uid=65535,fid=4294967295,target=hostdev0,id=zpci65535 \
c313de
+-device vfio-pci,host=ffff:00:00.0,id=hostdev0,bus=pci.1,addr=0x1f \
c313de
+-device zpci,uid=1,fid=0,target=hostdev1,id=zpci1 \
c313de
+-device vfio-pci,host=00:00.0,id=hostdev1,bus=pci.0,addr=0x2 \
c313de
+-device zpci,uid=2,fid=1,target=balloon0,id=zpci2 \
c313de
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
c313de
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.xml b/tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.xml
c313de
new file mode 100644
c313de
index 0000000000..1e6060345b
c313de
--- /dev/null
c313de
+++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci-boundaries.xml
c313de
@@ -0,0 +1,30 @@
c313de
+<domain type='qemu'>
c313de
+  <name>QEMUGuest1</name>
c313de
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c313de
+  <memory>219100</memory>
c313de
+  <os>
c313de
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
c313de
+  </os>
c313de
+  <devices>
c313de
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
c313de
+    <controller type='pci' index='0' model='pci-root'/>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0xffff' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x1f' function='0x0'>
c313de
+        <zpci uid='0xffff' fid='0xffffffff'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0000' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci'>
c313de
+        <zpci uid='0x0001' fid='0x00000000'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+  </devices>
c313de
+</domain>
c313de
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.args b/tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.args
c313de
new file mode 100644
c313de
index 0000000000..11a2e50f1e
c313de
--- /dev/null
c313de
+++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.args
c313de
@@ -0,0 +1,40 @@
c313de
+LC_ALL=C \
c313de
+PATH=/bin \
c313de
+HOME=/home/test \
c313de
+USER=test \
c313de
+LOGNAME=test \
c313de
+QEMU_AUDIO_DRV=none \
c313de
+/usr/bin/qemu-system-s390x \
c313de
+-name QEMUGuest1 \
c313de
+-S \
c313de
+-machine s390-ccw-virtio,accel=tcg,usb=off,dump-guest-core=off \
c313de
+-m 214 \
c313de
+-smp 1,sockets=1,cores=1,threads=1 \
c313de
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
c313de
+-display none \
c313de
+-no-user-config \
c313de
+-nodefaults \
c313de
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
c313de
+server,nowait \
c313de
+-mon chardev=charmonitor,id=monitor,mode=control \
c313de
+-rtc base=utc \
c313de
+-no-shutdown \
c313de
+-boot c \
c313de
+-device zpci,uid=35,fid=63,target=hostdev0,id=zpci35 \
c313de
+-device vfio-pci,host=0001:00:00.0,id=hostdev0,bus=pci.0,addr=0x3 \
c313de
+-device zpci,uid=53,fid=104,target=hostdev1,id=zpci53 \
c313de
+-device vfio-pci,host=0002:00:00.0,id=hostdev1,bus=pci.0,addr=0x1 \
c313de
+-device zpci,uid=1,fid=1,target=hostdev2,id=zpci1 \
c313de
+-device vfio-pci,host=0003:00:00.0,id=hostdev2,bus=pci.0,addr=0x2 \
c313de
+-device zpci,uid=2,fid=2,target=hostdev3,id=zpci2 \
c313de
+-device vfio-pci,host=0004:00:00.0,id=hostdev3,bus=pci.0,addr=0x5 \
c313de
+-device zpci,uid=83,fid=0,target=hostdev4,id=zpci83 \
c313de
+-device vfio-pci,host=0005:00:00.0,id=hostdev4,bus=pci.0,addr=0x7 \
c313de
+-device zpci,uid=3,fid=114,target=hostdev5,id=zpci3 \
c313de
+-device vfio-pci,host=0006:00:00.0,id=hostdev5,bus=pci.0,addr=0x9 \
c313de
+-device zpci,uid=23,fid=3,target=hostdev6,id=zpci23 \
c313de
+-device vfio-pci,host=0007:00:00.0,id=hostdev6,bus=pci.0,addr=0x4 \
c313de
+-device zpci,uid=4,fid=40,target=hostdev7,id=zpci4 \
c313de
+-device vfio-pci,host=0008:00:00.0,id=hostdev7,bus=pci.0,addr=0x6 \
c313de
+-device zpci,uid=5,fid=4,target=balloon0,id=zpci5 \
c313de
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x8
c313de
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.xml b/tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.xml
c313de
new file mode 100644
c313de
index 0000000000..da8305dd6d
c313de
--- /dev/null
c313de
+++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci-multidomain-many.xml
c313de
@@ -0,0 +1,79 @@
c313de
+<domain type='qemu'>
c313de
+  <name>QEMUGuest1</name>
c313de
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c313de
+  <memory>219100</memory>
c313de
+  <os>
c313de
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
c313de
+  </os>
c313de
+  <devices>
c313de
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
c313de
+    <controller type='pci' index='0' model='pci-root'/>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0001' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'>
c313de
+        <zpci uid='0x0023' fid='0x0000003f'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0002' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci'>
c313de
+        <zpci uid='0x0035' fid='0x00000068'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0003' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0004' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0005' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'>
c313de
+        <zpci uid='0x0053'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0006' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'>
c313de
+        <zpci uid='0x0003' fid='0x00000072'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0007' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci'>
c313de
+        <zpci uid='0x0017' fid='0x00000003'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0008' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci'>
c313de
+        <zpci uid='0x0004' fid='0x00000028'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+  </devices>
c313de
+</domain>
c313de
diff --git a/tests/qemuxml2argvdata/hostdev-vfio-zpci.args b/tests/qemuxml2argvdata/hostdev-vfio-zpci.args
c313de
index 622c504da0..80de60acaa 100644
c313de
--- a/tests/qemuxml2argvdata/hostdev-vfio-zpci.args
c313de
+++ b/tests/qemuxml2argvdata/hostdev-vfio-zpci.args
c313de
@@ -20,5 +20,7 @@ server,nowait \
c313de
 -rtc base=utc \
c313de
 -no-shutdown \
c313de
 -boot c \
c313de
+-device zpci,uid=25,fid=31,target=hostdev0,id=zpci25 \
c313de
 -device vfio-pci,host=00:00.0,id=hostdev0,bus=pci.0,addr=0x8 \
c313de
+-device zpci,uid=1,fid=0,target=balloon0,id=zpci1 \
c313de
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x1
c313de
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
c313de
index 1066de8bc4..9de0cbf7e9 100644
c313de
--- a/tests/qemuxml2argvtest.c
c313de
+++ b/tests/qemuxml2argvtest.c
c313de
@@ -1637,6 +1637,19 @@ mymain(void)
c313de
     DO_TEST("hostdev-vfio-zpci",
c313de
             QEMU_CAPS_DEVICE_VFIO_PCI,
c313de
             QEMU_CAPS_DEVICE_ZPCI);
c313de
+    DO_TEST("hostdev-vfio-zpci-multidomain-many",
c313de
+            QEMU_CAPS_DEVICE_VFIO_PCI,
c313de
+            QEMU_CAPS_DEVICE_PCI_BRIDGE,
c313de
+            QEMU_CAPS_DEVICE_ZPCI);
c313de
+    DO_TEST("hostdev-vfio-zpci-autogenerate",
c313de
+            QEMU_CAPS_DEVICE_VFIO_PCI,
c313de
+            QEMU_CAPS_DEVICE_ZPCI);
c313de
+    DO_TEST("hostdev-vfio-zpci-boundaries",
c313de
+            QEMU_CAPS_DEVICE_VFIO_PCI,
c313de
+            QEMU_CAPS_DEVICE_PCI_BRIDGE,
c313de
+            QEMU_CAPS_DEVICE_ZPCI);
c313de
+    DO_TEST_PARSE_ERROR("hostdev-vfio-zpci",
c313de
+                        QEMU_CAPS_DEVICE_VFIO_PCI);
c313de
     DO_TEST("pci-rom", NONE);
c313de
     DO_TEST("pci-rom-disabled", NONE);
c313de
     DO_TEST("pci-rom-disabled-invalid", NONE);
c313de
diff --git a/tests/qemuxml2xmloutdata/hostdev-vfio-zpci-autogenerate.xml b/tests/qemuxml2xmloutdata/hostdev-vfio-zpci-autogenerate.xml
c313de
new file mode 100644
c313de
index 0000000000..e94e63bd0a
c313de
--- /dev/null
c313de
+++ b/tests/qemuxml2xmloutdata/hostdev-vfio-zpci-autogenerate.xml
c313de
@@ -0,0 +1,34 @@
c313de
+<domain type='qemu'>
c313de
+  <name>QEMUGuest1</name>
c313de
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c313de
+  <memory unit='KiB'>219100</memory>
c313de
+  <currentMemory unit='KiB'>219100</currentMemory>
c313de
+  <vcpu placement='static'>1</vcpu>
c313de
+  <os>
c313de
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
c313de
+    <boot dev='hd'/>
c313de
+  </os>
c313de
+  <clock offset='utc'/>
c313de
+  <on_poweroff>destroy</on_poweroff>
c313de
+  <on_reboot>restart</on_reboot>
c313de
+  <on_crash>destroy</on_crash>
c313de
+  <devices>
c313de
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
c313de
+    <controller type='pci' index='0' model='pci-root'/>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0000' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'>
c313de
+        <zpci uid='0x0001' fid='0x00000000'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <memballoon model='virtio'>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'>
c313de
+        <zpci uid='0x0002' fid='0x00000001'/>
c313de
+      </address>
c313de
+    </memballoon>
c313de
+    <panic model='s390'/>
c313de
+  </devices>
c313de
+</domain>
c313de
diff --git a/tests/qemuxml2xmloutdata/hostdev-vfio-zpci-boundaries.xml b/tests/qemuxml2xmloutdata/hostdev-vfio-zpci-boundaries.xml
c313de
new file mode 100644
c313de
index 0000000000..81d2146188
c313de
--- /dev/null
c313de
+++ b/tests/qemuxml2xmloutdata/hostdev-vfio-zpci-boundaries.xml
c313de
@@ -0,0 +1,48 @@
c313de
+<domain type='qemu'>
c313de
+  <name>QEMUGuest1</name>
c313de
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c313de
+  <memory unit='KiB'>219100</memory>
c313de
+  <currentMemory unit='KiB'>219100</currentMemory>
c313de
+  <vcpu placement='static'>1</vcpu>
c313de
+  <os>
c313de
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
c313de
+    <boot dev='hd'/>
c313de
+  </os>
c313de
+  <clock offset='utc'/>
c313de
+  <on_poweroff>destroy</on_poweroff>
c313de
+  <on_reboot>restart</on_reboot>
c313de
+  <on_crash>destroy</on_crash>
c313de
+  <devices>
c313de
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
c313de
+    <controller type='pci' index='0' model='pci-root'/>
c313de
+    <controller type='pci' index='1' model='pci-bridge'>
c313de
+      <model name='pci-bridge'/>
c313de
+      <target chassisNr='1'/>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
c313de
+    </controller>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0xffff' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x1f' function='0x0'>
c313de
+        <zpci uid='0xffff' fid='0xffffffff'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0000' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'>
c313de
+        <zpci uid='0x0001' fid='0x00000000'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <memballoon model='virtio'>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'>
c313de
+        <zpci uid='0x0002' fid='0x00000001'/>
c313de
+      </address>
c313de
+    </memballoon>
c313de
+    <panic model='s390'/>
c313de
+  </devices>
c313de
+</domain>
c313de
diff --git a/tests/qemuxml2xmloutdata/hostdev-vfio-zpci-multidomain-many.xml b/tests/qemuxml2xmloutdata/hostdev-vfio-zpci-multidomain-many.xml
c313de
new file mode 100644
c313de
index 0000000000..e56106d103
c313de
--- /dev/null
c313de
+++ b/tests/qemuxml2xmloutdata/hostdev-vfio-zpci-multidomain-many.xml
c313de
@@ -0,0 +1,97 @@
c313de
+<domain type='qemu'>
c313de
+  <name>QEMUGuest1</name>
c313de
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c313de
+  <memory unit='KiB'>219100</memory>
c313de
+  <currentMemory unit='KiB'>219100</currentMemory>
c313de
+  <vcpu placement='static'>1</vcpu>
c313de
+  <os>
c313de
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
c313de
+    <boot dev='hd'/>
c313de
+  </os>
c313de
+  <clock offset='utc'/>
c313de
+  <on_poweroff>destroy</on_poweroff>
c313de
+  <on_reboot>restart</on_reboot>
c313de
+  <on_crash>destroy</on_crash>
c313de
+  <devices>
c313de
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
c313de
+    <controller type='pci' index='0' model='pci-root'/>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0001' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'>
c313de
+        <zpci uid='0x0023' fid='0x0000003f'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0002' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'>
c313de
+        <zpci uid='0x0035' fid='0x00000068'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0003' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'>
c313de
+        <zpci uid='0x0001' fid='0x00000001'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0004' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'>
c313de
+        <zpci uid='0x0002' fid='0x00000002'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0005' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'>
c313de
+        <zpci uid='0x0053' fid='0x00000000'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0006' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'>
c313de
+        <zpci uid='0x0003' fid='0x00000072'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0007' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'>
c313de
+        <zpci uid='0x0017' fid='0x00000003'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <hostdev mode='subsystem' type='pci' managed='no'>
c313de
+      <driver name='vfio'/>
c313de
+      <source>
c313de
+        <address domain='0x0008' bus='0x00' slot='0x00' function='0x0'/>
c313de
+      </source>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'>
c313de
+        <zpci uid='0x0004' fid='0x00000028'/>
c313de
+      </address>
c313de
+    </hostdev>
c313de
+    <memballoon model='virtio'>
c313de
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'>
c313de
+        <zpci uid='0x0005' fid='0x00000004'/>
c313de
+      </address>
c313de
+    </memballoon>
c313de
+    <panic model='s390'/>
c313de
+  </devices>
c313de
+</domain>
c313de
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
c313de
index a787f4f4a3..b2afc8a8ba 100644
c313de
--- a/tests/qemuxml2xmltest.c
c313de
+++ b/tests/qemuxml2xmltest.c
c313de
@@ -488,6 +488,17 @@ mymain(void)
c313de
     DO_TEST("hostdev-vfio-zpci",
c313de
             QEMU_CAPS_DEVICE_ZPCI,
c313de
             QEMU_CAPS_CCW);
c313de
+    DO_TEST("hostdev-vfio-zpci-multidomain-many",
c313de
+            QEMU_CAPS_DEVICE_VFIO_PCI,
c313de
+            QEMU_CAPS_DEVICE_PCI_BRIDGE,
c313de
+            QEMU_CAPS_DEVICE_ZPCI);
c313de
+    DO_TEST("hostdev-vfio-zpci-autogenerate",
c313de
+            QEMU_CAPS_DEVICE_VFIO_PCI,
c313de
+            QEMU_CAPS_DEVICE_ZPCI);
c313de
+    DO_TEST("hostdev-vfio-zpci-boundaries",
c313de
+            QEMU_CAPS_DEVICE_VFIO_PCI,
c313de
+            QEMU_CAPS_DEVICE_PCI_BRIDGE,
c313de
+            QEMU_CAPS_DEVICE_ZPCI);
c313de
     DO_TEST("hostdev-mdev-precreated", NONE);
c313de
     DO_TEST("hostdev-mdev-display", QEMU_CAPS_VFIO_PCI_DISPLAY);
c313de
     DO_TEST("pci-rom", NONE);
c313de
-- 
c313de
2.22.0
c313de