jffs2: extend write verification to all write paths
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest8 patches 0 repliesNew
- v38 patches 0 repliesSuperseded
- v27 patches 0 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 6 patches | 4 replies | Superseded |
Changes in v4 from the cover letter
- Change the OBSOLETE length in jffs2_wbuf_recover() secondary write
failure path from retlen to end - start, and update the commit message
- Link to v3: https://lore.kernel.org/linux-mtd/[email protected]/T/#t
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/8 | jffs2: wbuf: clear wbuf on recovery failure pathsfs/ | +4 | 0 replies | |
| 2/8 | jffs2: wbuf: fix OBSOLETE under-coverage on recovery failurefs/ | +1 | 0 replies | |
| 3/8 | jffs2: replace per-superblock verify buffer with per-write bufferfs/ fs/ | +23 | 0 replies | |
| 4/8 | jffs2: write verify: add byte-by-byte comparison on mismatchfs/ | +28 | 0 replies | |
| 5/8 | jffs2: add write verification to direct page writes in flash_writevfs/ | +21 | 0 replies | |
| 6/8 | jffs2: add write verification to NOR direct write pathsfs/ fs/ fs/ | +131 | 0 replies | |
| 7/8 | jffs2: rename CONFIG_JFFS2_FS_WBUF_VERIFY to CONFIG_JFFS2_FS_WRITE_VERIFYarch/ arch/ arch/ +5 more | +26 | 0 replies | |
| 8/8 | jffs2: add runtime toggle for write verificationfs/ fs/ | +31 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.
Cover letter [PATCH v4 0/8] jffs2: extend write verification to all write paths
When JFFS2 writes data to flash, corruption can occur during the write transfer (RAM failures, bus errors) or after commit to the medium (bit flips). To distinguish whether the corruption happened before or after the data reached the flash, commit a6bc432e296d ("[JFFS2] Add support for write-buffer verification.") introduced CONFIG_JFFS2_FS_WBUF_VERIFY: reading the data back immediately after a successful write and comparing it with the in-memory source buffer provides the missing observation point for that diagnosis.
However, the current implementation only performs read-back verification on write-buffer flush paths. NOR flash devices write directly through jffs2_flash_direct_write() and jffs2_flash_direct_writev(), with no equivalent check. Data corruption incidents have been observed on NOR-based devices in production environments, yet there is no quick diagnostic tool to isolate whether the corruption occurred during the write transfer or after commit to the medium. A significant number of deployed devices rely on JFFS2 on NOR flash, making this gap a practical concern.
During the investigation of the NOR flash gap, code inspection also revealed that when the write data length exceeds wbuf_pagesize in jffs2_flash_writev(), the excess data bypasses the write buffer and is written directly to flash via mtd_write(), with no verification. Additionally, jffs2_wbuf_recover() does not clear c->wbuf_len on recovery failure, which can lead to BUG_ON in jffs2_link_node_ref() or deadlock in jffs2_flush_wbuf_pad() on a subsequent write.
This series closes these gaps with the following changes:
- Patch 1: fix wbuf recovery failure exit paths to clear
c->wbuf_len, preventing BUG_ON and deadlock
- Patch 2: fix ref_totlen misuse in jffs2_wbuf_recover() failure path
- Patch 3: replace pre-allocated per-superblock wbuf_verify
buffer with on-demand allocation inside jffs2_verify_write()
- Patch 4: add byte-by-byte comparison after memcmp() mismatch to pinpoint the exact mismatch offset
- Patch 5: add verification in jffs2_flash_writev() for the mtd_write() path that bypasses the write buffer
- Patch 6: add verification calls in jffs2_flash_direct_write() and jffs2_flash_direct_writev() for NOR flash devices
- Patch 7: rename CONFIG_JFFS2_FS_WBUF_VERIFY to CONFIG_JFFS2_FS_WRITE_VERIFY and remove the Kconfig dependency on CONFIG_JFFS2_FS_WRITEBUFFER
- Patch 8: add module parameter write_verify for runtime enable/disable of write verification
This series extends the existing write verification mechanism to cover all write paths. It remains off by default and does not alter JFFS2's node CRC integrity checks.
Changes in v4:
- Change the OBSOLETE length in jffs2_wbuf_recover() secondary write
failure path from retlen to end - start, and update the commit message
- Link to v3: https://lore.kernel.org/linux-mtd/[email protected]/T/#t
Changes in v3:
- Add patch to fix incorrect ref_totlen usage in jffs2_wbuf_recover()
secondary write failure path, which could corrupt free_size accounting
- Add __GFP_NOWARN to jffs2_verify_write() kmalloc to suppres
high-order allocation splats on large-erasesize NAND
- Link to v2: https://lore.kernel.org/linux-mtd/[email protected]/T/#t
Changes in v2:
- Add patch to fix wbuf recovery failure exit paths not clearing
c->wbuf_len, preventing BUG_ON and deadlock on subsequent writes
- Use kmalloc() instead of vmalloc() for verify buffer allocation
- Keep memcmp() on the hotpath and add byte-by-byte comparison
only after a mismatch, rather than replacing memcmp() entirely
- In jffs2_flash_direct_write() and jffs2_flash_direct_writev(),
call mtd_write() before jffs2_sum_add_kvec() to prevent
retlen from being uninitialized if jffs2_sum_add_kvec() causes
an early return
- Update defconfig files to rename CONFIG_JFFS2_FS_WBUF_VERIFY to CONFIG_JFFS2_FS_WRITE_VERIFY
- Link to v1: https://lore.kernel.org/linux-mtd/[email protected]/T/#t
zhouminqiang (8):
jffs2: wbuf: clear wbuf on recovery failure paths
jffs2: wbuf: fix OBSOLETE under-coverage on recovery failure
jffs2: replace per-superblock verify buffer with per-write buffer
jffs2: write verify: add byte-by-byte comparison on mismatch
jffs2: add write verification to direct page writes in flash_writev
jffs2: add write verification to NOR direct write paths
jffs2: rename CONFIG_JFFS2_FS_WBUF_VERIFY to
CONFIG_JFFS2_FS_WRITE_VERIFY
jffs2: add runtime toggle for write verification
arch/arm/configs/keystone_defconfig | 2 +- arch/arm/configs/lpc32xx_defconfig | 2 +- arch/arm/configs/pxa3xx_defconfig | 2 +- arch/arm/configs/pxa_defconfig | 2 +- arch/powerpc/configs/44x/fsp2_defconfig | 2 +- fs/jffs2/Kconfig | 31 ++++- fs/jffs2/jffs2_fs_sb.h | 3 - fs/jffs2/os-linux.h | 11 ++ fs/jffs2/wbuf.c | 93 +++------------ fs/jffs2/writev.c | 144 +++++++++++++++++++++++- 10 files changed, 199 insertions(+), 93 deletions(-)
Signature · 1 line
2.52.0