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