From: sashiko-bot@kernel.org
To: ping.li <leeonion.muyu@gmail.com>,
miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH 2/3] mtd: rawnand: intel: declare NAND_USES_DMA
Date: Mon, 23 Nov 2026 06:01:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-228749@kernel.org> (raw)
In-Reply-To: <20261123055020.1995251-3-ping.li@horizon.auto>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mtd: rawnand: intel: Fixes tag cites mtdchar instead of driver
commit
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] mtd: rawnand: intel: DMA mapping leak and invalid unmap in
ebu_dma_start() [1]
--
commit 414432fa9d307fa5e3ae8ecf35d7868fc7b41467
Author: Ping Li <leeonion.muyu@gmail.com>
> mtd: rawnand: intel: declare NAND_USES_DMA
>
> ebu_nand_read_page_hwecc()/ebu_nand_write_page_hwecc() feed the
> page buffers provided by the NAND core straight to the DMA
> engine, but the driver never declares NAND_USES_DMA. Because of
> this, nand_base cannot know the controller DMAs these buffers and
> never bounces non-linear-map ones (see the use_bounce_buf logic
> in nand_do_read_ops()/nand_do_write_ops()).
>
> Since the mtdchar MEMREAD/MEMWRITE ioctls allocate their buffers
> with kvmalloc(), a heavily fragmented system can already feed a
> vmalloc'd buffer into the controller's DMA engine, which is not a
> valid dma_map_single() input.
>
> Declare NAND_USES_DMA so that nand_base bounces non-linear-map
> buffers through chip->data_buf, as the other DMA-capable
> controllers already do.
>
> Fixes: 83208e106a8e8 ("mtdchar: use kvmalloc() for potentially large allocations")
> Signed-off-by: Ping Li <leeonion.muyu@gmail.com>
[Severity: Low]
Should the Fixes: tag point to 0b1039f016e8 ("mtd: rawnand: Add NAND
controller support on Intel LGM SoC") instead? Upper MTD layers such as
UBI, JFFS2, and mtdblock already pass vmalloc() buffers to mtd_read() and
mtd_write(), so the missing NAND_USES_DMA flag has been an issue since the
driver was introduced.
> diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c b/drivers/mtd/nand/raw/intel-nand-controller.c
> index cfb4b231e0672..1f493fb426d61 100644
> --- a/drivers/mtd/nand/raw/intel-nand-controller.c
> +++ b/drivers/mtd/nand/raw/intel-nand-controller.c
> @@ -688,6 +688,7 @@ static int ebu_nand_probe(struct platform_device *pdev)
> nand = &ebu_host->chip;
> nand->controller = &ebu_host->controller;
> nand->controller->ops = &ebu_nand_controller_ops;
> + nand->options |= NAND_USES_DMA;
>
> /* Scan to find existence of the device */
> ret = nand_scan(&ebu_host->chip, 1);
[Severity: Critical]
This problem wasn't introduced by this patch, but does ebu_dma_start()
leak buf_dma on the success path and unmap the wrong device on error
[1]?
drivers/mtd/nand/raw/intel-nand-controller.c:ebu_dma_start() {
...
dma_dev = dmaengine_get_dma_device(chan);
buf_dma = dma_map_single(dma_dev, (void *)buf, len, dir);
if (dma_mapping_error(dma_dev, buf_dma)) {
dev_err(ebu_host->dev, "Failed to map DMA buffer\n");
ret = -EIO;
goto err_unmap;
}
...
return 0;
err_unmap:
dma_unmap_single(ebu_host->dev, buf_dma, len, dir);
return ret;
}
On the success path, buf_dma is never unmapped after the transfer
completes, leaking IOMMU mappings and skipping cache invalidations on
non-coherent architectures. Also, when dma_map_single() fails, jumping to
err_unmap unmaps an invalid DMA address, and err_unmap passes
ebu_host->dev instead of dma_dev.
[1] https://sashiko.dev/#/bug/linux-f7fd8979-ca31-481c-b79a-253f8225990b
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123055020.1995251-1-ping.li@horizon.auto?part=2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-11-23 6:01 UTC|newest]
Thread overview: 11+ 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 [this message]
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
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=sashiko-outbox-228749@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=leeonion.muyu@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=sashiko-reviews@lists.linux.dev \
--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;
as well as URLs for NNTP newsgroup(s).