Skip to content

Commit 90b1253

Browse files
author
Al Viro
committed
vfio: get rid of vfio_device_put()/vfio_group_get_device* races
we really need to make sure that dropping the last reference happens under the group->device_lock; otherwise a loop (under device_lock) might find vfio_device instance that is being freed right now, has already dropped the last reference and waits on device_lock to exclude the sucker from the list. Acked-by: Alex Williamson <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 6d2cd3c commit 90b1253

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/vfio/vfio.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ static void vfio_device_release(struct kref *kref)
396396
struct vfio_device, kref);
397397
struct vfio_group *group = device->group;
398398

399-
mutex_lock(&group->device_lock);
400399
list_del(&device->group_next);
401400
mutex_unlock(&group->device_lock);
402401

@@ -412,7 +411,7 @@ static void vfio_device_release(struct kref *kref)
412411
static void vfio_device_put(struct vfio_device *device)
413412
{
414413
struct vfio_group *group = device->group;
415-
kref_put(&device->kref, vfio_device_release);
414+
kref_put_mutex(&device->kref, vfio_device_release, &group->device_lock);
416415
vfio_group_put(group);
417416
}
418417

0 commit comments

Comments
 (0)