[libvirt PATCH 05/11] qemu: Update qemuDomainNeedsVFIO to ignore PCI hostdev with IOMMUFD

Pavel Hrdina via Devel posted 11 patches 4 days, 6 hours ago
[libvirt PATCH 05/11] qemu: Update qemuDomainNeedsVFIO to ignore PCI hostdev with IOMMUFD
Posted by Pavel Hrdina via Devel 4 days, 6 hours ago
From: Pavel Hrdina <phrdina@redhat.com>

This function is used to figure out if VM needs access to /dev/vfio/vfio.
In case of PCI host devices that is true only if IOMMUFD is not enabled.

This fixes error when hotplugging PCI host device with IOMMUFD disabled
to a VM that already has PCI host device with IOMMIFD enabled:

    Could not open '/dev/vfio/vfio': No such file or directory

The function is used in this case to check if /dev/vfio/vfio was already
made available to QEMU or not.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/conf/domain_conf.c   | 14 ++++++++++++++
 src/conf/domain_conf.h   |  3 +++
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_domain.c   |  2 +-
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2d6ae64210..562803ea87 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -32764,6 +32764,20 @@ virDomainDefHasPCIHostdevWithIOMMUFD(const virDomainDef *def)
 }
 
 
+bool
+virDomainDefHasPCIHostdevWithoutIOMMUFD(const virDomainDef *def)
+{
+    size_t i;
+
+    for (i = 0; i < def->nhostdevs; i++) {
+        if (virHostdevIsPCIDeviceWithoutIOMMUFD(def->hostdevs[i]))
+            return true;
+    }
+
+    return false;
+}
+
+
 bool
 virDomainDefHasMdevHostdev(const virDomainDef *def)
 {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 018daef4c7..3b4980394e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -4674,6 +4674,9 @@ virDomainDefHasPCIHostdev(const virDomainDef *def);
 bool
 virDomainDefHasPCIHostdevWithIOMMUFD(const virDomainDef *def);
 
+bool
+virDomainDefHasPCIHostdevWithoutIOMMUFD(const virDomainDef *def);
+
 bool
 virDomainDefHasMdevHostdev(const virDomainDef *def);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8dbbd7f64d..cf0e71cc6a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -349,6 +349,7 @@ virDomainDefHasOldStyleROUEFI;
 virDomainDefHasOldStyleUEFI;
 virDomainDefHasPCIHostdev;
 virDomainDefHasPCIHostdevWithIOMMUFD;
+virDomainDefHasPCIHostdevWithoutIOMMUFD;
 virDomainDefHasTimer;
 virDomainDefHasUSB;
 virDomainDefHasVcpusOffline;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 4520c3c28d..1d00ff2845 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9284,7 +9284,7 @@ qemuDomainSupportsVideoVga(const virDomainVideoDef *video,
 bool
 qemuDomainNeedsVFIO(const virDomainDef *def)
 {
-    return virDomainDefHasPCIHostdev(def) ||
+    return virDomainDefHasPCIHostdevWithoutIOMMUFD(def) ||
         virDomainDefHasMdevHostdev(def) ||
         virDomainDefHasNVMeDisk(def);
 }
-- 
2.53.0
Re: [libvirt PATCH 05/11] qemu: Update qemuDomainNeedsVFIO to ignore PCI hostdev with IOMMUFD
Posted by Peter Krempa via Devel 3 days, 14 hours ago
On Thu, Mar 19, 2026 at 17:36:51 +0100, Pavel Hrdina via Devel wrote:
> From: Pavel Hrdina <phrdina@redhat.com>
> 
> This function is used to figure out if VM needs access to /dev/vfio/vfio.
> In case of PCI host devices that is true only if IOMMUFD is not enabled.
> 
> This fixes error when hotplugging PCI host device with IOMMUFD disabled
> to a VM that already has PCI host device with IOMMIFD enabled:
> 
>     Could not open '/dev/vfio/vfio': No such file or directory
> 
> The function is used in this case to check if /dev/vfio/vfio was already
> made available to QEMU or not.
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/conf/domain_conf.c   | 14 ++++++++++++++
>  src/conf/domain_conf.h   |  3 +++
>  src/libvirt_private.syms |  1 +
>  src/qemu/qemu_domain.c   |  2 +-
>  4 files changed, 19 insertions(+), 1 deletion(-)

[...]

> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 4520c3c28d..1d00ff2845 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -9284,7 +9284,7 @@ qemuDomainSupportsVideoVga(const virDomainVideoDef *video,

This function really now needs a comment stating why/what and the
quirks.

>  bool
>  qemuDomainNeedsVFIO(const virDomainDef *def)
>  {
> -    return virDomainDefHasPCIHostdev(def) ||
> +    return virDomainDefHasPCIHostdevWithoutIOMMUFD(def) ||
>          virDomainDefHasMdevHostdev(def) ||
>          virDomainDefHasNVMeDisk(def);
>  }


Reviewed-by: Peter Krempa <pkrempa@redhat.com>