Skip to content

Commit 92d124f

Browse files
Artem BityutskiyArtem Bityutskiy
authored andcommitted
UBI: make self-checks dynamic
This patch adds a possibility to dynamically switch UBI self-checks on and off, instead of toggling them compile-time from the configuration menu. This is much more flexible, and consistent with UBIFS, and this also simplifies UBI Kconfig menu and the code. This patch introduces two levels of self-checks - general, which includes all self-checks which are relatively fast, and I/O, which includes write-verify checks and erase-verify checks, which are relatively slow and involve flash I/O. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent b342efd commit 92d124f

8 files changed

Lines changed: 70 additions & 25 deletions

File tree

‎drivers/mtd/ubi/Kconfig.debug‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ config MTD_UBI_DEBUG
1010

1111
if MTD_UBI_DEBUG
1212

13-
config MTD_UBI_DEBUG_PARANOID
14-
bool "Extra self-checks"
15-
help
16-
This option enables extra checks in UBI code. Note this slows UBI down
17-
significantly.
18-
1913
config MTD_UBI_DEBUG_DISABLE_BGT
2014
bool "Do not enable the UBI background thread"
2115
help

‎drivers/mtd/ubi/debug.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
#include <linux/moduleparam.h>
3232

3333
unsigned int ubi_msg_flags;
34+
unsigned int ubi_chk_flags;
3435

3536
module_param_named(debug_msgs, ubi_msg_flags, uint, S_IRUGO | S_IWUSR);
37+
module_param_named(debug_chks, ubi_chk_flags, uint, S_IRUGO | S_IWUSR);
3638

3739
MODULE_PARM_DESC(debug_msgs, "Debug message type flags");
40+
MODULE_PARM_DESC(debug_chks, "Debug check flags");
3841

3942
/**
4043
* ubi_dbg_dump_ec_hdr - dump an erase counter header.

‎drivers/mtd/ubi/debug.h‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,22 @@ enum {
9999
/* Initialization and build messages */
100100
#define dbg_bld(fmt, ...) dbg_do_msg(UBI_MSG_BLD, fmt, ##__VA_ARGS__)
101101

102-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
102+
extern unsigned int ubi_chk_flags;
103+
104+
/*
105+
* Debugging check flags.
106+
*
107+
* UBI_CHK_GEN: general checks
108+
* UBI_CHK_IO: check writes and erases
109+
*/
110+
enum {
111+
UBI_CHK_GEN = 0x1,
112+
UBI_CHK_IO = 0x2,
113+
};
114+
103115
int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
104116
int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
105117
int offset, int len);
106-
#else
107-
#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
108-
#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
109-
#endif
110118

111119
#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
112120
#define DBG_DISABLE_BGT 1

‎drivers/mtd/ubi/io.c‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#include <linux/slab.h>
9292
#include "ubi.h"
9393

94-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
94+
#ifdef CONFIG_MTD_UBI_DEBUG
9595
static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum);
9696
static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum);
9797
static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
@@ -1126,7 +1126,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
11261126
return err;
11271127
}
11281128

1129-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
1129+
#ifdef CONFIG_MTD_UBI_DEBUG
11301130

11311131
/**
11321132
* paranoid_check_not_bad - ensure that a physical eraseblock is not bad.
@@ -1140,6 +1140,9 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
11401140
{
11411141
int err;
11421142

1143+
if (!(ubi_chk_flags & UBI_CHK_IO))
1144+
return 0;
1145+
11431146
err = ubi_io_is_bad(ubi, pnum);
11441147
if (!err)
11451148
return err;
@@ -1164,6 +1167,9 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
11641167
int err;
11651168
uint32_t magic;
11661169

1170+
if (!(ubi_chk_flags & UBI_CHK_IO))
1171+
return 0;
1172+
11671173
magic = be32_to_cpu(ec_hdr->magic);
11681174
if (magic != UBI_EC_HDR_MAGIC) {
11691175
ubi_err("bad magic %#08x, must be %#08x",
@@ -1199,6 +1205,9 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
11991205
uint32_t crc, hdr_crc;
12001206
struct ubi_ec_hdr *ec_hdr;
12011207

1208+
if (!(ubi_chk_flags & UBI_CHK_IO))
1209+
return 0;
1210+
12021211
ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
12031212
if (!ec_hdr)
12041213
return -ENOMEM;
@@ -1240,6 +1249,9 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
12401249
int err;
12411250
uint32_t magic;
12421251

1252+
if (!(ubi_chk_flags & UBI_CHK_IO))
1253+
return 0;
1254+
12431255
magic = be32_to_cpu(vid_hdr->magic);
12441256
if (magic != UBI_VID_HDR_MAGIC) {
12451257
ubi_err("bad VID header magic %#08x at PEB %d, must be %#08x",
@@ -1278,6 +1290,9 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
12781290
struct ubi_vid_hdr *vid_hdr;
12791291
void *p;
12801292

1293+
if (!(ubi_chk_flags & UBI_CHK_IO))
1294+
return 0;
1295+
12811296
vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
12821297
if (!vid_hdr)
12831298
return -ENOMEM;
@@ -1327,6 +1342,9 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
13271342
void *buf1;
13281343
loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
13291344

1345+
if (!(ubi_chk_flags & UBI_CHK_IO))
1346+
return 0;
1347+
13301348
buf1 = __vmalloc(len, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
13311349
if (!buf1) {
13321350
ubi_err("cannot allocate memory to check writes");
@@ -1388,6 +1406,9 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
13881406
void *buf;
13891407
loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
13901408

1409+
if (!(ubi_chk_flags & UBI_CHK_IO))
1410+
return 0;
1411+
13911412
buf = __vmalloc(len, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
13921413
if (!buf) {
13931414
ubi_err("cannot allocate memory to check for 0xFFs");
@@ -1422,4 +1443,4 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
14221443
return err;
14231444
}
14241445

1425-
#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
1446+
#endif /* CONFIG_MTD_UBI_DEBUG */

‎drivers/mtd/ubi/scan.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
#include <linux/random.h>
8989
#include "ubi.h"
9090

91-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
91+
#ifdef CONFIG_MTD_UBI_DEBUG
9292
static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si);
9393
#else
9494
#define paranoid_check_si(ubi, si) 0
@@ -1329,7 +1329,7 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si)
13291329
kfree(si);
13301330
}
13311331

1332-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
1332+
#ifdef CONFIG_MTD_UBI_DEBUG
13331333

13341334
/**
13351335
* paranoid_check_si - check the scanning information.
@@ -1347,6 +1347,9 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
13471347
struct ubi_scan_leb *seb, *last_seb;
13481348
uint8_t *buf;
13491349

1350+
if (!(ubi_chk_flags & UBI_CHK_GEN))
1351+
return 0;
1352+
13501353
/*
13511354
* At first, check that scanning information is OK.
13521355
*/
@@ -1599,4 +1602,4 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
15991602
return -EINVAL;
16001603
}
16011604

1602-
#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
1605+
#endif /* CONFIG_MTD_UBI_DEBUG */

‎drivers/mtd/ubi/vmt.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <linux/slab.h>
2929
#include "ubi.h"
3030

31-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
31+
#ifdef CONFIG_MTD_UBI_DEBUG
3232
static int paranoid_check_volumes(struct ubi_device *ubi);
3333
#else
3434
#define paranoid_check_volumes(ubi) 0
@@ -711,7 +711,7 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
711711
volume_sysfs_close(vol);
712712
}
713713

714-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
714+
#ifdef CONFIG_MTD_UBI_DEBUG
715715

716716
/**
717717
* paranoid_check_volume - check volume information.
@@ -876,6 +876,9 @@ static int paranoid_check_volumes(struct ubi_device *ubi)
876876
{
877877
int i, err = 0;
878878

879+
if (!(ubi_chk_flags & UBI_CHK_GEN))
880+
return 0;
881+
879882
for (i = 0; i < ubi->vtbl_slots; i++) {
880883
err = paranoid_check_volume(ubi, i);
881884
if (err)

‎drivers/mtd/ubi/vtbl.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
#include <asm/div64.h>
6363
#include "ubi.h"
6464

65-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
65+
#ifdef CONFIG_MTD_UBI_DEBUG
6666
static void paranoid_vtbl_check(const struct ubi_device *ubi);
6767
#else
6868
#define paranoid_vtbl_check(ubi)
@@ -870,18 +870,21 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si)
870870
return err;
871871
}
872872

873-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
873+
#ifdef CONFIG_MTD_UBI_DEBUG
874874

875875
/**
876876
* paranoid_vtbl_check - check volume table.
877877
* @ubi: UBI device description object
878878
*/
879879
static void paranoid_vtbl_check(const struct ubi_device *ubi)
880880
{
881+
if (!(ubi_chk_flags & UBI_CHK_GEN))
882+
return;
883+
881884
if (vtbl_check(ubi, ubi->vtbl)) {
882885
ubi_err("paranoid check failed");
883886
BUG();
884887
}
885888
}
886889

887-
#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
890+
#endif /* CONFIG_MTD_UBI_DEBUG */

‎drivers/mtd/ubi/wl.c‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct ubi_work {
161161
int torture;
162162
};
163163

164-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
164+
#ifdef CONFIG_MTD_UBI_DEBUG
165165
static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec);
166166
static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
167167
struct rb_root *root);
@@ -1561,7 +1561,7 @@ void ubi_wl_close(struct ubi_device *ubi)
15611561
kfree(ubi->lookuptbl);
15621562
}
15631563

1564-
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
1564+
#ifdef CONFIG_MTD_UBI_DEBUG
15651565

15661566
/**
15671567
* paranoid_check_ec - make sure that the erase counter of a PEB is correct.
@@ -1578,6 +1578,9 @@ static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec)
15781578
long long read_ec;
15791579
struct ubi_ec_hdr *ec_hdr;
15801580

1581+
if (!(ubi_chk_flags & UBI_CHK_GEN))
1582+
return 0;
1583+
15811584
ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
15821585
if (!ec_hdr)
15831586
return -ENOMEM;
@@ -1614,6 +1617,9 @@ static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec)
16141617
static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
16151618
struct rb_root *root)
16161619
{
1620+
if (!(ubi_chk_flags & UBI_CHK_GEN))
1621+
return 0;
1622+
16171623
if (in_wl_tree(e, root))
16181624
return 0;
16191625

@@ -1636,6 +1642,9 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
16361642
struct ubi_wl_entry *p;
16371643
int i;
16381644

1645+
if (!(ubi_chk_flags & UBI_CHK_GEN))
1646+
return 0;
1647+
16391648
for (i = 0; i < UBI_PROT_QUEUE_LEN; ++i)
16401649
list_for_each_entry(p, &ubi->pq[i], u.list)
16411650
if (p == e)
@@ -1646,4 +1655,5 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
16461655
ubi_dbg_dump_stack();
16471656
return -EINVAL;
16481657
}
1649-
#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
1658+
1659+
#endif /* CONFIG_MTD_UBI_DEBUG */

0 commit comments

Comments
 (0)