linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: "Sharma, Sanjeev" <Sanjeev_Sharma@mentor.com>
Cc: Will Deacon <will.deacon@arm.com>,
	sanjeev sharma <sanjeevsharmaengg@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"m.szyprowski@samsung.com" <m.szyprowski@samsung.com>
Subject: Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in _dma_page_cpu_to_dev()
Date: Mon, 9 Nov 2015 12:00:17 +0000	[thread overview]
Message-ID: <20151109120017.GY8644@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <FDC088D3B5555644AE135ED28A7ABDE98636BE5D@EU-MBX-02.mgc.mentorg.com>

On Mon, Nov 09, 2015 at 10:15:34AM +0000, Sharma, Sanjeev wrote:
> It may cause the following issue.
> 1.we create the buffer with cache, and in some cases, the cache may be dirty.
> 2.then we call the sync_for_device function with flag DMA_BIDIRECTIONAL to
> avoid some cache problems.

This is wrong.  Please read the DMA-API document on proper use of these
functions.  Enable CONFIG_DMA_API_DEBUG as well.

> 3. however __dma_page_cpu_to_dev() just see DMA_BIDIRECTIONAL the same as 
> DMA_TO_DEVICE, which means the kernel will not invalid the cache if we use
> the flag DMA_BIDIRECTIONAL.
> 4.since the dirty cache is not invalid, the dirty content may be showed on
> the buffer in the future rendering.

This is again wrong.  __dma_page_cpu_to_dev() with DMA_BIDIRECTIONAL will
_clean_ the cache, which means it will push out all the dirty content
in the cache.  However, it leaves the data in the cache in case we want
to read it later (for the FROM_DEVICE.)

It is _invalid_ to read from the mapping while the device owns it, and
as Cortex CPUs speculatively prefetch, you can end up with new cach
lines allocated in this memory region.  So, before reading the memory,
you _must_ either unmap the DMA buffer, or call dma_sync_for_cpu().
Either of those two functions will then invalidate the cache for a
DMA_BIDIRECTIONAL mapping, allowing you to safely read the data.

-- 
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

      parent reply	other threads:[~2015-11-09 12:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-04  9:56 [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in _dma_page_cpu_to_dev() Sanjeev Sharma
2015-11-04 10:39 ` Will Deacon
2015-11-04 10:54   ` Russell King - ARM Linux
2015-11-05  5:56     ` Sharma, Sanjeev
     [not found]       ` <CAGUYZuQDiH_xzinEJ952rw9GuA9oUQSNASaNdOE1x_i97XCBrw@mail.gmail.com>
2015-11-09 10:08         ` Will Deacon
2015-11-09 10:15           ` Sharma, Sanjeev
2015-11-09 10:50             ` Robin Murphy
2015-11-09 12:00             ` Russell King - ARM Linux [this message]

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=20151109120017.GY8644@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=Sanjeev_Sharma@mentor.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=sanjeevsharmaengg@gmail.com \
    --cc=will.deacon@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;
as well as URLs for NNTP newsgroup(s).