Skip to content

Commit 4a8d8a1

Browse files
committed
arm64: dma-mapping: Only swizzle DMA ops for IOMMU_DOMAIN_DMA
The arm64 DMA-mapping implementation sets the DMA ops to the IOMMU DMA ops if we detect that an IOMMU is present for the master and the DMA ranges are valid. In the case when the IOMMU domain for the device is not of type IOMMU_DOMAIN_DMA, then we have no business swizzling the ops, since we're not in control of the underlying address space. This patch leaves the DMA ops alone for masters attached to non-DMA IOMMU domains. Reviewed-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 829d2bd commit 4a8d8a1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

arch/arm64/mm/dma-mapping.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -835,14 +835,21 @@ static bool do_iommu_attach(struct device *dev, const struct iommu_ops *ops,
835835
* then the IOMMU core will have already configured a group for this
836836
* device, and allocated the default domain for that group.
837837
*/
838-
if (!domain || iommu_dma_init_domain(domain, dma_base, size, dev)) {
839-
pr_warn("Failed to set up IOMMU for device %s; retaining platform DMA ops\n",
840-
dev_name(dev));
841-
return false;
838+
if (!domain)
839+
goto out_err;
840+
841+
if (domain->type == IOMMU_DOMAIN_DMA) {
842+
if (iommu_dma_init_domain(domain, dma_base, size, dev))
843+
goto out_err;
844+
845+
dev->archdata.dma_ops = &iommu_dma_ops;
842846
}
843847

844-
dev->archdata.dma_ops = &iommu_dma_ops;
845848
return true;
849+
out_err:
850+
pr_warn("Failed to set up IOMMU for device %s; retaining platform DMA ops\n",
851+
dev_name(dev));
852+
return false;
846853
}
847854

848855
static void queue_iommu_attach(struct device *dev, const struct iommu_ops *ops,

0 commit comments

Comments
 (0)