From: zhouminqiang <zhouminqiang2@huawei.com>
To: <linux@armlinux.org.uk>, <vz@mleia.com>,
<piotr.wojtaszczyk@timesys.com>, <maddy@linux.ibm.com>,
<dwmw2@infradead.org>, <richard@nod.at>
Cc: <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <linuxppc-dev@lists.ozlabs.org>,
<linux-mtd@lists.infradead.org>, <chengzhihao1@huawei.com>,
<yangerkun@huawei.com>, <yi.zhang@huawei.com>
Subject: [PATCH v2 7/7] jffs2: add runtime toggle for write verification
Date: Sat, 29 Aug 2026 14:16:57 +0800 [thread overview]
Message-ID: <20260829061658.306854-8-zhouminqiang2@huawei.com> (raw)
In-Reply-To: <20260829061658.306854-1-zhouminqiang2@huawei.com>
Write verification is a diagnostic facility that adds read-back
overhead to every write. In production, this overhead is undesirable
unless fault isolation is required.
Add a module parameter jffs2.write_verify (bool, 0644) that defaults
to off when CONFIG_JFFS2_FS_WRITE_VERIFY is enabled. The verification
entry checks READ_ONCE(jffs2_write_verify) and returns immediately
when disabled, avoiding any overhead. The parameter can be toggled at
runtime via /sys/module/jffs2/parameters/write_verify or set at
boot/modprobe time.
Signed-off-by: zhouminqiang <zhouminqiang2@huawei.com>
---
fs/jffs2/Kconfig | 8 ++++++++
fs/jffs2/writev.c | 23 +++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/fs/jffs2/Kconfig b/fs/jffs2/Kconfig
index 556025a5d438..03dadbd003cd 100644
--- a/fs/jffs2/Kconfig
+++ b/fs/jffs2/Kconfig
@@ -61,6 +61,14 @@ config JFFS2_FS_WRITE_VERIFY
tell transport/program-time corruption from post-commit media
damage.
+ Verification defaults to off when this option is selected and can
+ be enabled at runtime via sysfs:
+
+ /sys/module/jffs2/parameters/write_verify
+
+ Write 0 to disable, 1 to enable. Boot/modprobe parameter
+ jffs2.write_verify=0|1 is also supported.
+
If unsure, say 'N'.
config JFFS2_SUMMARY
diff --git a/fs/jffs2/writev.c b/fs/jffs2/writev.c
index 75b4244e93b8..913183329c54 100644
--- a/fs/jffs2/writev.c
+++ b/fs/jffs2/writev.c
@@ -9,12 +9,32 @@
*
*/
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
#include <linux/kernel.h>
+#include <linux/module.h>
#include <linux/slab.h>
#include <linux/mtd/mtd.h>
#include "nodelist.h"
#ifdef CONFIG_JFFS2_FS_WRITE_VERIFY
+/*
+ * Optional read-back after writes.
+ *
+ * Catch cases where data is corrupted after node CRCs are calculated but
+ * before it is correctly programmed -- e.g. in RAM or during DMA/bus
+ * transfer to the flash controller -- so mtd_write() succeeds while the
+ * medium does not match the in-memory image.
+ *
+ * Runtime toggle: /sys/module/jffs2/parameters/write_verify
+ * (also boot/modprobe: jffs2.write_verify=0|1)
+ */
+static bool jffs2_write_verify;
+module_param_named(write_verify, jffs2_write_verify, bool, 0644);
+MODULE_PARM_DESC(write_verify,
+ "Verify flash writes by reading back (default: N)");
+
+
int jffs2_verify_write(struct jffs2_sb_info *c, const unsigned char *buf,
uint32_t ofs, size_t len)
{
@@ -23,6 +43,9 @@ int jffs2_verify_write(struct jffs2_sb_info *c, const unsigned char *buf,
char *eccstr;
void *verify_buf;
+ if (!READ_ONCE(jffs2_write_verify))
+ return 0;
+
verify_buf = kmalloc(len, GFP_NOFS);
if (!verify_buf) {
pr_warn("%s(): verify buffer allocation failed, skipping verification\n",
--
2.52.0
prev parent reply other threads:[~2026-08-29 6:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-29 6:16 [PATCH v2 0/7] jffs2: extend write verification to all write paths zhouminqiang
2026-08-29 6:16 ` [PATCH v2 1/7] jffs2: wbuf: clear wbuf on recovery failure paths zhouminqiang
2026-08-29 6:16 ` [PATCH v2 2/7] jffs2: replace per-superblock verify buffer with per-write buffer zhouminqiang
2026-08-29 6:16 ` [PATCH v2 3/7] jffs2: write verify: add byte-by-byte comparison on mismatch zhouminqiang
2026-08-29 6:16 ` [PATCH v2 4/7] jffs2: add write verification to direct page writes in flash_writev zhouminqiang
2026-08-29 6:16 ` [PATCH v2 5/7] jffs2: add write verification to NOR direct write paths zhouminqiang
2026-08-29 6:16 ` [PATCH v2 6/7] jffs2: rename CONFIG_JFFS2_FS_WBUF_VERIFY to CONFIG_JFFS2_FS_WRITE_VERIFY zhouminqiang
2026-08-29 6:16 ` zhouminqiang [this message]
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=20260829061658.306854-8-zhouminqiang2@huawei.com \
--to=zhouminqiang2@huawei.com \
--cc=chengzhihao1@huawei.com \
--cc=dwmw2@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=piotr.wojtaszczyk@timesys.com \
--cc=richard@nod.at \
--cc=vz@mleia.com \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.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