linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 06/13] iommu/intel: Constrain return value of ->attach_dev()
@ 2022-09-14  5:15 Nicolin Chen
  0 siblings, 0 replies; only message in thread
From: Nicolin Chen @ 2022-09-14  5:15 UTC (permalink / raw)
  To: dwmw2, baolu.lu, joro, will, robin.murphy
  Cc: jgg, kevin.tian, iommu, linux-kernel

Ensure attach_dev() callback functions only return errno values expected
from the attach_dev() op. In particular, only return -EINVAL when we are
sure that the device is incompatible with the domain.

Also drop any dev_err next to -EINVAL, following the attach_dev op kdocs.

Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
 drivers/iommu/intel/iommu.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 1f2cd43cf9bc..34a54b74899e 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2457,8 +2457,10 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
 		return -ENODEV;
 
 	ret = domain_attach_iommu(domain, iommu);
-	if (ret)
+	if (ret) {
+		ret = -ENODEV;
 		return ret;
+	}
 	info->domain = domain;
 	spin_lock_irqsave(&domain->lock, flags);
 	list_add(&info->link, &domain->devices);
@@ -2470,6 +2472,7 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
 		if (ret) {
 			dev_err(dev, "PASID table allocation failed\n");
 			dmar_remove_one_dev_info(dev);
+			ret = -ENOMEM;
 			return ret;
 		}
 
@@ -2486,6 +2489,7 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
 		if (ret) {
 			dev_err(dev, "Setup RID2PASID failed\n");
 			dmar_remove_one_dev_info(dev);
+			ret = -ENODEV;
 			return ret;
 		}
 	}
@@ -2494,6 +2498,7 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
 	if (ret) {
 		dev_err(dev, "Domain context map failed\n");
 		dmar_remove_one_dev_info(dev);
+		ret = -ENODEV;
 		return ret;
 	}
 
@@ -4158,19 +4163,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;
 
 	/*
-- 
2.17.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-14  5:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14  5:15 [PATCH v2 06/13] iommu/intel: Constrain return value of ->attach_dev() Nicolin Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).