From: <shao.mingyin@zte.com.cn>
To: <chengzhihao1@huawei.com>
Cc: <linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
<yang.yang29@zte.com.cn>, <xu.xin16@zte.com.cn>,
<yang.tao172@zte.com.cn>, <richard@nod.at>
Subject: [PATCH] ubifs: address bit flips in unused free space
Date: Mon, 18 Aug 2025 16:46:35 +0800 (CST) [thread overview]
Message-ID: <20250818164635573BQolnx5DcBqRicqxF0DMl@zte.com.cn> (raw)
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
next reply other threads:[~2025-08-18 8:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-18 8:46 shao.mingyin [this message]
2025-08-18 9:01 ` Richard Weinberger
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=20250818164635573BQolnx5DcBqRicqxF0DMl@zte.com.cn \
--to=shao.mingyin@zte.com.cn \
--cc=chengzhihao1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=xu.xin16@zte.com.cn \
--cc=yang.tao172@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
/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
all inboxes | Powered by JetHome®