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_ATTR_CPU_CACHE_CLEAN

When multiple small DMA_FROM_DEVICE or DMA_BIDIRECTIONAL buffers share a
cacheline, and DMA_API_DEBUG is enabled, we get this warning:
cacheline tracking EEXIST, overlapping mappings aren't supported.

This is because when one of the mappings is removed, while another one
is active, CPU might write into the buffer.

Add an attribute for the driver to promise not to do this, making the
overlapping safe, and suppressing the warning.

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

+9 -1
+7
include/linux/dma-mapping.h
··· 80 80 #define DMA_ATTR_MMIO (1UL << 10) 81 81 82 82 /* 83 + * DMA_ATTR_CPU_CACHE_CLEAN: Indicates the CPU will not dirty any cacheline 84 + * overlapping this buffer while it is mapped for DMA. All mappings sharing 85 + * a cacheline must have this attribute for this to be considered safe. 86 + */ 87 + #define DMA_ATTR_CPU_CACHE_CLEAN (1UL << 11) 88 + 89 + /* 83 90 * A dma_addr_t can hold any valid DMA or bus address for the platform. It can 84 91 * be given to a device to use as a DMA source or target. It is specific to a 85 92 * given device and there may be a translation between the CPU physical address
+2 -1
kernel/dma/debug.c
··· 595 595 if (rc == -ENOMEM) { 596 596 pr_err_once("cacheline tracking ENOMEM, dma-debug disabled\n"); 597 597 global_disable = true; 598 - } else if (rc == -EEXIST && !(attrs & DMA_ATTR_SKIP_CPU_SYNC) && 598 + } else if (rc == -EEXIST && 599 + !(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_CPU_CACHE_CLEAN)) && 599 600 !(IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && 600 601 is_swiotlb_active(entry->dev))) { 601 602 err_printk(entry->dev, entry,