summaryrefslogtreecommitdiffstats
path: root/drivers/vfio/vfio.c
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2022-05-04 16:14:41 -0300
committerAlex Williamson <alex.williamson@redhat.com>2022-05-13 10:14:19 -0600
commit50d63b5bbfd12262069ad062611cd5e69c5e9e05 (patch)
tree1642d1f0eb0fdbb2d974138b2b911905bfbe257c /drivers/vfio/vfio.c
parentd55d9e7a4572182701ed0b62313b4f22e544e226 (diff)
downloadlinux-50d63b5bbfd12262069ad062611cd5e69c5e9e05.tar.gz
linux-50d63b5bbfd12262069ad062611cd5e69c5e9e05.tar.bz2
linux-50d63b5bbfd12262069ad062611cd5e69c5e9e05.zip
vfio: Change vfio_external_user_iommu_id() to vfio_file_iommu_group()
The only caller wants to get a pointer to the struct iommu_group associated with the VFIO group file. Instead of returning the group ID then searching sysfs for that string to get the struct iommu_group just directly return the iommu_group pointer already held by the vfio_group struct. It already has a safe lifetime due to the struct file kref, the vfio_group and thus the iommu_group cannot be destroyed while the group file is open. Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/3-v3-f7729924a7ea+25e33-vfio_kvm_no_group_jgg@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio/vfio.c')
-rw-r--r--drivers/vfio/vfio.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 8cb7ba03aa16..25f90f3773de 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -1653,10 +1653,7 @@ static const struct file_operations vfio_device_fops = {
* increments the container user counter to prevent
* the VFIO group from disposal before KVM exits.
*
- * 3. The external user calls vfio_external_user_iommu_id()
- * to know an IOMMU ID.
- *
- * 4. When the external KVM finishes, it calls
+ * 3. When the external KVM finishes, it calls
* vfio_group_put_external_user() to release the VFIO group.
* This call decrements the container user counter.
*/
@@ -1697,11 +1694,21 @@ bool vfio_external_group_match_file(struct vfio_group *test_group,
}
EXPORT_SYMBOL_GPL(vfio_external_group_match_file);
-int vfio_external_user_iommu_id(struct vfio_group *group)
+/**
+ * vfio_file_iommu_group - Return the struct iommu_group for the vfio group file
+ * @file: VFIO group file
+ *
+ * The returned iommu_group is valid as long as a ref is held on the file.
+ */
+struct iommu_group *vfio_file_iommu_group(struct file *file)
{
- return iommu_group_id(group->iommu_group);
+ struct vfio_group *group = file->private_data;
+
+ if (file->f_op != &vfio_group_fops)
+ return NULL;
+ return group->iommu_group;
}
-EXPORT_SYMBOL_GPL(vfio_external_user_iommu_id);
+EXPORT_SYMBOL_GPL(vfio_file_iommu_group);
long vfio_external_check_extension(struct vfio_group *group, unsigned long arg)
{