render / rpms / libvirt

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