Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH v2 05/13] iommu/fsl: Constrain return value of ->attach_dev()
@ 2022-09-14  5:15 Nicolin Chen
  2022-09-14  5:15 ` [PATCH v2 07/13] iommu/ipmmu-vmsa: " Nicolin Chen
  2022-09-14  5:15 ` [PATCH v2 09/13] iommu/omap: " Nicolin Chen
  0 siblings, 2 replies; 3+ messages in thread
From: Nicolin Chen @ 2022-09-14  5:15 UTC (permalink / raw)
  To: 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.

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

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 011f9ab7f743..a391ac733b5e 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -258,7 +258,7 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,
 	liodn = of_get_property(dev->of_node, "fsl,liodn", &len);
 	if (!liodn) {
 		pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node);
-		return -EINVAL;
+		return -ENODEV;
 	}
 
 	spin_lock_irqsave(&dma_domain->domain_lock, flags);
@@ -267,17 +267,21 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,
 		if (liodn[i] >= PAACE_NUMBER_ENTRIES) {
 			pr_debug("Invalid liodn %d, attach device failed for %pOF\n",
 				 liodn[i], dev->of_node);
-			ret = -EINVAL;
+			ret = -ENODEV;
 			break;
 		}
 
 		attach_device(dma_domain, liodn[i], dev);
 		ret = pamu_set_liodn(dma_domain, dev, liodn[i]);
-		if (ret)
+		if (ret) {
+			ret = -ENODEV;
 			break;
+		}
 		ret = pamu_enable_liodn(liodn[i]);
-		if (ret)
+		if (ret) {
+			ret = -ENODEV;
 			break;
+		}
 	}
 	spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
 	return ret;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 07/13] iommu/ipmmu-vmsa: Constrain return value of ->attach_dev()
  2022-09-14  5:15 [PATCH v2 05/13] iommu/fsl: Constrain return value of ->attach_dev() Nicolin Chen
@ 2022-09-14  5:15 ` Nicolin Chen
  2022-09-14  5:15 ` [PATCH v2 09/13] iommu/omap: " Nicolin Chen
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolin Chen @ 2022-09-14  5:15 UTC (permalink / raw)
  To: 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/ipmmu-vmsa.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 1d42084d0276..73e7d0c261c4 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -452,8 +452,10 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain)
 	 * Find an unused context.
 	 */
 	ret = ipmmu_domain_allocate_context(domain->mmu->root, domain);
-	if (ret < 0)
+	if (ret < 0) {
+		ret = -ENOMEM;
 		return ret;
+	}
 
 	domain->context_id = ret;
 
@@ -462,7 +464,7 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain)
 	if (!domain->iop) {
 		ipmmu_domain_free_context(domain->mmu->root,
 					  domain->context_id);
-		return -EINVAL;
+		return -ENOMEM;
 	}
 
 	ipmmu_domain_setup_context(domain);
@@ -607,7 +609,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
 
 	if (!mmu) {
 		dev_err(dev, "Cannot attach to IPMMU\n");
-		return -ENXIO;
+		return -ENODEV;
 	}
 
 	mutex_lock(&domain->mutex);
@@ -628,8 +630,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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 09/13] iommu/omap: Constrain return value of ->attach_dev()
  2022-09-14  5:15 [PATCH v2 05/13] iommu/fsl: Constrain return value of ->attach_dev() Nicolin Chen
  2022-09-14  5:15 ` [PATCH v2 07/13] iommu/ipmmu-vmsa: " Nicolin Chen
@ 2022-09-14  5:15 ` Nicolin Chen
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolin Chen @ 2022-09-14  5:15 UTC (permalink / raw)
  To: 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/omap-iommu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index d9cf2820c02e..e97ebb2c0133 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1464,15 +1464,14 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 
 	if (!arch_data || !arch_data->iommu_dev) {
 		dev_err(dev, "device doesn't have an associated iommu\n");
-		return -EINVAL;
+		return -ENODEV;
 	}
 
 	spin_lock(&omap_domain->lock);
 
 	/* 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;
 	}
 
@@ -1480,6 +1479,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 	if (ret) {
 		dev_err(dev, "failed to allocate required iommu data %d\n",
 			ret);
+		ret = -ENODEV;
 		goto init_fail;
 	}
 
@@ -1490,6 +1490,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 		ret = omap_iommu_attach(oiommu, iommu->pgtable);
 		if (ret) {
 			dev_err(dev, "can't get omap iommu: %d\n", ret);
+			ret = -ENODEV;
 			goto attach_fail;
 		}
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-14  5:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-14  5:15 [PATCH v2 05/13] iommu/fsl: Constrain return value of ->attach_dev() Nicolin Chen
2022-09-14  5:15 ` [PATCH v2 07/13] iommu/ipmmu-vmsa: " Nicolin Chen
2022-09-14  5:15 ` [PATCH v2 09/13] iommu/omap: " Nicolin Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox