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 1/4] mtd: core: add per-device bounce buffer allocation helper
Date: Fri, 04 Dec 2026 06:03:01 +0000 [thread overview]
Message-ID: <sashiko-outbox-249174@kernel.org> (raw)
In-Reply-To: <20261204054630.3443342-2-leeonion.muyu@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: mtd_alloc_buf() allows huge OOM-prone GFP_KERNEL
kvmalloc() buffers
--
commit 45e643b09417a7039e8cef4d6194c99c2a1545b9
Author: Ping Li <leeonion.muyu@gmail.com>
mtd: core: add per-device bounce buffer allocation helper
This commit adds the mtd->allows_vmalloc_bufs flag and the
mtd_alloc_buf()/mtd_free_buf() helpers so opted-in MTD drivers can
receive vmalloc-backed bounce buffers via kvmalloc() instead of
mtd_kmalloc_up_to().
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index b170c3144ca8f..83365c0fbf063 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -2566,6 +2566,50 @@ void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size)
[ ... ]
> +void *mtd_alloc_buf(const struct mtd_info *mtd, size_t *size)
> +{
> + if (!mtd->allows_vmalloc_bufs)
> + return mtd_kmalloc_up_to(mtd, size);
> +
> + *size = min_t(size_t, *size, KMALLOC_MAX_SIZE);
> + return kvmalloc(*size, GFP_KERNEL);
> +}
[Severity: Medium]
Can kvmalloc(*size, GFP_KERNEL) with only a KMALLOC_MAX_SIZE cap trigger the
out-of-memory killer or allocate oversized bounce buffers on large transfers?
KMALLOC_MAX_SIZE scales with MAX_PAGE_ORDER + PAGE_SHIFT, reaching 512 MiB
on arm64 with 64K pages (32 MiB with 16K pages). In mtd_kmalloc_up_to(),
that cap only bounded an optimistic __GFP_NORETRY kmalloc() attempt that
halved down under pressure.
With kvmalloc(*size, GFP_KERNEL), the vmalloc fallback allocates order-0
pages with plain GFP_KERNEL, which drives reclaim and can invoke the
out-of-memory killer instead of returning NULL cleanly.
Existing kvmalloc() bounce buffers in mtdchar_write_ioctl() cap allocations
at mtd->erasesize. Bounding *size to a smaller ceiling and passing
__GFP_RETRY_MAYFAIL or __GFP_NORETRY would avoid oversized buffers and
out-of-memory kills.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204054630.3443342-1-leeonion.muyu@gmail.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-12-04 6:03 UTC|newest]
Thread overview: 9+ 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 ` [PATCH v3 1/4] mtd: core: add per-device bounce buffer allocation helper Ping Li
2026-12-04 6:03 ` sashiko-bot [this message]
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 6:03 ` sashiko-bot
2026-12-04 5:46 ` [PATCH v3 3/4] mtd: hyperbus: accept vmalloc'd " Ping Li
2026-12-04 6:04 ` sashiko-bot
2026-12-04 5:46 ` [PATCH v3 4/4] mtd: onenand: samsung: " 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-249174@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox