From: Pavel Hrdina Date: Mon, 16 Feb 2026 08:12:02 +0000 (+0100) Subject: qemu: Move IOMMUFD validation to qemu_validate X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c1af67be554d4daa2facfb647ce6e9914da2f06;p=thirdparty%2Flibvirt.git qemu: Move IOMMUFD validation to qemu_validate Fail early if kernel doesn't support IOMMUFD. Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8554191503..2f9fdc04ad 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2649,6 +2649,7 @@ virInitctlSetRunLevel; # util/viriommufd.h virIOMMUFDSetRLimitMode; +virIOMMUFDSupported; # util/viriscsi.h virISCSIConnectionLogin; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c3f681f1dd..fd400ae8a6 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -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; } diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 18700b5a9b..16dd5fef1a 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -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; + } } } diff --git a/src/util/viriommufd.c b/src/util/viriommufd.c index 5af097683d..44b30029a5 100644 --- a/src/util/viriommufd.c +++ b/src/util/viriommufd.c @@ -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); +} diff --git a/src/util/viriommufd.h b/src/util/viriommufd.h index ebecfe3633..ec6be9fa66 100644 --- a/src/util/viriommufd.h +++ b/src/util/viriommufd.h @@ -23,3 +23,5 @@ #define VIR_IOMMU_DEV_PATH "/dev/iommu" int virIOMMUFDSetRLimitMode(int fd, bool processAccounting); + +bool virIOMMUFDSupported(void);