[RFC] UBI: harden torture_peb to miss less bad blocks.

Arnaud Mouiche arnaud.mouiche at invoxia.com
Fri Apr 8 00:23:34 PDT 2016


Using an uniform pattern spread all over the block under test detect
some issues but not all.

ex: bits in a page affected by bits at a same offset in another page.

Testing every cases is difficult, but at least we can use fuzzing
techniques to discover such issues.

Signed-off-by: Arnaud Mouiche <arnaud.mouiche at invoxia.com>
---
 drivers/mtd/ubi/io.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index ed0bcb3..91ab744 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -89,6 +89,7 @@
 #include <linux/crc32.h>
 #include <linux/err.h>
 #include <linux/slab.h>
+#include <linux/random.h>
 #include "ubi.h"
 
 static int self_check_not_bad(const struct ubi_device *ubi, int pnum);
@@ -412,6 +413,8 @@ static uint8_t patterns[] = {0xa5, 0x5a, 0x0};
 static int torture_peb(struct ubi_device *ubi, int pnum)
 {
 	int err, i, patt_count;
+	uint8_t *peb_rnd_buff = NULL;
+	const int rnd_check_count = 4;
 
 	ubi_msg(ubi, "run torture test for PEB %d", pnum);
 	patt_count = ARRAY_SIZE(patterns);
@@ -456,12 +459,41 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
 			goto out;
 		}
 	}
+	/* try a random pattern */
+	peb_rnd_buff = kmalloc(ubi->peb_size, GFP_KERNEL);
+	if (!peb_rnd_buff) {
+		err = 0;
+		goto out;
+	}
+	for (i=0; i < rnd_check_count; i++) {
+		get_random_bytes(peb_rnd_buff, ubi->peb_size);
+
+		err = do_sync_erase(ubi, pnum);
+		if (err)
+			goto out;
+
+		err = ubi_io_write(ubi, peb_rnd_buff, pnum, 0, ubi->peb_size);
+		if (err)
+			goto out;
+
+		err = ubi_io_read(ubi, ubi->peb_buf, pnum, 0, ubi->peb_size);
+		if (err)
+			goto out;
+
+		if (memcmp(peb_rnd_buff, ubi->peb_buf, ubi->peb_size)) {
+			ubi_err(ubi, "random pattern checking failed for PEB %d",
+				pnum);
+			err = -EIO;
+			goto out;
+		}
+	}
 
 	err = patt_count;
 	ubi_msg(ubi, "PEB %d passed torture test, do not mark it as bad", pnum);
 
 out:
 	mutex_unlock(&ubi->buf_mutex);
+	kfree(peb_rnd_buff);
 	if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) {
 		/*
 		 * If a bit-flip or data integrity error was detected, the test
-- 
1.9.1




More information about the linux-mtd mailing list