Skip to content

Commit 4c3f4f4

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommufd: Enforce PASID-compatible domain for RID
Per the definition of IOMMU_HWPT_ALLOC_PASID, iommufd needs to enforce the RID to use PASID-compatible domain if PASID has been attached, and vice versa. The PASID path has already enforced it. This adds the enforcement in the RID path. This enforcement requires a lock across the RID and PASID attach path, the idev->igroup->lock is used as both the RID and the PASID path holds it. Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Signed-off-by: Yi Liu <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 2fb69c6 commit 4c3f4f4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,28 @@ static int iommufd_hwpt_pasid_compat(struct iommufd_hw_pagetable *hwpt,
399399
struct iommufd_device *idev,
400400
ioasid_t pasid)
401401
{
402-
if (pasid != IOMMU_NO_PASID && !hwpt->pasid_compat)
403-
return -EINVAL;
402+
struct iommufd_group *igroup = idev->igroup;
403+
404+
lockdep_assert_held(&igroup->lock);
405+
406+
if (pasid == IOMMU_NO_PASID) {
407+
unsigned long start = IOMMU_NO_PASID;
408+
409+
if (!hwpt->pasid_compat &&
410+
xa_find_after(&igroup->pasid_attach,
411+
&start, UINT_MAX, XA_PRESENT))
412+
return -EINVAL;
413+
} else {
414+
struct iommufd_attach *attach;
415+
416+
if (!hwpt->pasid_compat)
417+
return -EINVAL;
418+
419+
attach = xa_load(&igroup->pasid_attach, IOMMU_NO_PASID);
420+
if (attach && attach->hwpt && !attach->hwpt->pasid_compat)
421+
return -EINVAL;
422+
}
423+
404424
return 0;
405425
}
406426

@@ -411,8 +431,6 @@ static int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,
411431
struct iommufd_attach_handle *handle;
412432
int rc;
413433

414-
lockdep_assert_held(&idev->igroup->lock);
415-
416434
rc = iommufd_hwpt_pasid_compat(hwpt, idev, pasid);
417435
if (rc)
418436
return rc;

0 commit comments

Comments
 (0)