- qemu: Introduce QEMU_CAPS_OBJECT_IOMMUFD (RHEL-150353) - qemu: Move IOMMUFD validation to qemu_validate (RHEL-150353) - util: Move openning IOMMU device to viriommufd (RHEL-150353) - qemu_process: Refactor qemuProcessOpenIommuFd (RHEL-150353) - util: Move openning VFIO device to virpci (RHEL-150353) - qemu_process: Refactor qemuProcessOpenVfioDeviceFd (RHEL-150353) - util: Use virPCIDevice as argument in virPCIDeviceGetVfioPath (RHEL-150353) - conf: Introduce virHostdevIsPCIDeviceWithIOMMUFD (RHEL-150353) - conf: Introduce virDomainDefHasPCIHostdevWithIOMMUFD (RHEL-150353) - qemu_domain: Add missing IOMMUFD cleanup (RHEL-150353) - qemu_process: Fix FD leak with multiple host devices using IOMMUFD (RHEL-150353) - qemu_process: Refactor qemuProcessOpenVfioFds (RHEL-150353) - qemuxmlconftest: Refactor host device preparation (RHEL-150353) - qemuxmlconftest: Rename and refactor testSetupHostdevPrivateData (RHEL-150353) - qemuxmlconftest: Set fake FD for IOMMUFD (RHEL-150353) - qemu: Convert IOMMUFD to qemuFDPassDirect (RHEL-150353) - qemu: Convert vfioDeviceFd to qemuFDPassDirect (RHEL-150353) - qemu_command: Don't use host property if IOMMUFD is used (RHEL-150353) - qemu: Save IOMMUFD state into status XML (RHEL-150353) - qemu_hotplug: Remove iommufd object if no longer needed (RHEL-150353) - qemu_command: Extract building IOMMUFD props to function (RHEL-150353) - qemu_hotplug: Add support to hotplug host device with IOMMUFD (RHEL-150353) - conf: Introduce iommufd enum for domaincaps (RHEL-138544) - qemu: Fill iommufd domain capability (RHEL-138544) - tests: properly mock VFIO and IOMMU checks (RHEL-138544) - iommufd: fix FD leak in case of error (RHEL-150353) Resolves: RHEL-138544, RHEL-150353
116 lines
3.3 KiB
Diff
116 lines
3.3 KiB
Diff
From 3fab098321e026e0ee33c8ef3c3e45f9976375d9 Mon Sep 17 00:00:00 2001
|
|
Message-ID: <3fab098321e026e0ee33c8ef3c3e45f9976375d9.1771423832.git.jdenemar@redhat.com>
|
|
From: Pavel Hrdina <phrdina@redhat.com>
|
|
Date: Sun, 15 Feb 2026 15:32:24 +0100
|
|
Subject: [PATCH] util: Move openning IOMMU device to viriommufd
|
|
|
|
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
(cherry picked from commit c684b83a68158cd15e262523db11259c9edabe4a)
|
|
|
|
Resolves: https://issues.redhat.com/browse/RHEL-150353
|
|
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
---
|
|
src/libvirt_private.syms | 2 +-
|
|
src/qemu/qemu_process.c | 9 +--------
|
|
src/util/viriommufd.c | 22 +++++++++++++++++++---
|
|
src/util/viriommufd.h | 2 +-
|
|
4 files changed, 22 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
index 0904265459..6c4918da9e 100644
|
|
--- a/src/libvirt_private.syms
|
|
+++ b/src/libvirt_private.syms
|
|
@@ -2653,7 +2653,7 @@ virInitctlFifos;
|
|
virInitctlSetRunLevel;
|
|
|
|
# util/viriommufd.h
|
|
-virIOMMUFDSetRLimitMode;
|
|
+virIOMMUFDOpenDevice;
|
|
virIOMMUFDSupported;
|
|
|
|
# util/viriscsi.h
|
|
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
|
|
index 479437fb34..dd165512f3 100644
|
|
--- a/src/qemu/qemu_process.c
|
|
+++ b/src/qemu/qemu_process.c
|
|
@@ -7689,15 +7689,8 @@ qemuProcessOpenIommuFd(virDomainObj *vm)
|
|
|
|
VIR_DEBUG("Opening IOMMU FD for domain %s", vm->def->name);
|
|
|
|
- if ((fd = open(VIR_IOMMU_DEV_PATH, O_RDWR | O_CLOEXEC)) < 0) {
|
|
- virReportSystemError(errno, "%s", _("cannot open /dev/iommu"));
|
|
+ if ((fd = virIOMMUFDOpenDevice()) < 0)
|
|
return -1;
|
|
- }
|
|
-
|
|
- if (virIOMMUFDSetRLimitMode(fd, true) < 0) {
|
|
- VIR_FORCE_CLOSE(fd);
|
|
- return -1;
|
|
- }
|
|
|
|
VIR_DEBUG("Opened IOMMU FD %d for domain %s", fd, vm->def->name);
|
|
return fd;
|
|
diff --git a/src/util/viriommufd.c b/src/util/viriommufd.c
|
|
index 44b30029a5..1f3353eab4 100644
|
|
--- a/src/util/viriommufd.c
|
|
+++ b/src/util/viriommufd.c
|
|
@@ -1,5 +1,7 @@
|
|
#include <config.h>
|
|
|
|
+#include <fcntl.h>
|
|
+
|
|
#include "viriommufd.h"
|
|
#include "virlog.h"
|
|
#include "virerror.h"
|
|
@@ -54,7 +56,7 @@ struct iommu_option {
|
|
*
|
|
* Returns: 0 on success, -1 on error
|
|
*/
|
|
-int
|
|
+static int
|
|
virIOMMUFDSetRLimitMode(int fd, bool processAccounting)
|
|
{
|
|
struct iommu_option option = {
|
|
@@ -77,10 +79,24 @@ virIOMMUFDSetRLimitMode(int fd, bool processAccounting)
|
|
return 0;
|
|
}
|
|
|
|
+int
|
|
+virIOMMUFDOpenDevice(void)
|
|
+{
|
|
+ int fd = -1;
|
|
+
|
|
+ if ((fd = open(VIR_IOMMU_DEV_PATH, O_RDWR | O_CLOEXEC)) < 0)
|
|
+ virReportSystemError(errno, "%s", _("cannot open IOMMUFD device"));
|
|
+
|
|
+ if (virIOMMUFDSetRLimitMode(fd, true) < 0)
|
|
+ return -1;
|
|
+
|
|
+ return fd;
|
|
+}
|
|
+
|
|
#else
|
|
|
|
-int virIOMMUFDSetRLimitMode(int fd G_GNUC_UNUSED,
|
|
- bool processAccounting G_GNUC_UNUSED)
|
|
+int
|
|
+virIOMMUFDOpenDevice(void)
|
|
{
|
|
virReportError(VIR_ERR_NO_SUPPORT, "%s",
|
|
_("IOMMUFD is not supported on this platform"));
|
|
diff --git a/src/util/viriommufd.h b/src/util/viriommufd.h
|
|
index ec6be9fa66..223f44eb5c 100644
|
|
--- a/src/util/viriommufd.h
|
|
+++ b/src/util/viriommufd.h
|
|
@@ -22,6 +22,6 @@
|
|
|
|
#define VIR_IOMMU_DEV_PATH "/dev/iommu"
|
|
|
|
-int virIOMMUFDSetRLimitMode(int fd, bool processAccounting);
|
|
+int virIOMMUFDOpenDevice(void);
|
|
|
|
bool virIOMMUFDSupported(void);
|
|
--
|
|
2.53.0
|