Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1265604

Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in _dma_page_cpu_to_dev()

From Russell King - ARM Linux <linux@arm.linux.org.uk>
Newsgroups linux.kernel
Subject Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in _dma_page_cpu_to_dev()
Date 2015-11-09 13:10 +0100
Message-ID <qsTqO-6dw-29@gated-at.bofh.it> (permalink)
References (2 earlier) <qr3Xl-7Mx-17@gated-at.bofh.it> <qrlKy-2wU-19@gated-at.bofh.it> <qsRyG-50w-29@gated-at.bofh.it> <qsRyG-50w-27@gated-at.bofh.it> <qsRIl-55g-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in _dma_page_cpu_to_dev() Sanjeev Sharma <sanjeev_sharma@mentor.com> - 2015-11-04 11:00 +0100
  Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Will Deacon <will.deacon@arm.com> - 2015-11-04 11:40 +0100
    Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-11-04 12:00 +0100
      RE: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() "Sharma, Sanjeev" <Sanjeev_Sharma@mentor.com> - 2015-11-05 07:00 +0100
        Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Will Deacon <will.deacon@arm.com> - 2015-11-09 11:10 +0100
          RE: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() "Sharma, Sanjeev" <Sanjeev_Sharma@mentor.com> - 2015-11-09 11:20 +0100
            Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Robin Murphy <robin.murphy@arm.com> - 2015-11-09 12:00 +0100
            Re: [PATCH] ARM:dma-mapping: Handle DMA_BIDIRECTIONAL in  _dma_page_cpu_to_dev() Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-11-09 13:10 +0100

csiph-web