Skip to content

Commit

Permalink
vfio: Move device_del() before waiting for the last vfio_device regis…
Browse files Browse the repository at this point in the history
…tration 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 <jgg@nvidia.com>
Tested-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Tested-by: Yanting Jiang <yanting.jiang@intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Link: https://lore.kernel.org/r/20230718135551.6592-18-yi.l.liu@intel.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
  • Loading branch information
Yi Liu authored and Alex Williamson committed Jul 25, 2023
1 parent 291872a commit 38c2454
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/vfio/vfio_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ void vfio_unregister_group_dev(struct vfio_device *device)
*/
vfio_device_group_unregister(device);

/* Balances device_add in register path */
device_del(&device->device);

vfio_device_put_registration(device);
rc = try_wait_for_completion(&device->comp);
while (rc <= 0) {
Expand All @@ -361,9 +364,6 @@ void vfio_unregister_group_dev(struct vfio_device *device)
}
}

/* Balances device_add in register path */
device_del(&device->device);

/* Balances vfio_device_set_group in register path */
vfio_device_remove_group(device);
}
Expand Down

0 comments on commit 38c2454

Please sign in to comment.