[BUG] dma-ranges, reserved memory regions, dma_alloc_coherent: possible bug?
Vladimir Murzin
vladimir.murzin at arm.com
Thu Oct 24 12:43:19 UTC 2019
On 10/17/19 10:46 AM, Vladimir Murzin wrote:
> I'm wondering if I've missed something with diff bellow (it was a long time ago when I touched DMA)?
Any comments on that? I can only build test it, so lack of testing stopping me from sending it as a
proper patch :(
>
> diff --git a/arch/arm/mm/dma-mapping-nommu.c b/arch/arm/mm/dma-mapping-nommu.c
> index db92478..287ef89 100644
> --- a/arch/arm/mm/dma-mapping-nommu.c
> +++ b/arch/arm/mm/dma-mapping-nommu.c
> @@ -35,7 +35,7 @@ static void *arm_nommu_dma_alloc(struct device *dev, size_t size,
> unsigned long attrs)
>
> {
> - void *ret = dma_alloc_from_global_coherent(size, dma_handle);
> + void *ret = dma_alloc_from_global_coherent(dev, size, dma_handle);
>
> /*
> * dma_alloc_from_global_coherent() may fail because:
> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
> index 4a1c4fc..10918c5 100644
> --- a/include/linux/dma-mapping.h
> +++ b/include/linux/dma-mapping.h
> @@ -162,7 +162,7 @@ int dma_release_from_dev_coherent(struct device *dev, int order, void *vaddr);
> int dma_mmap_from_dev_coherent(struct device *dev, struct vm_area_struct *vma,
> void *cpu_addr, size_t size, int *ret);
>
> -void *dma_alloc_from_global_coherent(ssize_t size, dma_addr_t *dma_handle);
> +void *dma_alloc_from_global_coherent(struct device *dev, ssize_t size, dma_addr_t *dma_handle);
> int dma_release_from_global_coherent(int order, void *vaddr);
> int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *cpu_addr,
> size_t size, int *ret);
> @@ -172,7 +172,7 @@ int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *cpu_addr,
> #define dma_release_from_dev_coherent(dev, order, vaddr) (0)
> #define dma_mmap_from_dev_coherent(dev, vma, vaddr, order, ret) (0)
>
> -static inline void *dma_alloc_from_global_coherent(ssize_t size,
> +static inline void *dma_alloc_from_global_coherent(struct device *dev, ssize_t size,
> dma_addr_t *dma_handle)
> {
> return NULL;
> diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c
> index 545e386..551b0eb 100644
> --- a/kernel/dma/coherent.c
> +++ b/kernel/dma/coherent.c
> @@ -123,8 +123,9 @@ int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
> return ret;
> }
>
> -static void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem,
> - ssize_t size, dma_addr_t *dma_handle)
> +static void *__dma_alloc_from_coherent(struct device *dev,
> + struct dma_coherent_mem *mem,
> + ssize_t size, dma_addr_t *dma_handle)
> {
> int order = get_order(size);
> unsigned long flags;
> @@ -143,7 +144,7 @@ static void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem,
> /*
> * Memory was found in the coherent area.
> */
> - *dma_handle = mem->device_base + (pageno << PAGE_SHIFT);
> + *dma_handle = dma_get_device_base(dev, mem) + (pageno << PAGE_SHIFT);
> ret = mem->virt_base + (pageno << PAGE_SHIFT);
> spin_unlock_irqrestore(&mem->spinlock, flags);
> memset(ret, 0, size);
> @@ -175,17 +176,18 @@ int dma_alloc_from_dev_coherent(struct device *dev, ssize_t size,
> if (!mem)
> return 0;
>
> - *ret = __dma_alloc_from_coherent(mem, size, dma_handle);
> + *ret = __dma_alloc_from_coherent(dev, mem, size, dma_handle);
> return 1;
> }
>
> -void *dma_alloc_from_global_coherent(ssize_t size, dma_addr_t *dma_handle)
> +void *dma_alloc_from_global_coherent(struct device *dev, ssize_t size,
> + dma_addr_t *dma_handle)
> {
> if (!dma_coherent_default_memory)
> return NULL;
>
> - return __dma_alloc_from_coherent(dma_coherent_default_memory, size,
> - dma_handle);
> + return __dma_alloc_from_coherent(dev, dma_coherent_default_memory, size,
> + dma_handle);
> }
>
> static int __dma_release_from_coherent(struct dma_coherent_mem *mem,
Thanks
Vladimir
More information about the iommu
mailing list