[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 02/16] iommu/dma: handle MMIO path in dma_iova_link



On Mon, Aug 04, 2025 at 03:42:36PM +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@xxxxxxxxxx>
> 
> Make sure that CPU is not synced if MMIO path is taken.

Let's elaborate..

Implement DMA_ATTR_MMIO for dma_iova_link().

This will replace the hacky use of DMA_ATTR_SKIP_CPU_SYNC to avoid
touching the possibly non-KVA MMIO memory.

Also correct the incorrect caching attribute for the IOMMU, MMIO
memory should not be cachable inside the IOMMU mapping or it can
possibly create system problems. Set IOMMU_MMIO for DMA_ATTR_MMIO.

> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index ea2ef53bd4fef..399838c17b705 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -1837,13 +1837,20 @@ static int __dma_iova_link(struct device *dev, 
> dma_addr_t addr,
>               phys_addr_t phys, size_t size, enum dma_data_direction dir,
>               unsigned long attrs)
>  {
> -     bool coherent = dev_is_dma_coherent(dev);
> +     int prot;
>  
> -     if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))
> -             arch_sync_dma_for_device(phys, size, dir);
> +     if (attrs & DMA_ATTR_MMIO)
> +             prot = dma_info_to_prot(dir, false, attrs) | IOMMU_MMIO;

Yeah, exactly, we need the IOPTE on ARM to have the right cachability
or some systems might go wrong.


> +     else {
> +             bool coherent = dev_is_dma_coherent(dev);
> +
> +             if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))
> +                     arch_sync_dma_for_device(phys, size, dir);
> +             prot = dma_info_to_prot(dir, coherent, attrs);
> +     }
>  
>       return iommu_map_nosync(iommu_get_dma_domain(dev), addr, phys, size,
> -                     dma_info_to_prot(dir, coherent, attrs), GFP_ATOMIC);
> +                     prot, GFP_ATOMIC);
>  }

Hmm, I missed this in prior series, ideally the GFP_ATOMIC should be
passed in as a gfp_t here so we can use GFP_KERNEL in callers that are
able.

Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>

Jason



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.