From: sashiko-bot@kernel.org
To: "Ping Li" <leeonion.muyu@gmail.com>,
miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com
Cc: tudor.ambarus@linaro.org, kyungmin.park@samsung.com,
linux-mtd@lists.infradead.org
Subject: Re: [PATCH v3 3/4] mtd: hyperbus: accept vmalloc'd bounce buffers
Date: Fri, 04 Dec 2026 06:04:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-249176@kernel.org> (raw)
In-Reply-To: <20261204054630.3443342-4-leeonion.muyu@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mtd: hyperbus: allows_vmalloc_bufs bypasses DMA on hbmc-am654
reads
- [Medium] mtd: hyperbus: allows_vmalloc_bufs exposes unclamped mtdchar
kvmalloc()
--
commit 29c3fce1e5634ffbe21dbeb565597da55a1a074e
Author: Ping Li <leeonion.muyu@gmail.com>
mtd: hyperbus: accept vmalloc'd bounce buffers
This commit sets allows_vmalloc_bufs on MTD devices registered through
hyperbus_register_device() so that mtd_alloc_buf() can allocate vmalloc
bounce buffers for HyperBus transfers.
> diff --git a/drivers/mtd/hyperbus/hyperbus-core.c b/drivers/mtd/hyperbus/hyperbus-core.c
> index 4d8047d43e48e..d61bd4fbc966a 100644
> --- a/drivers/mtd/hyperbus/hyperbus-core.c
> +++ b/drivers/mtd/hyperbus/hyperbus-core.c
> @@ -114,6 +114,7 @@ int hyperbus_register_device(struct hyperbus_device *hbdev)
>
> hbdev->mtd->dev.parent = dev;
> mtd_set_of_node(hbdev->mtd, np);
> + hbdev->mtd->allows_vmalloc_bufs = true;
>
> ret = mtd_device_register(hbdev->mtd, NULL, 0);
> if (ret) {
[Severity: Medium]
Can setting allows_vmalloc_bufs unconditionally regress read throughput on
hbmc-am654 by bypassing DMA?
With allows_vmalloc_bufs set, mtd_alloc_buf() uses kvmalloc(*size,
GFP_KERNEL) instead of mtd_kmalloc_up_to(). Above PAGE_SIZE,
kmalloc_gfp_adjust() drops __GFP_DIRECT_RECLAIM, so modest fragmentation
sends kvmalloc() to vmalloc instead of a smaller contiguous order.
am654_hbmc_dma_read() rejects vmalloc addresses via !virt_addr_valid(to),
so am654_hbmc_read() falls back to CPU memcpy_fromio() for the entire
transfer, losing the DMA speedup from 00c9cf49a613 ("mtd: hyperbus:
hbmc-am654: Add DMA support for reads").
Making allows_vmalloc_bufs a per-controller opt-in would preserve DMA on
hbmc-am654 while letting CPU-copy controllers like renesas-rpc-if opt in.
The commit message also says both current controllers fall back from a DMA
engine, whereas renesas-rpc-if has no DMA support.
[Severity: Medium]
Does opting HyperBus into allows_vmalloc_bufs expose an unclamped
allocation in mtdchar_read() and mtdchar_write()?
Both functions capture size = count before clamping count to
mtd->size - *ppos, then pass size to mtd_alloc_buf(). With
allows_vmalloc_bufs set, mtd_alloc_buf() calls kvmalloc(*size, GFP_KERNEL)
capped only at KMALLOC_MAX_SIZE, with no size backoff under pressure.
On ARM64 kernels with 16K or 64K pages, KMALLOC_MAX_SIZE is 32 MiB or
512 MiB. A read or write with a large count when only a few bytes remain
in a HyperBus partition therefore requests up to 512 MiB of non-swappable
kernel memory, risking reclaim stalls, spurious -ENOMEM, or OOM.
Clamping size after count is bounded by mtd->size - *ppos in
mtdchar_read() and mtdchar_write() would avoid allocating more than the
transfer can use.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204054630.3443342-1-leeonion.muyu@gmail.com?part=3
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-12-04 6:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 5:46 [PATCH v3 0/4] mtdchar: per-device bounce buffer policy Ping Li
2026-12-04 5:46 ` Ping Li
2026-12-04 5:46 ` [PATCH v3 1/4] mtd: core: add per-device bounce buffer allocation helper Ping Li
2026-12-04 5:46 ` Ping Li
2026-12-04 6:03 ` sashiko-bot
2026-12-04 5:46 ` [PATCH v3 2/4] mtd: mtdchar: use mtd_alloc_buf() for the read/write bounce buffers Ping Li
2026-12-04 5:46 ` Ping Li
2026-12-04 6:03 ` sashiko-bot
2026-12-04 5:46 ` [PATCH v3 3/4] mtd: hyperbus: accept vmalloc'd " Ping Li
2026-12-04 5:46 ` Ping Li
2026-12-04 6:04 ` sashiko-bot [this message]
2026-12-04 5:46 ` [PATCH v3 4/4] mtd: onenand: samsung: " Ping Li
2026-12-04 5:46 ` Ping Li
2026-12-04 6:04 ` sashiko-bot
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-249176@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kyungmin.park@samsung.com \
--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=tudor.ambarus@linaro.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.