Skip to content

Commit 31076af

Browse files
LuBaolujoergroedel
authored andcommitted
vfio: Remove use of vfio_group_viable()
As DMA ownership is claimed for the iommu group when a VFIO group is added to a VFIO container, the VFIO group viability is guaranteed as long as group->container_users > 0. Remove those unnecessary group viability checks which are only hit when group->container_users is not zero. The only remaining reference is in GROUP_GET_STATUS, which could be called at any time when group fd is valid. Here we just replace the vfio_group_viable() by directly calling IOMMU core to get viability status. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Acked-by: Alex Williamson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 70693f4 commit 31076af

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

drivers/vfio/vfio.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,12 +1313,6 @@ static int vfio_group_set_container(struct vfio_group *group, int container_fd)
13131313
return ret;
13141314
}
13151315

1316-
static bool vfio_group_viable(struct vfio_group *group)
1317-
{
1318-
return (iommu_group_for_each_dev(group->iommu_group,
1319-
group, vfio_dev_viable) == 0);
1320-
}
1321-
13221316
static int vfio_group_add_container_user(struct vfio_group *group)
13231317
{
13241318
if (!atomic_inc_not_zero(&group->container_users))
@@ -1328,7 +1322,7 @@ static int vfio_group_add_container_user(struct vfio_group *group)
13281322
atomic_dec(&group->container_users);
13291323
return -EPERM;
13301324
}
1331-
if (!group->container->iommu_driver || !vfio_group_viable(group)) {
1325+
if (!group->container->iommu_driver) {
13321326
atomic_dec(&group->container_users);
13331327
return -EINVAL;
13341328
}
@@ -1346,7 +1340,7 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf)
13461340
int ret = 0;
13471341

13481342
if (0 == atomic_read(&group->container_users) ||
1349-
!group->container->iommu_driver || !vfio_group_viable(group))
1343+
!group->container->iommu_driver)
13501344
return -EINVAL;
13511345

13521346
if (group->type == VFIO_NO_IOMMU && !capable(CAP_SYS_RAWIO))
@@ -1438,11 +1432,11 @@ static long vfio_group_fops_unl_ioctl(struct file *filep,
14381432

14391433
status.flags = 0;
14401434

1441-
if (vfio_group_viable(group))
1442-
status.flags |= VFIO_GROUP_FLAGS_VIABLE;
1443-
14441435
if (group->container)
1445-
status.flags |= VFIO_GROUP_FLAGS_CONTAINER_SET;
1436+
status.flags |= VFIO_GROUP_FLAGS_CONTAINER_SET |
1437+
VFIO_GROUP_FLAGS_VIABLE;
1438+
else if (!iommu_group_dma_owner_claimed(group->iommu_group))
1439+
status.flags |= VFIO_GROUP_FLAGS_VIABLE;
14461440

14471441
if (copy_to_user((void __user *)arg, &status, minsz))
14481442
return -EFAULT;

0 commit comments

Comments
 (0)