diff mbox series

[14/14] hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using iommufd_builtin

Message ID 20250307180337.14811-15-philmd@linaro.org
State New
Headers show
Series hw/vfio: Build various objects once | expand

Commit Message

Philippe Mathieu-Daudé March 7, 2025, 6:03 p.m. UTC
Convert the compile time check on the CONFIG_IOMMUFD definition
by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore,
move it to system_ss[] to build it once.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/vfio/platform.c  | 25 ++++++++++++-------------
 hw/vfio/meson.build |  2 +-
 2 files changed, 13 insertions(+), 14 deletions(-)

Comments

Pierrick Bouvier March 7, 2025, 7:20 p.m. UTC | #1
On 3/7/25 10:03, Philippe Mathieu-Daudé wrote:
> Convert the compile time check on the CONFIG_IOMMUFD definition
> by a runtime one by calling iommufd_builtin().
> 
> Since the file doesn't use any target-specific knowledge anymore,
> move it to system_ss[] to build it once.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/vfio/platform.c  | 25 ++++++++++++-------------
>   hw/vfio/meson.build |  2 +-
>   2 files changed, 13 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
> index 67bc57409c1..265c550b747 100644
> --- a/hw/vfio/platform.c
> +++ b/hw/vfio/platform.c
> @@ -15,7 +15,6 @@
>    */
>   
>   #include "qemu/osdep.h"
> -#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
>   #include "qapi/error.h"
>   #include <sys/ioctl.h>
>   #include <linux/vfio.h>
> @@ -637,10 +636,11 @@ static const Property vfio_platform_dev_properties[] = {
>       DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice,
>                          mmap_timeout, 1100),
>       DEFINE_PROP_BOOL("x-irqfd", VFIOPlatformDevice, irqfd_allowed, true),
> -#ifdef CONFIG_IOMMUFD
> +};
> +
> +static const Property vfio_platform_dev_iommufd_properties[] = {
>       DEFINE_PROP_LINK("iommufd", VFIOPlatformDevice, vbasedev.iommufd,
>                        TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
> -#endif
>   };
>   
>   static void vfio_platform_instance_init(Object *obj)
> @@ -652,12 +652,10 @@ static void vfio_platform_instance_init(Object *obj)
>                        DEVICE(vdev), false);
>   }
>   
> -#ifdef CONFIG_IOMMUFD
>   static void vfio_platform_set_fd(Object *obj, const char *str, Error **errp)
>   {
>       vfio_device_set_fd(&VFIO_PLATFORM_DEVICE(obj)->vbasedev, str, errp);
>   }
> -#endif
>   
>   static void vfio_platform_class_init(ObjectClass *klass, void *data)
>   {
> @@ -666,9 +664,10 @@ static void vfio_platform_class_init(ObjectClass *klass, void *data)
>   
>       dc->realize = vfio_platform_realize;
>       device_class_set_props(dc, vfio_platform_dev_properties);
> -#ifdef CONFIG_IOMMUFD
> -    object_class_property_add_str(klass, "fd", NULL, vfio_platform_set_fd);
> -#endif
> +    if (iommufd_builtin()) {
> +        device_class_set_props(dc, vfio_platform_dev_iommufd_properties);
> +        object_class_property_add_str(klass, "fd", NULL, vfio_platform_set_fd);
> +    }
>       dc->vmsd = &vfio_platform_vmstate;
>       dc->desc = "VFIO-based platform device assignment";
>       sbc->connect_irq_notifier = vfio_start_irqfd_injection;
> @@ -692,11 +691,11 @@ static void vfio_platform_class_init(ObjectClass *klass, void *data)
>       object_class_property_set_description(klass, /* 2.6 */
>                                             "sysfsdev",
>                                             "Host sysfs path of assigned device");
> -#ifdef CONFIG_IOMMUFD
> -    object_class_property_set_description(klass, /* 9.0 */
> -                                          "iommufd",
> -                                          "Set host IOMMUFD backend device");
> -#endif
> +    if (iommufd_builtin()) {
> +        object_class_property_set_description(klass, /* 9.0 */
> +                                              "iommufd",
> +                                              "Set host IOMMUFD backend device");
> +    }
>   }
>   
>   static const TypeInfo vfio_platform_dev_info = {
> diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
> index bd6e1d999e4..e5010db2c71 100644
> --- a/hw/vfio/meson.build
> +++ b/hw/vfio/meson.build
> @@ -7,7 +7,6 @@ vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
>   vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
>     'pci-quirks.c',
>   ))
> -vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
>   
>   specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
>   
> @@ -26,6 +25,7 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
>   ))
>   system_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
>   system_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
> +system_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
>   system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
>     'display.c',
>     'pci.c',

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Richard Henderson March 7, 2025, 8:48 p.m. UTC | #2
On 3/7/25 10:03, Philippe Mathieu-Daudé wrote:
> Convert the compile time check on the CONFIG_IOMMUFD definition
> by a runtime one by calling iommufd_builtin().
> 
> Since the file doesn't use any target-specific knowledge anymore,
> move it to system_ss[] to build it once.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/vfio/platform.c  | 25 ++++++++++++-------------
>   hw/vfio/meson.build |  2 +-
>   2 files changed, 13 insertions(+), 14 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 67bc57409c1..265c550b747 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -15,7 +15,6 @@ 
  */
 
 #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
 #include "qapi/error.h"
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
@@ -637,10 +636,11 @@  static const Property vfio_platform_dev_properties[] = {
     DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice,
                        mmap_timeout, 1100),
     DEFINE_PROP_BOOL("x-irqfd", VFIOPlatformDevice, irqfd_allowed, true),
-#ifdef CONFIG_IOMMUFD
+};
+
+static const Property vfio_platform_dev_iommufd_properties[] = {
     DEFINE_PROP_LINK("iommufd", VFIOPlatformDevice, vbasedev.iommufd,
                      TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
-#endif
 };
 
 static void vfio_platform_instance_init(Object *obj)
@@ -652,12 +652,10 @@  static void vfio_platform_instance_init(Object *obj)
                      DEVICE(vdev), false);
 }
 
-#ifdef CONFIG_IOMMUFD
 static void vfio_platform_set_fd(Object *obj, const char *str, Error **errp)
 {
     vfio_device_set_fd(&VFIO_PLATFORM_DEVICE(obj)->vbasedev, str, errp);
 }
-#endif
 
 static void vfio_platform_class_init(ObjectClass *klass, void *data)
 {
@@ -666,9 +664,10 @@  static void vfio_platform_class_init(ObjectClass *klass, void *data)
 
     dc->realize = vfio_platform_realize;
     device_class_set_props(dc, vfio_platform_dev_properties);
-#ifdef CONFIG_IOMMUFD
-    object_class_property_add_str(klass, "fd", NULL, vfio_platform_set_fd);
-#endif
+    if (iommufd_builtin()) {
+        device_class_set_props(dc, vfio_platform_dev_iommufd_properties);
+        object_class_property_add_str(klass, "fd", NULL, vfio_platform_set_fd);
+    }
     dc->vmsd = &vfio_platform_vmstate;
     dc->desc = "VFIO-based platform device assignment";
     sbc->connect_irq_notifier = vfio_start_irqfd_injection;
@@ -692,11 +691,11 @@  static void vfio_platform_class_init(ObjectClass *klass, void *data)
     object_class_property_set_description(klass, /* 2.6 */
                                           "sysfsdev",
                                           "Host sysfs path of assigned device");
-#ifdef CONFIG_IOMMUFD
-    object_class_property_set_description(klass, /* 9.0 */
-                                          "iommufd",
-                                          "Set host IOMMUFD backend device");
-#endif
+    if (iommufd_builtin()) {
+        object_class_property_set_description(klass, /* 9.0 */
+                                              "iommufd",
+                                              "Set host IOMMUFD backend device");
+    }
 }
 
 static const TypeInfo vfio_platform_dev_info = {
diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
index bd6e1d999e4..e5010db2c71 100644
--- a/hw/vfio/meson.build
+++ b/hw/vfio/meson.build
@@ -7,7 +7,6 @@  vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'pci-quirks.c',
 ))
-vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
 
 specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
 
@@ -26,6 +25,7 @@  system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
 ))
 system_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
 system_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
+system_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
 system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'display.c',
   'pci.c',