render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From 050eb598af9291f385998cb1127d5bdf83305501 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <050eb598af9291f385998cb1127d5bdf83305501@dist-git>
Pablo Greco 40546a
From: Yi Min Zhao <zyimin@linux.ibm.com>
Pablo Greco 40546a
Date: Mon, 8 Apr 2019 10:57:21 +0200
Pablo Greco 40546a
Subject: [PATCH] conf: Introduce extension flag and zPCI member for PCI
Pablo Greco 40546a
 address
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
This patch introduces PCI address extension flag for virDomainDeviceInfo
Pablo Greco 40546a
and virPCIDeviceAddress. The extension flag in virDomainDeviceInfo is
Pablo Greco 40546a
used internally during calculating PCI extension flag. The one in
Pablo Greco 40546a
virPCIDeviceAddress is the duplicate to indicate extension address is
Pablo Greco 40546a
being used. Currently only zPCI extension address is introduced to deal
Pablo Greco 40546a
with 'uid' and 'fid' on the S390 platform.
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: 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 478e5f90fd4c0c0a8c1b3a8e19b9cae93ed78a4e)
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_domain_address.c
Pablo Greco 40546a
    + context
Pablo Greco 40546a
      - missing db98a426a640
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Pablo Greco 40546a
Message-Id: <20190408085732.28684-5-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/conf/device_conf.h         |   4 +
Pablo Greco 40546a
 src/conf/domain_addr.h         |   5 ++
Pablo Greco 40546a
 src/qemu/qemu_domain_address.c | 140 ++++++++++++++++++++++++++++++++-
Pablo Greco 40546a
 src/util/virpci.h              |   2 +
Pablo Greco 40546a
 4 files changed, 149 insertions(+), 2 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
Pablo Greco 40546a
index a31ce9c376..c79066ec02 100644
Pablo Greco 40546a
--- a/src/conf/device_conf.h
Pablo Greco 40546a
+++ b/src/conf/device_conf.h
Pablo Greco 40546a
@@ -164,6 +164,10 @@ struct _virDomainDeviceInfo {
Pablo Greco 40546a
      * assignment, never saved and never reported.
Pablo Greco 40546a
      */
Pablo Greco 40546a
     int pciConnectFlags; /* enum virDomainPCIConnectFlags */
Pablo Greco 40546a
+    /* pciAddrExtFlags is only used internally to calculate PCI
Pablo Greco 40546a
+     * address extension flags during address assignment.
Pablo Greco 40546a
+     */
Pablo Greco 40546a
+    int pciAddrExtFlags; /* enum virDomainPCIAddressExtensionFlags */
Pablo Greco 40546a
     char *loadparm;
Pablo Greco 40546a
 
Pablo Greco 40546a
     /* PCI devices will only be automatically placed on a PCI bus
Pablo Greco 40546a
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
Pablo Greco 40546a
index 3236b7d6de..fd06008e26 100644
Pablo Greco 40546a
--- a/src/conf/domain_addr.h
Pablo Greco 40546a
+++ b/src/conf/domain_addr.h
Pablo Greco 40546a
@@ -29,6 +29,11 @@
Pablo Greco 40546a
 # define VIR_PCI_ADDRESS_SLOT_LAST 31
Pablo Greco 40546a
 # define VIR_PCI_ADDRESS_FUNCTION_LAST 7
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef enum {
Pablo Greco 40546a
+    VIR_PCI_ADDRESS_EXTENSION_NONE = 0, /* no extension */
Pablo Greco 40546a
+    VIR_PCI_ADDRESS_EXTENSION_ZPCI = 1 << 0, /* zPCI support */
Pablo Greco 40546a
+} virPCIDeviceAddressExtensionFlags;
Pablo Greco 40546a
+
Pablo Greco 40546a
 typedef enum {
Pablo Greco 40546a
    VIR_PCI_CONNECT_HOTPLUGGABLE = 1 << 0, /* is hotplug needed/supported */
Pablo Greco 40546a
 
Pablo Greco 40546a
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
Pablo Greco 40546a
index 79d2b9f9c4..3d01d14b46 100644
Pablo Greco 40546a
--- a/src/qemu/qemu_domain_address.c
Pablo Greco 40546a
+++ b/src/qemu/qemu_domain_address.c
Pablo Greco 40546a
@@ -511,6 +511,64 @@ qemuDomainAssignARMVirtioMMIOAddresses(virDomainDefPtr def,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static bool
Pablo Greco 40546a
+qemuDomainDeviceSupportZPCI(virDomainDeviceDefPtr device)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    switch ((virDomainDeviceType)device->type) {
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_CHR:
Pablo Greco 40546a
+        return false;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_DISK:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_LEASE:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_FS:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_NET:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_INPUT:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_SOUND:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_VIDEO:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_HUB:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_NVRAM:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_RNG:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_SHMEM:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_TPM:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_PANIC:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_MEMORY:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_IOMMU:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_VSOCK:
Pablo Greco 40546a
+        break;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_NONE:
Pablo Greco 40546a
+    case VIR_DOMAIN_DEVICE_LAST:
Pablo Greco 40546a
+    default:
Pablo Greco 40546a
+        virReportEnumRangeError(virDomainDeviceType, device->type);
Pablo Greco 40546a
+        return false;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return true;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static virPCIDeviceAddressExtensionFlags
Pablo Greco 40546a
+qemuDomainDeviceCalculatePCIAddressExtensionFlags(virQEMUCapsPtr qemuCaps,
Pablo Greco 40546a
+                                                  virDomainDeviceDefPtr dev)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    virPCIDeviceAddressExtensionFlags extFlags = 0;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_ZPCI) &&
Pablo Greco 40546a
+        qemuDomainDeviceSupportZPCI(dev)) {
Pablo Greco 40546a
+        extFlags |= VIR_PCI_ADDRESS_EXTENSION_ZPCI;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return extFlags;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
 /**
Pablo Greco 40546a
  * qemuDomainDeviceCalculatePCIConnectFlags:
Pablo Greco 40546a
  *
Pablo Greco 40546a
@@ -993,6 +1051,56 @@ qemuDomainFillAllPCIConnectFlags(virDomainDefPtr def,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+/**
Pablo Greco 40546a
+ * qemuDomainFillDevicePCIExtensionFlagsIter:
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * @def: the entire DomainDef
Pablo Greco 40546a
+ * @dev: The device to be checked
Pablo Greco 40546a
+ * @info: virDomainDeviceInfo within the device
Pablo Greco 40546a
+ * @opaque: qemu capabilities
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * Sets the pciAddressExtFlags for a single device's info. Has properly
Pablo Greco 40546a
+ * formatted arguments to be called by virDomainDeviceInfoIterate().
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * Always returns 0 - there is no failure.
Pablo Greco 40546a
+ */
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+qemuDomainFillDevicePCIExtensionFlagsIter(virDomainDefPtr def ATTRIBUTE_UNUSED,
Pablo Greco 40546a
+                                          virDomainDeviceDefPtr dev,
Pablo Greco 40546a
+                                          virDomainDeviceInfoPtr info,
Pablo Greco 40546a
+                                          void *opaque)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    virQEMUCapsPtr qemuCaps = opaque;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    info->pciAddrExtFlags =
Pablo Greco 40546a
+        qemuDomainDeviceCalculatePCIAddressExtensionFlags(qemuCaps, dev);
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return 0;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+/**
Pablo Greco 40546a
+ * qemuDomainFillAllPCIExtensionFlags:
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * @def: the entire DomainDef
Pablo Greco 40546a
+ * @qemuCaps: as you'd expect
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * Set the info->pciAddressExtFlags for all devices in the domain.
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * Returns 0 on success or -1 on failure (the only possibility of
Pablo Greco 40546a
+ * failure would be some internal problem with
Pablo Greco 40546a
+ * virDomainDeviceInfoIterate())
Pablo Greco 40546a
+ */
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+qemuDomainFillAllPCIExtensionFlags(virDomainDefPtr def,
Pablo Greco 40546a
+                                   virQEMUCapsPtr qemuCaps)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    return virDomainDeviceInfoIterate(def,
Pablo Greco 40546a
+                                      qemuDomainFillDevicePCIExtensionFlagsIter,
Pablo Greco 40546a
+                                      qemuCaps);
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
 /**
Pablo Greco 40546a
  * qemuDomainFindUnusedIsolationGroupIter:
Pablo Greco 40546a
  * @def: domain definition
Pablo Greco 40546a
@@ -1267,6 +1375,27 @@ qemuDomainFillDevicePCIConnectFlags(virDomainDefPtr def,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+/**
Pablo Greco 40546a
+ * qemuDomainFillDevicePCIExtensionFlags:
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * @dev: The device to be checked
Pablo Greco 40546a
+ * @info: virDomainDeviceInfo within the device
Pablo Greco 40546a
+ * @qemuCaps: as you'd expect
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * Set the info->pciAddressExtFlags for a single device.
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * No return value.
Pablo Greco 40546a
+ */
Pablo Greco 40546a
+static void
Pablo Greco 40546a
+qemuDomainFillDevicePCIExtensionFlags(virDomainDeviceDefPtr dev,
Pablo Greco 40546a
+                                      virDomainDeviceInfoPtr info,
Pablo Greco 40546a
+                                      virQEMUCapsPtr qemuCaps)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    info->pciAddrExtFlags =
Pablo Greco 40546a
+        qemuDomainDeviceCalculatePCIAddressExtensionFlags(qemuCaps, dev);
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
 static int
Pablo Greco 40546a
 qemuDomainPCIAddressReserveNextAddr(virDomainPCIAddressSetPtr addrs,
Pablo Greco 40546a
                                     virDomainDeviceInfoPtr dev)
Pablo Greco 40546a
@@ -2400,6 +2529,9 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
Pablo Greco 40546a
     if (qemuDomainFillAllPCIConnectFlags(def, qemuCaps, driver) < 0)
Pablo Greco 40546a
         goto cleanup;
Pablo Greco 40546a
 
Pablo Greco 40546a
+    if (qemuDomainFillAllPCIExtensionFlags(def, qemuCaps) < 0)
Pablo Greco 40546a
+        goto cleanup;
Pablo Greco 40546a
+
Pablo Greco 40546a
     if (qemuDomainSetupIsolationGroups(def) < 0)
Pablo Greco 40546a
         goto cleanup;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -2435,7 +2567,8 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
Pablo Greco 40546a
              */
Pablo Greco 40546a
             virDomainDeviceInfo info = {
Pablo Greco 40546a
                 .pciConnectFlags = (VIR_PCI_CONNECT_HOTPLUGGABLE |
Pablo Greco 40546a
-                                    VIR_PCI_CONNECT_TYPE_PCI_DEVICE)
Pablo Greco 40546a
+                                    VIR_PCI_CONNECT_TYPE_PCI_DEVICE),
Pablo Greco 40546a
+                .pciAddrExtFlags = VIR_PCI_ADDRESS_EXTENSION_NONE
Pablo Greco 40546a
             };
Pablo Greco 40546a
             bool buses_reserved = true;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -2472,7 +2605,8 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
Pablo Greco 40546a
             qemuDomainHasPCIeRoot(def)) {
Pablo Greco 40546a
             virDomainDeviceInfo info = {
Pablo Greco 40546a
                 .pciConnectFlags = (VIR_PCI_CONNECT_HOTPLUGGABLE |
Pablo Greco 40546a
-                                    VIR_PCI_CONNECT_TYPE_PCIE_DEVICE)
Pablo Greco 40546a
+                                    VIR_PCI_CONNECT_TYPE_PCIE_DEVICE),
Pablo Greco 40546a
+                .pciAddrExtFlags = VIR_PCI_ADDRESS_EXTENSION_NONE
Pablo Greco 40546a
             };
Pablo Greco 40546a
 
Pablo Greco 40546a
             /* if there isn't an empty pcie-root-port, this will
Pablo Greco 40546a
@@ -2989,6 +3123,8 @@ qemuDomainEnsurePCIAddress(virDomainObjPtr obj,
Pablo Greco 40546a
 
Pablo Greco 40546a
     qemuDomainFillDevicePCIConnectFlags(obj->def, dev, priv->qemuCaps, driver);
Pablo Greco 40546a
 
Pablo Greco 40546a
+    qemuDomainFillDevicePCIExtensionFlags(dev, info, priv->qemuCaps);
Pablo Greco 40546a
+
Pablo Greco 40546a
     return virDomainPCIAddressEnsureAddr(priv->pciaddrs, info,
Pablo Greco 40546a
                                          info->pciConnectFlags);
Pablo Greco 40546a
 }
Pablo Greco 40546a
diff --git a/src/util/virpci.h b/src/util/virpci.h
Pablo Greco 40546a
index 01df652b86..b366d7d9c3 100644
Pablo Greco 40546a
--- a/src/util/virpci.h
Pablo Greco 40546a
+++ b/src/util/virpci.h
Pablo Greco 40546a
@@ -49,6 +49,8 @@ struct _virPCIDeviceAddress {
Pablo Greco 40546a
     unsigned int slot;
Pablo Greco 40546a
     unsigned int function;
Pablo Greco 40546a
     int multi; /* virTristateSwitch */
Pablo Greco 40546a
+    int extFlags; /* enum virPCIDeviceAddressExtensionFlags */
Pablo Greco 40546a
+    virZPCIDeviceAddress zpci;
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 typedef enum {
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a