summaryrefslogtreecommitdiff
path: root/drivers/vfio/vfio.c
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2022-05-04 16:14:43 -0300
committerAlex Williamson <alex.williamson@redhat.com>2022-05-13 10:14:20 -0600
commita905ad043f32bbb0c35d4325036397f20f30c8a9 (patch)
treed6fd0152cfaec5856b36d73d84f729c02e69d9e2 /drivers/vfio/vfio.c
parentc38ff5b0c373fbbd6a249eb461ffd4ae0f9dbfa0 (diff)
vfio: Change vfio_external_check_extension() to vfio_file_enforced_coherent()
Instead of a general extension check change the function into a limited test if the iommu_domain has enforced coherency, which is the only thing kvm needs to query. Make the new op self contained by properly refcounting the container before touching it. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/5-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.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 4805e18f2272..c2a360437e6c 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -1701,11 +1701,35 @@ struct iommu_group *vfio_file_iommu_group(struct file *file)
}
EXPORT_SYMBOL_GPL(vfio_file_iommu_group);
-long vfio_external_check_extension(struct vfio_group *group, unsigned long arg)
+/**
+ * vfio_file_enforced_coherent - True if the DMA associated with the VFIO file
+ * is always CPU cache coherent
+ * @file: VFIO group file
+ *
+ * Enforced coherency means that the IOMMU ignores things like the PCIe no-snoop
+ * bit in DMA transactions. A return of false indicates that the user has
+ * rights to access additional instructions such as wbinvd on x86.
+ */
+bool vfio_file_enforced_coherent(struct file *file)
{
- return vfio_ioctl_check_extension(group->container, arg);
+ struct vfio_group *group = file->private_data;
+ bool ret;
+
+ if (file->f_op != &vfio_group_fops)
+ return true;
+
+ /*
+ * Since the coherency state is determined only once a container is
+ * attached the user must do so before they can prove they have
+ * permission.
+ */
+ if (vfio_group_add_container_user(group))
+ return true;
+ ret = vfio_ioctl_check_extension(group->container, VFIO_DMA_CC_IOMMU);
+ vfio_group_try_dissolve_container(group);
+ return ret;
}
-EXPORT_SYMBOL_GPL(vfio_external_check_extension);
+EXPORT_SYMBOL_GPL(vfio_file_enforced_coherent);
/*
* Sub-module support