render / rpms / libvirt

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