@@ -3366,10 +3366,12 @@ static int __iommu_set_group_pasid(struct iommu_domain *domain,
3366
3366
int ret ;
3367
3367
3368
3368
for_each_group_device (group , device ) {
3369
- ret = domain -> ops -> set_dev_pasid (domain , device -> dev ,
3370
- pasid , old );
3371
- if (ret )
3372
- goto err_revert ;
3369
+ if (device -> dev -> iommu -> max_pasids > 0 ) {
3370
+ ret = domain -> ops -> set_dev_pasid (domain , device -> dev ,
3371
+ pasid , old );
3372
+ if (ret )
3373
+ goto err_revert ;
3374
+ }
3373
3375
}
3374
3376
3375
3377
return 0 ;
@@ -3379,15 +3381,18 @@ static int __iommu_set_group_pasid(struct iommu_domain *domain,
3379
3381
for_each_group_device (group , device ) {
3380
3382
if (device == last_gdev )
3381
3383
break ;
3382
- /*
3383
- * If no old domain, undo the succeeded devices/pasid.
3384
- * Otherwise, rollback the succeeded devices/pasid to the old
3385
- * domain. And it is a driver bug to fail attaching with a
3386
- * previously good domain.
3387
- */
3388
- if (!old || WARN_ON (old -> ops -> set_dev_pasid (old , device -> dev ,
3384
+ if (device -> dev -> iommu -> max_pasids > 0 ) {
3385
+ /*
3386
+ * If no old domain, undo the succeeded devices/pasid.
3387
+ * Otherwise, rollback the succeeded devices/pasid to
3388
+ * the old domain. And it is a driver bug to fail
3389
+ * attaching with a previously good domain.
3390
+ */
3391
+ if (!old ||
3392
+ WARN_ON (old -> ops -> set_dev_pasid (old , device -> dev ,
3389
3393
pasid , domain )))
3390
- iommu_remove_dev_pasid (device -> dev , pasid , domain );
3394
+ iommu_remove_dev_pasid (device -> dev , pasid , domain );
3395
+ }
3391
3396
}
3392
3397
return ret ;
3393
3398
}
@@ -3398,8 +3403,10 @@ static void __iommu_remove_group_pasid(struct iommu_group *group,
3398
3403
{
3399
3404
struct group_device * device ;
3400
3405
3401
- for_each_group_device (group , device )
3402
- iommu_remove_dev_pasid (device -> dev , pasid , domain );
3406
+ for_each_group_device (group , device ) {
3407
+ if (device -> dev -> iommu -> max_pasids > 0 )
3408
+ iommu_remove_dev_pasid (device -> dev , pasid , domain );
3409
+ }
3403
3410
}
3404
3411
3405
3412
/*
@@ -3440,7 +3447,13 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
3440
3447
3441
3448
mutex_lock (& group -> mutex );
3442
3449
for_each_group_device (group , device ) {
3443
- if (pasid >= device -> dev -> iommu -> max_pasids ) {
3450
+ /*
3451
+ * Skip PASID validation for devices without PASID support
3452
+ * (max_pasids = 0). These devices cannot issue transactions
3453
+ * with PASID, so they don't affect group's PASID usage.
3454
+ */
3455
+ if ((device -> dev -> iommu -> max_pasids > 0 ) &&
3456
+ (pasid >= device -> dev -> iommu -> max_pasids )) {
3444
3457
ret = - EINVAL ;
3445
3458
goto out_unlock ;
3446
3459
}
0 commit comments