linux-embedded.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: dma_unmap_single() lacking cache sync on some archs?
@ 2011-09-27 12:13 Arvid Brodin
  2011-09-27 16:55 ` Håvard Skinnemoen
  0 siblings, 1 reply; 4+ messages in thread
From: Arvid Brodin @ 2011-09-27 12:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-embedded, Hans-Christian Egtvedt, Haavard Skinnemoen, arnd

[Resending with CC to affected parties]

Hi,

I would expect cache synchronization for DMA_TO_DEVICE and DMA_BIDIRECTIONAL
when dma_map_single() is called, and for DMA_FROM_DEVICE and DMA_BIDIRECTIONAL
when dma_unmap_single() is called.

However, on some architechtures (at least avr32, blackfin, ...), cache
synchronization only happens when dma_map_single() is called (and then
irrespective of DMA direction). dma_unmap_single() is a no-op for these archs.

See e.g. http://lxr.linux.no/#linux+v3.0.4/arch/avr32/include/asm/dma-mapping.h#L117

Isn't this a bug?

(Please CC me in responses.)

-- 
Arvid Brodin
Enea Services Stockholm AB

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: dma_unmap_single() lacking cache sync on some archs?
  2011-09-27 12:13 dma_unmap_single() lacking cache sync on some archs? Arvid Brodin
@ 2011-09-27 16:55 ` Håvard Skinnemoen
  2011-09-27 18:27   ` Arnd Bergmann
  2011-09-29 18:56   ` Arvid Brodin
  0 siblings, 2 replies; 4+ messages in thread
From: Håvard Skinnemoen @ 2011-09-27 16:55 UTC (permalink / raw)
  To: Arvid Brodin; +Cc: linux-kernel, linux-embedded, Hans-Christian Egtvedt, arnd

Hi,

On Tue, Sep 27, 2011 at 5:13 AM, Arvid Brodin <arvid.brodin@enea.com> wrote:
> [Resending with CC to affected parties]
>
> Hi,
>
> I would expect cache synchronization for DMA_TO_DEVICE and DMA_BIDIRECTIONAL
> when dma_map_single() is called, and for DMA_FROM_DEVICE and DMA_BIDIRECTIONAL
> when dma_unmap_single() is called.
>
> However, on some architechtures (at least avr32, blackfin, ...), cache
> synchronization only happens when dma_map_single() is called (and then
> irrespective of DMA direction). dma_unmap_single() is a no-op for these archs.
>
> See e.g. http://lxr.linux.no/#linux+v3.0.4/arch/avr32/include/asm/dma-mapping.h#L117
>
> Isn't this a bug?

I don't think so. What do other architectures do?

We always need to sync before the transfer because if there is dirty
data in the cache, it might get written to RAM during the transfer,
which would be bad. Then, since the relevant cache lines are already
clean and invalid, and the CPU is not allowed to access the buffer
during the transfer, there's no need to sync again when the transfer
is complete.

Havard

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: dma_unmap_single() lacking cache sync on some archs?
  2011-09-27 16:55 ` Håvard Skinnemoen
@ 2011-09-27 18:27   ` Arnd Bergmann
  2011-09-29 18:56   ` Arvid Brodin
  1 sibling, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2011-09-27 18:27 UTC (permalink / raw)
  To: Håvard Skinnemoen
  Cc: Arvid Brodin, linux-kernel, linux-embedded,
	Hans-Christian Egtvedt

On Tuesday 27 September 2011 09:55:02 Håvard Skinnemoen wrote:
> 
> On Tue, Sep 27, 2011 at 5:13 AM, Arvid Brodin <arvid.brodin@enea.com> wrote:
> > [Resending with CC to affected parties]
> >
> > Hi,
> >
> > I would expect cache synchronization for DMA_TO_DEVICE and DMA_BIDIRECTIONAL
> > when dma_map_single() is called, and for DMA_FROM_DEVICE and DMA_BIDIRECTIONAL
> > when dma_unmap_single() is called.
> >
> > However, on some architechtures (at least avr32, blackfin, ...), cache
> > synchronization only happens when dma_map_single() is called (and then
> > irrespective of DMA direction). dma_unmap_single() is a no-op for these archs.
> >
> > See e.g. http://lxr.linux.no/#linux+v3.0.4/arch/avr32/include/asm/dma-mapping.h#L117
> >
> > Isn't this a bug?
> 
> I don't think so. What do other architectures do?
> 
> We always need to sync before the transfer because if there is dirty
> data in the cache, it might get written to RAM during the transfer,
> which would be bad. Then, since the relevant cache lines are already
> clean and invalid, and the CPU is not allowed to access the buffer
> during the transfer, there's no need to sync again when the transfer
> is complete.

On some architectures, e.g. ARMv6 and higher, a speculative prefetch might
cause cache lines to be read again while an inbound DMA is on its way.
On those architectures you need to discard cache lines before reading from
the buffer. In fact also for DMA_FROM_DEVICE you need to flush or invalidate
the cache for the buffer before the transfer and invalidate the cache again
after the transfer.

Most architectures however do not require this.

	Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: dma_unmap_single() lacking cache sync on some archs?
  2011-09-27 16:55 ` Håvard Skinnemoen
  2011-09-27 18:27   ` Arnd Bergmann
@ 2011-09-29 18:56   ` Arvid Brodin
  1 sibling, 0 replies; 4+ messages in thread
From: Arvid Brodin @ 2011-09-29 18:56 UTC (permalink / raw)
  To: Håvard Skinnemoen
  Cc: linux-kernel, linux-embedded, Hans-Christian Egtvedt, arnd

Håvard Skinnemoen wrote:
> Hi,
> 
> On Tue, Sep 27, 2011 at 5:13 AM, Arvid Brodin <arvid.brodin@enea.com> wrote:
>> [Resending with CC to affected parties]
>>
>> Hi,
>>
>> I would expect cache synchronization for DMA_TO_DEVICE and DMA_BIDIRECTIONAL
>> when dma_map_single() is called, and for DMA_FROM_DEVICE and DMA_BIDIRECTIONAL
>> when dma_unmap_single() is called.
>>
>> However, on some architechtures (at least avr32, blackfin, ...), cache
>> synchronization only happens when dma_map_single() is called (and then
>> irrespective of DMA direction). dma_unmap_single() is a no-op for these archs.
>>
>> See e.g. http://lxr.linux.no/#linux+v3.0.4/arch/avr32/include/asm/dma-mapping.h#L117
>>
>> Isn't this a bug?
> 
> I don't think so. What do other architectures do?
> 
> We always need to sync before the transfer because if there is dirty
> data in the cache, it might get written to RAM during the transfer,
> which would be bad. Then, since the relevant cache lines are already
> clean and invalid, and the CPU is not allowed to access the buffer
> during the transfer, there's no need to sync again when the transfer
> is complete.

I see. Thanks for the explanation!

> 
> Havard

-- 
Arvid Brodin
Enea Services Stockholm AB

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-29 18:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-27 12:13 dma_unmap_single() lacking cache sync on some archs? Arvid Brodin
2011-09-27 16:55 ` Håvard Skinnemoen
2011-09-27 18:27   ` Arnd Bergmann
2011-09-29 18:56   ` Arvid Brodin

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).