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

asm-generic: Add memory barrier dma_mb()

The memory barrier dma_mb() is introduced by commit a76a37777f2c
("iommu/arm-smmu-v3: Ensure queue is read after updating prod pointer"),
which is used to ensure that prior (both reads and writes) accesses
to memory by a CPU are ordered w.r.t. a subsequent MMIO write.

Reviewed-by: Arnd Bergmann <arnd@arndb.de> # for asm-generic
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Marco Elver <elver@google.com>
Link: https://lore.kernel.org/r/20220523113126.171714-2-wangkefeng.wang@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Kefeng Wang and committed by
Will Deacon
ed59dfd9 a111daf0

+14 -5
+6 -5
Documentation/memory-barriers.txt
··· 1894 1894 1895 1895 (*) dma_wmb(); 1896 1896 (*) dma_rmb(); 1897 + (*) dma_mb(); 1897 1898 1898 1899 These are for use with consistent memory to guarantee the ordering 1899 1900 of writes or reads of shared memory accessible to both the CPU and a ··· 1926 1925 The dma_rmb() allows us guarantee the device has released ownership 1927 1926 before we read the data from the descriptor, and the dma_wmb() allows 1928 1927 us to guarantee the data is written to the descriptor before the device 1929 - can see it now has ownership. Note that, when using writel(), a prior 1930 - wmb() is not needed to guarantee that the cache coherent memory writes 1931 - have completed before writing to the MMIO region. The cheaper 1932 - writel_relaxed() does not provide this guarantee and must not be used 1933 - here. 1928 + can see it now has ownership. The dma_mb() implies both a dma_rmb() and 1929 + a dma_wmb(). Note that, when using writel(), a prior wmb() is not needed 1930 + to guarantee that the cache coherent memory writes have completed before 1931 + writing to the MMIO region. The cheaper writel_relaxed() does not provide 1932 + this guarantee and must not be used here. 1934 1933 1935 1934 See the subsection "Kernel I/O barrier effects" for more information on 1936 1935 relaxed I/O accessors and the Documentation/core-api/dma-api.rst file for
+8
include/asm-generic/barrier.h
··· 38 38 #define wmb() do { kcsan_wmb(); __wmb(); } while (0) 39 39 #endif 40 40 41 + #ifdef __dma_mb 42 + #define dma_mb() do { kcsan_mb(); __dma_mb(); } while (0) 43 + #endif 44 + 41 45 #ifdef __dma_rmb 42 46 #define dma_rmb() do { kcsan_rmb(); __dma_rmb(); } while (0) 43 47 #endif ··· 67 63 68 64 #ifndef wmb 69 65 #define wmb() mb() 66 + #endif 67 + 68 + #ifndef dma_mb 69 + #define dma_mb() mb() 70 70 #endif 71 71 72 72 #ifndef dma_rmb