iommu: Use EINVAL for incompatible device/domain in ->attach_dev
authorNicolin Chen <nicolinc@nvidia.com>
Mon, 17 Oct 2022 23:02:21 +0000 (16:02 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 1 Nov 2022 17:39:59 +0000 (14:39 -0300)
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 <jean-philippe@linaro.org>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
drivers/iommu/arm/arm-smmu/arm-smmu.c
drivers/iommu/arm/arm-smmu/qcom_iommu.c
drivers/iommu/intel/iommu.c
drivers/iommu/ipmmu-vmsa.c
drivers/iommu/omap-iommu.c
drivers/iommu/sprd-iommu.c
drivers/iommu/tegra-gart.c
drivers/iommu/virtio-iommu.c

index 6d5df91c5c465a4314f6a8bc41ec969d3d84c910..8b0a1e476d44d4f491c4ead627e240c67aa66e5c 100644 (file)
@@ -2430,23 +2430,14 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
                        goto out_unlock;
                }
        } else if (smmu_domain->smmu != smmu) {
-               dev_err(dev,
-                       "cannot attach to SMMU %s (upstream of %s)\n",
-                       dev_name(smmu_domain->smmu->dev),
-                       dev_name(smmu->dev));
-               ret = -ENXIO;
+               ret = -EINVAL;
                goto out_unlock;
        } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
                   master->ssid_bits != smmu_domain->s1_cfg.s1cdmax) {
-               dev_err(dev,
-                       "cannot attach to incompatible domain (%u SSID bits != %u)\n",
-                       smmu_domain->s1_cfg.s1cdmax, master->ssid_bits);
                ret = -EINVAL;
                goto out_unlock;
        } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
                   smmu_domain->stall_enabled != master->stall_enabled) {
-               dev_err(dev, "cannot attach to stall-%s domain\n",
-                       smmu_domain->stall_enabled ? "enabled" : "disabled");
                ret = -EINVAL;
                goto out_unlock;
        }
index 30dab1418e3ff09c0bc62d5c5058d1f37a3a197c..719fbca1fe52a0b329ccac1c3f8f1001b11194c7 100644 (file)
@@ -1150,9 +1150,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
         * different SMMUs.
         */
        if (smmu_domain->smmu != smmu) {
-               dev_err(dev,
-                       "cannot attach to SMMU %s whilst already attached to domain on SMMU %s\n",
-                       dev_name(smmu_domain->smmu->dev), dev_name(smmu->dev));
                ret = -EINVAL;
                goto rpm_put;
        }
index 3869c3ecda8cd1193cfdbeec0ac2d235ed3d04de..bfd7b51eb5dbfffab0565da800988b28e8df89bd 100644 (file)
@@ -381,13 +381,8 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev
         * Sanity check the domain. We don't support domains across
         * different IOMMUs.
         */
-       if (qcom_domain->iommu != qcom_iommu) {
-               dev_err(dev, "cannot attach to IOMMU %s while already "
-                       "attached to domain on IOMMU %s\n",
-                       dev_name(qcom_domain->iommu->dev),
-                       dev_name(qcom_iommu->dev));
+       if (qcom_domain->iommu != qcom_iommu)
                return -EINVAL;
-       }
 
        return 0;
 }
index 48cdcd0a5cf346fe8136b35ebd12b65d5546fde8..6f1a59206d2e07230973b42d4f5a8688d19dc530 100644 (file)
@@ -4194,19 +4194,15 @@ static int prepare_domain_attach_device(struct iommu_domain *domain,
                return -ENODEV;
 
        if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap))
-               return -EOPNOTSUPP;
+               return -EINVAL;
 
        /* check if this iommu agaw is sufficient for max mapped address */
        addr_width = agaw_to_width(iommu->agaw);
        if (addr_width > cap_mgaw(iommu->cap))
                addr_width = cap_mgaw(iommu->cap);
 
-       if (dmar_domain->max_addr > (1LL << addr_width)) {
-               dev_err(dev, "%s: iommu width (%d) is not "
-                       "sufficient for the mapped address (%llx)\n",
-                       __func__, addr_width, dmar_domain->max_addr);
-               return -EFAULT;
-       }
+       if (dmar_domain->max_addr > (1LL << addr_width))
+               return -EINVAL;
        dmar_domain->gaw = addr_width;
 
        /*
index 3b30c0752274fd43e13ac19908499a6fa1a65e0f..22230cc15dcd1fd17568faaeb6a2cdf3a01346d2 100644 (file)
@@ -628,8 +628,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
                 * Something is wrong, we can't attach two devices using
                 * different IOMMUs to the same domain.
                 */
-               dev_err(dev, "Can't attach IPMMU %s to domain on IPMMU %s\n",
-                       dev_name(mmu->dev), dev_name(domain->mmu->dev));
                ret = -EINVAL;
        } else
                dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id);
index 3f153f9e0ac59d1d07ec8e66a1a8dc91ae7d0999..2fd7702c6709690a770325ac52fa890ecae7410d 100644 (file)
@@ -1472,7 +1472,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
        /* only a single client device can be attached to a domain */
        if (omap_domain->dev) {
                dev_err(dev, "iommu domain is already attached\n");
-               ret = -EBUSY;
+               ret = -EINVAL;
                goto out;
        }
 
index fadd2c907222b9230b49b2ec54f6dbcfdf5914e5..e027933755989d16cc1c1ba1ad611821292b7ed2 100644 (file)
@@ -237,10 +237,8 @@ static int sprd_iommu_attach_device(struct iommu_domain *domain,
        struct sprd_iommu_domain *dom = to_sprd_domain(domain);
        size_t pgt_size = sprd_iommu_pgt_size(domain);
 
-       if (dom->sdev) {
-               pr_err("There's already a device attached to this domain.\n");
+       if (dom->sdev)
                return -EINVAL;
-       }
 
        dom->pgt_va = dma_alloc_coherent(sdev->dev, pgt_size, &dom->pgt_pa, GFP_KERNEL);
        if (!dom->pgt_va)
index e5ca3cf1a94964e1312b04703c73520a5d0b732d..ed53279d1106c437a3eb0dde68ff9beef7e3f3fd 100644 (file)
@@ -112,7 +112,7 @@ static int gart_iommu_attach_dev(struct iommu_domain *domain,
        spin_lock(&gart->dom_lock);
 
        if (gart->active_domain && gart->active_domain != domain) {
-               ret = -EBUSY;
+               ret = -EINVAL;
        } else if (dev_iommu_priv_get(dev) != domain) {
                dev_iommu_priv_set(dev, domain);
                gart->active_domain = domain;
index 0b64e7f64e68ce729f75f42f29977626e81452db..8226b4da435073c01a8417612b4a96e19bf9d9c7 100644 (file)
@@ -734,8 +734,7 @@ static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev)
                 */
                ret = viommu_domain_finalise(vdev, domain);
        } else if (vdomain->viommu != vdev->viommu) {
-               dev_err(dev, "cannot attach to foreign vIOMMU\n");
-               ret = -EXDEV;
+               ret = -EINVAL;
        }
        mutex_unlock(&vdomain->mutex);