libvirt/libvirt-util-Use-virPCIDevice-as-argument-in-virPCIDeviceGetVfioPath.patch
Jiri Denemark 481c875102 libvirt-11.10.0-10.el10
- qemu: Introduce QEMU_CAPS_OBJECT_IOMMUFD (RHEL-150351)
- qemu: Move IOMMUFD validation to qemu_validate (RHEL-150351)
- util: Move openning IOMMU device to viriommufd (RHEL-150351)
- qemu_process: Refactor qemuProcessOpenIommuFd (RHEL-150351)
- util: Move openning VFIO device to virpci (RHEL-150351)
- qemu_process: Refactor qemuProcessOpenVfioDeviceFd (RHEL-150351)
- util: Use virPCIDevice as argument in virPCIDeviceGetVfioPath (RHEL-150351)
- conf: Introduce virHostdevIsPCIDeviceWithIOMMUFD (RHEL-150351)
- conf: Introduce virDomainDefHasPCIHostdevWithIOMMUFD (RHEL-150351)
- qemu_domain: Add missing IOMMUFD cleanup (RHEL-150351)
- qemu_process: Fix FD leak with multiple host devices using IOMMUFD (RHEL-150351)
- qemu_process: Refactor qemuProcessOpenVfioFds (RHEL-150351)
- qemuxmlconftest: Refactor host device preparation (RHEL-150351)
- qemuxmlconftest: Rename and refactor testSetupHostdevPrivateData (RHEL-150351)
- qemuxmlconftest: Set fake FD for IOMMUFD (RHEL-150351)
- qemu: Convert IOMMUFD to qemuFDPassDirect (RHEL-150351)
- qemu: Convert vfioDeviceFd to qemuFDPassDirect (RHEL-150351)
- qemu_command: Don't use host property if IOMMUFD is used (RHEL-150351)
- qemu: Save IOMMUFD state into status XML (RHEL-150351)
- qemu_hotplug: Remove iommufd object if no longer needed (RHEL-150351)
- qemu_command: Extract building IOMMUFD props to function (RHEL-150351)
- qemu_hotplug: Add support to hotplug host device with IOMMUFD (RHEL-150351)
- conf: Introduce iommufd enum for domaincaps (RHEL-148135)
- qemu: Fill iommufd domain capability (RHEL-148135)
- tests: properly mock VFIO and IOMMU checks (RHEL-148135)
- iommufd: fix FD leak in case of error (RHEL-150351)

Resolves: RHEL-148135, RHEL-150351
2026-02-18 15:07:39 +01:00

144 lines
5.6 KiB
Diff

From 25fa4eb529f1d54995b66ebe3b38bafb3ab755c6 Mon Sep 17 00:00:00 2001
Message-ID: <25fa4eb529f1d54995b66ebe3b38bafb3ab755c6.1771423658.git.jdenemar@redhat.com>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Sun, 15 Feb 2026 17:51:46 +0100
Subject: [PATCH] util: Use virPCIDevice as argument in virPCIDeviceGetVfioPath
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 3365bff598a0d0a5b21afc7060e10a0a2f7d21a7)
Resolves: https://issues.redhat.com/browse/RHEL-150351
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
src/security/security_apparmor.c | 2 +-
src/security/security_dac.c | 4 ++--
src/security/security_selinux.c | 4 ++--
src/util/virpci.c | 14 ++++++++------
src/util/virpci.h | 2 +-
5 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index 934acfb461..6c5da2a650 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -860,7 +860,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManager *mgr,
} else {
g_autofree char *vfiofdDev = NULL;
- if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0)
+ if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0)
goto done;
ret = AppArmorSetSecurityPCILabel(pci, vfiofdDev, ptr);
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index d0ed22db2d..704c8dbfec 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -1295,7 +1295,7 @@ virSecurityDACSetHostdevLabel(virSecurityManager *mgr,
} else {
g_autofree char *vfiofdDev = NULL;
- if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0)
+ if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0)
return -1;
ret = virSecurityDACSetHostdevLabelHelper(vfiofdDev, false, &cbdata);
@@ -1468,7 +1468,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManager *mgr,
} else {
g_autofree char *vfiofdDev = NULL;
- if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0)
+ if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0)
return -1;
ret = virSecurityDACRestoreFileLabelInternal(mgr, NULL,
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 834383a7de..4a5f61d16b 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -2269,7 +2269,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManager *mgr,
} else {
g_autofree char *vfiofdDev = NULL;
- if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0)
+ if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0)
return -1;
ret = virSecuritySELinuxSetHostdevLabelHelper(vfiofdDev, false, &data);
@@ -2515,7 +2515,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManager *mgr,
} else {
g_autofree char *vfiofdDev = NULL;
- if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0)
+ if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0)
return -1;
ret = virSecuritySELinuxRestoreFileLabel(mgr, vfiofdDev, false, false);
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 30feec6dae..78c47869ef 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -3331,19 +3331,17 @@ virPCIDeviceAddressFree(virPCIDeviceAddress *address)
* Returns: 0 on success, -1 on failure
*/
int
-virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr,
+virPCIDeviceGetVfioPath(virPCIDevice *pci,
char **vfioPath)
{
- g_autofree char *addrStr = NULL;
g_autofree char *sysfsPath = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *entry = NULL;
*vfioPath = NULL;
- addrStr = virPCIDeviceAddressAsString(addr);
/* Look in device's vfio-dev subdirectory */
- sysfsPath = g_strdup_printf("/sys/bus/pci/devices/%s/vfio-dev/", addrStr);
+ sysfsPath = virPCIFile(pci->name, "vfio-dev");
if (virDirOpen(&dir, sysfsPath) == 1) {
while (virDirRead(dir, &entry, sysfsPath) > 0) {
@@ -3356,7 +3354,7 @@ virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot find VFIO device for PCI device %1$s"),
- addrStr);
+ pci->name);
return -1;
}
@@ -3371,10 +3369,14 @@ virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr,
int
virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr)
{
+ g_autoptr(virPCIDevice) pci = NULL;
g_autofree char *vfioPath = NULL;
int fd = -1;
- if (virPCIDeviceGetVfioPath(addr, &vfioPath) < 0)
+ if (!(pci = virPCIDeviceNew(addr)))
+ return -1;
+
+ if (virPCIDeviceGetVfioPath(pci, &vfioPath) < 0)
return -1;
VIR_DEBUG("Opening VFIO device %s", vfioPath);
diff --git a/src/util/virpci.h b/src/util/virpci.h
index 7848567285..933099da6c 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -296,7 +296,7 @@ void virPCIEDeviceInfoFree(virPCIEDeviceInfo *dev);
void virPCIDeviceAddressFree(virPCIDeviceAddress *address);
-int virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, char **vfioPath);
+int virPCIDeviceGetVfioPath(virPCIDevice *pci, char **vfioPath);
int virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr);
--
2.53.0