Skip to content

Commit 4396cbe

Browse files
committed
iommu: Skip PASID validation for devices without PASID capability
Generally PASID support requires ACS settings that usually create single device groups, but there are some niche cases where we can get multi-device groups and still have working PASID support. The primary issue is that PCI switches are not required to treat PASID tagged TLPs specially so appropriate ACS settings are required to route all TLPs to the host bridge if PASID is going to work properly. pci_enable_pasid() does check that each device that will use PASID has the proper ACS settings to achieve this routing. However, no-PASID devices can be combined with PASID capable devices within the same topology using non-uniform ACS settings. In this case the no-PASID devices may not have strict route to host ACS flags and end up being grouped with the PASID devices. This configuration fails to allow use of the PASID within the iommu core code which wrongly checks if the no-PASID device supports PASID. Fix this by ignoring no-PASID devices during the PASID validation. They will never issue a PASID TLP anyhow so they can be ignored. Fixes: c404f55 ("iommu: Validate the PASID in iommu_attach_device_pasid()") Cc: [email protected] (backported from commit b3f6fcd) Signed-off-by: Tushar Dave <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent ed619b9 commit 4396cbe

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

drivers/iommu/iommu.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,9 +3341,11 @@ static int __iommu_set_group_pasid(struct iommu_domain *domain,
33413341
int ret;
33423342

33433343
for_each_group_device(group, device) {
3344-
ret = domain->ops->set_dev_pasid(domain, device->dev, pasid);
3345-
if (ret)
3346-
goto err_revert;
3344+
if (device->dev->iommu->max_pasids > 0) {
3345+
ret = domain->ops->set_dev_pasid(domain, device->dev, pasid);
3346+
if (ret)
3347+
goto err_revert;
3348+
}
33473349
}
33483350

33493351
return 0;
@@ -3355,7 +3357,8 @@ static int __iommu_set_group_pasid(struct iommu_domain *domain,
33553357

33563358
if (device == last_gdev)
33573359
break;
3358-
ops->remove_dev_pasid(device->dev, pasid, domain);
3360+
if (device->dev->iommu->max_pasids > 0)
3361+
ops->remove_dev_pasid(device->dev, pasid, domain);
33593362
}
33603363
return ret;
33613364
}
@@ -3368,8 +3371,10 @@ static void __iommu_remove_group_pasid(struct iommu_group *group,
33683371
const struct iommu_ops *ops;
33693372

33703373
for_each_group_device(group, device) {
3371-
ops = dev_iommu_ops(device->dev);
3372-
ops->remove_dev_pasid(device->dev, pasid, domain);
3374+
if (device->dev->iommu->max_pasids > 0) {
3375+
ops = dev_iommu_ops(device->dev);
3376+
ops->remove_dev_pasid(device->dev, pasid, domain);
3377+
}
33733378
}
33743379
}
33753380

@@ -3403,7 +3408,13 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
34033408

34043409
mutex_lock(&group->mutex);
34053410
for_each_group_device(group, device) {
3406-
if (pasid >= device->dev->iommu->max_pasids) {
3411+
/*
3412+
* Skip PASID validation for devices without PASID support
3413+
* (max_pasids = 0). These devices cannot issue transactions
3414+
* with PASID, so they don't affect group's PASID usage.
3415+
*/
3416+
if ((device->dev->iommu->max_pasids > 0) &&
3417+
(pasid >= device->dev->iommu->max_pasids)) {
34073418
ret = -EINVAL;
34083419
goto out_unlock;
34093420
}

0 commit comments

Comments
 (0)