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