render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
edecca
From 4b249d6de82cd42d29aeccccef4ae483c71b1528 Mon Sep 17 00:00:00 2001
edecca
Message-Id: <4b249d6de82cd42d29aeccccef4ae483c71b1528@dist-git>
edecca
From: Boris Fiuczynski <fiuczy@linux.ibm.com>
edecca
Date: Fri, 30 Nov 2018 15:49:24 +0100
edecca
Subject: [PATCH] qemu: vfio-ap device support
edecca
edecca
Adjusting domain format documentation, adding device address
edecca
support and adding command line generation for vfio-ap.
edecca
Since only one mediated hostdev with model vfio-ap is supported a check
edecca
disallows to define domains with more than one such hostdev device.
edecca
edecca
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
edecca
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
edecca
Reviewed-by: Chris Venteicher <cventeic@redhat.com>
edecca
(cherry picked from commit 11708641983e9107a129c62fd343d0fec228342f)
edecca
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1508146
edecca
edecca
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
edecca
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
edecca
---
edecca
 docs/formatdomain.html.in      |  3 ++-
edecca
 docs/schemas/domaincommon.rng  |  1 +
edecca
 src/conf/domain_conf.c         | 28 ++++++++++++++++++++++++++++
edecca
 src/qemu/qemu_command.c        |  8 ++++++++
edecca
 src/qemu/qemu_domain_address.c |  4 ++++
edecca
 src/util/virmdev.c             |  3 ++-
edecca
 src/util/virmdev.h             |  1 +
edecca
 7 files changed, 46 insertions(+), 2 deletions(-)
edecca
edecca
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
edecca
index c019b26644..54eb298414 100644
edecca
--- a/docs/formatdomain.html.in
edecca
+++ b/docs/formatdomain.html.in
edecca
@@ -4528,8 +4528,9 @@
edecca
           
For mediated devices (Since 3.2.0)
edecca
           the model attribute specifies the device API which
edecca
           determines how the host's vfio driver will expose the device to the
edecca
-          guest. Currently, model='vfio-pci' and
edecca
+          guest. Currently, model='vfio-pci',
edecca
           model='vfio-ccw' (Since 4.4.0)
edecca
+          and model='vfio-ap' (Since 4.9.0)
edecca
           is supported. MDEV section
edecca
           provides more information about mediated devices as well as how to
edecca
           create mediated devices on the host.
edecca
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
edecca
index 1c6f2a295d..e4ce7804b9 100644
edecca
--- a/docs/schemas/domaincommon.rng
edecca
+++ b/docs/schemas/domaincommon.rng
edecca
@@ -4578,6 +4578,7 @@
edecca
       <choice>
edecca
         <value>vfio-pci</value>
edecca
         <value>vfio-ccw</value>
edecca
+        <value>vfio-ap</value>
edecca
       </choice>
edecca
     </attribute>
edecca
     <optional>
edecca
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
edecca
index e013e9f0c5..ea7152eb94 100644
edecca
--- a/src/conf/domain_conf.c
edecca
+++ b/src/conf/domain_conf.c
edecca
@@ -4325,6 +4325,31 @@ virDomainDefPostParseGraphics(virDomainDef *def)
edecca
 }
edecca
 
edecca
 
edecca
+static int
edecca
+virDomainDefPostParseHostdev(virDomainDefPtr def)
edecca
+{
edecca
+    size_t i;
edecca
+    bool vfioap_found = false;
edecca
+
edecca
+    /* verify settings of hostdevs vfio-ap */
edecca
+    for (i = 0; i < def->nhostdevs; i++) {
edecca
+        virDomainHostdevDefPtr hostdev = def->hostdevs[i];
edecca
+
edecca
+        if (virHostdevIsMdevDevice(hostdev) &&
edecca
+            hostdev->source.subsys.u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_AP) {
edecca
+            if (vfioap_found) {
edecca
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
edecca
+                               _("Only one hostdev of model vfio-ap is "
edecca
+                                 "supported"));
edecca
+                return -1;
edecca
+            }
edecca
+            vfioap_found = true;
edecca
+        }
edecca
+    }
edecca
+    return 0;
edecca
+}
edecca
+
edecca
+
edecca
 /**
edecca
  * virDomainDriveAddressIsUsedByDisk:
edecca
  * @def: domain definition containing the disks to check
edecca
@@ -5237,6 +5262,9 @@ virDomainDefPostParseCommon(virDomainDefPtr def,
edecca
 
edecca
     virDomainDefPostParseGraphics(def);
edecca
 
edecca
+    if (virDomainDefPostParseHostdev(def) < 0)
edecca
+        return -1;
edecca
+
edecca
     if (virDomainDefPostParseCPU(def) < 0)
edecca
         return -1;
edecca
 
edecca
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
edecca
index a3d605c00f..320ecd902c 100644
edecca
--- a/src/qemu/qemu_command.c
edecca
+++ b/src/qemu/qemu_command.c
edecca
@@ -5430,6 +5430,14 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
edecca
                     return -1;
edecca
                 }
edecca
                 break;
edecca
+            case VIR_MDEV_MODEL_TYPE_VFIO_AP:
edecca
+                if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_AP)) {
edecca
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
edecca
+                                   _("VFIO AP device assignment is not "
edecca
+                                     "supported by this version of QEMU"));
edecca
+                    return -1;
edecca
+                }
edecca
+                break;
edecca
             case VIR_MDEV_MODEL_TYPE_LAST:
edecca
                 virReportError(VIR_ERR_INTERNAL_ERROR,
edecca
                                _("unexpected vfio type '%d'"), subsys->u.mdev.model);
edecca
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
edecca
index 0cb5af4a87..3e50521c11 100644
edecca
--- a/src/qemu/qemu_domain_address.c
edecca
+++ b/src/qemu/qemu_domain_address.c
edecca
@@ -294,6 +294,10 @@ qemuDomainPrimeVfioDeviceAddresses(virDomainDefPtr def,
edecca
             subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_CCW &&
edecca
             def->hostdevs[i]->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
edecca
             def->hostdevs[i]->info->type = type;
edecca
+
edecca
+        if (virHostdevIsMdevDevice(def->hostdevs[i]) &&
edecca
+            subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_AP)
edecca
+            def->hostdevs[i]->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE;
edecca
     }
edecca
 }
edecca
 
edecca
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
edecca
index 6c513884b8..1b5897c654 100644
edecca
--- a/src/util/virmdev.c
edecca
+++ b/src/util/virmdev.c
edecca
@@ -49,7 +49,8 @@ struct _virMediatedDeviceList {
edecca
 
edecca
 VIR_ENUM_IMPL(virMediatedDeviceModel, VIR_MDEV_MODEL_TYPE_LAST,
edecca
               "vfio-pci",
edecca
-              "vfio-ccw")
edecca
+              "vfio-ccw",
edecca
+              "vfio-ap")
edecca
 
edecca
 static virClassPtr virMediatedDeviceListClass;
edecca
 
edecca
diff --git a/src/util/virmdev.h b/src/util/virmdev.h
edecca
index cfda2cacab..ba411a933a 100644
edecca
--- a/src/util/virmdev.h
edecca
+++ b/src/util/virmdev.h
edecca
@@ -26,6 +26,7 @@
edecca
 typedef enum {
edecca
     VIR_MDEV_MODEL_TYPE_VFIO_PCI = 0,
edecca
     VIR_MDEV_MODEL_TYPE_VFIO_CCW = 1,
edecca
+    VIR_MDEV_MODEL_TYPE_VFIO_AP  = 2,
edecca
 
edecca
     VIR_MDEV_MODEL_TYPE_LAST
edecca
 } virMediatedDeviceModelType;
edecca
-- 
edecca
2.19.2
edecca