arc: Hardcode ARCH_DMA_MINALIGN to max line length we may have
PATCH 1/1 arc: Hardcode ARCH_DMA_MINALIGN to max line length we may have
Current implementation relies on L1 line length which might easily be smaller than L2 line (which is usually the case BTW).
Imagine this typical case: L2 line is 128 bytes while L1 line is 64-bytes. Now we want to allocate small buffer and later use it for DMA (consider IOC is not available).
kmalloc() allocates small KMALLOC_MIN_SIZE-sized, KMALLOC_MIN_SIZE-aligned That way if buffer happens to be aligned to L1 line and not L2 line we'll be flushing and invalidating extra portions of data from L2 which will cause cache coherency issues.
And since KMALLOC_MIN_SIZE is bound to ARCH_DMA_MINALIGN the fix could be simple - set ARCH_DMA_MINALIGN to the largest cache line we may ever get. As of today neither L1 of ARC700 and ARC HS38 nor SLC might not be longer than 128 bytes.
--- arch/arc/include/asm/cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arc/include/asm/cache.h +2 -1
@@ -47,7 +47,8 @@ : "r"(data), "r"(ptr)); \ }) -#define ARCH_DMA_MINALIGN L1_CACHE_BYTES +/* Largest line length for either L1 or L2 is 128 bytes */ +#define ARCH_DMA_MINALIGN 128extern void arc_cache_init (void );extern char *arc_cache_mumbojumbo (int cpu_id,char *buf,int len);
Signature · 1 line
2.7.5
Quoted 12 lines · Alexey Brodkin
Current implementation relies on L1 line length which might easily be smaller than L2 line (which is usually the case BTW).
Imagine this typical case: L2 line is 128 bytes while L1 line is 64-bytes. Now we want to allocate small buffer and later use it for DMA (consider IOC is not available).
kmalloc()allocates small KMALLOC_MIN_SIZE-sized, KMALLOC_MIN_SIZE-aligned That way if buffer happens to be aligned to L1 line and not L2 line we'll be flushing and invalidating extra portions of data from L2 which will cause cache coherency issues.
Quoted 4 lines
And since
KMALLOC_MIN_SIZEis bound toARCH_DMA_MINALIGNthe fix could be simple - setARCH_DMA_MINALIGNto the largest cache line we may ever get. As of today neither L1 of ARC700 and ARC HS38 nor SLC might not be longer than 128 bytes.
The patch itself makes sense - but is this preventive / code review thing or does it really fix soem issue at your end ?
Quoted 19 lines
Signed-off-by Alexey Brodkin <abrodkin at synopsys.com>--- arch/arc/include/asm/cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/arc/include/asm/cache.h +2
-1@@ -47,7 +47,8 @@ : "r"(data), "r"(ptr)); \ }) -#define ARCH_DMA_MINALIGN L1_CACHE_BYTES +/* Largest line length for either L1 or L2 is 128 bytes */ +#define ARCH_DMA_MINALIGN 128extern void arc_cache_init (void );extern char *arc_cache_mumbojumbo (int cpu_id,char *buf,int len);