Skip to content

Commit ff3f014

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommufd: Enforce PASID-compatible domain in PASID path
AMD IOMMU requires attaching PASID-compatible domains to PASID-capable devices. This includes the domains attached to RID and PASIDs. Related discussions in link [1] and [2]. ARM also has such a requirement, Intel does not need it, but can live up with it. Hence, iommufd is going to enforce this requirement as it is not harmful to vendors that do not need it. Mark the PASID-compatible domains and enforce it in the PASID path. [1] https://lore.kernel.org/linux-iommu/[email protected]/ [2] https://lore.kernel.org/linux-iommu/[email protected]/ Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Signed-off-by: Yi Liu <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent c0e301b commit ff3f014

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,15 @@ static bool iommufd_device_is_attached(struct iommufd_device *idev,
395395
return xa_load(&attach->device_array, idev->obj.id);
396396
}
397397

398+
static int iommufd_hwpt_pasid_compat(struct iommufd_hw_pagetable *hwpt,
399+
struct iommufd_device *idev,
400+
ioasid_t pasid)
401+
{
402+
if (pasid != IOMMU_NO_PASID && !hwpt->pasid_compat)
403+
return -EINVAL;
404+
return 0;
405+
}
406+
398407
static int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,
399408
struct iommufd_device *idev,
400409
ioasid_t pasid)
@@ -404,6 +413,10 @@ static int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,
404413

405414
lockdep_assert_held(&idev->igroup->lock);
406415

416+
rc = iommufd_hwpt_pasid_compat(hwpt, idev, pasid);
417+
if (rc)
418+
return rc;
419+
407420
handle = kzalloc(sizeof(*handle), GFP_KERNEL);
408421
if (!handle)
409422
return -ENOMEM;
@@ -472,6 +485,10 @@ static int iommufd_hwpt_replace_device(struct iommufd_device *idev,
472485

473486
WARN_ON(pasid != IOMMU_NO_PASID);
474487

488+
rc = iommufd_hwpt_pasid_compat(hwpt, idev, pasid);
489+
if (rc)
490+
return rc;
491+
475492
old_handle = iommufd_device_get_attach_handle(idev, pasid);
476493

477494
handle = kzalloc(sizeof(*handle), GFP_KERNEL);

drivers/iommu/iommufd/hw_pagetable.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
136136
if (IS_ERR(hwpt_paging))
137137
return ERR_CAST(hwpt_paging);
138138
hwpt = &hwpt_paging->common;
139+
hwpt->pasid_compat = flags & IOMMU_HWPT_ALLOC_PASID;
139140

140141
INIT_LIST_HEAD(&hwpt_paging->hwpt_item);
141142
/* Pairs with iommufd_hw_pagetable_destroy() */
@@ -244,6 +245,7 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx,
244245
if (IS_ERR(hwpt_nested))
245246
return ERR_CAST(hwpt_nested);
246247
hwpt = &hwpt_nested->common;
248+
hwpt->pasid_compat = flags & IOMMU_HWPT_ALLOC_PASID;
247249

248250
refcount_inc(&parent->common.obj.users);
249251
hwpt_nested->parent = parent;
@@ -300,6 +302,7 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags,
300302
if (IS_ERR(hwpt_nested))
301303
return ERR_CAST(hwpt_nested);
302304
hwpt = &hwpt_nested->common;
305+
hwpt->pasid_compat = flags & IOMMU_HWPT_ALLOC_PASID;
303306

304307
hwpt_nested->viommu = viommu;
305308
refcount_inc(&viommu->obj.users);

drivers/iommu/iommufd/iommufd_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ struct iommufd_hw_pagetable {
299299
struct iommufd_object obj;
300300
struct iommu_domain *domain;
301301
struct iommufd_fault *fault;
302+
bool pasid_compat : 1;
302303
};
303304

304305
struct iommufd_hwpt_paging {

0 commit comments

Comments
 (0)