Commit 03d70617 authored by Andrew Lewis's avatar Andrew Lewis Committed by Paul Mackerras

powerpc: Prevent memory corruption due to cache invalidation of unaligned DMA buffer

On PowerPC processors with non-coherent cache architectures the DMA
subsystem calls invalidate_dcache_range() before performing a DMA read
operation.  If the address and length of the DMA buffer are not aligned
to a cache-line boundary this can result in memory outside of the DMA
buffer being invalidated in the cache.  If this memory has an
uncommitted store then the data will be lost and a subsequent read of
that address will result in an old value being returned from main memory.

Only when the DMA buffer starts on a cache-line boundary and is an exact
mutiple of the cache-line size can invalidate_dcache_range() be called,
otherwise flush_dcache_range() must be called.  flush_dcache_range()
will first flush uncommitted writes, and then invalidate the cache.

Signed-off-by: Andrew Lewis <andrew-lewis at netspace.net.au>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 9d4ae9fc
...@@ -348,7 +348,14 @@ void __dma_sync(void *vaddr, size_t size, int direction) ...@@ -348,7 +348,14 @@ void __dma_sync(void *vaddr, size_t size, int direction)
switch (direction) { switch (direction) {
case DMA_NONE: case DMA_NONE:
BUG(); BUG();
case DMA_FROM_DEVICE: /* invalidate only */ case DMA_FROM_DEVICE:
/*
* invalidate only when cache-line aligned otherwise there is
* the potential for discarding uncommitted data from the cache
*/
if ((start & (L1_CACHE_BYTES - 1)) || (size & (L1_CACHE_BYTES - 1)))
flush_dcache_range(start, end);
else
invalidate_dcache_range(start, end); invalidate_dcache_range(start, end);
break; break;
case DMA_TO_DEVICE: /* writeback only */ case DMA_TO_DEVICE: /* writeback only */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment