Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

dma-mapping: add __dma_from_device_group_begin()/end()

When a structure contains a buffer that DMA writes to alongside fields
that the CPU writes to, cache line sharing between the DMA buffer and
CPU-written fields can cause data corruption on non-cache-coherent
platforms.

Add __dma_from_device_group_begin()/end() annotations to ensure proper
alignment to prevent this:

struct my_device {
spinlock_t lock1;
__dma_from_device_group_begin();
char dma_buffer1[16];
char dma_buffer2[16];
__dma_from_device_group_end();
spinlock_t lock2;
};

Message-ID: <19163086d5e4704c316f18f6da06bc1c72968904.1767601130.git.mst@redhat.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Petr Tesarik <ptesarik@suse.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

+13
+13
include/linux/dma-mapping.h
··· 7 7 #include <linux/dma-direction.h> 8 8 #include <linux/scatterlist.h> 9 9 #include <linux/bug.h> 10 + #include <linux/cache.h> 10 11 11 12 /** 12 13 * List of possible attributes associated with a DMA mapping. The semantics ··· 703 702 return 1; 704 703 } 705 704 #endif 705 + 706 + #ifdef ARCH_HAS_DMA_MINALIGN 707 + #define ____dma_from_device_aligned __aligned(ARCH_DMA_MINALIGN) 708 + #else 709 + #define ____dma_from_device_aligned 710 + #endif 711 + /* Mark start of DMA buffer */ 712 + #define __dma_from_device_group_begin(GROUP) \ 713 + __cacheline_group_begin(GROUP) ____dma_from_device_aligned 714 + /* Mark end of DMA buffer */ 715 + #define __dma_from_device_group_end(GROUP) \ 716 + __cacheline_group_end(GROUP) ____dma_from_device_aligned 706 717 707 718 static inline void *dmam_alloc_coherent(struct device *dev, size_t size, 708 719 dma_addr_t *dma_handle, gfp_t gfp)