diff options
author | Jason Gunthorpe <jgg@nvidia.com> | 2022-11-29 21:31:47 +0100 |
---|---|---|
committer | Jason Gunthorpe <jgg@nvidia.com> | 2022-12-02 16:52:03 +0100 |
commit | bab6fabc01d99c7e0293807e835231740379b692 (patch) | |
tree | b7d0e509f059d386f6dc8adc4da286856f620183 /drivers/vfio/container.c | |
parent | vfio: Move vfio_device driver open/close code to a function (diff) | |
download | linux-bab6fabc01d99c7e0293807e835231740379b692.tar.xz linux-bab6fabc01d99c7e0293807e835231740379b692.zip |
vfio: Move vfio_device_assign_container() into vfio_device_first_open()
The only thing this function does is assert the group has an assigned
container and incrs refcounts.
The overall model we have is that once a container_users refcount is
incremented it cannot be de-assigned from the group -
vfio_group_ioctl_unset_container() will fail and the group FD cannot be
closed.
Thus we do not need to check this on every device FD open, just the
first. Reorganize the code so that only the first open and last close
manages the container.
Link: https://lore.kernel.org/r/2-v4-42cd2eb0e3eb+335a-vfio_iommufd_jgg@nvidia.com
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Yi Liu <yi.l.liu@intel.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Tested-by: Alex Williamson <alex.williamson@redhat.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Tested-by: Yi Liu <yi.l.liu@intel.com>
Tested-by: Lixiao Yang <lixiao.yang@intel.com>
Tested-by: Matthew Rosato <mjrosato@linux.ibm.com>
Tested-by: Yu He <yu.he@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Diffstat (limited to 'drivers/vfio/container.c')
-rw-r--r-- | drivers/vfio/container.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/vfio/container.c b/drivers/vfio/container.c index d74164abbf40..dd79a66ec62c 100644 --- a/drivers/vfio/container.c +++ b/drivers/vfio/container.c @@ -531,11 +531,11 @@ int vfio_device_assign_container(struct vfio_device *device) void vfio_device_unassign_container(struct vfio_device *device) { - mutex_lock(&device->group->group_lock); + lockdep_assert_held_write(&device->group->group_lock); + WARN_ON(device->group->container_users <= 1); device->group->container_users--; fput(device->group->opened_file); - mutex_unlock(&device->group->group_lock); } /* |