render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
Pablo Greco 40546a
From 8996236421b4adf090ac721e8d525953deb9687a Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <8996236421b4adf090ac721e8d525953deb9687a@dist-git>
Pablo Greco 40546a
From: Daniel Henrique Barboza <danielhb413@gmail.com>
Pablo Greco 40546a
Date: Fri, 3 May 2019 13:54:52 +0200
Pablo Greco 40546a
Subject: [PATCH] qemu_domain: NVLink2 bridge detection function for PPC64
Pablo Greco 40546a
Pablo Greco 40546a
The NVLink2 support in QEMU implements the detection of NVLink2
Pablo Greco 40546a
capable devices by verifying the attributes of the VFIO mem region
Pablo Greco 40546a
QEMU allocates for the NVIDIA GPUs. To properly allocate an
Pablo Greco 40546a
adequate amount of memLock, Libvirt needs this information before
Pablo Greco 40546a
a QEMU instance is even created, thus querying QEMU is not
Pablo Greco 40546a
possible and opening a VFIO window is too much.
Pablo Greco 40546a
Pablo Greco 40546a
An alternative is presented in this patch. Making the following
Pablo Greco 40546a
assumptions:
Pablo Greco 40546a
Pablo Greco 40546a
- if we want GPU RAM to be available in the guest, an NVLink2 bridge
Pablo Greco 40546a
must be passed through;
Pablo Greco 40546a
Pablo Greco 40546a
- an unknown PCI device can be classified as a NVLink2 bridge
Pablo Greco 40546a
if its device tree node has 'ibm,gpu', 'ibm,nvlink',
Pablo Greco 40546a
'ibm,nvlink-speed' and 'memory-region'.
Pablo Greco 40546a
Pablo Greco 40546a
This patch introduces a helper called @ppc64VFIODeviceIsNV2Bridge
Pablo Greco 40546a
that checks the device tree node of a given PCI device and
Pablo Greco 40546a
check if it meets the criteria to be a NVLink2 bridge. This
Pablo Greco 40546a
new function will be used in a follow-up patch that, using the
Pablo Greco 40546a
first assumption, will set up the rlimits of the guest
Pablo Greco 40546a
accordingly.
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Pablo Greco 40546a
(cherry picked from commit cc9f03801c2618102027ddc4a988193ae290b651)
Pablo Greco 40546a
Pablo Greco 40546a
https: //bugzilla.redhat.com/show_bug.cgi?id=1505998
Pablo Greco 40546a
Signed-off-by: Erik Skultety <eskultet@redhat.com>
Pablo Greco 40546a
Message-Id: <99efa386adcf68789b7c8cffda2ef24f5f47f0c4.1556884443.git.eskultet@redhat.com>
Pablo Greco 40546a
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 src/qemu/qemu_domain.c | 30 ++++++++++++++++++++++++++++++
Pablo Greco 40546a
 1 file changed, 30 insertions(+)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
Pablo Greco 40546a
index f91de0b743..a8bc618389 100644
Pablo Greco 40546a
--- a/src/qemu/qemu_domain.c
Pablo Greco 40546a
+++ b/src/qemu/qemu_domain.c
Pablo Greco 40546a
@@ -9805,6 +9805,36 @@ qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+/**
Pablo Greco 40546a
+ * ppc64VFIODeviceIsNV2Bridge:
Pablo Greco 40546a
+ * @device: string with the PCI device address
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * This function receives a string that represents a PCI device,
Pablo Greco 40546a
+ * such as '0004:04:00.0', and tells if the device is a NVLink2
Pablo Greco 40546a
+ * bridge.
Pablo Greco 40546a
+ */
Pablo Greco 40546a
+static ATTRIBUTE_UNUSED bool
Pablo Greco 40546a
+ppc64VFIODeviceIsNV2Bridge(const char *device)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    const char *nvlink2Files[] = {"ibm,gpu", "ibm,nvlink",
Pablo Greco 40546a
+                                  "ibm,nvlink-speed", "memory-region"};
Pablo Greco 40546a
+    size_t i;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    for (i = 0; i < ARRAY_CARDINALITY(nvlink2Files); i++) {
Pablo Greco 40546a
+        VIR_AUTOFREE(char *) file = NULL;
Pablo Greco 40546a
+
Pablo Greco 40546a
+        if ((virAsprintf(&file, "/sys/bus/pci/devices/%s/of_node/%s",
Pablo Greco 40546a
+                         device, nvlink2Files[i])) < 0)
Pablo Greco 40546a
+            return false;
Pablo Greco 40546a
+
Pablo Greco 40546a
+        if (!virFileExists(file))
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
 /**
Pablo Greco 40546a
  * getPPC64MemLockLimitBytes:
Pablo Greco 40546a
  * @def: domain definition
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.21.0
Pablo Greco 40546a