diff mbox series

[v1,11/16] vfio/container: Change VFIOContainerBase to use QOM

Message ID 20240612130122.813935-12-clg@redhat.com
State New
Headers show
Series vfio: QOMify VFIOContainer | expand

Commit Message

Cédric Le Goater June 12, 2024, 1:01 p.m. UTC
VFIOContainerBase was made a QOM interface because we believed that a
QOM object would expose all the IOMMU backends to the QEMU machine and
human interface. This only applies to user creatable devices or objects.

Change the VFIOContainerBase nature from interface to object and make
the necessary adjustments in the VFIO_IOMMU hierarchy.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h         |  4 ++++
 include/hw/vfio/vfio-container-base.h | 12 +++---------
 hw/vfio/container-base.c              |  4 +++-
 hw/vfio/container.c                   |  1 +
 hw/vfio/iommufd.c                     |  1 +
 hw/vfio/spapr.c                       |  3 +++
 6 files changed, 15 insertions(+), 10 deletions(-)

Comments

Duan, Zhenzhong June 13, 2024, 9:17 a.m. UTC | #1
Hi Cédric,

>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: [PATCH v1 11/16] vfio/container: Change VFIOContainerBase to use
>QOM
>
>VFIOContainerBase was made a QOM interface because we believed that a
>QOM object would expose all the IOMMU backends to the QEMU machine
>and
>human interface. This only applies to user creatable devices or objects.
>
>Change the VFIOContainerBase nature from interface to object and make
>the necessary adjustments in the VFIO_IOMMU hierarchy.
>
>Signed-off-by: Cédric Le Goater <clg@redhat.com>
>---
> include/hw/vfio/vfio-common.h         |  4 ++++
> include/hw/vfio/vfio-container-base.h | 12 +++---------
> hw/vfio/container-base.c              |  4 +++-
> hw/vfio/container.c                   |  1 +
> hw/vfio/iommufd.c                     |  1 +
> hw/vfio/spapr.c                       |  3 +++
> 6 files changed, 15 insertions(+), 10 deletions(-)
>
>diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-
>common.h
>index
>825d80130bd435fe50830c8ae5b7905d18104dd6..5d0b8496cf85bac8d4ea
>770fae04acc02d84df82 100644
>--- a/include/hw/vfio/vfio-common.h
>+++ b/include/hw/vfio/vfio-common.h
>@@ -84,6 +84,8 @@ typedef struct VFIOContainer {
>     QLIST_HEAD(, VFIOGroup) group_list;
> } VFIOContainer;
>
>+OBJECT_DECLARE_TYPE(VFIOContainer, VFIOIOMMUClass,
>VFIO_IOMMU_LEGACY);

What about using OBJECT_DECLARE_SIMPLE_TYPE?

>+
> typedef struct VFIOHostDMAWindow {
>     hwaddr min_iova;
>     hwaddr max_iova;
>@@ -99,6 +101,8 @@ typedef struct VFIOIOMMUFDContainer {
>     uint32_t ioas_id;
> } VFIOIOMMUFDContainer;
>
>+OBJECT_DECLARE_TYPE(VFIOIOMMUFDContainer, VFIOIOMMUClass,
>VFIO_IOMMU_IOMMUFD);

Same here.

>+
> typedef struct VFIODeviceOps VFIODeviceOps;
>
> typedef struct VFIODevice {
>diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-
>container-base.h
>index
>d505f63607ec40e6aa44aeb3e20848ac780562a1..b079b76f68975c5701a28
>9ce9012e912a8e44fc6 100644
>--- a/include/hw/vfio/vfio-container-base.h
>+++ b/include/hw/vfio/vfio-container-base.h
>@@ -34,6 +34,7 @@ typedef struct VFIOAddressSpace {
>  * This is the base object for vfio container backends
>  */
> typedef struct VFIOContainerBase {
>+    Object parent;
>     const VFIOIOMMUClass *ops;
>     VFIOAddressSpace *space;
>     MemoryListener listener;
>@@ -96,17 +97,10 @@ void vfio_container_destroy(VFIOContainerBase
>*bcontainer);
> #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr"
> #define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd"
>
>-/*
>- * VFIOContainerBase is not an abstract QOM object because it felt
>- * unnecessary to expose all the IOMMU backends to the QEMU machine
>- * and human interface. However, we can still abstract the IOMMU
>- * backend handlers using a QOM interface class. This provides more
>- * flexibility when referencing the various implementations.
>- */
>-DECLARE_CLASS_CHECKERS(VFIOIOMMUClass, VFIO_IOMMU,
>TYPE_VFIO_IOMMU)
>+OBJECT_DECLARE_TYPE(VFIOContainerBase, VFIOIOMMUClass,
>VFIO_IOMMU)
>
> struct VFIOIOMMUClass {
>-    InterfaceClass parent_class;
>+    ObjectClass parent_class;
>
>     /* Properties */
>     const char *hiod_typename;
>diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
>index
>280f0dd2db1fc3939fe9925ce00a2c50d0e14196..98c15e174dd78df5146ee8
>3c05c98f3ea9c1e52c 100644
>--- a/hw/vfio/container-base.c
>+++ b/hw/vfio/container-base.c
>@@ -102,8 +102,10 @@ void vfio_container_destroy(VFIOContainerBase
>*bcontainer)
> static const TypeInfo types[] = {
>     {
>         .name = TYPE_VFIO_IOMMU,
>-        .parent = TYPE_INTERFACE,
>+        .parent = TYPE_OBJECT,
>+        .instance_size = sizeof(VFIOContainerBase),
>         .class_size = sizeof(VFIOIOMMUClass),
>+        .abstract = true,
>     },
> };
>
>diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>index
>983726f9514ec1106d521c9711a46a4780688ee1..f1519518d0b7efd2a6086
>f07bc497596a5236abf 100644
>--- a/hw/vfio/container.c
>+++ b/hw/vfio/container.c
>@@ -1194,6 +1194,7 @@ static const TypeInfo types[] = {
>     {
>         .name = TYPE_VFIO_IOMMU_LEGACY,
>         .parent = TYPE_VFIO_IOMMU,
>+        .instance_size = sizeof(VFIOContainer),
>         .class_init = vfio_iommu_legacy_class_init,
>     }, {
>         .name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO,
>diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>index
>d97a4f7393791660b90e340436c6e084c0781444..80ba09b859a02bb89823
>460064a9f099fd98cff0 100644
>--- a/hw/vfio/iommufd.c
>+++ b/hw/vfio/iommufd.c
>@@ -670,6 +670,7 @@ static const TypeInfo types[] = {
>     {
>         .name = TYPE_VFIO_IOMMU_IOMMUFD,
>         .parent = TYPE_VFIO_IOMMU,
>+        .instance_size = sizeof(VFIOIOMMUFDContainer),
>         .class_init = vfio_iommu_iommufd_class_init,
>     }, {
>         .name = TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO,
>diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
>index
>47b040f1bcca7dd0b5cf052d941b43541e98a3c5..05a3cedc4b1703a615737
>30bc77fc15d44f7a9eb 100644
>--- a/hw/vfio/spapr.c
>+++ b/hw/vfio/spapr.c
>@@ -30,6 +30,8 @@ typedef struct VFIOSpaprContainer {
>     QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list;
> } VFIOSpaprContainer;
>
>+OBJECT_DECLARE_TYPE(VFIOSpaprContainer, VFIOIOMMUClass,
>VFIO_IOMMU_SPAPR);

Same here.

Thanks
Zhenzhong

>+
> static bool vfio_prereg_listener_skipped_section(MemoryRegionSection
>*section)
> {
>     if (memory_region_is_iommu(section->mr)) {
>@@ -548,6 +550,7 @@ static const TypeInfo types[] = {
>     {
>         .name = TYPE_VFIO_IOMMU_SPAPR,
>         .parent = TYPE_VFIO_IOMMU_LEGACY,
>+        .instance_size = sizeof(VFIOSpaprContainer),
>         .class_init = vfio_iommu_spapr_class_init,
>     },
> };
>--
>2.45.2
Cédric Le Goater June 13, 2024, 12:21 p.m. UTC | #2
On 6/13/24 11:17 AM, Duan, Zhenzhong wrote:
> Hi Cédric,
> 
>> -----Original Message-----
>> From: Cédric Le Goater <clg@redhat.com>
>> Subject: [PATCH v1 11/16] vfio/container: Change VFIOContainerBase to use
>> QOM
>>
>> VFIOContainerBase was made a QOM interface because we believed that a
>> QOM object would expose all the IOMMU backends to the QEMU machine
>> and
>> human interface. This only applies to user creatable devices or objects.
>>
>> Change the VFIOContainerBase nature from interface to object and make
>> the necessary adjustments in the VFIO_IOMMU hierarchy.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>> include/hw/vfio/vfio-common.h         |  4 ++++
>> include/hw/vfio/vfio-container-base.h | 12 +++---------
>> hw/vfio/container-base.c              |  4 +++-
>> hw/vfio/container.c                   |  1 +
>> hw/vfio/iommufd.c                     |  1 +
>> hw/vfio/spapr.c                       |  3 +++
>> 6 files changed, 15 insertions(+), 10 deletions(-)
>>
>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-
>> common.h
>> index
>> 825d80130bd435fe50830c8ae5b7905d18104dd6..5d0b8496cf85bac8d4ea
>> 770fae04acc02d84df82 100644
>> --- a/include/hw/vfio/vfio-common.h
>> +++ b/include/hw/vfio/vfio-common.h
>> @@ -84,6 +84,8 @@ typedef struct VFIOContainer {
>>      QLIST_HEAD(, VFIOGroup) group_list;
>> } VFIOContainer;
>>
>> +OBJECT_DECLARE_TYPE(VFIOContainer, VFIOIOMMUClass,
>> VFIO_IOMMU_LEGACY);
> 
> What about using OBJECT_DECLARE_SIMPLE_TYPE?

Sure. Will change.

Thanks,

C.


> 
>> +
>> typedef struct VFIOHostDMAWindow {
>>      hwaddr min_iova;
>>      hwaddr max_iova;
>> @@ -99,6 +101,8 @@ typedef struct VFIOIOMMUFDContainer {
>>      uint32_t ioas_id;
>> } VFIOIOMMUFDContainer;
>>
>> +OBJECT_DECLARE_TYPE(VFIOIOMMUFDContainer, VFIOIOMMUClass,
>> VFIO_IOMMU_IOMMUFD);
> 
> Same here.
> 
>> +
>> typedef struct VFIODeviceOps VFIODeviceOps;
>>
>> typedef struct VFIODevice {
>> diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-
>> container-base.h
>> index
>> d505f63607ec40e6aa44aeb3e20848ac780562a1..b079b76f68975c5701a28
>> 9ce9012e912a8e44fc6 100644
>> --- a/include/hw/vfio/vfio-container-base.h
>> +++ b/include/hw/vfio/vfio-container-base.h
>> @@ -34,6 +34,7 @@ typedef struct VFIOAddressSpace {
>>   * This is the base object for vfio container backends
>>   */
>> typedef struct VFIOContainerBase {
>> +    Object parent;
>>      const VFIOIOMMUClass *ops;
>>      VFIOAddressSpace *space;
>>      MemoryListener listener;
>> @@ -96,17 +97,10 @@ void vfio_container_destroy(VFIOContainerBase
>> *bcontainer);
>> #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr"
>> #define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd"
>>
>> -/*
>> - * VFIOContainerBase is not an abstract QOM object because it felt
>> - * unnecessary to expose all the IOMMU backends to the QEMU machine
>> - * and human interface. However, we can still abstract the IOMMU
>> - * backend handlers using a QOM interface class. This provides more
>> - * flexibility when referencing the various implementations.
>> - */
>> -DECLARE_CLASS_CHECKERS(VFIOIOMMUClass, VFIO_IOMMU,
>> TYPE_VFIO_IOMMU)
>> +OBJECT_DECLARE_TYPE(VFIOContainerBase, VFIOIOMMUClass,
>> VFIO_IOMMU)
>>
>> struct VFIOIOMMUClass {
>> -    InterfaceClass parent_class;
>> +    ObjectClass parent_class;
>>
>>      /* Properties */
>>      const char *hiod_typename;
>> diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
>> index
>> 280f0dd2db1fc3939fe9925ce00a2c50d0e14196..98c15e174dd78df5146ee8
>> 3c05c98f3ea9c1e52c 100644
>> --- a/hw/vfio/container-base.c
>> +++ b/hw/vfio/container-base.c
>> @@ -102,8 +102,10 @@ void vfio_container_destroy(VFIOContainerBase
>> *bcontainer)
>> static const TypeInfo types[] = {
>>      {
>>          .name = TYPE_VFIO_IOMMU,
>> -        .parent = TYPE_INTERFACE,
>> +        .parent = TYPE_OBJECT,
>> +        .instance_size = sizeof(VFIOContainerBase),
>>          .class_size = sizeof(VFIOIOMMUClass),
>> +        .abstract = true,
>>      },
>> };
>>
>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>> index
>> 983726f9514ec1106d521c9711a46a4780688ee1..f1519518d0b7efd2a6086
>> f07bc497596a5236abf 100644
>> --- a/hw/vfio/container.c
>> +++ b/hw/vfio/container.c
>> @@ -1194,6 +1194,7 @@ static const TypeInfo types[] = {
>>      {
>>          .name = TYPE_VFIO_IOMMU_LEGACY,
>>          .parent = TYPE_VFIO_IOMMU,
>> +        .instance_size = sizeof(VFIOContainer),
>>          .class_init = vfio_iommu_legacy_class_init,
>>      }, {
>>          .name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO,
>> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>> index
>> d97a4f7393791660b90e340436c6e084c0781444..80ba09b859a02bb89823
>> 460064a9f099fd98cff0 100644
>> --- a/hw/vfio/iommufd.c
>> +++ b/hw/vfio/iommufd.c
>> @@ -670,6 +670,7 @@ static const TypeInfo types[] = {
>>      {
>>          .name = TYPE_VFIO_IOMMU_IOMMUFD,
>>          .parent = TYPE_VFIO_IOMMU,
>> +        .instance_size = sizeof(VFIOIOMMUFDContainer),
>>          .class_init = vfio_iommu_iommufd_class_init,
>>      }, {
>>          .name = TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO,
>> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
>> index
>> 47b040f1bcca7dd0b5cf052d941b43541e98a3c5..05a3cedc4b1703a615737
>> 30bc77fc15d44f7a9eb 100644
>> --- a/hw/vfio/spapr.c
>> +++ b/hw/vfio/spapr.c
>> @@ -30,6 +30,8 @@ typedef struct VFIOSpaprContainer {
>>      QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list;
>> } VFIOSpaprContainer;
>>
>> +OBJECT_DECLARE_TYPE(VFIOSpaprContainer, VFIOIOMMUClass,
>> VFIO_IOMMU_SPAPR);
>
> Same here.
> 
> Thanks
> Zhenzhong
> 
>> +
>> static bool vfio_prereg_listener_skipped_section(MemoryRegionSection
>> *section)
>> {
>>      if (memory_region_is_iommu(section->mr)) {
>> @@ -548,6 +550,7 @@ static const TypeInfo types[] = {
>>      {
>>          .name = TYPE_VFIO_IOMMU_SPAPR,
>>          .parent = TYPE_VFIO_IOMMU_LEGACY,
>> +        .instance_size = sizeof(VFIOSpaprContainer),
>>          .class_init = vfio_iommu_spapr_class_init,
>>      },
>> };
>> --
>> 2.45.2
>
diff mbox series

Patch

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 825d80130bd435fe50830c8ae5b7905d18104dd6..5d0b8496cf85bac8d4ea770fae04acc02d84df82 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -84,6 +84,8 @@  typedef struct VFIOContainer {
     QLIST_HEAD(, VFIOGroup) group_list;
 } VFIOContainer;
 
+OBJECT_DECLARE_TYPE(VFIOContainer, VFIOIOMMUClass, VFIO_IOMMU_LEGACY);
+
 typedef struct VFIOHostDMAWindow {
     hwaddr min_iova;
     hwaddr max_iova;
@@ -99,6 +101,8 @@  typedef struct VFIOIOMMUFDContainer {
     uint32_t ioas_id;
 } VFIOIOMMUFDContainer;
 
+OBJECT_DECLARE_TYPE(VFIOIOMMUFDContainer, VFIOIOMMUClass, VFIO_IOMMU_IOMMUFD);
+
 typedef struct VFIODeviceOps VFIODeviceOps;
 
 typedef struct VFIODevice {
diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
index d505f63607ec40e6aa44aeb3e20848ac780562a1..b079b76f68975c5701a289ce9012e912a8e44fc6 100644
--- a/include/hw/vfio/vfio-container-base.h
+++ b/include/hw/vfio/vfio-container-base.h
@@ -34,6 +34,7 @@  typedef struct VFIOAddressSpace {
  * This is the base object for vfio container backends
  */
 typedef struct VFIOContainerBase {
+    Object parent;
     const VFIOIOMMUClass *ops;
     VFIOAddressSpace *space;
     MemoryListener listener;
@@ -96,17 +97,10 @@  void vfio_container_destroy(VFIOContainerBase *bcontainer);
 #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr"
 #define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd"
 
-/*
- * VFIOContainerBase is not an abstract QOM object because it felt
- * unnecessary to expose all the IOMMU backends to the QEMU machine
- * and human interface. However, we can still abstract the IOMMU
- * backend handlers using a QOM interface class. This provides more
- * flexibility when referencing the various implementations.
- */
-DECLARE_CLASS_CHECKERS(VFIOIOMMUClass, VFIO_IOMMU, TYPE_VFIO_IOMMU)
+OBJECT_DECLARE_TYPE(VFIOContainerBase, VFIOIOMMUClass, VFIO_IOMMU)
 
 struct VFIOIOMMUClass {
-    InterfaceClass parent_class;
+    ObjectClass parent_class;
 
     /* Properties */
     const char *hiod_typename;
diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
index 280f0dd2db1fc3939fe9925ce00a2c50d0e14196..98c15e174dd78df5146ee83c05c98f3ea9c1e52c 100644
--- a/hw/vfio/container-base.c
+++ b/hw/vfio/container-base.c
@@ -102,8 +102,10 @@  void vfio_container_destroy(VFIOContainerBase *bcontainer)
 static const TypeInfo types[] = {
     {
         .name = TYPE_VFIO_IOMMU,
-        .parent = TYPE_INTERFACE,
+        .parent = TYPE_OBJECT,
+        .instance_size = sizeof(VFIOContainerBase),
         .class_size = sizeof(VFIOIOMMUClass),
+        .abstract = true,
     },
 };
 
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 983726f9514ec1106d521c9711a46a4780688ee1..f1519518d0b7efd2a6086f07bc497596a5236abf 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -1194,6 +1194,7 @@  static const TypeInfo types[] = {
     {
         .name = TYPE_VFIO_IOMMU_LEGACY,
         .parent = TYPE_VFIO_IOMMU,
+        .instance_size = sizeof(VFIOContainer),
         .class_init = vfio_iommu_legacy_class_init,
     }, {
         .name = TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO,
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index d97a4f7393791660b90e340436c6e084c0781444..80ba09b859a02bb89823460064a9f099fd98cff0 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -670,6 +670,7 @@  static const TypeInfo types[] = {
     {
         .name = TYPE_VFIO_IOMMU_IOMMUFD,
         .parent = TYPE_VFIO_IOMMU,
+        .instance_size = sizeof(VFIOIOMMUFDContainer),
         .class_init = vfio_iommu_iommufd_class_init,
     }, {
         .name = TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO,
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
index 47b040f1bcca7dd0b5cf052d941b43541e98a3c5..05a3cedc4b1703a61573730bc77fc15d44f7a9eb 100644
--- a/hw/vfio/spapr.c
+++ b/hw/vfio/spapr.c
@@ -30,6 +30,8 @@  typedef struct VFIOSpaprContainer {
     QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list;
 } VFIOSpaprContainer;
 
+OBJECT_DECLARE_TYPE(VFIOSpaprContainer, VFIOIOMMUClass, VFIO_IOMMU_SPAPR);
+
 static bool vfio_prereg_listener_skipped_section(MemoryRegionSection *section)
 {
     if (memory_region_is_iommu(section->mr)) {
@@ -548,6 +550,7 @@  static const TypeInfo types[] = {
     {
         .name = TYPE_VFIO_IOMMU_SPAPR,
         .parent = TYPE_VFIO_IOMMU_LEGACY,
+        .instance_size = sizeof(VFIOSpaprContainer),
         .class_init = vfio_iommu_spapr_class_init,
     },
 };