Skip to content

Commit bd7ebb7

Browse files
nicolincjgunthorpe
authored andcommitted
iommu: Regulate EINVAL in ->attach_dev callback functions
Following the new rules in include/linux/iommu.h kdocs, EINVAL now can be used to indicate that domain and device are incompatible by a caller that treats it as a soft failure and tries attaching to another domain. On the other hand, there are ->attach_dev callback functions returning it for obvious device-specific errors. They will result in some inefficiency in the caller handling routine. Update these places to corresponding errnos following the new rules. Link: https://lore.kernel.org/r/5924c03bea637f05feb2a20d624bae086b555ec5.1666042872.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 0020885 commit bd7ebb7

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

drivers/iommu/fsl_pamu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ int pamu_config_ppaace(int liodn, u32 omi, u32 stashid, int prot)
211211
ppaace->op_encode.index_ot.omi = omi;
212212
} else if (~omi != 0) {
213213
pr_debug("bad operation mapping index: %d\n", omi);
214-
return -EINVAL;
214+
return -ENODEV;
215215
}
216216

217217
/* configure stash id */

drivers/iommu/fsl_pamu_domain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,
258258
liodn = of_get_property(dev->of_node, "fsl,liodn", &len);
259259
if (!liodn) {
260260
pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node);
261-
return -EINVAL;
261+
return -ENODEV;
262262
}
263263

264264
spin_lock_irqsave(&dma_domain->domain_lock, flags);
@@ -267,7 +267,7 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,
267267
if (liodn[i] >= PAACE_NUMBER_ENTRIES) {
268268
pr_debug("Invalid liodn %d, attach device failed for %pOF\n",
269269
liodn[i], dev->of_node);
270-
ret = -EINVAL;
270+
ret = -ENODEV;
271271
break;
272272
}
273273

drivers/iommu/intel/pasid.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ int intel_pasid_alloc_table(struct device *dev)
101101

102102
might_sleep();
103103
info = dev_iommu_priv_get(dev);
104-
if (WARN_ON(!info || !dev_is_pci(dev) || info->pasid_table))
105-
return -EINVAL;
104+
if (WARN_ON(!info || !dev_is_pci(dev)))
105+
return -ENODEV;
106+
if (WARN_ON(info->pasid_table))
107+
return -EEXIST;
106108

107109
pasid_table = kzalloc(sizeof(*pasid_table), GFP_KERNEL);
108110
if (!pasid_table)

drivers/iommu/mtk_iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
609609
dom->iop = alloc_io_pgtable_ops(ARM_V7S, &dom->cfg, data);
610610
if (!dom->iop) {
611611
dev_err(data->dev, "Failed to alloc io pgtable\n");
612-
return -EINVAL;
612+
return -ENOMEM;
613613
}
614614

615615
/* Update our support page sizes bitmap */

drivers/iommu/omap-iommu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ static int omap_iommu_attach_init(struct device *dev,
14141414

14151415
odomain->num_iommus = omap_iommu_count(dev);
14161416
if (!odomain->num_iommus)
1417-
return -EINVAL;
1417+
return -ENODEV;
14181418

14191419
odomain->iommus = kcalloc(odomain->num_iommus, sizeof(*iommu),
14201420
GFP_ATOMIC);
@@ -1464,7 +1464,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
14641464

14651465
if (!arch_data || !arch_data->iommu_dev) {
14661466
dev_err(dev, "device doesn't have an associated iommu\n");
1467-
return -EINVAL;
1467+
return -ENODEV;
14681468
}
14691469

14701470
spin_lock(&omap_domain->lock);

drivers/iommu/virtio-iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ static int viommu_domain_finalise(struct viommu_endpoint *vdev,
670670
dev_err(vdev->dev,
671671
"granule 0x%lx larger than system page size 0x%lx\n",
672672
viommu_page_size, PAGE_SIZE);
673-
return -EINVAL;
673+
return -ENODEV;
674674
}
675675

676676
ret = ida_alloc_range(&viommu->domain_ids, viommu->first_domain,

0 commit comments

Comments
 (0)