mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-25 21:24:08 +08:00
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 <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Acked-by: Alex Williamson <alex.williamson@redhat.com> Link: https://lore.kernel.org/r/20220418005000.897664-9-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
70693f4708
commit
31076af0cb
@ -1313,12 +1313,6 @@ unlock_out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool vfio_group_viable(struct vfio_group *group)
|
||||
{
|
||||
return (iommu_group_for_each_dev(group->iommu_group,
|
||||
group, vfio_dev_viable) == 0);
|
||||
}
|
||||
|
||||
static int vfio_group_add_container_user(struct vfio_group *group)
|
||||
{
|
||||
if (!atomic_inc_not_zero(&group->container_users))
|
||||
@ -1328,7 +1322,7 @@ static int vfio_group_add_container_user(struct vfio_group *group)
|
||||
atomic_dec(&group->container_users);
|
||||
return -EPERM;
|
||||
}
|
||||
if (!group->container->iommu_driver || !vfio_group_viable(group)) {
|
||||
if (!group->container->iommu_driver) {
|
||||
atomic_dec(&group->container_users);
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -1346,7 +1340,7 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf)
|
||||
int ret = 0;
|
||||
|
||||
if (0 == atomic_read(&group->container_users) ||
|
||||
!group->container->iommu_driver || !vfio_group_viable(group))
|
||||
!group->container->iommu_driver)
|
||||
return -EINVAL;
|
||||
|
||||
if (group->type == VFIO_NO_IOMMU && !capable(CAP_SYS_RAWIO))
|
||||
@ -1438,11 +1432,11 @@ static long vfio_group_fops_unl_ioctl(struct file *filep,
|
||||
|
||||
status.flags = 0;
|
||||
|
||||
if (vfio_group_viable(group))
|
||||
status.flags |= VFIO_GROUP_FLAGS_VIABLE;
|
||||
|
||||
if (group->container)
|
||||
status.flags |= VFIO_GROUP_FLAGS_CONTAINER_SET;
|
||||
status.flags |= VFIO_GROUP_FLAGS_CONTAINER_SET |
|
||||
VFIO_GROUP_FLAGS_VIABLE;
|
||||
else if (!iommu_group_dma_owner_claimed(group->iommu_group))
|
||||
status.flags |= VFIO_GROUP_FLAGS_VIABLE;
|
||||
|
||||
if (copy_to_user((void __user *)arg, &status, minsz))
|
||||
return -EFAULT;
|
||||
|
Loading…
Reference in New Issue
Block a user