Skip to content

Commit

Permalink
iommu: Regulate EINVAL in ->attach_dev callback functions
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nicolinc authored and jgunthorpe committed Nov 1, 2022
1 parent 0020885 commit bd7ebb7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion drivers/iommu/fsl_pamu.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int pamu_config_ppaace(int liodn, u32 omi, u32 stashid, int prot)
ppaace->op_encode.index_ot.omi = omi;
} else if (~omi != 0) {
pr_debug("bad operation mapping index: %d\n", omi);
return -EINVAL;
return -ENODEV;
}

/* configure stash id */
Expand Down
4 changes: 2 additions & 2 deletions drivers/iommu/fsl_pamu_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -267,7 +267,7 @@ 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;
}

Expand Down
6 changes: 4 additions & 2 deletions drivers/iommu/intel/pasid.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ int intel_pasid_alloc_table(struct device *dev)

might_sleep();
info = dev_iommu_priv_get(dev);
if (WARN_ON(!info || !dev_is_pci(dev) || info->pasid_table))
return -EINVAL;
if (WARN_ON(!info || !dev_is_pci(dev)))
return -ENODEV;
if (WARN_ON(info->pasid_table))
return -EEXIST;

pasid_table = kzalloc(sizeof(*pasid_table), GFP_KERNEL);
if (!pasid_table)
Expand Down
2 changes: 1 addition & 1 deletion drivers/iommu/mtk_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
dom->iop = alloc_io_pgtable_ops(ARM_V7S, &dom->cfg, data);
if (!dom->iop) {
dev_err(data->dev, "Failed to alloc io pgtable\n");
return -EINVAL;
return -ENOMEM;
}

/* Update our support page sizes bitmap */
Expand Down
4 changes: 2 additions & 2 deletions drivers/iommu/omap-iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ static int omap_iommu_attach_init(struct device *dev,

odomain->num_iommus = omap_iommu_count(dev);
if (!odomain->num_iommus)
return -EINVAL;
return -ENODEV;

odomain->iommus = kcalloc(odomain->num_iommus, sizeof(*iommu),
GFP_ATOMIC);
Expand Down Expand Up @@ -1464,7 +1464,7 @@ 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);
Expand Down
2 changes: 1 addition & 1 deletion drivers/iommu/virtio-iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ static int viommu_domain_finalise(struct viommu_endpoint *vdev,
dev_err(vdev->dev,
"granule 0x%lx larger than system page size 0x%lx\n",
viommu_page_size, PAGE_SIZE);
return -EINVAL;
return -ENODEV;
}

ret = ida_alloc_range(&viommu->domain_ids, viommu->first_domain,
Expand Down

0 comments on commit bd7ebb7

Please sign in to comment.