[PATCH v4 0/9] mtdchar: keep data and OOB aligned across ioctl chunks
From: James Hilliard
Date: Sun Dec 06 2026 - 04:59:31 EST
MEMREAD and MEMWRITE split requests into bounded data and OOB buffers.
Their chunk lengths and flash-address updates must keep both streams
associated with the same pages.
An intermediate read can consume OOB from pages beyond its data chunk.
OOB-only requests do not advance the flash address between chunks, while
a buffer ending within a page's OOB can leave the next operation starting
at the wrong page. When the OOB buffer is the limiting factor, the data
chunk must stop at the same page boundary.
The OOB-limited case was found while testing a proposed BootROM-format
MTD view with 1024 data bytes and 1152 OOB bytes per page. A 64-page
request has 65536 data bytes and 73728 OOB bytes, but the original
65536-byte buffer limit lets the first operation consume all the data
while transferring only part of the OOB.
Reject requests that extend beyond the device before either stream is
transferred. Bound each intermediate chunk to the same data and OOB
pages, and finish any OOB left after the data runs out. MEMREAD still
advances the address returned to userspace only by the main data read.
On raw NAND and OneNAND, check data writes against the subpage size
before programming, and split OOB-only writes at page boundaries.
Check writability and known NAND write-mode restrictions on every
member before programming the first one. Use the backing page column
even after a combined write has transferred its last spare byte.
DiskOnChip G3 can stage one complete spare area for a later data write.
Use the driver's page rules to reject an invalid tail before programming
the first page. On concatenated devices, finish each member's OOB even
when its last main-data byte has already been read.
This series applies after the DiskOnChip G3 v2 [1] and OneNAND v1 [2]
OOB fixes. It uses the DiskOnChip write validator and relies on the
OneNAND fixes for reads with a partial spare area or a nonzero OOB
column.
[1] https://lore.kernel.org/r/20261206-submit-docg3-oob-fixes-v1-v2-0-3b0c523d750c@xxxxxxxxx/
[2] https://lore.kernel.org/r/20261204-submit-onenand-oob-fixes-v1-v1-0-6c68634d239b@xxxxxxxxx/
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
Changes in v4:
- Check the whole data and OOB range, including each concat member,
before splitting a request. Use the backing page column for unaligned
partitions.
- Use the DiskOnChip G3 write validator before programming any prefix;
keep the native DiskOnChip and OneNAND OOB fixes in separate series.
- Keep the OOB buffer on later data chunks of a combined MEMWRITE so
DiskOnChip G3 cannot use a spare area staged by an earlier request.
- Check each member's writability, NAND subpage alignment and known raw
write restrictions on OneNAND, raw NAND and SPI-NAND. Limit OOB-only
writes to one page on devices that require it.
- Use each backing member's geometry even on data-only continuations.
- Keep MEMREAD's returned start tied to main data. After a short read,
resume the remaining stream at its own offset. If both streams remain,
require a common restart address.
- Return a concat member's short write to the caller before advancing.
Stop a mixed write if a retry would program the same page again.
- Preserve ECC errors across clean MEMREAD chunks.
- Link to v3: https://patch.msgid.link/20261204-submit-mtdchar-page-chunking-v1-v3-0-2f36958a6e8d@xxxxxxxxx
Changes in v3:
- Rebase on mtd/next and preserve the per-chunk MEMREAD statistics
initialization in patch 4.
- Link to v2: https://patch.msgid.link/20261108-submit-mtdchar-page-chunking-v1-v2-0-838cf8934ba6@xxxxxxxxx
Changes in v2:
- Add a fourth patch to finish requests whose OOB extends past the data,
following Sashiko's review of patch 3.
- Switch to OOB-only operations once the data runs out, including when
the original non-NULL data buffer has zero remaining length.
- Advance beyond the final data page when OOB was consumed there, and
keep raw-NAND OOB-only writes to one page per backend operation.
- Link to v1: https://patch.msgid.link/20261106-submit-mtdchar-page-chunking-v1-v1-0-2973a03531bc@xxxxxxxxx
---
James Hilliard (9):
mtdchar: calculate OOB capacity from the backing page column
mtdchar: validate the full OOB range before splitting requests
mtd: concat: keep both streams of an OOB read within each member
mtdchar: check each member before splitting MEMWRITE
mtdchar: keep MEMREAD data and OOB on their backing pages
mtdchar: keep MEMWRITE data and OOB on their backing pages
mtd: nand: check MEMWRITE alignment and raw mode before programming
mtd: concat: return a short OOB write before advancing to another member
mtdchar: retain ECC errors across MEMREAD chunks
drivers/mtd/devices/docg3.c | 11 ++
drivers/mtd/mtdchar.c | 216 ++++++++++++++++++++++++--------
drivers/mtd/mtdconcat.c | 119 ++++++++++++------
drivers/mtd/mtdcore.c | 60 ++++++---
drivers/mtd/mtdcore.h | 68 +++++++++-
drivers/mtd/nand/onenand/onenand_base.c | 25 ++--
drivers/mtd/nand/raw/nand_base.c | 17 +++
drivers/mtd/nand/spi/core.c | 19 ++-
include/linux/mtd/mtd.h | 19 +++
9 files changed, 424 insertions(+), 130 deletions(-)
---
base-commit: 4e5457fcbc14d21e7c004c3159e78fc63838029e
base-tree: https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next
change-id: 20261106-submit-mtdchar-page-chunking-v1-668636b0becd
prerequisite-change-id: 20261204-submit-docg3-oob-fixes-v1-3ac1e192f872:v2
prerequisite-patch-id: f9a0098b4b9ed5ed775a47942b6ee3bd047b4365
prerequisite-patch-id: c57eb30e2678a75aa7dd5683b557a4e22b94c1f5
prerequisite-patch-id: 07fe496f9c338749547a17449ae49d9bb842596d
prerequisite-patch-id: a355a2c8b80a3e5274337309b0053319ba31c927
prerequisite-patch-id: 1c04bb6a01bf3995d7da59b8c8117549d1adebb4
prerequisite-change-id: 20261204-submit-onenand-oob-fixes-v1-10db347cf4bc:v1
prerequisite-patch-id: 5e8c344b71554f2d37c3e3c199a2b9d6f6208118
prerequisite-patch-id: c16f2d9da60d0ea1b17fb4c0147fd35b0635bcc8
Best regards,
--
James Hilliard <james.hilliard1@xxxxxxxxx>