diff mbox series

[v1,07/22] vfio/common: Refactor vfio_viommu_preset() to be group agnostic

Message ID 20230830103754.36461-8-zhenzhong.duan@intel.com (mailing list archive)
State New, archived
Headers show
Series vfio: Adopt iommufd | expand

Commit Message

Duan, Zhenzhong Aug. 30, 2023, 10:37 a.m. UTC
So that it doesn't need to be moved into container.c as done
in following patch.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 hw/vfio/common.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Comments

Eric Auger Sept. 20, 2023, 1 p.m. UTC | #1
On 8/30/23 12:37, Zhenzhong Duan wrote:
> So that it doesn't need to be moved into container.c as done
> in following patch.
This is a bit weird to refer to container.c which is not yet created. I
would suggested just reuse the commit title as a commit msg + this will
become easier to handle multiple IOMMU BEs

Eric
>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>  hw/vfio/common.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 51c6e7598e..fda5fc87b9 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -219,7 +219,22 @@ void vfio_unblock_multiple_devices_migration(void)
>  
>  bool vfio_viommu_preset(VFIODevice *vbasedev)
>  {
> -    return vbasedev->group->container->space->as != &address_space_memory;
> +    VFIOAddressSpace *space;
> +    VFIOContainer *container;
> +    VFIODevice *tmp_dev;
> +
> +    QLIST_FOREACH(space, &vfio_address_spaces, list) {
> +        QLIST_FOREACH(container, &space->containers, next) {
> +            tmp_dev = NULL;
> +            while ((tmp_dev = vfio_container_dev_iter_next(container,
> +                                                           tmp_dev))) {
> +                if (vbasedev == tmp_dev) {
> +                    return space->as != &address_space_memory;
> +                }
> +            }
> +        }
> +    }
> +    g_assert_not_reached();
>  }
>  
>  static void vfio_set_migration_error(int err)
Alex Williamson Sept. 20, 2023, 10:51 p.m. UTC | #2
On Wed, 30 Aug 2023 18:37:39 +0800
Zhenzhong Duan <zhenzhong.duan@intel.com> wrote:

> So that it doesn't need to be moved into container.c as done
> in following patch.
> 
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>  hw/vfio/common.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 51c6e7598e..fda5fc87b9 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -219,7 +219,22 @@ void vfio_unblock_multiple_devices_migration(void)
>  
>  bool vfio_viommu_preset(VFIODevice *vbasedev)
>  {
> -    return vbasedev->group->container->space->as != &address_space_memory;
> +    VFIOAddressSpace *space;
> +    VFIOContainer *container;
> +    VFIODevice *tmp_dev;
> +
> +    QLIST_FOREACH(space, &vfio_address_spaces, list) {
> +        QLIST_FOREACH(container, &space->containers, next) {
> +            tmp_dev = NULL;
> +            while ((tmp_dev = vfio_container_dev_iter_next(container,
> +                                                           tmp_dev))) {
> +                if (vbasedev == tmp_dev) {
> +                    return space->as != &address_space_memory;
> +                }
> +            }
> +        }
> +    }
> +    g_assert_not_reached();

Should the VFIODevice just have a pointer to the VFIOAddressSpace?
Thanks,

Alex


>  }
>  
>  static void vfio_set_migration_error(int err)
Duan, Zhenzhong Sept. 21, 2023, 2:52 a.m. UTC | #3
>-----Original Message-----
>From: Eric Auger <eric.auger@redhat.com>
>Sent: Wednesday, September 20, 2023 9:01 PM
>Subject: Re: [PATCH v1 07/22] vfio/common: Refactor vfio_viommu_preset() to
>be group agnostic
>
>
>
>On 8/30/23 12:37, Zhenzhong Duan wrote:
>> So that it doesn't need to be moved into container.c as done
>> in following patch.
>This is a bit weird to refer to container.c which is not yet created. I
>would suggested just reuse the commit title as a commit msg + this will
>become easier to handle multiple IOMMU BEs

Will fix, thanks Eric.

BRs.
Zhenzhong
Duan, Zhenzhong Sept. 21, 2023, 6:13 a.m. UTC | #4
>-----Original Message-----
>From: Alex Williamson <alex.williamson@redhat.com>
>Sent: Thursday, September 21, 2023 6:51 AM
>Subject: Re: [PATCH v1 07/22] vfio/common: Refactor vfio_viommu_preset() to
>be group agnostic
>
>On Wed, 30 Aug 2023 18:37:39 +0800
>Zhenzhong Duan <zhenzhong.duan@intel.com> wrote:
>
>> So that it doesn't need to be moved into container.c as done
>> in following patch.
>>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> ---
>>  hw/vfio/common.c | 17 ++++++++++++++++-
>>  1 file changed, 16 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>> index 51c6e7598e..fda5fc87b9 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/common.c
>> @@ -219,7 +219,22 @@ void vfio_unblock_multiple_devices_migration(void)
>>
>>  bool vfio_viommu_preset(VFIODevice *vbasedev)
>>  {
>> -    return vbasedev->group->container->space->as != &address_space_memory;
>> +    VFIOAddressSpace *space;
>> +    VFIOContainer *container;
>> +    VFIODevice *tmp_dev;
>> +
>> +    QLIST_FOREACH(space, &vfio_address_spaces, list) {
>> +        QLIST_FOREACH(container, &space->containers, next) {
>> +            tmp_dev = NULL;
>> +            while ((tmp_dev = vfio_container_dev_iter_next(container,
>> +                                                           tmp_dev))) {
>> +                if (vbasedev == tmp_dev) {
>> +                    return space->as != &address_space_memory;
>> +                }
>> +            }
>> +        }
>> +    }
>> +    g_assert_not_reached();
>
>Should the VFIODevice just have a pointer to the VFIOAddressSpace?

After "[PATCH v1 13/22] vfio: Add base container", VFIODevice has pointer
to base container which has pointer further to VFIOAddressSpace.
Is that meet your expectation?

Thanks
Zhenzhong
diff mbox series

Patch

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 51c6e7598e..fda5fc87b9 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -219,7 +219,22 @@  void vfio_unblock_multiple_devices_migration(void)
 
 bool vfio_viommu_preset(VFIODevice *vbasedev)
 {
-    return vbasedev->group->container->space->as != &address_space_memory;
+    VFIOAddressSpace *space;
+    VFIOContainer *container;
+    VFIODevice *tmp_dev;
+
+    QLIST_FOREACH(space, &vfio_address_spaces, list) {
+        QLIST_FOREACH(container, &space->containers, next) {
+            tmp_dev = NULL;
+            while ((tmp_dev = vfio_container_dev_iter_next(container,
+                                                           tmp_dev))) {
+                if (vbasedev == tmp_dev) {
+                    return space->as != &address_space_memory;
+                }
+            }
+        }
+    }
+    g_assert_not_reached();
 }
 
 static void vfio_set_migration_error(int err)