Skip to content

Commit a3da1ab

Browse files
jgunthorpeawilliam
authored andcommitted
vfio: Do not manipulate iommu dma_owner for fake iommu groups
Since asserting dma ownership now causes the group to have its DMA blocked the iommu layer requires a working iommu. This means the dma_owner APIs cannot be used on the fake groups that VFIO creates. Test for this and avoid calling them. Otherwise asserting dma ownership will fail for VFIO mdev devices as a BLOCKING iommu_domain cannot be allocated due to the NULL iommu ops. Fixes: 0286300 ("iommu: iommu_group_claim_dma_owner() must always assign a domain") Reported-by: Eric Farman <farman@linux.ibm.com> Tested-by: Eric Farman <farman@linux.ibm.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/0-v1-9cfc47edbcd4+13546-vfio_dma_owner_fix_jgg@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 7ab5e10 commit a3da1ab

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

drivers/vfio/vfio.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,8 @@ static void __vfio_group_unset_container(struct vfio_group *group)
927927
driver->ops->detach_group(container->iommu_data,
928928
group->iommu_group);
929929

930-
iommu_group_release_dma_owner(group->iommu_group);
930+
if (group->type == VFIO_IOMMU)
931+
iommu_group_release_dma_owner(group->iommu_group);
931932

932933
group->container = NULL;
933934
group->container_users = 0;
@@ -1001,17 +1002,21 @@ static int vfio_group_set_container(struct vfio_group *group, int container_fd)
10011002
goto unlock_out;
10021003
}
10031004

1004-
ret = iommu_group_claim_dma_owner(group->iommu_group, f.file);
1005-
if (ret)
1006-
goto unlock_out;
1005+
if (group->type == VFIO_IOMMU) {
1006+
ret = iommu_group_claim_dma_owner(group->iommu_group, f.file);
1007+
if (ret)
1008+
goto unlock_out;
1009+
}
10071010

10081011
driver = container->iommu_driver;
10091012
if (driver) {
10101013
ret = driver->ops->attach_group(container->iommu_data,
10111014
group->iommu_group,
10121015
group->type);
10131016
if (ret) {
1014-
iommu_group_release_dma_owner(group->iommu_group);
1017+
if (group->type == VFIO_IOMMU)
1018+
iommu_group_release_dma_owner(
1019+
group->iommu_group);
10151020
goto unlock_out;
10161021
}
10171022
}

0 commit comments

Comments
 (0)