Skip to content

Commit 38c2454

Browse files
yiliu1765awilliam
authored andcommitted
vfio: Move device_del() before waiting for the last vfio_device registration refcount
device_del() destroys the vfio-dev/vfioX under the sysfs for vfio_device. There is no reason to keep it while the device is going to be unregistered. This movement is also a preparation for adding vfio_device cdev. Kernel should remove the cdev node of the vfio_device to avoid new registration refcount increment while the device is going to be unregistered. Reviewed-by: Jason Gunthorpe <[email protected]> Tested-by: Zhenzhong Duan <[email protected]> Tested-by: Yanting Jiang <[email protected]> Signed-off-by: Yi Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent 291872a commit 38c2454

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/vfio/vfio_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ void vfio_unregister_group_dev(struct vfio_device *device)
338338
*/
339339
vfio_device_group_unregister(device);
340340

341+
/* Balances device_add in register path */
342+
device_del(&device->device);
343+
341344
vfio_device_put_registration(device);
342345
rc = try_wait_for_completion(&device->comp);
343346
while (rc <= 0) {
@@ -361,9 +364,6 @@ void vfio_unregister_group_dev(struct vfio_device *device)
361364
}
362365
}
363366

364-
/* Balances device_add in register path */
365-
device_del(&device->device);
366-
367367
/* Balances vfio_device_set_group in register path */
368368
vfio_device_remove_group(device);
369369
}

0 commit comments

Comments
 (0)