@samitouri / QOSamiQemu / commits / 97395da20d

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 possible difference is that user may see a different error message when trying to attach a vfio device with a QEMU not supporting iommufd, without declaring iommufd object associated. Instead of: ``` $ qemu-system-* -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 ``` User will now see: ``` qemu-system-aarch64: -device vfio-pci,host=0000:01:00.0,iommufd=iommufd0: Device 'iommufd0' not found ``` However, since declaring the iommufd object is needed, error reported before and after is still the same: ``` $ qemu-system-* -object iommufd,id=iommufd0 -device vfio-pci,host=0000:01:00.0,iommufd=iommufd0 qemu-system-*: invalid object type: iommufd ``` Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Reviewed-by: Cédric Le Goater <clg@redhat.com> Tested-by: Cédric Le Goater <clg@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/qemu-devel/20260318174733.1717643-5-pierrick.bouvier@linaro.org Signed-off-by: Cédric Le Goater <clg@redhat.com>

Pierrick Bouvier committed Mar 18, 2026 at 10:47 UTC 97395da20d0642fd61e7d92a1d0a0becd2b06136
3 files changed -29
hw/vfio/ap.c
-9
@@ -11,7 +11,6 @@
11 */
12
13 #include "qemu/osdep.h"
14 -#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
14 #include <linux/vfio.h>
15 #include <sys/ioctl.h>
16 #include "qapi/error.h"
@@ -279,10 +278,8 @@ static void vfio_ap_unrealize(DeviceState *dev)
278
279 static const Property vfio_ap_properties[] = {
280 DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev),
282 -#ifdef CONFIG_IOMMUFD
281 DEFINE_PROP_LINK("iommufd", VFIOAPDevice, vdev.iommufd,
282 TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
285 -#endif
283 };
284
285 static void vfio_ap_reset(DeviceState *dev)
@@ -320,21 +317,17 @@ static void vfio_ap_instance_init(Object *obj)
317 vbasedev->mdev = true;
318 }
319
323 -#ifdef CONFIG_IOMMUFD
320 static void vfio_ap_set_fd(Object *obj, const char *str, Error **errp)
321 {
322 vfio_device_set_fd(&VFIO_AP_DEVICE(obj)->vdev, str, errp);
323 }
328 -#endif
324
325 static void vfio_ap_class_init(ObjectClass *klass, const void *data)
326 {
327 DeviceClass *dc = DEVICE_CLASS(klass);
328
329 device_class_set_props(dc, vfio_ap_properties);
335 -#ifdef CONFIG_IOMMUFD
330 object_class_property_add_str(klass, "fd", NULL, vfio_ap_set_fd);
337 -#endif
331 dc->vmsd = &vfio_ap_vmstate;
332 dc->desc = "VFIO-based AP device assignment";
333 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -347,11 +340,9 @@ static void vfio_ap_class_init(ObjectClass *klass, const void *data)
340 object_class_property_set_description(klass, /* 3.1 */
341 "sysfsdev",
342 "Host sysfs path of assigned device");
350 -#ifdef CONFIG_IOMMUFD
343 object_class_property_set_description(klass, /* 9.0 */
344 "iommufd",
345 "Set host IOMMUFD backend device");
354 -#endif
346 }
347
348 static const TypeInfo vfio_ap_info = {
hw/vfio/ccw.c
-9
@@ -15,7 +15,6 @@
15 */
16
17 #include "qemu/osdep.h"
18 -#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
18 #include <linux/vfio.h>
19 #include <linux/vfio_ccw.h>
20 #include <sys/ioctl.h>
@@ -647,10 +646,8 @@ static void vfio_ccw_unrealize(DeviceState *dev)
646 static const Property vfio_ccw_properties[] = {
647 DEFINE_PROP_STRING("sysfsdev", VFIOCCWDevice, vdev.sysfsdev),
648 DEFINE_PROP_BOOL("force-orb-pfch", VFIOCCWDevice, force_orb_pfch, false),
650 -#ifdef CONFIG_IOMMUFD
649 DEFINE_PROP_LINK("iommufd", VFIOCCWDevice, vdev.iommufd,
650 TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
653 -#endif
651 DEFINE_PROP_CCW_LOADPARM("loadparm", CcwDevice, loadparm),
652 };
653
@@ -679,12 +676,10 @@ static void vfio_ccw_instance_init(Object *obj)
676 DEVICE(vcdev), true);
677 }
678
682 -#ifdef CONFIG_IOMMUFD
679 static void vfio_ccw_set_fd(Object *obj, const char *str, Error **errp)
680 {
681 vfio_device_set_fd(&VFIO_CCW(obj)->vdev, str, errp);
682 }
687 -#endif
683
684 static void vfio_ccw_class_init(ObjectClass *klass, const void *data)
685 {
@@ -692,9 +687,7 @@ static void vfio_ccw_class_init(ObjectClass *klass, const void *data)
687 S390CCWDeviceClass *cdc = S390_CCW_DEVICE_CLASS(klass);
688
689 device_class_set_props(dc, vfio_ccw_properties);
695 -#ifdef CONFIG_IOMMUFD
690 object_class_property_add_str(klass, "fd", NULL, vfio_ccw_set_fd);
697 -#endif
691 dc->vmsd = &vfio_ccw_vmstate;
692 dc->desc = "VFIO-based subchannel assignment";
693 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -713,11 +706,9 @@ static void vfio_ccw_class_init(ObjectClass *klass, const void *data)
706 object_class_property_set_description(klass, /* 3.0 */
707 "force-orb-pfch",
708 "Force unlimited prefetch");
716 -#ifdef CONFIG_IOMMUFD
709 object_class_property_set_description(klass, /* 9.0 */
710 "iommufd",
711 "Set host IOMMUFD backend device");
720 -#endif
712 object_class_property_set_description(klass, /* 9.2 */
713 "loadparm",
714 "Define which devices that can be used for booting");
hw/vfio/pci.c
-11
@@ -19,7 +19,6 @@
19 */
20
21 #include "qemu/osdep.h"
22 -#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
22 #include <linux/vfio.h>
23 #include <sys/ioctl.h>
24
@@ -3471,9 +3470,7 @@ static void vfio_pci_realize(PCIDevice *pdev, Error **errp)
3470 ~vdev->host.slot || ~vdev->host.function)) {
3471 error_setg(errp, "No provided host device");
3472 error_append_hint(errp, "Use -device vfio-pci,host=DDDD:BB:DD.F "
3474 -#ifdef CONFIG_IOMMUFD
3473 "or -device vfio-pci,fd=DEVICE_FD "
3476 -#endif
3474 "or -device vfio-pci,sysfsdev=PATH_TO_DEVICE\n");
3475 return;
3476 }
@@ -3816,22 +3813,18 @@ static const Property vfio_pci_properties[] = {
3813 qdev_prop_nv_gpudirect_clique, uint8_t),
3814 DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_relo,
3815 OFF_AUTO_PCIBAR_OFF),
3819 -#ifdef CONFIG_IOMMUFD
3816 DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd,
3817 TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
3822 -#endif
3818 DEFINE_PROP_BOOL("skip-vsc-check", VFIOPCIDevice, skip_vsc_check, true),
3819 DEFINE_PROP_UINT16("x-vpasid-cap-offset", VFIOPCIDevice,
3820 vpasid_cap_offset, 0),
3821 };
3822
3828 -#ifdef CONFIG_IOMMUFD
3823 static void vfio_pci_set_fd(Object *obj, const char *str, Error **errp)
3824 {
3825 VFIOPCIDevice *vdev = VFIO_PCI_DEVICE(obj);
3826 vfio_device_set_fd(&vdev->vbasedev, str, errp);
3827 }
3834 -#endif
3828
3829 static void vfio_pci_class_init(ObjectClass *klass, const void *data)
3830 {
@@ -3840,9 +3833,7 @@ static void vfio_pci_class_init(ObjectClass *klass, const void *data)
3833
3834 device_class_set_legacy_reset(dc, vfio_pci_reset);
3835 device_class_set_props(dc, vfio_pci_properties);
3843 -#ifdef CONFIG_IOMMUFD
3836 object_class_property_add_str(klass, "fd", NULL, vfio_pci_set_fd);
3845 -#endif
3837 dc->vmsd = &vfio_cpr_pci_vmstate;
3838 dc->desc = "VFIO-based PCI device assignment";
3839 pdc->realize = vfio_pci_realize;
@@ -3944,11 +3935,9 @@ static void vfio_pci_class_init(ObjectClass *klass, const void *data)
3935 "vf-token",
3936 "Specify UUID VF token. Required for VF when PF is owned "
3937 "by another VFIO driver");
3947 -#ifdef CONFIG_IOMMUFD
3938 object_class_property_set_description(klass, /* 9.0 */
3939 "iommufd",
3940 "Set host IOMMUFD backend device");
3951 -#endif
3941 object_class_property_set_description(klass, /* 9.1 */
3942 "x-device-dirty-page-tracking",
3943 "Disable device dirty page tracking and use "