On 3/17/26 6:55 AM, Cédric Le Goater wrote:
Let's come back to the proposal. Currently, when the QEMU platform
doesn't support IOMMUFD (i.e no support for the backend), QEMU reports
at runtime :

     qemu-XYZ...: invalid object type: iommufd

As a consequence, the vfio-pci device doesn't expose the "iommufd"
property when the backend IOMMUFD is not available.

However, the additional filtering on the vfio-pci properties based
on CONFIG_IOMMUFD seems unnecessary. Instead the "iommufd" property
could always be exposed, whether or not the QEMU build includes IOMMUFD
support (kernel support is another topic). If the property is used
in an environment where IOMMUFD is unsupported, QEMU will simply
fail to create the IOMMUFD object.

Could you please rephrase the commit log with some of this information ?


Sure, how about:

{{{
hw/vfio: eradicate CONFIG_IOMMU from sources

This commit removes usage of CONFIG_IOMMU in hw/vfio sources, exposing 
inconditionally iommufd related properties, which are declared statically (in 
const arrays). The alternative to expose them dynamically is more complex and 
requires boilerplate to set properties at runtime, with set_* callbacks and 
added logic to check if iommufd backend is available, with no obvious benefit.

One difference is that user will have a different error message when trying to 
attach a vfio device on a platform not supporting iommufd.
Instead of:
```
$ qemu-system-* -device vfio-pci,host=0000:01:00.0,iommufd=iommufd0

This should be

    # ... -device vfio-pci,host=0000:01:00.0,iommufd=iommufd0
    qemu-system-*: -device vfio-pci,host=0000:01:00.0,iommufd=iommufd0: 
Property 'vfio-pci.iommufd' not found

but, since we need to specify '-object iommufd,id=iommufd0' anyway,
the error is :

    # ... -object iommufd,id=iommufd0  -device 
vfio-pci,host=0000:01:00.0,iommufd=iommufd0
    qemu-system-*: invalid object type: iommufd

and it stays the same with your proposal :

    # ... -object iommufd,id=iommufd0  -device 
vfio-pci,host=0000:01:00.0,iommufd=iommufd0
    qemu-system-*: invalid object type: iommufd



Right, in my previous answer, I was (wrongly) focused on kernel config instead of QEMU one. I'll update message description.

invalid object type: iommufd
```

QEMU will try to attach device and error will be reported as:
```
-device vfio-pci,host=0000:01:00.0,iommufd=iommufd0:
vfio 0000:01:00.0: vfio/sys/bus/pci/devices/0000:01:00.0/vfio-dev: failed to load 
"/sys/bus/pci/devices/0000:01:00.0/vfio-dev/vfio0/dev
```

This error only occurs when the kernel doesn't have proper IOMMUFD support.
I don't think it is worth mentioning for this change.


Ok, I'll remove it.


Note: This second error can already happen if user's kernel does not have 
CONFIG_IOMMUFD or CONFIG_VFIO_DEVICE_CDEV support, but QEMU has it.
}}}

Anything you would like to add?

Thanks,

C.

Writing my answer and seeing current behavior, I wonder if we could not have 
better error messages simply by checking if /dev/iommu exists when setting the 
iommufd property of vfio-pci device or when realizing the iommufd object 
(-object iommufd,id=iommufd0). For the latter, I need to double check order or 
initialization/realization as it might be tricky to catch before setting 
accessing vfio-dev/vfio0/dev.

yes. as said before, QEMU attaches to the device before connecting it
to the IOMMU backend. So the iommufd object is unused until we reach
this step of the device initialization.

$ qemu-system-* -object iommufd,id=iommufd0
can't create iommufd object: /dev/iommu not found
Is your kernel config missing CONFIG_IOMMUFD?

Why not. Would you have time for it ?


Yes, I'll take a look to add it as an additional patch on top of this series.

As well, we could report "Is your kernel config missing 
CONFIG_VFIO_DEVICE_CDEV?" on the error mentioned in commit message.

This could added in one of the error messages of iommufd_cdev_getfd().

And while we're at it, in case we report one of those errors, we could check target_arch(), and if 
it's not one supporting actively support iommufd, say to the user "Linux does not support 
iommufd on this platform" instead of "Is your kernel missing X or Y?".

The Kconfig file of the machines have 'imply IOMMUFD' so that the object
iommufd is only built on systems where it makes sense: i386, arm, s390x,
as of today. We should be fine.


Good point, iommufd object won't be available in this case.
Thanks,

C.



Regards,
Pierrick

Reply via email to