From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 568BA418A54 for ; Thu, 20 Aug 2026 10:57:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.217 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787223430; cv=none; b=MMxLZb2k/ux6CPndJ7VCVGGSXuaDV6yehy4q85iP2XkbVfDYBJOxN4sUBeNSiV9POpPzo/SUAGaDaojw+gzJi0yPvowjnvKQSo+LITsDMjshXgyidP6Fq3YY24kZiyk5tvi6qKDusoZk6ikx0jCmzwinluMq3kcRGy8jYjzCpwk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787223430; c=relaxed/simple; bh=cmSuT8jA/uj5eeRS4o7NBRgmaydHr1PZ2chaAErybtM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PFw74ZfHDfsExlemwWNTuEJk5ZbNwIEtBk1M6SJiADQqRtU+hLM1UhUwicYendX2Qw40v24guvPpKjjy1Si4+rzRkO0kHRJ4nIcK4xSeHvAAn6vQfRP5mcuamGBGmpv0Qrna99cxvQzK0Z6haZ/dou+HyBaqoz5Co35Qu6hI3VQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=vpAivaB1; arc=none smtp.client-ip=113.46.200.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="vpAivaB1" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=oVvANMbS+pKKFKvKgNIn7+GZynnIjYMHabFNZQ7LCTE=; b=vpAivaB1O9LfNH8j6JFpkFICL+Joxel+lCeddz4BTALGy5uBfJiERXzB2pPd8EzfTHMnSsuhA TBUXhtniPVIRjqQPxWdJBHuHDiLMe6zB9Z3ODafsJJjfzqzbwnC0XLysIsOHPgwkicFEPGDmZRY 2eQfmUUby3Sv7YNln4y8H34= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4hQg990NYhzcb0T; Thu, 20 Aug 2026 18:46:37 +0800 (CST) Received: from dggpemr100018.china.huawei.com (unknown [7.185.36.64]) by mail.maildlp.com (Postfix) with ESMTPS id 0106640561; Thu, 20 Aug 2026 18:56:59 +0800 (CST) Received: from huawei.com (10.50.85.155) by dggpemr100018.china.huawei.com (7.185.36.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Thu, 20 Aug 2026 18:56:58 +0800 From: zhouminqiang To: , CC: , , , , Subject: [PATCH 3/6] jffs2: add write verification to direct page writes in flash_writev Date: Thu, 20 Aug 2026 18:49:59 +0800 Message-ID: <20260820105003.2525647-4-zhouminqiang2@huawei.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260820105003.2525647-1-zhouminqiang2@huawei.com> References: <20260820105003.2525647-1-zhouminqiang2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemr100018.china.huawei.com (7.185.36.64) jffs2_flash_writev() performs writes in three phases: phase 1 fills the write buffer and flushes it when full, phase 2 writes full pages directly via mtd_write() bypassing the buffer, and phase 3 fills the remaining data into the write buffer. Phases 1 and 3 both invoke __jffs2_flush_wbuf() when the buffer is full, which includes write-back verification when CONFIG_JFFS2_FS_WBUF_VERIFY is enabled. However phase 2, which handles the bulk of the write data, calls mtd_write() directly without any verification. Phase 2 direct writes may span multiple wbuf_pagesize pages. Extend jffs2_verify_write() with a len parameter to specify the data length to verify, and add the verification call after the phase 2 mtd_write() to cover this gap. Signed-off-by: zhouminqiang --- fs/jffs2/wbuf.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index da6da813a4ef..3e99587f40e4 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -229,33 +229,33 @@ static struct jffs2_raw_node_ref **jffs2_incore_replace_raw(struct jffs2_sb_info #ifdef CONFIG_JFFS2_FS_WBUF_VERIFY static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf, - uint32_t ofs) + uint32_t ofs, size_t len) { int ret = 0; size_t retlen, i; char *eccstr; void *verify_buf; - verify_buf = __vmalloc(c->wbuf_pagesize, GFP_NOFS); + verify_buf = __vmalloc(len, GFP_NOFS); if (!verify_buf) { pr_warn("%s(): verify buffer allocation failed, skipping verification\n", __func__); return 0; } - ret = mtd_read(c->mtd, ofs, c->wbuf_pagesize, &retlen, verify_buf); + ret = mtd_read(c->mtd, ofs, len, &retlen, verify_buf); if (ret && ret != -EUCLEAN && ret != -EBADMSG) { pr_warn("%s(): Read back of page at %08x failed: %d\n", __func__, ofs, ret); goto out_free; - } else if (retlen != c->wbuf_pagesize) { - pr_warn("%s(): Read back of page at %08x gave short read: %zu not %d\n", - __func__, ofs, retlen, c->wbuf_pagesize); + } else if (retlen != len) { + pr_warn("%s(): Read back of page at %08x gave short read: %zu not %zu\n", + __func__, ofs, retlen, len); ret = -EIO; goto out_free; } - for (i = 0; i < c->wbuf_pagesize; i++) { + for (i = 0; i < len; i++) { uint8_t c1 = ((uint8_t *)buf)[i]; uint8_t c2 = ((uint8_t *)verify_buf)[i]; int dump_len; @@ -270,9 +270,9 @@ static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf, else eccstr = "OK or unused"; - dump_len = min_t(int, 128, c->wbuf_pagesize - i); - pr_warn("Write verify error (ECC %s) at %08x (+%zu/%d). Wrote:\n", - eccstr, ofs, i, c->wbuf_pagesize); + dump_len = min_t(int, 128, len - i); + pr_warn("Write verify error (ECC %s) at %08x (+%zu/%zu). Wrote:\n", + eccstr, ofs, i, len); print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1, buf + i, dump_len, 0); @@ -292,7 +292,7 @@ static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf, return ret; } #else -#define jffs2_verify_write(c,b,o) (0) +#define jffs2_verify_write(c,b,o,l) (0) #endif /* Recover from failure to write wbuf. Recover the nodes up to the @@ -455,7 +455,7 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c) ret = mtd_write(c->mtd, ofs, towrite, &retlen, rewrite_buf); - if (ret || retlen != towrite || jffs2_verify_write(c, rewrite_buf, ofs)) { + if (ret || retlen != towrite || jffs2_verify_write(c, rewrite_buf, ofs, towrite)) { /* Argh. We tried. Really we did. */ pr_crit("Recovery of wbuf failed due to a second write error\n"); kfree(buf); @@ -672,7 +672,10 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad) retlen, c->wbuf_pagesize); ret = -EIO; goto wfail; - } else if ((ret = jffs2_verify_write(c, c->wbuf, c->wbuf_ofs))) { + } + + ret = jffs2_verify_write(c, c->wbuf, c->wbuf_ofs, c->wbuf_pagesize); + if (ret) { wfail: jffs2_wbuf_recover(c); @@ -904,6 +907,10 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, if (ret < 0 || wbuf_retlen != PAGE_DIV(vlen)) goto outfile; + ret = jffs2_verify_write(c, v, outvec_to, PAGE_DIV(vlen)); + if (ret) + goto outfile; + vlen -= wbuf_retlen; outvec_to += wbuf_retlen; c->wbuf_ofs = outvec_to; -- 2.52.0