Skip to contentSkip to conversation

UBI: fix endless loop when a bitflip was detected

PATCH New Holger Brunck 2 participants 4 messages Sep 13, 2011 – Oct 7, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 UBI: fix endless loop when a bitflip was detected

On km_kirkwood boards we saw that u-boot gets stuck if the UBI layer detects a correctable bitflip in the NAND flash when u-boot tries to attach to the UBI device.

This was already fixed in the UBI layer in the current mainline linux. The original commit was:

"commit b86a2c56e512f46d140a4bcb4e35e8a7d4a99a4b

Author: Artem Bityutskiy <[email protected]>
Date:   Sun May 24 14:13:34 2009 +0300

UBI: do not switch to R/O mode on read errors

This patch improves UBI errors handling. ATM UBI switches to R/O mode when the WL worker fails to read the source PEB. This means that the upper layers (e.g., UBIFS) has no chances to unmap the erroneous PEB and fix the error. This patch changes this behaviour and makes UBI put PEBs like this into a separate RB-tree, thus preventing the WL worker from hitting the same read errors again and again.

But there is a 10% limit on a maximum amount of PEBs like this. If there are too much of them, UBI switches to R/O mode.

Additionally, this patch teaches UBI not to panic and switch to R/O mode if after a PEB has been copied, the target LEB cannot be read back. Instead, now UBI cancels the operation and schedules the target PEB for torturing.

The error paths has been tested by ingecting errors into 'ubi_eba_copy_leb()'."

This patch is the portation to u-boot with some changes. The constants for errors used in the original patch were replaced with numeric values as present in current ubi layer. The constant "MOVE_TARGET_RD_ERR" was removed from the original patch because the current u-boot version didn't evaluate this value.

---
 drivers/mtd/ubi/build.c |    9 +++++++++
 drivers/mtd/ubi/eba.c   |    8 ++++++--
 drivers/mtd/ubi/ubi.h   |   10 ++++++++--
 drivers/mtd/ubi/wl.c    |   43 +++++++++++++++++++++++++++++++++++++------
 4 files changed, 60 insertions(+), 10 deletions(-)
drivers/mtd/ubi/build.c +9 -0
index 3ea0e6c..95ce665 100644
@@ -607,6 +607,15 @@ static int io_init(struct ubi_device *ubi)
 	}
 
 	/*
+	 * Set maximum amount of physical erroneous eraseblocks to be 10%.
+	 * Erroneous PEB are those which have read errors.
+	 */
+	ubi->max_erroneous = ubi->peb_count / 10;
+	if (ubi->max_erroneous < 16)
+		ubi->max_erroneous = 16;
+	dbg_msg("max_erroneous    %d", ubi->max_erroneous);
+
+	/*
 	 * It may happen that EC and VID headers are situated in one minimal
 	 * I/O unit. In this case we can only accept this UBI image in
 	 * read-only mode.
drivers/mtd/ubi/eba.c +6 -2
index d523c94..82131b7 100644
@@ -438,8 +438,9 @@ retry:
 				 * not implemented.
 				 */
 				if (err == UBI_IO_BAD_VID_HDR) {
-					ubi_warn("bad VID header at PEB %d, LEB"
-						 "%d:%d", pnum, vol_id, lnum);
+					ubi_warn("corrupted VID header at PEB "
+						 "%d, LEB %d:%d", pnum, vol_id,
+						 lnum);
 					err = -EBADMSG;
 				} else
 					ubi_ro_mode(ubi);
@@ -1053,6 +1054,9 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
 	if (err && err != UBI_IO_BITFLIPS) {
 		ubi_warn("error %d while reading data from PEB %d",
 			 err, from);
+		if (err == -EIO)
+			err = 2;
+
 		goto out_unlock_buf;
 	}
 
drivers/mtd/ubi/ubi.h +8 -2
index bf77a15..dbb00c3 100644
@@ -293,14 +293,15 @@ struct ubi_wl_entry;
  * @alc_mutex: serializes "atomic LEB change" operations
  *
  * @used: RB-tree of used physical eraseblocks
+ * @erroneous: RB-tree of erroneous used physical eraseblocks
  * @free: RB-tree of free physical eraseblocks
  * @scrub: RB-tree of physical eraseblocks which need scrubbing
  * @prot: protection trees
  * @prot.pnum: protection tree indexed by physical eraseblock numbers
  * @prot.aec: protection tree indexed by absolute erase counter value
  * @wl_lock: protects the @used, @free, @prot, @lookuptbl, @abs_ec, @move_from,
- *           @move_to, @move_to_put @erase_pending, @wl_scheduled, and @works
- *           fields
+ * 	     @move_to, @move_to_put @erase_pending, @wl_scheduled, @works and
+ * 	     @erroneous_peb_count fields
  * @move_mutex: serializes eraseblock moves
  * @wl_scheduled: non-zero if the wear-leveling was scheduled
  * @lookuptbl: a table to quickly find a &struct ubi_wl_entry object for any
@@ -320,6 +321,8 @@ struct ubi_wl_entry;
  * @peb_size: physical eraseblock size
  * @bad_peb_count: count of bad physical eraseblocks
  * @good_peb_count: count of good physical eraseblocks
+ * @erroneous_peb_count: count of erroneous physical eraseblocks in @erroneous
+ * @max_erroneous: maximum allowed amount of erroneous physical eraseblocks
  * @min_io_size: minimal input/output unit size of the underlying MTD device
  * @hdrs_min_io_size: minimal I/O unit size used for VID and EC headers
  * @ro_mode: if the UBI device is in read-only mode
@@ -376,6 +379,7 @@ struct ubi_device {
 
 	/* Wear-leveling unit's stuff */
 	struct rb_root used;
+	struct rb_root erroneous;
 	struct rb_root free;
 	struct rb_root scrub;
 	struct {
@@ -403,6 +407,8 @@ struct ubi_device {
 	int peb_size;
 	int bad_peb_count;
 	int good_peb_count;
+	int erroneous_peb_count;
+	int max_erroneous;
 	int min_io_size;
 	int hdrs_min_io_size;
 	int ro_mode;
drivers/mtd/ubi/wl.c +37 -6

91 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 UBI: fix endless loop when a bitflip was detected

Quoted 39 lines · Holger Brunck

On km_kirkwood boards we saw that u-boot gets stuck if the UBI layer detects a correctable bitflip in the NAND flash when u-boot tries to attach to the UBI device.

This was already fixed in the UBI layer in the current mainline linux. The original commit was:

"commit b86a2c56e512f46d140a4bcb4e35e8a7d4a99a4b

Author: Artem Bityutskiy <[email protected]>
Date:   Sun May 24 14:13:34 2009 +0300

UBI: do not switch to R/O mode on read errors

This patch improves UBI errors handling. ATM UBI switches to R/O mode when the WL worker fails to read the source PEB. This means that the upper layers (e.g., UBIFS) has no chances to unmap the erroneous PEB and fix the error. This patch changes this behaviour and makes UBI put PEBs like this into a separate RB-tree, thus preventing the WL worker from hitting the same read errors again and again.

But there is a 10% limit on a maximum amount of PEBs like this. If there are too much of them, UBI switches to R/O mode.

Additionally, this patch teaches UBI not to panic and switch to R/O mode if after a PEB has been copied, the target LEB cannot be read back. Instead, now UBI cancels the operation and schedules the target PEB for torturing.

The error paths has been tested by ingecting errors into 'ubi_eba_copy_leb()'."

This patch is the portation to u-boot with some changes. The constants for errors used in the original patch were replaced with numeric values as present in current ubi layer. The constant "MOVE_TARGET_RD_ERR" was removed from the original patch because the current u-boot version didn't evaluate this value.

Quoted 9 lines
---
 drivers/mtd/ubi/build.c |    9 +++++++++
 drivers/mtd/ubi/eba.c   |    8 ++++++--
 drivers/mtd/ubi/ubi.h   |   10 ++++++++--
 drivers/mtd/ubi/wl.c    |   43 +++++++++++++++++++++++++++++++++++++------
 4 files changed, 60 insertions(+), 10 deletions(-)

please drop this patch. I was wrong, see:
http://lists.denx.de/pipermail/u-boot/2011-September/101887.html

Best regards
Holger

#2 lore raw

PATCH 1/1 UBI: fix endless loop when a bitflip was detected

In reply to Holger Brunck

Dear Holger Brunck,

Quoted 39 lines · In message <[email protected]> you…

On km_kirkwood boards we saw that u-boot gets stuck if the UBI layer detects a correctable bitflip in the NAND flash when u-boot tries to attach to the UBI device.

This was already fixed in the UBI layer in the current mainline linux. The original commit was:

"commit b86a2c56e512f46d140a4bcb4e35e8a7d4a99a4b

Author: Artem Bityutskiy <[email protected]>
Date:   Sun May 24 14:13:34 2009 +0300

UBI: do not switch to R/O mode on read errors

This patch improves UBI errors handling. ATM UBI switches to R/O mode when the WL worker fails to read the source PEB. This means that the upper layers (e.g., UBIFS) has no chances to unmap the erroneous PEB and fix the error. This patch changes this behaviour and makes UBI put PEBs like this into a separate RB-tree, thus preventing the WL worker from hitting the same read errors again and again.

But there is a 10% limit on a maximum amount of PEBs like this. If there are too much of them, UBI switches to R/O mode.

Additionally, this patch teaches UBI not to panic and switch to R/O mode if after a PEB has been copied, the target LEB cannot be read back. Instead, now UBI cancels the operation and schedules the target PEB for torturing.

The error paths has been tested by ingecting errors into 'ubi_eba_copy_leb()'."

This patch is the portation to u-boot with some changes. The constants for errors used in the original patch were replaced with numeric values as present in current ubi layer. The constant "MOVE_TARGET_RD_ERR" was removed from the original patch because the current u-boot version didn't evaluate this value.

Quoted 8 lines
---
 drivers/mtd/ubi/build.c |    9 +++++++++
 drivers/mtd/ubi/eba.c   |    8 ++++++--
 drivers/mtd/ubi/ubi.h   |   10 ++++++++--
 drivers/mtd/ubi/wl.c    |   43 +++++++++++++++++++++++++++++++++++++------
 4 files changed, 60 insertions(+), 10 deletions(-)

Checkpatch says:

total: 0 errors, 2 warnings, 166 lines checked

Please clean up and resubmit. Thanks.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A modem is a baudy house.
#3 lore raw

PATCH 1/1 UBI: fix endless loop when a bitflip was detected

Hi Wolfgang,

Quoted 12 lines · Wolfgang Denk
Quoted 11 lines · In message <[email protected]> you…

On km_kirkwood boards we saw that u-boot gets stuck if the UBI layer detects a correctable bitflip in the NAND flash when u-boot tries to attach to the UBI device.

This was already fixed in the UBI layer in the current mainline linux. The original commit was:

"commit b86a2c56e512f46d140a4bcb4e35e8a7d4a99a4b

Author: Artem Bityutskiy <[email protected]>
Date:   Sun May 24 14:13:34 2009 +0300

[...]

Quoted 10 lines
Quoted 9 lines
---
 drivers/mtd/ubi/build.c |    9 +++++++++
 drivers/mtd/ubi/eba.c   |    8 ++++++--
 drivers/mtd/ubi/ubi.h   |   10 ++++++++--
 drivers/mtd/ubi/wl.c    |   43 +++++++++++++++++++++++++++++++++++++------
 4 files changed, 60 insertions(+), 10 deletions(-)
Quoted 6 lines

Checkpatch says:

total: 0 errors, 2 warnings, 166 lines checked

Please clean up and resubmit. Thanks.

I already made the request to drop this patch. Please take a look at:
http://lists.denx.de/pipermail/u-boot/2011-September/101888.html

Best regards
Holger Brunck