Skip to content

Commit fb3de9f

Browse files
yiliu1765joergroedel
authored andcommitted
iommu: Prevent pasid attach if no ops->remove_dev_pasid
driver should implement both set_dev_pasid and remove_dev_pasid op, otherwise it is a problem how to detach pasid. In reality, it is impossible that an iommu driver implements set_dev_pasid() but no remove_dev_pasid() op. However, it is better to check it. Move the group check to be the first as dev_iommu_ops() may fail when there is no valid group. Also take the chance to remove the dev_has_iommu() check as it is duplicated to the group check. Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Yi Liu <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 78d4f34 commit fb3de9f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/iommu/iommu.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,16 +3368,19 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
33683368
/* Caller must be a probed driver on dev */
33693369
struct iommu_group *group = dev->iommu_group;
33703370
struct group_device *device;
3371+
const struct iommu_ops *ops;
33713372
int ret;
33723373

3373-
if (!domain->ops->set_dev_pasid)
3374-
return -EOPNOTSUPP;
3375-
33763374
if (!group)
33773375
return -ENODEV;
33783376

3379-
if (!dev_has_iommu(dev) || dev_iommu_ops(dev) != domain->owner ||
3380-
pasid == IOMMU_NO_PASID)
3377+
ops = dev_iommu_ops(dev);
3378+
3379+
if (!domain->ops->set_dev_pasid ||
3380+
!ops->remove_dev_pasid)
3381+
return -EOPNOTSUPP;
3382+
3383+
if (ops != domain->owner || pasid == IOMMU_NO_PASID)
33813384
return -EINVAL;
33823385

33833386
mutex_lock(&group->mutex);

0 commit comments

Comments
 (0)