Skip to content

Commit 291872a

Browse files
yiliu1765awilliam
authored andcommitted
vfio: Move vfio_device_group_unregister() to be the first operation in unregister
This avoids endless vfio_device refcount increment by userspace, which would keep blocking the vfio_unregister_group_dev(). Reviewed-by: Jason Gunthorpe <[email protected]> Tested-by: Nicolin Chen <[email protected]> Tested-by: Matthew Rosato <[email protected]> Tested-by: Yanting Jiang <[email protected]> Tested-by: Shameer Kolothum <[email protected]> Tested-by: Terrence Xu <[email protected]> Tested-by: Zhenzhong Duan <[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 8cfa718 commit 291872a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/vfio/vfio_main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ void vfio_unregister_group_dev(struct vfio_device *device)
332332
bool interrupted = false;
333333
long rc;
334334

335+
/*
336+
* Prevent new device opened by userspace via the
337+
* VFIO_GROUP_GET_DEVICE_FD in the group path.
338+
*/
339+
vfio_device_group_unregister(device);
340+
335341
vfio_device_put_registration(device);
336342
rc = try_wait_for_completion(&device->comp);
337343
while (rc <= 0) {
@@ -355,8 +361,6 @@ void vfio_unregister_group_dev(struct vfio_device *device)
355361
}
356362
}
357363

358-
vfio_device_group_unregister(device);
359-
360364
/* Balances device_add in register path */
361365
device_del(&device->device);
362366

0 commit comments

Comments
 (0)