]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dma-mapping: Clarify valid conditions for CPU cache line overlap
authorLeon Romanovsky <leonro@nvidia.com>
Mon, 16 Mar 2026 19:06:47 +0000 (21:06 +0200)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Fri, 20 Mar 2026 10:33:24 +0000 (11:33 +0100)
Rename the DMA_ATTR_CPU_CACHE_CLEAN attribute to better reflect that it
is debugging aid to inform DMA core code that CPU cache line overlaps are
allowed, and refine the documentation describing its use.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20260316-dma-debug-overlap-v3-3-1dde90a7f08b@nvidia.com
Documentation/core-api/dma-attributes.rst
drivers/virtio/virtio_ring.c
include/linux/dma-mapping.h
include/trace/events/dma.h
kernel/dma/debug.c

index 1d7bfad73b1c7a85d9b17e3c31ceb5ef6a4e8bbd..48cfe86cc06d75e3bb1feeabf5a6c0c3420351f7 100644 (file)
@@ -149,11 +149,17 @@ For architectures that require cache flushing for DMA coherence
 DMA_ATTR_MMIO will not perform any cache flushing. The address
 provided must never be mapped cacheable into the CPU.
 
-DMA_ATTR_CPU_CACHE_CLEAN
-------------------------
-
-This attribute indicates the CPU will not dirty any cacheline overlapping this
-DMA_FROM_DEVICE/DMA_BIDIRECTIONAL buffer while it is mapped. This allows
-multiple small buffers to safely share a cacheline without risk of data
-corruption, suppressing DMA debug warnings about overlapping mappings.
-All mappings sharing a cacheline should have this attribute.
+DMA_ATTR_DEBUGGING_IGNORE_CACHELINES
+------------------------------------
+
+This attribute indicates that CPU cache lines may overlap for buffers mapped
+with DMA_FROM_DEVICE or DMA_BIDIRECTIONAL.
+
+Such overlap may occur when callers map multiple small buffers that reside
+within the same cache line. In this case, callers must guarantee that the CPU
+will not dirty these cache lines after the mappings are established. When this
+condition is met, multiple buffers can safely share a cache line without risking
+data corruption.
+
+All mappings that share a cache line must set this attribute to suppress DMA
+debug warnings about overlapping mappings.
index 335692d41617a297e33c44d92733ce5820c584f3..fbca7ce1c6bf0f4d1de7387057c6be72a6adbf47 100644 (file)
@@ -2912,10 +2912,10 @@ EXPORT_SYMBOL_GPL(virtqueue_add_inbuf);
  * @data: the token identifying the buffer.
  * @gfp: how to do memory allocations (if necessary).
  *
- * Same as virtqueue_add_inbuf but passes DMA_ATTR_CPU_CACHE_CLEAN to indicate
- * that the CPU will not dirty any cacheline overlapping this buffer while it
- * is available, and to suppress overlapping cacheline warnings in DMA debug
- * builds.
+ * Same as virtqueue_add_inbuf but passes DMA_ATTR_DEBUGGING_IGNORE_CACHELINES
+ * to indicate that the CPU will not dirty any cacheline overlapping this buffer
+ * while it is available, and to suppress overlapping cacheline warnings in DMA
+ * debug builds.
  *
  * Caller must ensure we don't call this with other virtqueue operations
  * at the same time (except where noted).
@@ -2928,7 +2928,7 @@ int virtqueue_add_inbuf_cache_clean(struct virtqueue *vq,
                                    gfp_t gfp)
 {
        return virtqueue_add(vq, &sg, num, 0, 1, data, NULL, false, gfp,
-                            DMA_ATTR_CPU_CACHE_CLEAN);
+                            DMA_ATTR_DEBUGGING_IGNORE_CACHELINES);
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_cache_clean);
 
index 29973baa0581682937159106e3c5a0ede142c3e4..da44394b3a1a747846fe28e5cf188f96dca1f645 100644 (file)
 #define DMA_ATTR_MMIO          (1UL << 10)
 
 /*
- * DMA_ATTR_CPU_CACHE_CLEAN: Indicates the CPU will not dirty any cacheline
- * overlapping this buffer while it is mapped for DMA. All mappings sharing
- * a cacheline must have this attribute for this to be considered safe.
+ * DMA_ATTR_DEBUGGING_IGNORE_CACHELINES: Indicates the CPU cache line can be
+ * overlapped. All mappings sharing a cacheline must have this attribute for
+ * this to be considered safe.
  */
-#define DMA_ATTR_CPU_CACHE_CLEAN       (1UL << 11)
+#define DMA_ATTR_DEBUGGING_IGNORE_CACHELINES   (1UL << 11)
 
 /*
  * A dma_addr_t can hold any valid DMA or bus address for the platform.  It can
index 69cb3805ee81caebbd770d284651c6984e673e36..8c64bc0721fe4d81a131d620347cc1524e348515 100644 (file)
@@ -33,7 +33,7 @@ TRACE_DEFINE_ENUM(DMA_NONE);
                { DMA_ATTR_NO_WARN, "NO_WARN" }, \
                { DMA_ATTR_PRIVILEGED, "PRIVILEGED" }, \
                { DMA_ATTR_MMIO, "MMIO" }, \
-               { DMA_ATTR_CPU_CACHE_CLEAN, "CACHE_CLEAN" })
+               { DMA_ATTR_DEBUGGING_IGNORE_CACHELINES, "CACHELINES_OVERLAP" })
 
 DECLARE_EVENT_CLASS(dma_map,
        TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr,
index be207be749968ed8fa0a66cea4123dd4c5a16983..83e1cfe05f08d73e68b7ecf6b3d37b0c9e4055a2 100644 (file)
@@ -601,7 +601,7 @@ static void add_dma_entry(struct dma_debug_entry *entry, unsigned long attrs)
        unsigned long flags;
        int rc;
 
-       entry->is_cache_clean = !!(attrs & DMA_ATTR_CPU_CACHE_CLEAN);
+       entry->is_cache_clean = attrs & DMA_ATTR_DEBUGGING_IGNORE_CACHELINES;
 
        bucket = get_hash_bucket(entry, &flags);
        hash_bucket_add(bucket, entry);