Linux IOMMU Development
 help / color / mirror / Atom feed
From: Vladimir Murzin <vladimir.murzin@arm.com>
To: Alexandre Torgue <alexandre.torgue@st.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Daniele Alessandrelli <daniele.alessandrelli@gmail.com>,
	Christoph Hellwig <hch@lst.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Cc: iommu@lists.linux-foundation.org, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [BUG] dma-ranges, reserved memory regions, dma_alloc_coherent: possible bug?
Date: Mon, 28 Oct 2019 10:59:03 +0000	[thread overview]
Message-ID: <2153b504-8c98-6c43-6ae3-9fb355d88417@arm.com> (raw)
In-Reply-To: <6b024e69-f612-6850-8a04-9b3049549092@st.com>

On 10/28/19 10:55 AM, Alexandre Torgue wrote:
> Hi Vlad,
> 
> On 10/24/19 5:27 PM, Vladimir Murzin wrote:
>> Hi Alex,
>>
>> On 10/24/19 4:20 PM, Alexandre Torgue wrote:
>>> Hi Vlad,
>>>
>>> On 10/24/19 2:43 PM, Vladimir Murzin wrote:
>>>> 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 :(
>>>
>>> I can make some tests tomorrow. Which particular setup I need to test: cortex M7 + cache + dma + xip ? Let me know.
>>
>> I assume xip implies dma-ranges in dt, then yes it looks like what we need.
>>
> 
> I tested your patch on stm32h7431-eval board (cortex-M7). No issues reported. I use reserved dma memory pool for dma access ( Dcache disabled) and dma_alloc_coherent is ok. Note there is no "dma-ranges" for this board.
> 
> I also tested it on stm32f469-disco (cortex-M4) which uses dma-ranges. No issues reported too. Note there is no data cache at all in this case.

Happy to hear it doesn't introduce regression for NOMM - thanks got giving it a try!

@Daniele, it'd be handy to know if that fix issue for you...

Cheers
Vladimir

> 
> regards
> 
> Alex
> 
>> Great thanks!
>>
>> Vladimir
>>
>>>
>>> regards
>>> alex
>>>
>>>>
>>>>>
>>>>> 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
>>>>
>>

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2019-10-28 10:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-13 14:28 [BUG] dma-ranges, reserved memory regions, dma_alloc_coherent: possible bug? Daniele Alessandrelli
2019-10-14 13:54 ` Robin Murphy
2019-10-14 15:01   ` Vladimir Murzin
2019-10-17  9:46     ` Vladimir Murzin
2019-10-17 10:03       ` Alexandre Torgue
2019-10-17 10:16         ` Vladimir Murzin
2019-10-17 10:33           ` Alexandre Torgue
2019-10-24 12:43       ` Vladimir Murzin
2019-10-24 15:20         ` Alexandre Torgue
2019-10-24 15:27           ` Vladimir Murzin
2019-10-28 10:55             ` Alexandre Torgue
2019-10-28 10:59               ` Vladimir Murzin [this message]
2019-10-29  9:43                 ` Daniele Alessandrelli
2019-10-29 16:52                   ` Daniele Alessandrelli
2019-10-30 10:16                     ` Vladimir Murzin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2153b504-8c98-6c43-6ae3-9fb355d88417@arm.com \
    --to=vladimir.murzin@arm.com \
    --cc=alexandre.torgue@st.com \
    --cc=arnd@arndb.de \
    --cc=daniele.alessandrelli@gmail.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=m.szyprowski@samsung.com \
    --cc=robin.murphy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox