[PATCH v2 05/11] ARM: dma-mapping: Bypass the legacy path for core-owned DMA API domains

Robin Murphy robin.murphy at arm.com
Mon Oct 19 09:55:02 PDT 2026


On 16/10/2026 7:46 am, Mikko Perttunen wrote:
> ARM's arch_setup_dma_ops / arm_setup_iommu_dma_ops creates a custom
> IOMMU domain for DMA API usage, and continues to do so when the IOMMU
> driver doesn't explicitly request a DMA default domain type.
> 
> When, however, that DMA default domain is requested and the core owns
> the domain, we need to skip our own domain management. Add checks to
> arm_setup/teardown_iommu_dma_ops for these cases. In such a case IOVAs
> can be allocated from anywhere in the domain's geometry, so also add a
> check to ensure the device's dma-ranges cover it. Presently, this is the
> case for all platforms except some OMAP platforms with a non-zero
> dma-ranges base.

It's probably worth adding some cleverness to arm_iommu_detach_device() 
as well - it might work out benign to attempt to detach from a real 
core-owned default domain, but we'll now want to set dma_ops and 
to_dma_iommu_mapping according to the default domain itself (since we'll 
now have the possibility of switching between an explicit unmanaged 
dma_iommu_mapping and the implicit default one.)

Thanks,
Robin.

> Signed-off-by: Mikko Perttunen <mperttunen at nvidia.com>
> ---
>   arch/arm/mm/dma-mapping.c | 25 ++++++++++++++++++++++++-
>   1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index f2d3e8ec3487..d6315baeddb9 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -1761,13 +1761,33 @@ EXPORT_SYMBOL_GPL(arm_iommu_detach_device);
>   
>   static void arm_setup_iommu_dma_ops(struct device *dev)
>   {
> -	struct dma_iommu_mapping *mapping;
> +	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
>   	u64 dma_base = 0, size = 1ULL << 32;
>   
>   	if (dev->dma_range_map) {
>   		dma_base = dma_range_map_min(dev->dma_range_map);
>   		size = dma_range_map_max(dev->dma_range_map) - dma_base;
>   	}
> +
> +	/*
> +	 * An existing cookie means the core owns the domain. Only set the
> +	 * per-binding DMA ops. IOVAs are allocated from the whole aperture,
> +	 * so the device's dma-ranges must cover it.
> +	 */
> +	if (mapping) {
> +		const struct iommu_domain_geometry *geo =
> +			&mapping->domain->geometry;
> +
> +		if (dma_base > geo->aperture_start ||
> +		    dma_base + size < geo->aperture_end) {
> +			dev_err(dev, "dma-ranges do not cover the IOMMU aperture\n");
> +			return;
> +		}
> +
> +		set_dma_ops(dev, &iommu_ops);
> +		return;
> +	}
> +
>   	mapping = arm_iommu_create_mapping(dev, dma_base, size);
>   	if (IS_ERR(mapping)) {
>   		pr_warn("Failed to create %llu-byte IOMMU mapping for device %s\n",
> @@ -1792,6 +1812,9 @@ static void arm_teardown_iommu_dma_ops(struct device *dev)
>   	if (!mapping)
>   		return;
>   
> +	if (!mapping->owns_domain)
> +		return;
> +
>   	arm_iommu_detach_device(dev);
>   	arm_iommu_release_mapping(mapping);
>   }
> 




More information about the linux-arm-kernel mailing list