lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250522-qpic-snand-overestimate-bitflips-v1-1-35c65c05068e@gmail.com>
Date: Thu, 22 May 2025 19:33:26 +0200
From: Gabor Juhos <j4g8y7@...il.com>
To: Mark Brown <broonie@...nel.org>, 
 Miquel Raynal <miquel.raynal@...tlin.com>
Cc: Md Sadre Alam <quic_mdalam@...cinc.com>, 
 Varadarajan Narayanan <quic_varada@...cinc.com>, 
 Sricharan Ramabadhran <quic_srichara@...cinc.com>, 
 linux-spi@...r.kernel.org, linux-mtd@...ts.infradead.org, 
 linux-arm-msm@...r.kernel.org, linux-kernel@...r.kernel.org, 
 Gabor Juhos <j4g8y7@...il.com>
Subject: [PATCH RFC] spi: spi-qpic-snand: overestimate corrected bitflips

The QPIC hardware is not capable of reporting the exact number of the
corrected bitflips, it only reports the number of the corrected bytes.
However the current code treats that as corrected bitflips which is
quite inaccurate in most cases. For example, even if the hardware reports
only one byte as corrected, that byte may have contained multiple bit
errors from one up to the maximum number of correctable bits.

Change the code to report the maximum of the possibly corrected bits,
thus allowing upper layers to do certain actions before the data gets
lost due to uncorrectable errors.

Signed-off-by: Gabor Juhos <j4g8y7@...il.com>
---
The patch tries to address Miquel's concerns [1] about the corrected bit
error reporting capabilities of the QPIC hardware.

[1] https://lore.kernel.org/all/87h61e8kow.fsf@bootlin.com

nanbiterrs test result after the change:

  # insmod mtd_test; insmod mtd_nandbiterrs dev=4
  [   40.685251]
  [   40.685278] ==================================================
  [   40.685803] mtd_nandbiterrs: MTD device: 4
  [   40.691566] mtd_nandbiterrs: MTD device size 7602176, eraseblock=131072, page=2048, oob=128
  [   40.695528] mtd_nandbiterrs: Device uses 1 subpages of 2048 bytes
  [   40.703789] mtd_nandbiterrs: Using page=0, offset=0, eraseblock=0
  [   40.713655] mtd_nandbiterrs: incremental biterrors test
  [   40.716118] mtd_nandbiterrs: write_page
  [   40.722126] mtd_nandbiterrs: rewrite page
  [   40.725878] mtd_nandbiterrs: read_page
  [   41.103196] mtd_nandbiterrs: verify_page
  [   41.106915] mtd_nandbiterrs: Successfully corrected 0 bit errors per subpage
  [   41.111001] mtd_nandbiterrs: Inserted biterror @ 1/7
  [   41.118007] mtd_nandbiterrs: rewrite page
  [   41.123850] mtd_nandbiterrs: read_page
  [   41.127458] qcom_snand 79b0000.spi: the number of corrected bits may be inaccurate
  [   41.130538] mtd_nandbiterrs: Read reported 4 corrected bit errors
  [   41.138060] mtd_nandbiterrs: verify_page
  [   41.144265] mtd_nandbiterrs: Successfully corrected 1 bit errors per subpage
  [   41.148217] mtd_nandbiterrs: Inserted biterror @ 3/7
  [   41.155260] mtd_nandbiterrs: rewrite page
  [   41.161076] mtd_nandbiterrs: read_page
  [   41.164687] qcom_snand 79b0000.spi: the number of corrected bits may be inaccurate
  [   41.167750] mtd_nandbiterrs: Read reported 4 corrected bit errors
  [   41.175324] mtd_nandbiterrs: verify_page
  [   41.181511] mtd_nandbiterrs: Successfully corrected 2 bit errors per subpage
  [   41.185456] mtd_nandbiterrs: Inserted biterror @ 5/7
  [   41.192516] mtd_nandbiterrs: rewrite page
  [   41.198301] mtd_nandbiterrs: read_page
  [   41.201949] qcom_snand 79b0000.spi: the number of corrected bits may be inaccurate
  [   41.204990] mtd_nandbiterrs: Read reported 4 corrected bit errors
  [   41.212568] mtd_nandbiterrs: verify_page
  [   41.218720] mtd_nandbiterrs: Successfully corrected 3 bit errors per subpage
  [   41.222714] mtd_nandbiterrs: Inserted biterror @ 7/7
  [   41.229739] mtd_nandbiterrs: rewrite page
  [   41.235548] mtd_nandbiterrs: read_page
  [   41.239168] mtd_nandbiterrs: Read reported 4 corrected bit errors
  [   41.242252] mtd_nandbiterrs: verify_page
  [   41.248407] mtd_nandbiterrs: Successfully corrected 4 bit errors per subpage
  [   41.252406] mtd_nandbiterrs: Inserted biterror @ 8/7
  [   41.259413] mtd_nandbiterrs: rewrite page
  [   41.265238] mtd_nandbiterrs: read_page
  [   41.268858] mtd_nandbiterrs: error: read failed at 0x0
  [   41.271937] mtd_nandbiterrs: After 5 biterrors per subpage, read reported error -74
  [   41.280512] mtd_nandbiterrs: finished successfully.
  [   41.284587] ==================================================
  failed to insert /lib/modules/6.15.0-rc5+/mtd_nandbiterrs.ko
  #
---
 drivers/spi/spi-qpic-snand.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index 17bcd12f6cb932fdf2d968692359a0301ce4acdc..137d60081754db04ceb5db64e6f250f6477021db 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -638,6 +638,21 @@ static int qcom_spi_check_error(struct qcom_nand_controller *snandc)
 			unsigned int stat;
 
 			stat = buffer & BS_CORRECTABLE_ERR_MSK;
+
+			if (stat && stat != ecc_cfg->strength) {
+				/*
+				 * The exact number of the corrected bits is
+				 * unknown because the hardware only reports
+				 * the number of the corrected bytes.
+				 *
+				 * Assume the worst case scenario and use
+				 * the maximum.
+				 */
+				dev_warn(snandc->dev,
+					 "the number of corrected bits may be inaccurate\n");
+				stat = ecc_cfg->strength;
+			}
+
 			snandc->qspi->ecc_stats.corrected += stat;
 			max_bitflips = max(max_bitflips, stat);
 		}

---
base-commit: e7f3d11567c2c79c4342791ba91c500b434ce147
change-id: 20250521-qpic-snand-overestimate-bitflips-64112df41c38

Best regards,
-- 
Gabor Juhos <j4g8y7@...il.com>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ