Skip to content

Commit

Permalink
vfio: Rename vfio_device_assign/unassign_container()
Browse files Browse the repository at this point in the history
These functions don't really assign anything anymore, they just increment
some refcounts and do a sanity check. Call them
vfio_group_[un]use_container()

Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Kevin Tian <[email protected]>
Reviewed-by: Yi Liu <[email protected]>
Reviewed-by: Alex Williamson <[email protected]>
Tested-by: Alex Williamson <[email protected]>
Tested-by: Nicolin Chen <[email protected]>
Tested-by: Yi Liu <[email protected]>
Tested-by: Lixiao Yang <[email protected]>
Tested-by: Matthew Rosato <[email protected]>
Tested-by: Yu He <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
  • Loading branch information
jgunthorpe committed Dec 2, 2022
1 parent bab6fab commit 04f930c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
14 changes: 6 additions & 8 deletions drivers/vfio/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,8 @@ void vfio_group_detach_container(struct vfio_group *group)
vfio_container_put(container);
}

int vfio_device_assign_container(struct vfio_device *device)
int vfio_group_use_container(struct vfio_group *group)
{
struct vfio_group *group = device->group;

lockdep_assert_held(&group->group_lock);

if (!group->container || !group->container->iommu_driver ||
Expand All @@ -529,13 +527,13 @@ int vfio_device_assign_container(struct vfio_device *device)
return 0;
}

void vfio_device_unassign_container(struct vfio_device *device)
void vfio_group_unuse_container(struct vfio_group *group)
{
lockdep_assert_held_write(&device->group->group_lock);
lockdep_assert_held(&group->group_lock);

WARN_ON(device->group->container_users <= 1);
device->group->container_users--;
fput(device->group->opened_file);
WARN_ON(group->container_users <= 1);
group->container_users--;
fput(group->opened_file);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions drivers/vfio/vfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ void vfio_unregister_iommu_driver(const struct vfio_iommu_driver_ops *ops);
bool vfio_assert_device_open(struct vfio_device *device);

struct vfio_container *vfio_container_from_file(struct file *filep);
int vfio_device_assign_container(struct vfio_device *device);
void vfio_device_unassign_container(struct vfio_device *device);
int vfio_group_use_container(struct vfio_group *group);
void vfio_group_unuse_container(struct vfio_group *group);
int vfio_container_attach_group(struct vfio_container *container,
struct vfio_group *group);
void vfio_group_detach_container(struct vfio_group *group);
Expand Down
6 changes: 3 additions & 3 deletions drivers/vfio/vfio_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ static int vfio_device_first_open(struct vfio_device *device)
* during close_device.
*/
mutex_lock(&device->group->group_lock);
ret = vfio_device_assign_container(device);
ret = vfio_group_use_container(device->group);
if (ret)
goto err_module_put;

Expand All @@ -765,7 +765,7 @@ static int vfio_device_first_open(struct vfio_device *device)

err_container:
device->kvm = NULL;
vfio_device_unassign_container(device);
vfio_group_unuse_container(device->group);
err_module_put:
mutex_unlock(&device->group->group_lock);
module_put(device->dev->driver->owner);
Expand All @@ -781,7 +781,7 @@ static void vfio_device_last_close(struct vfio_device *device)
if (device->ops->close_device)
device->ops->close_device(device);
device->kvm = NULL;
vfio_device_unassign_container(device);
vfio_group_unuse_container(device->group);
mutex_unlock(&device->group->group_lock);
module_put(device->dev->driver->owner);
}
Expand Down

0 comments on commit 04f930c

Please sign in to comment.