diff mbox series

[v2,05/17] vfio/container: Introduce vfio_address_space_insert()

Message ID 20240617063409.34393-6-clg@redhat.com (mailing list archive)
State New, archived
Headers show
Series vfio: QOMify VFIOContainer | expand

Commit Message

Cédric Le Goater June 17, 2024, 6:33 a.m. UTC
It will ease future changes.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 include/hw/vfio/vfio-common.h | 2 ++
 hw/vfio/common.c              | 6 ++++++
 hw/vfio/container.c           | 2 +-
 hw/vfio/iommufd.c             | 2 +-
 4 files changed, 10 insertions(+), 2 deletions(-)

Comments

Eric Auger June 17, 2024, 2:04 p.m. UTC | #1
On 6/17/24 08:33, Cédric Le Goater wrote:
> It will ease future changes.
Does it, really?

Besides
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>  include/hw/vfio/vfio-common.h | 2 ++
>  hw/vfio/common.c              | 6 ++++++
>  hw/vfio/container.c           | 2 +-
>  hw/vfio/iommufd.c             | 2 +-
>  4 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index c19572f90b277193491020af28e8b5587f15bfd1..825d80130bd435fe50830c8ae5b7905d18104dd6 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -206,6 +206,8 @@ typedef struct VFIODisplay {
>  
>  VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
>  void vfio_put_address_space(VFIOAddressSpace *space);
> +void vfio_address_space_insert(VFIOAddressSpace *space,
> +                               VFIOContainerBase *bcontainer);
>  
>  void vfio_disable_irqindex(VFIODevice *vbasedev, int index);
>  void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index);
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index f28641bad5cf4b71fcdc0a6c9d42b24c8d786248..8cdf26c6f5a490cfa02bdf1087a91948709aaa33 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -1508,6 +1508,12 @@ void vfio_put_address_space(VFIOAddressSpace *space)
>      }
>  }
>  
> +void vfio_address_space_insert(VFIOAddressSpace *space,
> +                               VFIOContainerBase *bcontainer)
> +{
> +    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
> +}
> +
>  struct vfio_device_info *vfio_get_device_info(int fd)
>  {
>      struct vfio_device_info *info;
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index c48749c089a67ee4d0e6b8dd975562e2938500cd..0237c216987ff64a6d11bef8688bb000d93a7f09 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -637,7 +637,7 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
>      vfio_kvm_device_add_group(group);
>  
>      QLIST_INIT(&container->group_list);
> -    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
> +    vfio_address_space_insert(space, bcontainer);
>  
>      group->container = container;
>      QLIST_INSERT_HEAD(&container->group_list, group, container_next);
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index e502081c2ad9eda31769176f875fef60a77e2b43..9f8f33e383a38827ceca0f73cb77f5ca6b123198 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -358,7 +358,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
>  
>      bcontainer = &container->bcontainer;
>      vfio_container_init(bcontainer, space, iommufd_vioc);
> -    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
> +    vfio_address_space_insert(space, bcontainer);
>  
>      if (!iommufd_cdev_attach_container(vbasedev, container, errp)) {
>          goto err_attach_container;
Cédric Le Goater June 18, 2024, 11:27 a.m. UTC | #2
On 6/17/24 4:04 PM, Eric Auger wrote:
> 
> 
> On 6/17/24 08:33, Cédric Le Goater wrote:
>> It will ease future changes.
> Does it, really?

Changed to :

   It prepares gound for a future change initializing the 'space' pointer
   of VFIOContainerBase. The goal is to replace vfio_container_init() by
   an .instance_init() handler when VFIOContainerBase is QOMified.

Thanks,

C.


> 
> Besides
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> 
> Eric
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> ---
>>   include/hw/vfio/vfio-common.h | 2 ++
>>   hw/vfio/common.c              | 6 ++++++
>>   hw/vfio/container.c           | 2 +-
>>   hw/vfio/iommufd.c             | 2 +-
>>   4 files changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>> index c19572f90b277193491020af28e8b5587f15bfd1..825d80130bd435fe50830c8ae5b7905d18104dd6 100644
>> --- a/include/hw/vfio/vfio-common.h
>> +++ b/include/hw/vfio/vfio-common.h
>> @@ -206,6 +206,8 @@ typedef struct VFIODisplay {
>>   
>>   VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
>>   void vfio_put_address_space(VFIOAddressSpace *space);
>> +void vfio_address_space_insert(VFIOAddressSpace *space,
>> +                               VFIOContainerBase *bcontainer);
>>   
>>   void vfio_disable_irqindex(VFIODevice *vbasedev, int index);
>>   void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index);
>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>> index f28641bad5cf4b71fcdc0a6c9d42b24c8d786248..8cdf26c6f5a490cfa02bdf1087a91948709aaa33 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/common.c
>> @@ -1508,6 +1508,12 @@ void vfio_put_address_space(VFIOAddressSpace *space)
>>       }
>>   }
>>   
>> +void vfio_address_space_insert(VFIOAddressSpace *space,
>> +                               VFIOContainerBase *bcontainer)
>> +{
>> +    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
>> +}
>> +
>>   struct vfio_device_info *vfio_get_device_info(int fd)
>>   {
>>       struct vfio_device_info *info;
>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>> index c48749c089a67ee4d0e6b8dd975562e2938500cd..0237c216987ff64a6d11bef8688bb000d93a7f09 100644
>> --- a/hw/vfio/container.c
>> +++ b/hw/vfio/container.c
>> @@ -637,7 +637,7 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
>>       vfio_kvm_device_add_group(group);
>>   
>>       QLIST_INIT(&container->group_list);
>> -    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
>> +    vfio_address_space_insert(space, bcontainer);
>>   
>>       group->container = container;
>>       QLIST_INSERT_HEAD(&container->group_list, group, container_next);
>> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>> index e502081c2ad9eda31769176f875fef60a77e2b43..9f8f33e383a38827ceca0f73cb77f5ca6b123198 100644
>> --- a/hw/vfio/iommufd.c
>> +++ b/hw/vfio/iommufd.c
>> @@ -358,7 +358,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
>>   
>>       bcontainer = &container->bcontainer;
>>       vfio_container_init(bcontainer, space, iommufd_vioc);
>> -    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
>> +    vfio_address_space_insert(space, bcontainer);
>>   
>>       if (!iommufd_cdev_attach_container(vbasedev, container, errp)) {
>>           goto err_attach_container;
>
diff mbox series

Patch

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index c19572f90b277193491020af28e8b5587f15bfd1..825d80130bd435fe50830c8ae5b7905d18104dd6 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -206,6 +206,8 @@  typedef struct VFIODisplay {
 
 VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
 void vfio_put_address_space(VFIOAddressSpace *space);
+void vfio_address_space_insert(VFIOAddressSpace *space,
+                               VFIOContainerBase *bcontainer);
 
 void vfio_disable_irqindex(VFIODevice *vbasedev, int index);
 void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index);
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index f28641bad5cf4b71fcdc0a6c9d42b24c8d786248..8cdf26c6f5a490cfa02bdf1087a91948709aaa33 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1508,6 +1508,12 @@  void vfio_put_address_space(VFIOAddressSpace *space)
     }
 }
 
+void vfio_address_space_insert(VFIOAddressSpace *space,
+                               VFIOContainerBase *bcontainer)
+{
+    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
+}
+
 struct vfio_device_info *vfio_get_device_info(int fd)
 {
     struct vfio_device_info *info;
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index c48749c089a67ee4d0e6b8dd975562e2938500cd..0237c216987ff64a6d11bef8688bb000d93a7f09 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -637,7 +637,7 @@  static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
     vfio_kvm_device_add_group(group);
 
     QLIST_INIT(&container->group_list);
-    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
+    vfio_address_space_insert(space, bcontainer);
 
     group->container = container;
     QLIST_INSERT_HEAD(&container->group_list, group, container_next);
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index e502081c2ad9eda31769176f875fef60a77e2b43..9f8f33e383a38827ceca0f73cb77f5ca6b123198 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -358,7 +358,7 @@  static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
 
     bcontainer = &container->bcontainer;
     vfio_container_init(bcontainer, space, iommufd_vioc);
-    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
+    vfio_address_space_insert(space, bcontainer);
 
     if (!iommufd_cdev_attach_container(vbasedev, container, errp)) {
         goto err_attach_container;