diff mbox series

[V1,4/8] vfio/type1: close dma owner

Message ID 1670363753-249738-5-git-send-email-steven.sistare@oracle.com (mailing list archive)
State New, archived
Headers show
Series vfio virtual address update redo | expand

Commit Message

Steven Sistare Dec. 6, 2022, 9:55 p.m. UTC
If a task exits or exec, unmap and unpin all dma mappings owned by the
task.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 drivers/vfio/vfio_iommu_type1.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 4429794..51bb687 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -2932,6 +2932,16 @@  static int vfio_iommu_type1_dirty_pages(struct vfio_iommu *iommu,
 	return -EINVAL;
 }
 
+static void vfio_iommu_type1_close_dma_owner(void *iommu_data)
+{
+	struct vfio_iommu *iommu = iommu_data;
+
+	mutex_lock(&iommu->lock);
+	if (iommu->task == current->group_leader)
+		vfio_iommu_unmap_unpin_all(iommu);
+	mutex_unlock(&iommu->lock);
+}
+
 static long vfio_iommu_type1_ioctl(void *iommu_data,
 				   unsigned int cmd, unsigned long arg)
 {
@@ -3114,6 +3124,7 @@  static int vfio_iommu_type1_dma_rw(void *iommu_data, dma_addr_t user_iova,
 	.unregister_device	= vfio_iommu_type1_unregister_device,
 	.dma_rw			= vfio_iommu_type1_dma_rw,
 	.group_iommu_domain	= vfio_iommu_type1_group_iommu_domain,
+	.close_dma_owner	= vfio_iommu_type1_close_dma_owner,
 };
 
 static int __init vfio_iommu_type1_init(void)