]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
vfio: Move vfio_device_assign_container() into vfio_device_first_open()
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 29 Nov 2022 20:31:47 +0000 (16:31 -0400)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 2 Dec 2022 15:52:03 +0000 (11:52 -0400)
commitbab6fabc01d99c7e0293807e835231740379b692
treeb7d0e509f059d386f6dc8adc4da286856f620183
parent294aaccb50130f596943be892c5d3a3568b76c57
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>
drivers/vfio/container.c
drivers/vfio/vfio_main.c