]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Move IOMMUFD validation to qemu_validate
authorPavel Hrdina <phrdina@redhat.com>
Mon, 16 Feb 2026 08:12:02 +0000 (09:12 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 16 Feb 2026 14:50:39 +0000 (15:50 +0100)
Fail early if kernel doesn't support IOMMUFD.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/qemu/qemu_process.c
src/qemu/qemu_validate.c
src/util/viriommufd.c
src/util/viriommufd.h

index 855419150359ec741d107e6826ce25727503315f..2f9fdc04ad03fc8609c1fa4085d8a69c794fa39e 100644 (file)
@@ -2649,6 +2649,7 @@ virInitctlSetRunLevel;
 
 # util/viriommufd.h
 virIOMMUFDSetRLimitMode;
+virIOMMUFDSupported;
 
 # util/viriscsi.h
 virISCSIConnectionLogin;
index c3f681f1dd3ca99ba3a7dfc03a5198fe38a5e4af..fd400ae8a6d399fe5d924bcabbdac2cf099a3491 100644 (file)
@@ -7694,13 +7694,7 @@ 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) {
-        if (errno == ENOENT) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("IOMMU FD support requires /dev/iommu device"));
-        } else {
-            virReportSystemError(errno, "%s",
-                                 _("cannot open /dev/iommu"));
-        }
+        virReportSystemError(errno, "%s", _("cannot open /dev/iommu"));
         return -1;
     }
 
index 18700b5a9bc526e7247ddcd0cfe1f6a2450fbed3..16dd5fef1aafea95657b32dee79f06c3395900cd 100644 (file)
@@ -27,6 +27,7 @@
 #include "qemu_process.h"
 #include "domain_conf.h"
 #include "virbitmap.h"
+#include "viriommufd.h"
 #include "virlog.h"
 #include "virutil.h"
 
@@ -2729,6 +2730,12 @@ qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev,
                                        _("IOMMUFD is not supported by this version of qemu"));
                         return -1;
                     }
+
+                    if (!virIOMMUFDSupported()) {
+                        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                                       _("IOMMUFD is not supported by host kernel"));
+                        return -1;
+                    }
                 }
             }
 
index 5af097683d6bfa7849c6aa838092554e4accdfbe..44b30029a593da1593cd454e8deda27145fe7532 100644 (file)
@@ -88,3 +88,16 @@ int virIOMMUFDSetRLimitMode(int fd G_GNUC_UNUSED,
 }
 
 #endif
+
+/**
+ * virIOMMUFDSupported:
+ *
+ * Check the presence of IOMMU device.
+ *
+ * Retruns: true if it exists, false otherwise
+ */
+bool
+virIOMMUFDSupported(void)
+{
+    return virFileExists(VIR_IOMMU_DEV_PATH);
+}
index ebecfe36336293783f9e503e54ca8ed367f7bc4e..ec6be9fa6615073cd4c7b74bbb9ade514e3f4e85 100644 (file)
@@ -23,3 +23,5 @@
 #define VIR_IOMMU_DEV_PATH "/dev/iommu"
 
 int virIOMMUFDSetRLimitMode(int fd, bool processAccounting);
+
+bool virIOMMUFDSupported(void);