[libvirt] [PATCH] qemu: support bootindex on vfio-ccw mdev device

Boris Fiuczynski posted 1 patch 4 years, 7 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20190802131559.7181-1-fiuczy@linux.ibm.com
src/qemu/qemu_command.c                       | 27 +++++++++++++----
.../hostdev-subsys-mdev-vfio-ccw-boot.args    | 29 +++++++++++++++++++
.../hostdev-subsys-mdev-vfio-ccw-boot.xml     | 23 +++++++++++++++
tests/qemuxml2argvtest.c                      |  4 +++
4 files changed, 78 insertions(+), 5 deletions(-)
create mode 100644 tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.args
create mode 100644 tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.xml
[libvirt] [PATCH] qemu: support bootindex on vfio-ccw mdev device
Posted by Boris Fiuczynski 4 years, 7 months ago
Add support to specify a boot order on vfio-ccw passthrough devices.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Acked-by: Jason J. Herne <jjherne@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
---
 src/qemu/qemu_command.c                       | 27 +++++++++++++----
 .../hostdev-subsys-mdev-vfio-ccw-boot.args    | 29 +++++++++++++++++++
 .../hostdev-subsys-mdev-vfio-ccw-boot.xml     | 23 +++++++++++++++
 tests/qemuxml2argvtest.c                      |  4 +++
 4 files changed, 78 insertions(+), 5 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.args
 create mode 100644 tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index fee51158a9..36138e2ccf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5613,6 +5613,9 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
     if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0)
         goto cleanup;
 
+    if (dev->info->bootIndex)
+        virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex);
+
     if (virBufferCheckError(&buf) < 0)
         goto cleanup;
 
@@ -5624,6 +5627,22 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
     return ret;
 }
 
+static bool
+qemuHostdevSupportsBoot(virDomainHostdevDefPtr hostdev)
+{
+    if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
+        virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
+        if (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI ||
+            subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB ||
+            subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI ||
+            (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
+            subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_CCW)) {
+            return true;
+        }
+    }
+    return false;
+}
+
 static int
 qemuBuildHostdevCommandLine(virCommandPtr cmd,
                             const virDomainDef *def,
@@ -5638,13 +5657,11 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
         char *devstr;
 
         if (hostdev->info->bootIndex) {
-            if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-                (subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-                 subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB &&
-                 subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)) {
+            if (!qemuHostdevSupportsBoot(hostdev)) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                _("booting from assigned devices is only "
-                                 "supported for PCI, USB and SCSI devices"));
+                                 "supported for PCI, USB, SCSI and MDEV "
+                                 "of model vfio-ccw devices"));
                 return -1;
             }
         }
diff --git a/tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.args b/tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.args
new file mode 100644
index 0000000000..6fb22b3014
--- /dev/null
+++ b/tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.args
@@ -0,0 +1,29 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+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 512 \
+-realtime mlock=off \
+-smp 2,sockets=2,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 \
+-device vfio-ccw,id=hostdev0,\
+sysfsdev=/sys/bus/mdev/devices/90c6c135-ad44-41d0-b1b7-bae47de48627,\
+devno=fe.0.0000,bootindex=1 \
+-device virtio-balloon-ccw,id=balloon0,devno=fe.0.0001
diff --git a/tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.xml b/tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.xml
new file mode 100644
index 0000000000..6cca13c33f
--- /dev/null
+++ b/tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.xml
@@ -0,0 +1,23 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>524288</memory>
+  <currentMemory unit='KiB'>524288</currentMemory>
+  <vcpu placement='static'>2</vcpu>
+  <os>
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
+  </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>
+    <hostdev mode='subsystem' type='mdev' model='vfio-ccw'>
+      <source>
+        <address uuid='90c6c135-ad44-41d0-b1b7-bae47de48627'/>
+      </source>
+      <boot order='1'/>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index c166fd18d6..c30a0c74ca 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1621,6 +1621,10 @@ mymain(void)
             QEMU_CAPS_CCW,
             QEMU_CAPS_CCW_CSSID_UNRESTRICTED,
             QEMU_CAPS_DEVICE_VFIO_CCW);
+    DO_TEST("hostdev-subsys-mdev-vfio-ccw-boot",
+            QEMU_CAPS_CCW,
+            QEMU_CAPS_CCW_CSSID_UNRESTRICTED,
+            QEMU_CAPS_DEVICE_VFIO_CCW);
     DO_TEST_FAILURE("hostdev-subsys-mdev-vfio-ccw",
             QEMU_CAPS_CCW,
             QEMU_CAPS_CCW_CSSID_UNRESTRICTED);
-- 
2.17.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: support bootindex on vfio-ccw mdev device
Posted by Peter Krempa 4 years, 7 months ago
On Fri, Aug 02, 2019 at 15:15:59 +0200, Boris Fiuczynski wrote:
> Add support to specify a boot order on vfio-ccw passthrough devices.
> 
> Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
> Acked-by: Jason J. Herne <jjherne@linux.ibm.com>
> Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> ---
>  src/qemu/qemu_command.c                       | 27 +++++++++++++----
>  .../hostdev-subsys-mdev-vfio-ccw-boot.args    | 29 +++++++++++++++++++
>  .../hostdev-subsys-mdev-vfio-ccw-boot.xml     | 23 +++++++++++++++
>  tests/qemuxml2argvtest.c                      |  4 +++
>  4 files changed, 78 insertions(+), 5 deletions(-)
>  create mode 100644 tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.args
>  create mode 100644 tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.xml

Note that I don't currently have enough information to verify that the
mdev claim is correct (e.g. why it's only with CCW devices?), but I have
two formal comments:

> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index fee51158a9..36138e2ccf 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -5613,6 +5613,9 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
>      if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0)
>          goto cleanup;
>  
> +    if (dev->info->bootIndex)
> +        virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex);
> +
>      if (virBufferCheckError(&buf) < 0)
>          goto cleanup;
>  
> @@ -5624,6 +5627,22 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
>      return ret;
>  }
>  
> +static bool
> +qemuHostdevSupportsBoot(virDomainHostdevDefPtr hostdev)

Refactor to this function should be separate from the logic change
below.

> +{
> +    if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
> +        virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
> +        if (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI ||
> +            subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB ||
> +            subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI ||
> +            (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
> +            subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_CCW)) {

This line is misaligned. Please make sure that it's clear that the above
line belongs to the term in the brackets.


> +            return true;
> +        }
> +    }
> +    return false;
> +}
> +
>  static int
>  qemuBuildHostdevCommandLine(virCommandPtr cmd,
>                              const virDomainDef *def,
> @@ -5638,13 +5657,11 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
>          char *devstr;
>  
>          if (hostdev->info->bootIndex) {
> -            if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
> -                (subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
> -                 subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB &&
> -                 subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)) {
> +            if (!qemuHostdevSupportsBoot(hostdev)) {
>                  virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>                                 _("booting from assigned devices is only "
> -                                 "supported for PCI, USB and SCSI devices"));
> +                                 "supported for PCI, USB, SCSI and MDEV "
> +                                 "of model vfio-ccw devices"));

Ideally this validation will be done in the validation callback rather
than in the command line generator. (pre-existing so I don't require you
to refactor this at this time).

Also this error can be probably stashed into qemuHostdevSupportsBoot.
(and name it like qemuHostdevValidateBoot).
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: support bootindex on vfio-ccw mdev device
Posted by Boris Fiuczynski 4 years, 7 months ago
On 8/2/19 3:30 PM, Peter Krempa wrote:
> On Fri, Aug 02, 2019 at 15:15:59 +0200, Boris Fiuczynski wrote:
>> Add support to specify a boot order on vfio-ccw passthrough devices.
>>
>> Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
>> Acked-by: Jason J. Herne <jjherne@linux.ibm.com>
>> Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
>> ---
>>   src/qemu/qemu_command.c                       | 27 +++++++++++++----
>>   .../hostdev-subsys-mdev-vfio-ccw-boot.args    | 29 +++++++++++++++++++
>>   .../hostdev-subsys-mdev-vfio-ccw-boot.xml     | 23 +++++++++++++++
>>   tests/qemuxml2argvtest.c                      |  4 +++
>>   4 files changed, 78 insertions(+), 5 deletions(-)
>>   create mode 100644 tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.args
>>   create mode 100644 tests/qemuxml2argvdata/hostdev-subsys-mdev-vfio-ccw-boot.xml
> 
> Note that I don't currently have enough information to verify that the
> mdev claim is correct (e.g. why it's only with CCW devices?), but I have
> two formal comments:
Since I know that on s390 you can boot from a vfio-ccw mediated device 
but not from a vfio-ap mediated device I chose the default as "not 
capable to boot from" and check especially for the "known to be capable 
to boot from" mdevs. I have no problem changing the logic if desired.

If we want to skip the checking than an qemu internal error like this 
occurs:
error: Failed to start domain mini-ap
error: internal error: qemu unexpectedly closed the monitor: 
2019-08-05T13:44:27.871697Z qemu-system-s390x: -device 
vfio-ap,id=hostdev0,sysfsdev=/sys/bus/mdev/devices/9063cba3-ecef-47b6-abcf-3fef4fdcad85,bootindex=1: 
Property '.bootindex' not found

> 
>>
>> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
>> index fee51158a9..36138e2ccf 100644
>> --- a/src/qemu/qemu_command.c
>> +++ b/src/qemu/qemu_command.c
>> @@ -5613,6 +5613,9 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
>>       if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0)
>>           goto cleanup;
>>   
>> +    if (dev->info->bootIndex)
>> +        virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex);
>> +
>>       if (virBufferCheckError(&buf) < 0)
>>           goto cleanup;
>>   
>> @@ -5624,6 +5627,22 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
>>       return ret;
>>   }
>>   
>> +static bool
>> +qemuHostdevSupportsBoot(virDomainHostdevDefPtr hostdev)
> 
> Refactor to this function should be separate from the logic change
> below.

Agreed.

> 
>> +{
>> +    if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
>> +        virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
>> +        if (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI ||
>> +            subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB ||
>> +            subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI ||
>> +            (subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
>> +            subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_CCW)) {
> 
> This line is misaligned. Please make sure that it's clear that the above
> line belongs to the term in the brackets.

I will fix it.

> 
> 
>> +            return true;
>> +        }
>> +    }
>> +    return false;
>> +}
>> +
>>   static int
>>   qemuBuildHostdevCommandLine(virCommandPtr cmd,
>>                               const virDomainDef *def,
>> @@ -5638,13 +5657,11 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
>>           char *devstr;
>>   
>>           if (hostdev->info->bootIndex) {
>> -            if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
>> -                (subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
>> -                 subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB &&
>> -                 subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)) {
>> +            if (!qemuHostdevSupportsBoot(hostdev)) {
>>                   virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>>                                  _("booting from assigned devices is only "
>> -                                 "supported for PCI, USB and SCSI devices"));
>> +                                 "supported for PCI, USB, SCSI and MDEV "
>> +                                 "of model vfio-ccw devices"));
> 
> Ideally this validation will be done in the validation callback rather
> than in the command line generator. (pre-existing so I don't require you
> to refactor this at this time). >
> Also this error can be probably stashed into qemuHostdevSupportsBoot.
> (and name it like qemuHostdevValidateBoot).

Ok, I will rename the method and move the error report.

> 
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
> 


-- 
Mit freundlichen Grüßen/Kind regards
    Boris Fiuczynski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Matthias Hartmann
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list