linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Dong Aisheng <dongas86@gmail.com>
Cc: Will Deacon <will@kernel.org>,
	Dong Aisheng <aisheng.dong@nxp.com>,
	iommu@lists.linux-foundation.org,
	open list <linux-kernel@vger.kernel.org>,
	linux-mm@kvack.org,
	"moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" 
	<linux-arm-kernel@lists.infradead.org>,
	Christoph Hellwig <hch@lst.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Subject: Re: [PATCH 1/1] dma: coherent: check no-map property for arm64
Date: Mon, 14 Jun 2021 16:34:05 +0100	[thread overview]
Message-ID: <6f897830-301f-3eb4-785f-de446476e676@arm.com> (raw)
In-Reply-To: <20210614145105.GC30667@arm.com>

On 2021-06-14 15:51, Catalin Marinas wrote:
> On Mon, Jun 14, 2021 at 06:07:04PM +0800, Dong Aisheng wrote:
>> On Mon, Jun 14, 2021 at 4:36 PM Will Deacon <will@kernel.org> wrote:
>>> On Fri, Jun 11, 2021 at 09:10:56PM +0800, Dong Aisheng wrote:
>>>> Coherent dma on ARM64 also can't work with mapped system ram,
>>>> that means 'no-map' property must be specified in dts.
>>>> Add the missing check for ARM64 platforms as well.
>>>> Besides 'no-map' checking, 'linux,dma-default' feature is also
>>>> enabled for ARM64 along with this patch.

Note that the "linux,dma-default" stuff is really only for NOMMU (with 
caches), so hardly relevant to arm64.

>>> Please can you explain _why_ it can't work? We don't need to tear down
>>> aliases from the linear map for the streaming DMA API, so why is this
>>> case different? Also, coherent devices wouldn't need this either way,
>>> would they? What problem are you solving here?
>>>
>>
>> Not sure if i get your point correctly. Here is my understanding. (fix
>> me if wrong)
>> In current implementation, the coherent dma memory will be remapped as
>> writecombine and uncached type which can't reuse the linear mapping.
>> The prerequisite to do this is the memory must not be mapped System RAM.
>> e.g. reserved memory with no-map property and invisible to the buddy system.
> 
> The architecture allows the system RAM to be mapped in the linear map
> while there's another writecombine alias, as long as there are no dirty
> cache lines that could be evicted randomly. This works fine with the DMA
> API (and we have some cache maintenance when the non-cacheable mapping
> is first created).
> 
> Looking at the rmem_dma_device_init() -> dma_init_coherent_memory(), it
> ends up calling memremap(MEMREMAP_WC) which would warn if it intersects
> with system RAM regardless of the architecture. If the memory region is
> nomap, it doesn't end up as IORESOURCE_SYSTEM_RAM, so memremap() won't
> warn. But why is this specific only to arm (or arm64)?

Didn't some ARMv7 implementations permit unexpected cache hits for the 
non-cacheable address if the same PA has been speculatively fetched via 
the cacheable alias?

> Is the "shared-dma-pool" property only meant for Normal Non-cacheable
> memory (hence the MEMREMAP_WC flag)? If a system is fully cache
> coherent, does this check still make sense or the DT is not supposed to
> have such nodes?

I don't think "shared-dma-pool" carries any particular expectation 
itself of how things are mapped, especially since "reusable" effectively 
implies a cacheable mapping for 'normal' kernel usage.

Absent "reusable" to take things down the CMA path instead, "no-map" 
would currently be needed for coherent devices, since even when the CPU 
is guaranteed to bypass the cacheable alias the device can still 
inadvertently snoop it and see stale data. However if the device *is* 
coherent then it would seem more sensible to skip the remap entirely and 
just use the linear map address of the pool, unless of course it needs 
to be shared by multiple devices some of which are non-coherent... :/

>> This seems a little different from CMA which the memory is still
>> underlying managed by the buddy system in order to support migration.
>>
>> The patch here does not resolve a real issue but just open the sanity check for
>> ARM64 case as well as ARM  which reports the issue a little bit earlier at
>> rmem_dma_setup() time.
> 
> I think we first need to figure out what the real issue is and then try
> to solve it.

Agreed.

Robin.

  reply	other threads:[~2021-06-14 15:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11 13:10 [PATCH 1/1] dma: coherent: check no-map property for arm64 Dong Aisheng
2021-06-14  8:36 ` Will Deacon
2021-06-14 10:07   ` Dong Aisheng
2021-06-14 14:51     ` Catalin Marinas
2021-06-14 15:34       ` Robin Murphy [this message]
2021-06-14 15:36         ` Christoph Hellwig
2021-06-15  7:19           ` Marek Szyprowski

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=6f897830-301f-3eb4-785f-de446476e676@arm.com \
    --to=robin.murphy@arm.com \
    --cc=aisheng.dong@nxp.com \
    --cc=catalin.marinas@arm.com \
    --cc=dongas86@gmail.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=m.szyprowski@samsung.com \
    --cc=will@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).