Skip to content

Commit 9bb0a4d

Browse files
rleonmszyprow
authored andcommitted
dma-mapping: Clarify valid conditions for CPU cache line overlap
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 <[email protected]> Signed-off-by: Marek Szyprowski <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6f45b16 commit 9bb0a4d

5 files changed

Lines changed: 25 additions & 19 deletions

File tree

Documentation/core-api/dma-attributes.rst

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,17 @@ For architectures that require cache flushing for DMA coherence
149149
DMA_ATTR_MMIO will not perform any cache flushing. The address
150150
provided must never be mapped cacheable into the CPU.
151151

152-
DMA_ATTR_CPU_CACHE_CLEAN
153-
------------------------
154-
155-
This attribute indicates the CPU will not dirty any cacheline overlapping this
156-
DMA_FROM_DEVICE/DMA_BIDIRECTIONAL buffer while it is mapped. This allows
157-
multiple small buffers to safely share a cacheline without risk of data
158-
corruption, suppressing DMA debug warnings about overlapping mappings.
159-
All mappings sharing a cacheline should have this attribute.
152+
DMA_ATTR_DEBUGGING_IGNORE_CACHELINES
153+
------------------------------------
154+
155+
This attribute indicates that CPU cache lines may overlap for buffers mapped
156+
with DMA_FROM_DEVICE or DMA_BIDIRECTIONAL.
157+
158+
Such overlap may occur when callers map multiple small buffers that reside
159+
within the same cache line. In this case, callers must guarantee that the CPU
160+
will not dirty these cache lines after the mappings are established. When this
161+
condition is met, multiple buffers can safely share a cache line without risking
162+
data corruption.
163+
164+
All mappings that share a cache line must set this attribute to suppress DMA
165+
debug warnings about overlapping mappings.

drivers/virtio/virtio_ring.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,10 +2912,10 @@ EXPORT_SYMBOL_GPL(virtqueue_add_inbuf);
29122912
* @data: the token identifying the buffer.
29132913
* @gfp: how to do memory allocations (if necessary).
29142914
*
2915-
* Same as virtqueue_add_inbuf but passes DMA_ATTR_CPU_CACHE_CLEAN to indicate
2916-
* that the CPU will not dirty any cacheline overlapping this buffer while it
2917-
* is available, and to suppress overlapping cacheline warnings in DMA debug
2918-
* builds.
2915+
* Same as virtqueue_add_inbuf but passes DMA_ATTR_DEBUGGING_IGNORE_CACHELINES
2916+
* to indicate that the CPU will not dirty any cacheline overlapping this buffer
2917+
* while it is available, and to suppress overlapping cacheline warnings in DMA
2918+
* debug builds.
29192919
*
29202920
* Caller must ensure we don't call this with other virtqueue operations
29212921
* at the same time (except where noted).
@@ -2928,7 +2928,7 @@ int virtqueue_add_inbuf_cache_clean(struct virtqueue *vq,
29282928
gfp_t gfp)
29292929
{
29302930
return virtqueue_add(vq, &sg, num, 0, 1, data, NULL, false, gfp,
2931-
DMA_ATTR_CPU_CACHE_CLEAN);
2931+
DMA_ATTR_DEBUGGING_IGNORE_CACHELINES);
29322932
}
29332933
EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_cache_clean);
29342934

include/linux/dma-mapping.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@
8080
#define DMA_ATTR_MMIO (1UL << 10)
8181

8282
/*
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.
83+
* DMA_ATTR_DEBUGGING_IGNORE_CACHELINES: Indicates the CPU cache line can be
84+
* overlapped. All mappings sharing a cacheline must have this attribute for
85+
* this to be considered safe.
8686
*/
87-
#define DMA_ATTR_CPU_CACHE_CLEAN (1UL << 11)
87+
#define DMA_ATTR_DEBUGGING_IGNORE_CACHELINES (1UL << 11)
8888

8989
/*
9090
* A dma_addr_t can hold any valid DMA or bus address for the platform. It can

include/trace/events/dma.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TRACE_DEFINE_ENUM(DMA_NONE);
3333
{ DMA_ATTR_NO_WARN, "NO_WARN" }, \
3434
{ DMA_ATTR_PRIVILEGED, "PRIVILEGED" }, \
3535
{ DMA_ATTR_MMIO, "MMIO" }, \
36-
{ DMA_ATTR_CPU_CACHE_CLEAN, "CACHE_CLEAN" })
36+
{ DMA_ATTR_DEBUGGING_IGNORE_CACHELINES, "CACHELINES_OVERLAP" })
3737

3838
DECLARE_EVENT_CLASS(dma_map,
3939
TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr,

kernel/dma/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ static void add_dma_entry(struct dma_debug_entry *entry, unsigned long attrs)
601601
unsigned long flags;
602602
int rc;
603603

604-
entry->is_cache_clean = !!(attrs & DMA_ATTR_CPU_CACHE_CLEAN);
604+
entry->is_cache_clean = attrs & DMA_ATTR_DEBUGGING_IGNORE_CACHELINES;
605605

606606
bucket = get_hash_bucket(entry, &flags);
607607
hash_bucket_add(bucket, entry);

0 commit comments

Comments
 (0)