Skip to content

dma-mapping: unify support for cache flushes

Arnd Bergmann linux-arm-kernel linux-csky linux-hexagon linux-m68k linux-mips linux-oxnas linux-parisc linux-riscv linux-sh linux-snps-arc linuxppc-dev lkml oe-kbuild-all openrisc sparclinux 1 version NAK

Status from this message: NAK...

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest21 patches 56 repliesNAK

Patches in v1

#Subject and filesSizeRepliesApplied
1/21openrisc: dma-mapping: flush bidirectional mappingsarch/openrisc/kernel/dma.c+8 -70 replies
2/21xtensa: dma-mapping: use normal cache invalidation rulesarch/xtensa/Kconfig arch/xtensa/include/asm/cacheflush.h arch/xtensa/kernel/pci-dma.c+8 -281 reply
3/21sparc32: flush caches in dma_sync_*for_devicearch/sparc/Kconfig arch/sparc/kernel/ioport.c+2 -20 replies
4/21microblaze: dma-mapping: skip extra DMA flushesarch/microblaze/kernel/dma.c+12 -100 replies
5/21powerpc: dma-mapping: split out cache operation logicarch/powerpc/mm/dma-noncoherent.c+63 -280 replies
6/21powerpc: dma-mapping: minimize for_cpu flushingarch/powerpc/mm/dma-noncoherent.c+4 -142 replies
7/21powerpc: dma-mapping: always clean cache in _for_device() oparch/powerpc/mm/dma-noncoherent.c+1 -200 replies
8/21riscv: dma-mapping: only invalidate after DMA, not flusharch/riscv/mm/dma-noncoherent.c+1 -15 replies
9/21riscv: dma-mapping: skip invalidation before bidirectional DMAarch/riscv/mm/dma-noncoherent.c+1 -17 replies
10/21csky: dma-mapping: skip invalidating before DMA from devicearch/csky/mm/dma-mapping.c+1 -31 reply
11/21mips: dma-mapping: skip invalidating before bidirectional DMAarch/mips/mm/dma-noncoherent.c+5 -10 replies
12/21mips: dma-mapping: split out cache operation logicarch/mips/mm/dma-noncoherent.c+30 -450 replies
13/21arc: dma-mapping: skip invalidating before bidirectional DMAarch/arc/mm/dma.c+2 -23 replies
14/21parisc: dma-mapping: use regular flush/invalidate opsarch/parisc/include/asm/cacheflush.h arch/parisc/kernel/pci-dma.c+28 -30 replies
15/21ARM: dma-mapping: always invalidate WT caches before DMAarch/arm/mm/cache-v4.S arch/arm/mm/cache-v4wt.S+8 -87 replies
16/21ARM: dma-mapping: bring back dmac_{clean,inv}_rangearch/arm/include/asm/cacheflush.h arch/arm/include/asm/glue-cache.h arch/arm/mm/cache-fa.S +22 more+95 -411 reply
17/21ARM: dma-mapping: use arch_sync_dma_for_{device,cpu}() internallyarch/arm/mm/dma-mapping.c+33 -602 replies
18/21ARM: drop SMP support for ARM11MPCorearch/arm/mach-oxnas/Kconfig arch/arm/mach-oxnas/Makefile arch/arm/mach-oxnas/headsmp.S +4 more+0 -1789 replies
19/21ARM: dma-mapping: use generic form of arch_sync_dma_* helpersarch/arm/mm/dma-mapping-nommu.c arch/arm/mm/dma-mapping.c+43 -210 replies
20/21ARM: dma-mapping: split out arch_dma_mark_clean() helperarch/arm/Kconfig arch/arm/mm/dma-mapping.c+43 -299 replies
21/21dma-mapping: replace custom code with generic implementationarch/arc/mm/dma.c arch/arm/Kconfig arch/arm/mm/dma-mapping-nommu.c +16 more+527 -3916 replies

Reviews trailers per patch

9 of 21 patches have a Reviewed-by or Acked-by.

PatchGuo RenMax FilippovConor DooleyNeil ArmstrongLinus WalleijArd BiesheuvelLad PrabhakarCatalin MarinasVineet GuptaShahab VahediPalmer Dabbelt
1/21
2/21R-b
3/21
4/21
5/21
6/21
7/21
8/21R-b R-b A-b
9/21A-b R-b R-b A-b
10/21R-b
11/21
12/21
13/21R-b T-b
14/21
15/21R-b
16/21
17/21R-b
18/21A-b A-b A-b A-b
19/21
20/21
21/21R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 11 reviewers.

Read the v1 thread

Cover letter [PATCH 00/21] dma-mapping: unify support for cache flushes

From: Arnd Bergmann <[email protected]>

After a long discussion about adding SoC specific semantics for when to flush caches in drivers/soc/ drivers that we determined to be fundamentally flawed[1], I volunteered to try to move that logic into architecture-independent code and make all existing architectures do the same thing.

As we had determined earlier, the behavior is wildly different across architectures, but most of the differences come down to either bugs (when required flushes are missing) or extra flushes that are harmless but might hurt performance.

I finally found the time to come up with an implementation of this, which starts by replacing every outlier with one of the three common options:

1. architectures without speculative prefetching (hegagon, m68k, openrisc, sh, sparc, and certain armv4 and xtensa implementations) only flush their caches before a DMA, by cleaning write-back caches (if any) before a DMA to the device, and by invalidating the caches before a DMA from a device

2. arc, microblaze, mips, nios2, sh and later xtensa now follow the normal 32-bit arm model and invalidate their writeback caches again after a DMA from the device, to remove stale cache lines that got prefetched during the DMA. arc, csky and mips used to invalidate buffers also before the bidirectional DMA, but this is now skipped whenever we know it gets invalidated again after the DMA.

3. parisc, powerpc and riscv already flushed buffers before a DMA_FROM_DEVICE, and these get moved to the arm64 behavior that does the writeback before and invalidate after both DMA_FROM_DEVICE and DMA_BIDIRECTIONAL in order to avoid the problem of accidentally leaking stale data if the DMA does not actually happen[2].

The last patch in the series replaces the architecture specific code with a shared version that implements all three based on architecture specific parameters that are almost always determined at compile time.

The difference between cases 1. and 2. is hardware specific, while between
2. and 3. we need to decide which semantics we want, but I explicitly avoid this question in my series and leave it to be decided later.

Another difference that I do not address here is what cache invalidation does for partical cache lines. On arm32, arm64 and powerpc, a partial cache line always gets written back before invalidation in order to ensure that data before or after the buffer is not discarded. On all other architectures, the assumption is cache lines are never shared between DMA buffer and data that is accessed by the CPU. If we end up always writing back dirty cache lines before a DMA (option 3 above), then this point becomes moot, otherwise we should probably address this in a follow-up series to document one behavior or the other and implement it consistently.

Please review!

Arnd

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/20220606152150.GA31568@willie-the-truck/

Arnd Bergmann (21):
openrisc: dma-mapping: flush bidirectional mappings
xtensa: dma-mapping: use normal cache invalidation rules
sparc32: flush caches in dma_sync_*for_device
microblaze: dma-mapping: skip extra DMA flushes
powerpc: dma-mapping: split out cache operation logic
powerpc: dma-mapping: minimize for_cpu flushing
powerpc: dma-mapping: always clean cache in _for_device() op
riscv: dma-mapping: only invalidate after DMA, not flush
riscv: dma-mapping: skip invalidation before bidirectional DMA
csky: dma-mapping: skip invalidating before DMA from device
mips: dma-mapping: skip invalidating before bidirectional DMA
mips: dma-mapping: split out cache operation logic
arc: dma-mapping: skip invalidating before bidirectional DMA
parisc: dma-mapping: use regular flush/invalidate ops
ARM: dma-mapping: always invalidate WT caches before DMA
ARM: dma-mapping: bring back dmac_{clean,inv}_range
ARM: dma-mapping: use arch_sync_dma_for_{device,cpu}() internally
ARM: drop SMP support for ARM11MPCore
ARM: dma-mapping: use generic form of arch_sync_dma_* helpers
ARM: dma-mapping: split out arch_dma_mark_clean() helper
dma-mapping: replace custom code with generic implementation

 arch/arc/mm/dma.c                          |  66 ++------
 arch/arm/Kconfig                           |   4 +
 arch/arm/include/asm/cacheflush.h          |  21 +++
 arch/arm/include/asm/glue-cache.h          |   4 +
 arch/arm/mach-oxnas/Kconfig                |   4 -
 arch/arm/mach-oxnas/Makefile               |   1 -
 arch/arm/mach-oxnas/headsmp.S              |  23 ---
 arch/arm/mach-oxnas/platsmp.c              |  96 -----------
 arch/arm/mach-versatile/platsmp-realview.c |   4 -
 arch/arm/mm/Kconfig                        |  19 ---
 arch/arm/mm/cache-fa.S                     |   4 +-
 arch/arm/mm/cache-nop.S                    |   6 +
 arch/arm/mm/cache-v4.S                     |  13 +-
 arch/arm/mm/cache-v4wb.S                   |   4 +-
 arch/arm/mm/cache-v4wt.S                   |  22 ++-
 arch/arm/mm/cache-v6.S                     |  35 +---
 arch/arm/mm/cache-v7.S                     |   6 +-
 arch/arm/mm/cache-v7m.S                    |   4 +-
 arch/arm/mm/dma-mapping-nommu.c            |  36 ++--
 arch/arm/mm/dma-mapping.c                  | 181 ++++++++++-----------
 arch/arm/mm/proc-arm1020.S                 |   4 +-
 arch/arm/mm/proc-arm1020e.S                |   4 +-
 arch/arm/mm/proc-arm1022.S                 |   4 +-
 arch/arm/mm/proc-arm1026.S                 |   4 +-
 arch/arm/mm/proc-arm920.S                  |   4 +-
 arch/arm/mm/proc-arm922.S                  |   4 +-
 arch/arm/mm/proc-arm925.S                  |   4 +-
 arch/arm/mm/proc-arm926.S                  |   4 +-
 arch/arm/mm/proc-arm940.S                  |   4 +-
 arch/arm/mm/proc-arm946.S                  |   4 +-
 arch/arm/mm/proc-feroceon.S                |   8 +-
 arch/arm/mm/proc-macros.S                  |   2 +
 arch/arm/mm/proc-mohawk.S                  |   4 +-
 arch/arm/mm/proc-xsc3.S                    |   4 +-
 arch/arm/mm/proc-xscale.S                  |   6 +-
 arch/arm64/mm/dma-mapping.c                |  28 ++--
 arch/csky/mm/dma-mapping.c                 |  46 +++---
 arch/hexagon/kernel/dma.c                  |  44 ++---
 arch/m68k/kernel/dma.c                     |  43 +++--
 arch/microblaze/kernel/dma.c               |  38 ++---
 arch/mips/mm/dma-noncoherent.c             |  75 +++------
 arch/nios2/mm/dma-mapping.c                |  57 +++----
 arch/openrisc/kernel/dma.c                 |  62 ++++---
 arch/parisc/include/asm/cacheflush.h       |   6 +-
 arch/parisc/kernel/pci-dma.c               |  33 +++-
 arch/powerpc/mm/dma-noncoherent.c          |  76 +++++----
 arch/riscv/mm/dma-noncoherent.c            |  51 +++---
 arch/sh/kernel/dma-coherent.c              |  43 +++--
 arch/sparc/Kconfig                         |   2 +-
 arch/sparc/kernel/ioport.c                 |  38 +++--
 arch/xtensa/Kconfig                        |   1 -
 arch/xtensa/include/asm/cacheflush.h       |   6 +-
 arch/xtensa/kernel/pci-dma.c               |  47 +++---
 include/linux/dma-sync.h                   | 107 ++++++++++++
 54 files changed, 721 insertions(+), 699 deletions(-)
 delete mode 100644 arch/arm/mach-oxnas/headsmp.S
 delete mode 100644 arch/arm/mach-oxnas/platsmp.c
 create mode 100644 include/linux/dma-sync.h
Signature · 43 lines
2.39.2

Cc: Vineet Gupta <[email protected]>
Cc: Russell King <[email protected]>
Cc: Neil Armstrong <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Guo Ren <[email protected]>
Cc: Brian Cain <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Thomas Bogendoerfer <[email protected]>
Cc: Dinh Nguyen <[email protected]>
Cc: Stafford Horne <[email protected]>
Cc: Helge Deller <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Paul Walmsley <[email protected]>
Cc: Palmer Dabbelt <[email protected]>
Cc: Rich Felker <[email protected]>
Cc: John Paul Adrian Glaubitz <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Robin Murphy <[email protected]>
Cc: Lad Prabhakar <[email protected]>
Cc: Conor Dooley <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]