[RFC PATCH v4 07/24] vfio/common: Refactor vfio_viommu_preset() to be group agnostic

Zhenzhong Duan posted 24 patches 2 years, 5 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Yi Liu <yi.l.liu@intel.com>, Eric Auger <eric.auger@redhat.com>, Thomas Huth <thuth@redhat.com>, Tony Krowiak <akrowiak@linux.ibm.com>, Halil Pasic <pasic@linux.ibm.com>, Jason Herne <jjherne@linux.ibm.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Eric Farman <farman@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Greg Kurz <groug@kaod.org>, Harsh Prateek Bora <harshpb@linux.ibm.com>, "Michael S. Tsirkin" <mst@redhat.com>, Cornelia Huck <cohuck@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Eduardo Habkost <eduardo@habkost.net>
There is a newer version of this series
[RFC PATCH v4 07/24] vfio/common: Refactor vfio_viommu_preset() to be group agnostic
Posted by Zhenzhong Duan 2 years, 5 months ago
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 f7e4dc0cef..a1fb0dafda 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -215,7 +215,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_vbasedev;
+
+    QLIST_FOREACH(space, &vfio_address_spaces, list) {
+        QLIST_FOREACH(container, &space->containers, next) {
+            tmp_vbasedev = NULL;
+            while ((vbasedev = vfio_container_dev_iter_next(container,
+                                                            vbasedev))) {
+                if (vbasedev == tmp_vbasedev) {
+                    return space->as != &address_space_memory;
+                }
+            }
+        }
+    }
+    g_assert_not_reached();
 }
 
 static void vfio_set_migration_error(int err)
-- 
2.34.1