Skip to content

Commit f4a1477

Browse files
nicolincjgunthorpe
authored andcommitted
iommu: Use EINVAL for incompatible device/domain in ->attach_dev
Following the new rules in include/linux/iommu.h kdocs, update all drivers ->attach_dev callback functions to return EINVAL in the failure paths that are related to domain incompatibility. Also, drop adjacent error prints to prevent a kernel log spam. Link: https://lore.kernel.org/r/f52a07f7320da94afe575c9631340d0019a203a7.1666042873.git.nicolinc@nvidia.com Reviewed-by: Jean-Philippe Brucker <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent bd7ebb7 commit f4a1477

File tree

9 files changed

+9
-35
lines changed

9 files changed

+9
-35
lines changed

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,23 +2430,14 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
24302430
goto out_unlock;
24312431
}
24322432
} else if (smmu_domain->smmu != smmu) {
2433-
dev_err(dev,
2434-
"cannot attach to SMMU %s (upstream of %s)\n",
2435-
dev_name(smmu_domain->smmu->dev),
2436-
dev_name(smmu->dev));
2437-
ret = -ENXIO;
2433+
ret = -EINVAL;
24382434
goto out_unlock;
24392435
} else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
24402436
master->ssid_bits != smmu_domain->s1_cfg.s1cdmax) {
2441-
dev_err(dev,
2442-
"cannot attach to incompatible domain (%u SSID bits != %u)\n",
2443-
smmu_domain->s1_cfg.s1cdmax, master->ssid_bits);
24442437
ret = -EINVAL;
24452438
goto out_unlock;
24462439
} else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
24472440
smmu_domain->stall_enabled != master->stall_enabled) {
2448-
dev_err(dev, "cannot attach to stall-%s domain\n",
2449-
smmu_domain->stall_enabled ? "enabled" : "disabled");
24502441
ret = -EINVAL;
24512442
goto out_unlock;
24522443
}

drivers/iommu/arm/arm-smmu/arm-smmu.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,9 +1150,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
11501150
* different SMMUs.
11511151
*/
11521152
if (smmu_domain->smmu != smmu) {
1153-
dev_err(dev,
1154-
"cannot attach to SMMU %s whilst already attached to domain on SMMU %s\n",
1155-
dev_name(smmu_domain->smmu->dev), dev_name(smmu->dev));
11561153
ret = -EINVAL;
11571154
goto rpm_put;
11581155
}

drivers/iommu/arm/arm-smmu/qcom_iommu.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,8 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev
381381
* Sanity check the domain. We don't support domains across
382382
* different IOMMUs.
383383
*/
384-
if (qcom_domain->iommu != qcom_iommu) {
385-
dev_err(dev, "cannot attach to IOMMU %s while already "
386-
"attached to domain on IOMMU %s\n",
387-
dev_name(qcom_domain->iommu->dev),
388-
dev_name(qcom_iommu->dev));
384+
if (qcom_domain->iommu != qcom_iommu)
389385
return -EINVAL;
390-
}
391386

392387
return 0;
393388
}

drivers/iommu/intel/iommu.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4194,19 +4194,15 @@ static int prepare_domain_attach_device(struct iommu_domain *domain,
41944194
return -ENODEV;
41954195

41964196
if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap))
4197-
return -EOPNOTSUPP;
4197+
return -EINVAL;
41984198

41994199
/* check if this iommu agaw is sufficient for max mapped address */
42004200
addr_width = agaw_to_width(iommu->agaw);
42014201
if (addr_width > cap_mgaw(iommu->cap))
42024202
addr_width = cap_mgaw(iommu->cap);
42034203

4204-
if (dmar_domain->max_addr > (1LL << addr_width)) {
4205-
dev_err(dev, "%s: iommu width (%d) is not "
4206-
"sufficient for the mapped address (%llx)\n",
4207-
__func__, addr_width, dmar_domain->max_addr);
4208-
return -EFAULT;
4209-
}
4204+
if (dmar_domain->max_addr > (1LL << addr_width))
4205+
return -EINVAL;
42104206
dmar_domain->gaw = addr_width;
42114207

42124208
/*

drivers/iommu/ipmmu-vmsa.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
628628
* Something is wrong, we can't attach two devices using
629629
* different IOMMUs to the same domain.
630630
*/
631-
dev_err(dev, "Can't attach IPMMU %s to domain on IPMMU %s\n",
632-
dev_name(mmu->dev), dev_name(domain->mmu->dev));
633631
ret = -EINVAL;
634632
} else
635633
dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id);

drivers/iommu/omap-iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
14721472
/* only a single client device can be attached to a domain */
14731473
if (omap_domain->dev) {
14741474
dev_err(dev, "iommu domain is already attached\n");
1475-
ret = -EBUSY;
1475+
ret = -EINVAL;
14761476
goto out;
14771477
}
14781478

drivers/iommu/sprd-iommu.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,8 @@ static int sprd_iommu_attach_device(struct iommu_domain *domain,
237237
struct sprd_iommu_domain *dom = to_sprd_domain(domain);
238238
size_t pgt_size = sprd_iommu_pgt_size(domain);
239239

240-
if (dom->sdev) {
241-
pr_err("There's already a device attached to this domain.\n");
240+
if (dom->sdev)
242241
return -EINVAL;
243-
}
244242

245243
dom->pgt_va = dma_alloc_coherent(sdev->dev, pgt_size, &dom->pgt_pa, GFP_KERNEL);
246244
if (!dom->pgt_va)

drivers/iommu/tegra-gart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int gart_iommu_attach_dev(struct iommu_domain *domain,
112112
spin_lock(&gart->dom_lock);
113113

114114
if (gart->active_domain && gart->active_domain != domain) {
115-
ret = -EBUSY;
115+
ret = -EINVAL;
116116
} else if (dev_iommu_priv_get(dev) != domain) {
117117
dev_iommu_priv_set(dev, domain);
118118
gart->active_domain = domain;

drivers/iommu/virtio-iommu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,7 @@ static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev)
734734
*/
735735
ret = viommu_domain_finalise(vdev, domain);
736736
} else if (vdomain->viommu != vdev->viommu) {
737-
dev_err(dev, "cannot attach to foreign vIOMMU\n");
738-
ret = -EXDEV;
737+
ret = -EINVAL;
739738
}
740739
mutex_unlock(&vdomain->mutex);
741740

0 commit comments

Comments
 (0)