From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout01.his.huawei.com (canpmsgout01.his.huawei.com [113.46.200.216]) (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 33E17418A50 for ; Thu, 20 Aug 2026 10:57:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.216 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787223430; cv=none; b=nbLhPNG3MY62n3mAaSN8JTudKu4v5mXy+x8EcIUhy7DJqnO+LluJyUwAy57sjxIBzj+LgKoKKxysZGDyKL44q2Lohgpz6nbApiJzZUwTVMv92OVZvsQJHfXcO6Q9TGs7wU/tov++DfOt9+4RN8ccwj7T2perhJK6s/Txttt8GNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787223430; c=relaxed/simple; bh=keq8McMmPFnSU/3XjVKmZxxVopH9J9O0jWSGyNM6SIM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZLZdSI5PCKefXZCp5ECZgoxWKxdki4h/pBOHOFWgSoYzt7s++PLDFks2ivyEjC5t6QmGZ60rV1v9WUkTi1UDBv+PbOeBmxfxuzvWSXMnp33SyZiWfrDp+1gO7olia1dWfP/3U5rh5kyh+XAoZvGXanHv1jcWEi3AlrgbpJUkIp4= 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=DEYeTK0h; arc=none smtp.client-ip=113.46.200.216 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="DEYeTK0h" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=xsvBPHM9Phkp22E5ouyU3mr8Yzj5fMI5tGo8rhe5V5Y=; b=DEYeTK0hgoY78K/E4TV0+ygXFxkcArkZghR58Xf2H8upX/XcA/eUTU6kJPUnyMYPP1Mkt9f8e pmb/cGnl8d0S/tRJpojttttiK2725aps0gMKiw6Okk74Uun6nVhnth/CZl4TL9hdqnPGQqp2DBj jOHZFfmbNNnjDAdZDKUm48w= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4hQg9W3DQ8z1T4Fq; Thu, 20 Aug 2026 18:46:55 +0800 (CST) Received: from dggpemr100018.china.huawei.com (unknown [7.185.36.64]) by mail.maildlp.com (Postfix) with ESMTPS id 50F604057D; Thu, 20 Aug 2026 18:56:57 +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:56 +0800 From: zhouminqiang To: , CC: , , , , Subject: [PATCH 0/6] jffs2: extend write verification to all write paths Date: Thu, 20 Aug 2026 18:49:56 +0800 Message-ID: <20260820105003.2525647-1-zhouminqiang2@huawei.com> X-Mailer: git-send-email 2.52.0 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) When JFFS2 writes data to flash, it first calculates a node CRC, and the NAND controller calculates ECC as the data is programmed. If corruption occurs between these two points, the possible causes are RAM failures or bus transfer errors before the data reaches the flash, or bit flips on the flash medium itself. To distinguish whether the corruption happened during the write transfer or after commit to the medium, 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. Two scenarios remain uncovered: 1. When the write data length exceeds wbuf_pagesize, the excess data bypasses the write buffer and is written directly to flash via mtd_write() in jffs2_flash_writev(), with no verification. 2. NOR Flash and other non-writebuffered devices write directly through jffs2_flash_direct_write() and jffs2_flash_direct_writev(), with no equivalent check. In both cases, if MTD reports a successful write but the readable medium differs from JFFS2's source buffer, a later node CRC failure cannot distinguish transport/program-time corruption from post-commit media damage, defeating the original diagnostic intent. This series covers both scenarios with the following changes. Replace the pre-allocated per-superblock wbuf_verify buffer with on-demand allocation inside jffs2_verify_write(). This allows concurrent verification calls to proceed independently without contending for a shared buffer. Additionally, memcmp() is replaced with a byte-by-byte comparison that pinpoints the exact mismatch offset, rather than merely reporting equal or not-equal. Add verification calls in jffs2_flash_writev() for direct page writes, and in jffs2_flash_direct_write() and jffs2_flash_direct_writev() for NOR and other non-writebuffered devices. Since verification now covers all write paths rather than only the write-buffer path, rename CONFIG_JFFS2_FS_WBUF_VERIFY to CONFIG_JFFS2_FS_WRITE_VERIFY and remove the Kconfig dependency on CONFIG_JFFS2_FS_WRITEBUFFER. Add a module parameter write_verify (default off, 0644) to allow dynamic enable/disable of write verification at runtime, so kernels can carry the diagnostic facility without read-back overhead until fault isolation is required. The parameter can be accessed through: /sys/module/jffs2/parameters/write_verify This remains an optional diagnostic aid; node CRCs continue to provide JFFS2's normal on-media integrity check. zhouminqiang (6): jffs2: replace per-superblock verify buffer with per-write buffer jffs2: write verify: replace memcmp with byte-by-byte comparison 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 fs/jffs2/Kconfig | 31 +++++++-- fs/jffs2/jffs2_fs_sb.h | 3 - fs/jffs2/os-linux.h | 11 ++++ fs/jffs2/wbuf.c | 86 +++--------------------- fs/jffs2/writev.c | 145 ++++++++++++++++++++++++++++++++++++++++- 5 files changed, 188 insertions(+), 88 deletions(-) -- 2.52.0