ARM: preserve DMA_FROM_DEVICE buffer contents
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest2 patches 6 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | ARM: dma-mapping: preserve DMA_FROM_DEVICE buffer contentsarch/ arch/ arch/ +2 more | +2 | 0 replies | |
| 2/2 | ARM: dma-mapping: flush FROM_DEVICE buffers on legacy backendsarch/ arch/ arch/ +13 more | +0 | 1 reply |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/2] ARM: preserve DMA_FROM_DEVICE buffer contents
This series prevents a DMA_FROM_DEVICE map from discarding CPU-written buffer contents on non-coherent 32-bit ARM. It is based on v7.3-rc1-324-g986c24e0fe44.
ARM currently invalidates these buffers before the device writes them. If the device writes only part of a buffer, discarded dirty cache lines can expose older memory contents in the untouched bytes. A stock USB webcam demonstrated this through usbfs. Short isochronous packets left gaps, and usbfs returned non-zero data to userspace from bytes it had cleared.
arm64 changed this handoff from invalidate to clean in 2022 with commit c50f11c6196f ("arm64: mm: Don't invalidate FROM_DEVICE buffers at start of DMA transfer"). Arnd Bergmann's 2023 ARM32 cache-maintenance series left DMA_FROM_DEVICE preservation unresolved [1]. This series keeps the existing ownership hooks.
Patch 1 covers v6, v7, v7-M and the common outer-cache path. These paths already invalidate when ownership returns to the CPU. Patch 2 makes the legacy write-back backends use their existing clean-and-invalidate operation at device handoff. Their no-op ownership-return hooks remain unchanged, avoiding the additional completion traversal raised during review [2].
[1] https://lore.kernel.org/r/[email protected]
[2] https://lists.infradead.org/pipermail/linux-riscv/2023-March/029740.html
Testing:
- An ARM11 MPCore (ARMv6) in a New Nintendo 2DS XL lost 402,080 of 409,600 CPU-written bytes in a mapping-only test. With patch 1, none were lost. The UP kernel used out-of-tree platform support and the same map-time invalidate as mainline.
- On an ARM926EJ-S (ARMv5TEJ) SAM9X75, eleven mapping-only runs lost 339,936 to 351,744 of 409,600 bytes with the existing code. Five usbfs runs checked 245,708 unwritten gap bytes and exposed 29,403 of them as non-zero. With this series, five fresh 100-iteration mapping-only runs on the same board each lost 0 of 409,600 bytes.
- A Cortex-A72 running AArch32/LPAE did not reproduce the loss in 22 existing-kernel runs. This does not establish whether other v7 cores are affected.
The one-pass series passed focused W=1 object builds for ARM926, Feroceon, XScale, ARM940 and v7. The remaining legacy backends have source review and compile coverage from the previous two-pass revision.
Neither patch adds a cache traversal. Patch 2 changes the legacy DMA_FROM_DEVICE operation from invalidate to clean-and-invalidate. This can add per-line work and memory writes on dirty buffers. Throughput and CPU cost have not been measured.
Karl Mehltretter (2):
ARM: dma-mapping: preserve DMA_FROM_DEVICE buffer contents
ARM: dma-mapping: flush FROM_DEVICE buffers on legacy backends
arch/arm/mm/cache-fa.S | 1 - arch/arm/mm/cache-v4wb.S | 1 - arch/arm/mm/cache-v6.S | 2 -- arch/arm/mm/cache-v7.S | 2 -- arch/arm/mm/cache-v7m.S | 2 -- arch/arm/mm/dma-mapping-nommu.c | 5 +---- arch/arm/mm/dma-mapping.c | 8 +------- arch/arm/mm/proc-arm1020.S | 1 - arch/arm/mm/proc-arm1020e.S | 1 - arch/arm/mm/proc-arm1022.S | 1 - arch/arm/mm/proc-arm1026.S | 1 - arch/arm/mm/proc-arm920.S | 1 - arch/arm/mm/proc-arm922.S | 1 - arch/arm/mm/proc-arm925.S | 1 - arch/arm/mm/proc-arm926.S | 1 - arch/arm/mm/proc-arm940.S | 1 - arch/arm/mm/proc-arm946.S | 1 - arch/arm/mm/proc-feroceon.S | 2 -- arch/arm/mm/proc-mohawk.S | 1 - arch/arm/mm/proc-xsc3.S | 1 - arch/arm/mm/proc-xscale.S | 1 - 21 files changed, 2 insertions(+), 34 deletions(-)
Signature · 1 line
2.53.0