linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ubifs: address bit flips in unused free space
@ 2025-08-18  8:46 shao.mingyin
  2025-08-18  9:01 ` Richard Weinberger
  0 siblings, 1 reply; 2+ messages in thread
From: shao.mingyin @ 2025-08-18  8:46 UTC (permalink / raw)
  To: chengzhihao1
  Cc: linux-mtd, linux-kernel, yang.yang29, xu.xin16, yang.tao172,
	richard

From: Shao Mingyin <shao.mingyin@zte.com.cn>

When the recovery detects a free space bit flip, the UBIFS mount fails,
rendering the UBIFS unusable. This issue can be addressed by reclaiming
the affected erase block, which involves relocating its valid data. So
attempting to fix free space bit flip during recovery reduces scenarios
where users cannot access UBIFS normally.

Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
Signed-off-by: yang tao <yang.tao172@zte.com.cn>
---
 fs/ubifs/recovery.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c
index f0d51dd21c9e..cebf4098557c 100644
--- a/fs/ubifs/recovery.c
+++ b/fs/ubifs/recovery.c
@@ -77,6 +77,25 @@ static int first_non_ff(void *buf, int len)
 	return -1;
 }

+static int ubifs_buf_bitflip_count(void *buf, int len)
+{
+	uint8_t tmp, shift;
+	uint8_t *p = buf;
+	int i, count = 0;
+
+	for (i = 0; i < len; i++) {
+		tmp = *p++;
+		if (tmp != 0xff) {
+			shift = (uint8_t)0;
+			while (shift <= 7)
+				if (!(tmp & (uint8_t)(1 << shift++)))
+					count++;
+		}
+	}
+
+	return count;
+}
+
 /**
  * get_master_node - get the last valid master node allowing for corruption.
  * @c: UBIFS file-system description object
@@ -690,6 +709,12 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
 			 * See header comment for this file for more
 			 * explanations about the reasons we have this check.
 			 */
+			int bitflip_count = ubifs_buf_bitflip_count(buf, len);
+
+			ubifs_assert(c, bitflip_count > 0);
+			ubifs_msg(c, "corrupt empty space LEB %d:%d, corruption starts at %d, bitflip count %d, try to rescure",
+					lnum, offs, corruption, bitflip_count);
+			goto rescure;
 			ubifs_err(c, "corrupt empty space LEB %d:%d, corruption starts at %d",
 				  lnum, offs, corruption);
 			/* Make sure we dump interesting non-0xFF data */
@@ -766,6 +790,7 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
 	len = c->leb_size - offs;

 	clean_buf(c, &buf, lnum, &offs, &len);
+rescure:
 	ubifs_end_scan(c, sleb, lnum, offs);

 	err = fix_unclean_leb(c, sleb, start);
-- 
2.25.1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ubifs: address bit flips in unused free space
  2025-08-18  8:46 [PATCH] ubifs: address bit flips in unused free space shao.mingyin
@ 2025-08-18  9:01 ` Richard Weinberger
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Weinberger @ 2025-08-18  9:01 UTC (permalink / raw)
  To: shao.mingyin
  Cc: chengzhihao1, linux-mtd, linux-kernel, yang.yang29, xu.xin16,
	yang.tao172, richard

On Mon, Aug 18, 2025 at 10:46 AM <shao.mingyin@zte.com.cn> wrote:
>
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
>
> When the recovery detects a free space bit flip, the UBIFS mount fails,
> rendering the UBIFS unusable. This issue can be addressed by reclaiming
> the affected erase block, which involves relocating its valid data. So
> attempting to fix free space bit flip during recovery reduces scenarios
> where users cannot access UBIFS normally.

UBIFS should never see bit flips in empty space.
Fixing this situation happens in the NAND layer.
Please see  nand_check_erased_ecc_chunk() and it's users.

Maybe your NAND driver does not call it?

-- 
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-18 13:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18  8:46 [PATCH] ubifs: address bit flips in unused free space shao.mingyin
2025-08-18  9:01 ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).