Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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/20250321171940.7213-13-yi.l.liu@intel.com
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Yi Liu and committed by
Jason Gunthorpe
4c3f4f43 2fb69c60

+22 -4
+22 -4
drivers/iommu/iommufd/device.c
··· 399 399 struct iommufd_device *idev, 400 400 ioasid_t pasid) 401 401 { 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 + 404 424 return 0; 405 425 } 406 426 ··· 430 410 { 431 411 struct iommufd_attach_handle *handle; 432 412 int rc; 433 - 434 - lockdep_assert_held(&idev->igroup->lock); 435 413 436 414 rc = iommufd_hwpt_pasid_compat(hwpt, idev, pasid); 437 415 if (rc)