Skip to content

mtd: rawnand: protect DMA engines from vmalloc'd buffers

Ping Li linux-mtd lkml sashiko-reviews stable 5 versions – Applied

Status from this message: Applied to nand/next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest3 patches 7 repliesApplied
  2. v43 patches 1 replySuperseded
  3. v33 patches 2 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v23 patches2 repliesSuperseded
v13 patches1 replySuperseded

Changes in v5 from the cover letter

- r852: gate NAND_USES_DMA and chip->buf_align on dev->dma_usable, as the PIO fallback path does not care about buffer addresses being linear-map or 512-byte aligned.

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/3mtd: rawnand: intel: declare NAND_USES_DMAdrivers/mtd/nand/raw/intel-nand-controller.c+1 -00 replies
2/3mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start()drivers/mtd/nand/raw/intel-nand-controller.c+4 -30 replies
3/3mtd: rawnand: r852: declare NAND_USES_DMAdrivers/mtd/nand/raw/r852.c+5 -06 replies

Reviews trailers per patch

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

Read the v5 thread

Cover letter [PATCH v5 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers

While discussing a proposal to also allocate the mtdchar read/write bounce buffers with kvmalloc() [1], an audit showed that raw NAND controllers may DMA the buffers handed by the NAND core without declaring NAND_USES_DMA, so nand_base never bounces non-linear-map buffers for them (see the use_bounce_buf logic in nand_do_read_ops()/nand_do_write_ops()).

Non-linear-map buffers are not hypothetical: mtdblock's write cache is vmalloc'ed and UBIFS passes vmalloc'ed LPT buffers to mtd_write().

intel and r852 have no protection at all; declaring NAND_USES_DMA lets nand_base bounce through chip->data_buf as the other DMA-capable controllers (arasan, denali, meson, mtk, nuvoton...) already do. r852 also advertises its 512-byte alignment requirement through chip->buf_align, so misaligned linear buffers are bounced by the core as well.

While at it, a leak in intel's ebu_dma_start() (mapping never unmapped on success, wrong device used on the error path) found during the audit is fixed as well.

Changes in v5 (following the AI review [2]):
- r852: gate NAND_USES_DMA and chip->buf_align on dev->dma_usable, as the PIO fallback path does not care about buffer addresses being linear-map or 512-byte aligned.

Changes in v4 (following Miquel's review [3]):
- r852: advertise the 512-byte alignment requirement through chip->buf_align instead of keeping a local justification; drop the code comment.

Changes in v3 (following Miquel's review [4]):
- r852: use the core bounce through NAND_USES_DMA instead of extending the local condition.
- Add Cc: stable to the three patches.

Changes in v2 (following the AI review of v1):
- Drop the fsmc patch: nothing has set host->mode since a1b1e1d5bdfe ("mtd: nand: fsmc: finally remove fsmc_nand_platform_data"), so the DMA paths are dead code and fsmc_exec_op() always takes the PIO branch.
- Fix the Fixes: tags.
- Add a fix for the ebu_dma_start() unmap problems.

[1] https://lore.kernel.org/linux-mtd/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/

Ping Li (3):
mtd: rawnand: intel: declare NAND_USES_DMA
mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start()
mtd: rawnand: r852: declare NAND_USES_DMA

 drivers/mtd/nand/raw/intel-nand-controller.c | 8 +++++---
 drivers/mtd/nand/raw/r852.c                  | 5 +++++
 2 files changed, 10 insertions(+), 3 deletions(-)

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.34.1