[PATCH 09/22] vfio/container.c: use QOM casts where appropriate

Mark Cave-Ayland posted 22 patches 4 months ago
Maintainers: Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Richard Henderson <richard.henderson@linaro.org>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, John Levon <john.levon@nutanix.com>, Thanos Makatos <thanos.makatos@nutanix.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Steve Sistare <steven.sistare@oracle.com>, Tomita Moeko <tomitamoeko@gmail.com>
[PATCH 09/22] vfio/container.c: use QOM casts where appropriate
Posted by Mark Cave-Ayland 4 months ago
Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
of accessing bcontainer directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio-user/container.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c
index d318e6a339..025db93ff3 100644
--- a/hw/vfio-user/container.c
+++ b/hw/vfio-user/container.c
@@ -24,16 +24,14 @@
  */
 static void vfio_user_listener_begin(VFIOContainerBase *bcontainer)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                                 bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
 
     container->proxy->async_ops = true;
 }
 
 static void vfio_user_listener_commit(VFIOContainerBase *bcontainer)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                            bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
 
     /* wait here for any async requests sent during the transaction */
     container->proxy->async_ops = false;
@@ -44,8 +42,8 @@ static int vfio_user_dma_unmap(const VFIOContainerBase *bcontainer,
                                hwaddr iova, ram_addr_t size,
                                IOMMUTLBEntry *iotlb, bool unmap_all)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                            bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
+
     Error *local_err = NULL;
     int ret = 0;
 
@@ -88,8 +86,8 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                              ram_addr_t size, void *vaddr, bool readonly,
                              MemoryRegion *mrp)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                                bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
+
     int fd = memory_region_get_fd(mrp);
     Error *local_err = NULL;
     int ret;
@@ -177,8 +175,7 @@ static int vfio_user_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
 
 static bool vfio_user_setup(VFIOContainerBase *bcontainer, Error **errp)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                                bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
 
     assert(container->proxy->dma_pgsizes != 0);
     bcontainer->pgsizes = container->proxy->dma_pgsizes;
@@ -222,7 +219,7 @@ vfio_user_container_connect(AddressSpace *as, VFIODevice *vbasedev,
         goto put_space_exit;
     }
 
-    bcontainer = &container->bcontainer;
+    bcontainer = VFIO_IOMMU(container);
 
     ret = ram_block_uncoordinated_discard_disable(true);
     if (ret) {
@@ -267,7 +264,7 @@ put_space_exit:
 
 static void vfio_user_container_disconnect(VFIOUserContainer *container)
 {
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
     VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
     VFIOAddressSpace *space = bcontainer->space;
 
@@ -295,7 +292,7 @@ static bool vfio_user_device_get(VFIOUserContainer *container,
 
     vbasedev->fd = -1;
 
-    vfio_device_prepare(vbasedev, &container->bcontainer, &info);
+    vfio_device_prepare(vbasedev, VFIO_IOMMU(container), &info);
 
     return true;
 }
@@ -319,8 +316,7 @@ static bool vfio_user_device_attach(const char *name, VFIODevice *vbasedev,
 
 static void vfio_user_device_detach(VFIODevice *vbasedev)
 {
-    VFIOUserContainer *container = container_of(vbasedev->bcontainer,
-                                                VFIOUserContainer, bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(vbasedev->bcontainer);
 
     vfio_device_unprepare(vbasedev);
 
-- 
2.43.0
Re: [PATCH 09/22] vfio/container.c: use QOM casts where appropriate
Posted by Cédric Le Goater 3 months ago
On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio-user/container.c | 26 +++++++++++---------------
>   1 file changed, 11 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c
> index d318e6a339..025db93ff3 100644
> --- a/hw/vfio-user/container.c
> +++ b/hw/vfio-user/container.c
> @@ -24,16 +24,14 @@
>    */
>   static void vfio_user_listener_begin(VFIOContainerBase *bcontainer)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                                 bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
>   
>       container->proxy->async_ops = true;
>   }
>   
>   static void vfio_user_listener_commit(VFIOContainerBase *bcontainer)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                            bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
>   
>       /* wait here for any async requests sent during the transaction */
>       container->proxy->async_ops = false;
> @@ -44,8 +42,8 @@ static int vfio_user_dma_unmap(const VFIOContainerBase *bcontainer,
>                                  hwaddr iova, ram_addr_t size,
>                                  IOMMUTLBEntry *iotlb, bool unmap_all)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                            bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
> +
>       Error *local_err = NULL;
>       int ret = 0;
>   
> @@ -88,8 +86,8 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
>                                ram_addr_t size, void *vaddr, bool readonly,
>                                MemoryRegion *mrp)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                                bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
> +
>       int fd = memory_region_get_fd(mrp);
>       Error *local_err = NULL;
>       int ret;
> @@ -177,8 +175,7 @@ static int vfio_user_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>   
>   static bool vfio_user_setup(VFIOContainerBase *bcontainer, Error **errp)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                                bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
>   
>       assert(container->proxy->dma_pgsizes != 0);
>       bcontainer->pgsizes = container->proxy->dma_pgsizes;
> @@ -222,7 +219,7 @@ vfio_user_container_connect(AddressSpace *as, VFIODevice *vbasedev,
>           goto put_space_exit;
>       }
>   
> -    bcontainer = &container->bcontainer;
> +    bcontainer = VFIO_IOMMU(container);
>   
>       ret = ram_block_uncoordinated_discard_disable(true);
>       if (ret) {
> @@ -267,7 +264,7 @@ put_space_exit:
>   
>   static void vfio_user_container_disconnect(VFIOUserContainer *container)
>   {
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
>       VFIOAddressSpace *space = bcontainer->space;
>   
> @@ -295,7 +292,7 @@ static bool vfio_user_device_get(VFIOUserContainer *container,
>   
>       vbasedev->fd = -1;
>   
> -    vfio_device_prepare(vbasedev, &container->bcontainer, &info);
> +    vfio_device_prepare(vbasedev, VFIO_IOMMU(container), &info);
>   
>       return true;
>   }
> @@ -319,8 +316,7 @@ static bool vfio_user_device_attach(const char *name, VFIODevice *vbasedev,
>   
>   static void vfio_user_device_detach(VFIODevice *vbasedev)
>   {
> -    VFIOUserContainer *container = container_of(vbasedev->bcontainer,
> -                                                VFIOUserContainer, bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(vbasedev->bcontainer);
>   
>       vfio_device_unprepare(vbasedev);
>   


Re: [PATCH 09/22] vfio/container.c: use QOM casts where appropriate
Posted by John Levon 4 months ago
On Tue, Jul 15, 2025 at 10:25:49AM +0100, Mark Cave-Ayland wrote:

> Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>

Patch subject should be  "vfio-user/container.c" not vfio/container.c

regards
john
Re: [PATCH 09/22] vfio/container.c: use QOM casts where appropriate
Posted by Mark Cave-Ayland 2 months, 2 weeks ago
On 15/07/2025 15:13, John Levon wrote:

> On Tue, Jul 15, 2025 at 10:25:49AM +0100, Mark Cave-Ayland wrote:
> 
>> Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
>> of accessing bcontainer directly.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> 
> Patch subject should be  "vfio-user/container.c" not vfio/container.c
> 
> regards
> john

Ooops yes, I can easily fix that in v2. With that fixed, are you happy 
to give a SoB tag?


ATB,

Mark.
Re: [PATCH 09/22] vfio/container.c: use QOM casts where appropriate
Posted by John Levon 2 months, 2 weeks ago
On Thu, Aug 28, 2025 at 04:14:06PM +0100, Mark Cave-Ayland wrote:

> On 15/07/2025 15:13, John Levon wrote:
> 
> > On Tue, Jul 15, 2025 at 10:25:49AM +0100, Mark Cave-Ayland wrote:
> > 
> > > Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
> > > of accessing bcontainer directly.
> > > 
> > > Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> > 
> > Patch subject should be  "vfio-user/container.c" not vfio/container.c
> > 
> > regards
> > john
> 
> Ooops yes, I can easily fix that in v2. With that fixed, are you happy to
> give a SoB tag?

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john