Re: [RFC PATCH 1/1] mtd: mtdchar: use kvmalloc() for large read/write buffers
From: Ping Li
Date: Thu Nov 19 2026 - 04:37:20 EST
From: leeonion.muyu@xxxxxxxxx
Hi,
Thanks for the review. I verified the three findings in the tree and
all of them check out.
1. powernv_flash registers _read/_write directly and passes __pa(buf)
down to OPAL (powernv_flash.c:69, :220), so a vmalloc'd buffer
would hand firmware a bogus physical address. fsmc_nand.c:505,
intel-nand-controller.c:312 and r852.c:196 dma_map_single() the
buffer without any virt_addr_valid() check. This also explains
why the 2022 ioctl conversion (83208e106a8e8) was safe: MEMREAD
and MEMWRITE require _read_oob/_write_oob, which these drivers do
not implement.
2. Agreed on the low-memory regression: kvmalloc() makes a single
kmalloc() attempt and then goes straight to vmalloc(), so the
size backoff that used to make progress under fragmentation is
gone. The stale comment above mtdchar_read() is my oversight.
3. Agreed that "shrink first, vmalloc last" is the right shape;
jumping to vmalloc while intermediate contiguous sizes are still
available trades a cheap shrink for an expensive bounce path.
So the answer to the cover letter's question is: quite concerned.
Plain kvmalloc() in the _read/_write path is a no-go as long as
drivers assume a linear-map buffer.
The options I see from here:
a) a small pre-cleanup series making the affected drivers
vmalloc-safe (bounce or reject), then converting
mtdchar_read()/mtdchar_write() with the size backoff kept and
vmalloc only as a last resort;
b) keeping the current halving-only behavior and dropping this
RFC.
I am happy to work on (a) if that direction is acceptable;
otherwise I will withdraw the RFC.
Thanks,
Ping