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

dma-mapping: fix sync_single_range_* DMA debugging

Commit 5fd75a7850b5 (dma-mapping: remove unnecessary sync_single_range_*
in dma_map_ops) unified not only the dma_map_ops but also the
corresponding debug_dma_sync_* calls. This led to spurious WARN()ings
like the following because the DMA debug code was no longer able to detect
the DMA buffer base address without the separate offset parameter:

WARNING: at lib/dma-debug.c:911 check_sync+0xce/0x446()
firewire_ohci 0000:04:00.0: DMA-API: device driver tries to sync DMA memory it has not allocated [device address=0x00000000cedaa400] [size=1024 bytes]
Call Trace: ...
[<ffffffff811326a5>] check_sync+0xce/0x446
[<ffffffff81132ad9>] debug_dma_sync_single_for_device+0x39/0x3b
[<ffffffffa01d6e6a>] ohci_queue_iso+0x4f3/0x77d [firewire_ohci]
...

To fix this, unshare the sync_single_* and sync_single_range_*
implementations so that we are able to call the correct debug_dma_sync_*
functions.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Clemens Ladisch and committed by
Linus Torvalds
07a72309 1a4ceab1

+12 -2
+12 -2
include/asm-generic/dma-mapping-common.h
··· 123 123 size_t size, 124 124 enum dma_data_direction dir) 125 125 { 126 - dma_sync_single_for_cpu(dev, addr + offset, size, dir); 126 + const struct dma_map_ops *ops = get_dma_ops(dev); 127 + 128 + BUG_ON(!valid_dma_direction(dir)); 129 + if (ops->sync_single_for_cpu) 130 + ops->sync_single_for_cpu(dev, addr + offset, size, dir); 131 + debug_dma_sync_single_range_for_cpu(dev, addr, offset, size, dir); 127 132 } 128 133 129 134 static inline void dma_sync_single_range_for_device(struct device *dev, ··· 137 132 size_t size, 138 133 enum dma_data_direction dir) 139 134 { 140 - dma_sync_single_for_device(dev, addr + offset, size, dir); 135 + const struct dma_map_ops *ops = get_dma_ops(dev); 136 + 137 + BUG_ON(!valid_dma_direction(dir)); 138 + if (ops->sync_single_for_device) 139 + ops->sync_single_for_device(dev, addr + offset, size, dir); 140 + debug_dma_sync_single_range_for_device(dev, addr, offset, size, dir); 141 141 } 142 142 143 143 static inline void