Skip to content

Commit 330c179

Browse files
yiliu1765awilliam
authored andcommitted
vfio: Move "device->open_count--" out of group_rwsem in vfio_device_open()
We do not protect the vfio_device::open_count with group_rwsem elsewhere (see vfio_device_fops_release as a comparison, where we already drop group_rwsem before open_count--). So move the group_rwsem unlock prior to open_count--. This change now also drops group_rswem before setting device->kvm = NULL, but that's also OK (again, just like vfio_device_fops_release). The setting of device->kvm before open_device is technically done while holding the group_rwsem, this is done to protect the group kvm value we are copying from, and we should not be relying on that to protect the contents of device->kvm; instead we assume this value will not change until after the device is closed and while under the dev_set->lock. Cc: Matthew Rosato <[email protected]> Cc: Jason Gunthorpe <[email protected]> Signed-off-by: Yi Liu <[email protected]> Reviewed-by: Matthew Rosato <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent d1877e6 commit 330c179

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/vfio/vfio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,10 +1146,10 @@ static struct file *vfio_device_open(struct vfio_device *device)
11461146
if (device->open_count == 1 && device->ops->close_device)
11471147
device->ops->close_device(device);
11481148
err_undo_count:
1149+
up_read(&device->group->group_rwsem);
11491150
device->open_count--;
11501151
if (device->open_count == 0 && device->kvm)
11511152
device->kvm = NULL;
1152-
up_read(&device->group->group_rwsem);
11531153
mutex_unlock(&device->dev_set->lock);
11541154
module_put(device->dev->driver->owner);
11551155
err_unassign_container:

0 commit comments

Comments
 (0)