From: Ping Li <leeonion.muyu@gmail.com>
To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Ping Li <leeonion.muyu@gmail.com>
Subject: [PATCH v5 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers
Date: Wed, 25 Nov 2026 20:21:32 +0800 [thread overview]
Message-ID: <20261125122135.44696-1-leeonion.muyu@gmail.com> (raw)
In-Reply-To: <20261125115108.4147741-1-leeonion.muyu@gmail.com>
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/20261119090055.1255028-1-ping.li@horizon.auto/
[2] https://lore.kernel.org/all/sashiko-outbox-233336@kernel.org/
[3] https://lore.kernel.org/all/87o6bdz1fm.fsf@bootlin.com/
[4] https://lore.kernel.org/all/875wxl1ea6.fsf@bootlin.com/
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
--
2.34.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-11-25 12:21 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 5:50 [PATCH 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers ping.li
2026-11-23 5:50 ` [PATCH 1/3] mtd: rawnand: fsmc: declare NAND_USES_DMA ping.li
2026-11-23 6:01 ` sashiko-bot
2026-11-23 7:04 ` Ping Li
2026-11-23 5:50 ` [PATCH 2/3] mtd: rawnand: intel: " ping.li
2026-11-23 6:01 ` sashiko-bot
2026-11-23 5:50 ` [PATCH 3/3] mtd: rawnand: r852: bounce non-linear-map buffers ping.li
2026-11-23 7:04 ` [PATCH v2 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers Ping Li
2026-11-23 7:04 ` [PATCH v2 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
2026-11-23 7:04 ` [PATCH v2 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-23 7:04 ` [PATCH v2 3/3] mtd: rawnand: r852: bounce non-linear-map buffers Ping Li
2026-11-25 8:55 ` Miquel Raynal
2026-11-25 9:25 ` Ping Li
2026-11-25 9:25 ` [PATCH v3 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers Ping Li
2026-11-25 9:25 ` [PATCH v3 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
2026-11-25 9:25 ` [PATCH v3 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-25 9:25 ` [PATCH v3 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
2026-11-25 9:48 ` Miquel Raynal
2026-11-25 11:50 ` Ping Li
2026-11-25 11:51 ` [PATCH v4 0/3] mtd: rawnand: protect DMA engines from vmalloc'd buffers Ping Li
2026-11-25 11:51 ` [PATCH v4 1/3] mtd: rawnand: intel: declare NAND_USES_DMA Ping Li
2026-11-25 11:51 ` [PATCH v4 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-25 11:51 ` [PATCH v4 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
2026-11-25 12:10 ` sashiko-bot
2026-11-25 12:20 ` Miquel Raynal
2026-11-25 12:21 ` Ping Li [this message]
2026-11-25 12:21 ` [PATCH v5 1/3] mtd: rawnand: intel: " Ping Li
2026-11-25 12:21 ` [PATCH v5 2/3] mtd: rawnand: intel: unmap the DMA buffer in ebu_dma_start() Ping Li
2026-11-25 12:21 ` [PATCH v5 3/3] mtd: rawnand: r852: declare NAND_USES_DMA Ping Li
2026-11-25 12:55 ` Miquel Raynal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125122135.44696-1-leeonion.muyu@gmail.com \
--to=leeonion.muyu@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox