Commit 291872a5 authored by Yi Liu's avatar Yi Liu Committed by Alex Williamson
Browse files

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: default avatarJason Gunthorpe <jgg@nvidia.com>
Tested-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Tested-by: default avatarMatthew Rosato <mjrosato@linux.ibm.com>
Tested-by: default avatarYanting Jiang <yanting.jiang@intel.com>
Tested-by: default avatarShameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Tested-by: default avatarTerrence Xu <terrence.xu@intel.com>
Tested-by: default avatarZhenzhong Duan <zhenzhong.duan@intel.com>
Signed-off-by: default avatarYi Liu <yi.l.liu@intel.com>
Link: https://lore.kernel.org/r/20230718135551.6592-17-yi.l.liu@intel.com


Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 8cfa7186
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -332,6 +332,12 @@ void vfio_unregister_group_dev(struct vfio_device *device)
	bool interrupted = false;
	long rc;

	/*
	 * Prevent new device opened by userspace via the
	 * VFIO_GROUP_GET_DEVICE_FD in the group path.
	 */
	vfio_device_group_unregister(device);

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

	vfio_device_group_unregister(device);

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