Skip to content

mtd: nand: stop DMA before unmapping on error and timeout paths

Samarth Narang imx linux-arm-kernel linux-arm-msm linux-mtd lkml 3 versions New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest posting 2/26 patches 0 repliesNew
  2. v2 posting 1/21 patch 2 repliesSuperseded
  3. v11 patch 2 repliesSuperseded

Changes in v2 from the cover letter

- Combined the previously submitted patches into a single series, as requested by Miquel, and included three additional drivers with similar issues (omap2, marvell, and sh_flctl).
- Removed the code comment from the gpmi patch.
- Left qpic_common and stm32_fmc2 unchanged from their earlier submissions.

Patches in v2 posting 2/2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6mtd: rawnand: gpmi: terminate the DMA chain on completion timeoutdrivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c+1 -00 replies
2/6mtd: nand: qpic_common: terminate DMA channels on transfer timeoutdrivers/mtd/nand/qpic_common.c+9 -20 replies
3/6mtd: rawnand: stm32_fmc2: retire data DMA before unmapping on errorsdrivers/mtd/nand/raw/stm32_fmc2_nand.c+8 -50 replies
4/6mtd: rawnand: omap2: terminate DMA when prefetch cannot be enableddrivers/mtd/nand/raw/omap2.c+3 -10 replies
5/6mtd: rawnand: marvell: stop DMA before unmapping on timeoutdrivers/mtd/nand/raw/marvell_nand.c+5 -40 replies
6/6mtd: rawnand: sh_flctl: use dmaengine_terminate_sync() on DMA timeoutdrivers/mtd/nand/raw/sh_flctl.c+1 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/6] mtd: nand: stop DMA before unmapping on error and timeout paths

This series addresses DMA lifecycle issues in six NAND drivers where error or timeout paths may unmap buffers before the associated DMA transfers have stopped. Some paths do not terminate the outstanding transfers, while others use dmaengine_terminate_all(), which does not guarantee that the channel has stopped before returning. The patches use dmaengine_terminate_sync() to ensure that DMA has stopped before releasing the mappings, and all affected functions already run in a context where sleeping is permitted.

These issues were identified by a research static analyzer for DMA lifecycle ordering and have not been validated on hardware. The patches have only been compile-tested on arm64 with W=1.

Changes in v2:
- Combined the previously submitted patches into a single series, as requested by Miquel, and included three additional drivers with similar issues (omap2, marvell, and sh_flctl).
- Removed the code comment from the gpmi patch.
- Left qpic_common and stm32_fmc2 unchanged from their earlier submissions.

Two questions remain for the qpic_common patch. The BAM driver warns that resetting a pipe while the attached engine is still active may cause a fatal error, so it is unclear whether the NAND controller must be stopped or reset before terminating the DMA channels. The success path also assumes that completion of the final command descriptor guarantees completion of the RX data descriptor, which may need confirmation from the hardware maintainers.

v1:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/

Samarth Narang (6):
mtd: rawnand: gpmi: terminate the DMA chain on completion timeout
mtd: nand: qpic_common: terminate DMA channels on transfer timeout
mtd: rawnand: stm32_fmc2: retire data DMA before unmapping on errors
mtd: rawnand: omap2: terminate DMA when prefetch cannot be enabled
mtd: rawnand: marvell: stop DMA before unmapping on timeout
mtd: rawnand: sh_flctl: use dmaengine_terminate_sync() on DMA timeout

 drivers/mtd/nand/qpic_common.c             | 11 +++++++++--
 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c |  1 +
 drivers/mtd/nand/raw/marvell_nand.c        |  9 +++++----
 drivers/mtd/nand/raw/omap2.c               |  4 +++-
 drivers/mtd/nand/raw/sh_flctl.c            |  2 +-
 drivers/mtd/nand/raw/stm32_fmc2_nand.c     | 13 ++++++++-----
 6 files changed, 27 insertions(+), 13 deletions(-)

base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907

Signature · 1 line
2.34.1