]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
vfio: add vfio_device_unprepare()
authorJohn Levon <john.levon@nutanix.com>
Wed, 7 May 2025 15:20:07 +0000 (16:20 +0100)
committerCédric Le Goater <clg@redhat.com>
Fri, 9 May 2025 10:42:28 +0000 (12:42 +0200)
Add a helper that's the inverse of vfio_device_prepare().

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: John Levon <john.levon@nutanix.com>
Link: https://lore.kernel.org/qemu-devel/20250507152020.1254632-3-john.levon@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
hw/vfio/container.c
hw/vfio/device.c
hw/vfio/iommufd.c
include/hw/vfio/vfio-device.h

index d30c1a141d34d8b026876e4a289c08ba067ef8a7..cf23aa799f61da58da09411ca6213a753a7f4794 100644 (file)
@@ -927,10 +927,10 @@ static void vfio_legacy_detach_device(VFIODevice *vbasedev)
 {
     VFIOGroup *group = vbasedev->group;
 
-    QLIST_REMOVE(vbasedev, global_next);
-    QLIST_REMOVE(vbasedev, container_next);
-    vbasedev->bcontainer = NULL;
     trace_vfio_device_detach(vbasedev->name, group->groupid);
+
+    vfio_device_unprepare(vbasedev);
+
     object_unref(vbasedev->hiod);
     vfio_device_put(vbasedev);
     vfio_group_put(group);
index f3b9902d21cdb4443ffd603b1b3f8ad5950996fc..31c441a3dfffdf459994407904ab78b1798bf979 100644 (file)
@@ -412,3 +412,10 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
 
     QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
 }
+
+void vfio_device_unprepare(VFIODevice *vbasedev)
+{
+    QLIST_REMOVE(vbasedev, container_next);
+    QLIST_REMOVE(vbasedev, global_next);
+    vbasedev->bcontainer = NULL;
+}
index 83033c352a7d8d868aea52b2bdfcdcbbb6914bff..62ecb758f1ade0e39efaef2b4001dab91abaa001 100644 (file)
@@ -615,9 +615,7 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev)
     VFIOIOMMUFDContainer *container = container_of(bcontainer,
                                                    VFIOIOMMUFDContainer,
                                                    bcontainer);
-    QLIST_REMOVE(vbasedev, global_next);
-    QLIST_REMOVE(vbasedev, container_next);
-    vbasedev->bcontainer = NULL;
+    vfio_device_unprepare(vbasedev);
 
     if (!vbasedev->ram_block_discard_allowed) {
         iommufd_cdev_ram_block_discard_disable(false);
index 081929ca4b9bc59217c633421fcbe84ea4171aa7..342c4ba3bfec8d143a297203dbfa0e6f6fae3535 100644 (file)
@@ -137,6 +137,8 @@ extern VFIODeviceList vfio_device_list;
 void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
                          struct vfio_device_info *info);
 
+void vfio_device_unprepare(VFIODevice *vbasedev);
+
 int vfio_device_get_region_info(VFIODevice *vbasedev, int index,
                                 struct vfio_region_info **info);
 int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type,