History

Merge tag 'ubifs-for-linus-7.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs

Pull UBI and UBIFS updates from Richard Weinberger: "UBI: - Support for a per-device wear-leveling threshold - Various fixes and cleanups of error paths - Correctly preserve torture flag up wear-leveling UBIFS: - Various fixes and cleanups of error paths and kernel-doc" * tag 'ubifs-for-linus-7.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs: UBI: support per-device wear-leveling threshold UBI: fix two issues in the ubi.mtd MODULE_PARM_DESC mtd: ubi: Release device reference on busy detach ubi: Fix rollback for explicit UBI device numbers ubifs: fix out-of-bounds read in signature length check UBI: fastmap: Pass to_be_tortured when reusing old fastmap PEBs UBI: Preserve torture flag when rescheduling failed erasures ubifs: ubifs.h: clean up kernel-doc comments ubifs: key.h: use correct function parameter name ubifs: debug.h: fix kernel-doc struct prototypes

Linus Torvalds committed 2 months ago

Commit ce727a02 parents 115bd36 a5e005513 files · +122 −74Browse files

Unified · Split

13 files
  1. drivers/mtd/ubi/attach.c +2 −2
  2. drivers/mtd/ubi/build.c +39 −9
  3. drivers/mtd/ubi/cdev.c +1 −1
  4. drivers/mtd/ubi/fastmap-wl.c +4 −4
  5. drivers/mtd/ubi/fastmap.c +4 −2
  6. drivers/mtd/ubi/io.c +7 −4
  7. drivers/mtd/ubi/ubi.h +22 −3
  8. drivers/mtd/ubi/wl.c +18 −36
  9. fs/ubifs/auth.c +1 −1
  10. fs/ubifs/debug.h +2 −2
  11. fs/ubifs/key.h +1 −1
  12. fs/ubifs/ubifs.h +12 −8
  13. include/uapi/mtd/ubi-user.h +9 −1
drivers/mtd/ubi/attach.c+2−2
@@ -771,7 +771,7 @@ void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av) · 770 unmodified lines
771771 static int early_erase_peb(struct ubi_device *ubi,
772772 const struct ubi_attach_info *ai, int pnum, int ec)
773773 {
774− int err;
774+ int err, torture = 0;
775775 struct ubi_ec_hdr *ec_hdr;
776776
777777 if ((long long)ec >= UBI_MAX_ERASECOUNTER) {
@@ -790,7 +790,7 @@ static int early_erase_peb(struct ubi_device *ubi, · 12 unmodified lines
790790
791791 ec_hdr->ec = cpu_to_be64(ec);
792792
793− err = ubi_io_sync_erase(ubi, pnum, 0);
793+ err = ubi_io_sync_erase(ubi, pnum, &torture);
794794 if (err < 0)
795795 goto out_free;
796796
drivers/mtd/ubi/build.c+39−9
@@ -36,7 +36,7 @@ · 35 unmodified lines
3636 #define MTD_PARAM_LEN_MAX 64
3737
3838 /* Maximum number of comma-separated items in the 'mtd=' parameter */
39−#define MTD_PARAM_MAX_COUNT 6
39+#define MTD_PARAM_MAX_COUNT 7
4040
4141 /* Maximum value for the number of bad PEBs per 1024 PEBs */
4242 #define MAX_MTD_UBI_BEB_LIMIT 768
@@ -56,6 +56,7 @@ · 13 unmodified lines
5656 * @max_beb_per1024: maximum expected number of bad PEBs per 1024 PEBs
5757 * @enable_fm: enable fastmap when value is non-zero
5858 * @need_resv_pool: reserve pool->max_size pebs when value is none-zero
59+ * @wl_threshold: wear-leveling threshold, 0 means use CONFIG_MTD_UBI_WL_THRESHOLD
5960 */
6061 struct mtd_dev_param {
6162 char name[MTD_PARAM_LEN_MAX];
@@ -64,6 +65,7 @@ struct mtd_dev_param { · 2 unmodified lines
6465 int max_beb_per1024;
6566 int enable_fm;
6667 int need_resv_pool;
68+ int wl_threshold;
6769 };
6870
6971 /* Numbers of elements set in the @mtd_dev_param array */
@@ -832,6 +834,8 @@ static int autoresize(struct ubi_device *ubi, int vol_id) · 762 unmodified lines
832834 * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs
833835 * @disable_fm: whether disable fastmap
834836 * @need_resv_pool: whether reserve pebs to fill fm_pool
837+ * @wl_threshold: wear-leveling threshold for this UBI device; 0 means use
838+ * %CONFIG_MTD_UBI_WL_THRESHOLD; accepted range is 2-65536
835839 *
836840 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number
837841 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in
@@ -848,7 +852,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id) · 10 unmodified lines
848852 */
849853 int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
850854 int vid_hdr_offset, int max_beb_per1024, bool disable_fm,
851− bool need_resv_pool)
855+ bool need_resv_pool, int wl_threshold)
852856 {
853857 struct ubi_device *ubi;
854858 int i, err;
@@ -859,6 +863,15 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, · 4 unmodified lines
859863 if (!max_beb_per1024)
860864 max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT;
861865
866+ if (!wl_threshold)
867+ wl_threshold = CONFIG_MTD_UBI_WL_THRESHOLD;
868+
869+ if (wl_threshold < 2 || wl_threshold > 65536) {
870+ pr_err("ubi: bad wear-leveling threshold %d\n",
871+ wl_threshold);
872+ return -EINVAL;
873+ }
874+
862875 /*
863876 * Check if we already have the same MTD device attached.
864877 *
@@ -944,6 +957,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, · 79 unmodified lines
944957 ubi->ubi_num = ubi_num;
945958 ubi->vid_hdr_offset = vid_hdr_offset;
946959 ubi->autoresize_vol_id = -1;
960+ ubi->wl_threshold = wl_threshold;
961+ ubi->wl_free_max_diff = wl_threshold * 2;
947962
948963 #ifdef CONFIG_MTD_UBI_FASTMAP
949964 ubi->fm_pool.used = ubi->fm_pool.size = 0;
@@ -1044,7 +1059,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, · 94 unmodified lines
10441059 ubi->vol_count - UBI_INT_VOL_COUNT, UBI_INT_VOL_COUNT,
10451060 ubi->vtbl_slots);
10461061 ubi_msg(ubi, "max/mean erase counter: %d/%d, WL threshold: %d, image sequence number: %u",
1047− ubi->max_ec, ubi->mean_ec, CONFIG_MTD_UBI_WL_THRESHOLD,
1062+ ubi->max_ec, ubi->mean_ec, ubi->wl_threshold,
10481063 ubi->image_seq);
10491064 ubi_msg(ubi, "available PEBs: %d, total reserved PEBs: %d, PEBs reserved for bad PEB handling: %d",
10501065 ubi->avail_pebs, ubi->rsvd_pebs, ubi->beb_rsvd_pebs);
@@ -1105,6 +1120,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) · 54 unmodified lines
11051120 ubi->ref_count -= 1;
11061121 if (ubi->ref_count) {
11071122 if (!anyway) {
1123+ put_device(&ubi->dev);
11081124 spin_unlock(&ubi_devices_lock);
11091125 return -EBUSY;
11101126 }
@@ -1247,7 +1263,7 @@ static void ubi_notify_add(struct mtd_info *mtd) · 136 unmodified lines
12471263
12481264 /* called while holding mtd_table_mutex */
12491265 mutex_lock_nested(&ubi_devices_mutex, SINGLE_DEPTH_NESTING);
1250− err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0, false, false);
1266+ err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0, false, false, 0);
12511267 mutex_unlock(&ubi_devices_mutex);
12521268 if (err < 0)
12531269 __put_mtd_device(mtd);
@@ -1289,7 +1305,8 @@ static int __init ubi_init_attach(void) · 35 unmodified lines
12891305 err = ubi_attach_mtd_dev(mtd, p->ubi_num,
12901306 p->vid_hdr_offs, p->max_beb_per1024,
12911307 p->enable_fm == 0,
1292− p->need_resv_pool != 0);
1308+ p->need_resv_pool != 0,
1309+ p->wl_threshold);
12931310 mutex_unlock(&ubi_devices_mutex);
12941311 if (err < 0) {
12951312 pr_err("UBI error: cannot attach mtd%d\n",
@@ -1317,10 +1334,10 @@ static int __init ubi_init_attach(void) · 21 unmodified lines
13171334 return 0;
13181335
13191336 out_detach:
1320− for (k = 0; k < i; k++)
1337+ for (k = 0; k < UBI_MAX_DEVICES; k++)
13211338 if (ubi_devices[k]) {
13221339 mutex_lock(&ubi_devices_mutex);
1323− ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1);
1340+ ubi_detach_mtd_dev(k, 1);
13241341 mutex_unlock(&ubi_devices_mutex);
13251342 }
13261343 return err;
@@ -1569,12 +1586,24 @@ static int ubi_mtd_param_parse(const char *val, const struct kernel_param *kp) · 242 unmodified lines
15691586 } else
15701587 p->need_resv_pool = 0;
15711588
1589+ token = tokens[6];
1590+ if (token) {
1591+ int err = kstrtoint(token, 10, &p->wl_threshold);
1592+
1593+ if (err) {
1594+ pr_err("UBI error: bad value for wl_threshold parameter: %s\n",
1595+ token);
1596+ return -EINVAL;
1597+ }
1598+ } else
1599+ p->wl_threshold = 0;
1600+
15721601 mtd_devs += 1;
15731602 return 0;
15741603 }
15751604
15761605 module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 0400);
1577−MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024[,ubi_num]]].\n"
1606+MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024[,ubi_num[,enable_fm[,need_resv_pool[,wl_threshold]]]]]].\n"
15781607 "Multiple \"mtd\" parameters may be specified.\n"
15791608 "MTD devices may be specified by their number, name, or path to the MTD character device node.\n"
15801609 "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0)\n"
@@ -1587,9 +1616,10 @@ MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|pa · 6 unmodified lines
15871616 "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n"
15881617 "Example 2: mtd=content,1984 mtd=4 - attach MTD device with name \"content\" using VID header offset 1984, and MTD device number 4 with default VID header offset.\n"
15891618 "Example 3: mtd=/dev/mtd1,0,25 - attach MTD device /dev/mtd1 using default VID header offset and reserve 25*nand_size_in_blocks/1024 erase blocks for bad block handling.\n"
1619+ "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device).\n"
15901620 "Example 4: mtd=/dev/mtd1,0,0,5 - attach MTD device /dev/mtd1 to UBI 5 and using default values for the other fields.\n"
15911621 "example 5: mtd=1,0,0,5 mtd=2,0,0,6,1 - attach MTD device /dev/mtd1 to UBI 5 and disable fastmap; attach MTD device /dev/mtd2 to UBI 6 and enable fastmap.(only works when fastmap is enabled and fm_autoconvert=Y).\n"
1592− "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device).");
1622+ "Example 6: mtd=/dev/mtd0,0,0,0,0,0,256 mtd=/dev/mtd1,0,0,0,0,0,4096 - attach MTD device /dev/mtd0 with wear-leveling threshold 256, and MTD device /dev/mtd1 with threshold 4096.\n");
15931623 #ifdef CONFIG_MTD_UBI_FASTMAP
15941624 module_param(fm_autoconvert, bool, 0644);
15951625 MODULE_PARM_DESC(fm_autoconvert, "Set this parameter to enable fastmap automatically on images without a fastmap.");
drivers/mtd/ubi/cdev.c+1−1
@@ -1112,7 +1112,7 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd, · 1111 unmodified lines
11121112 mutex_lock(&ubi_devices_mutex);
11131113 err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset,
11141114 req.max_beb_per1024, !!req.disable_fm,
1115− !!req.need_resv_pool);
1115+ !!req.need_resv_pool, req.wl_threshold);
11161116 mutex_unlock(&ubi_devices_mutex);
11171117 if (err < 0)
11181118 put_mtd_device(mtd);
drivers/mtd/ubi/fastmap-wl.c+4−4
@@ -238,7 +238,7 @@ void ubi_refill_pools_and_lock(struct ubi_device *ubi) · 237 unmodified lines
238238 if (left_free <= 0)
239239 break;
240240
241− e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF,
241+ e = find_wl_entry(ubi, &ubi->free, ubi->wl_free_max_diff,
242242 !can_fill_pools(ubi, left_free));
243243 self_check_in_wl_tree(ubi, e, &ubi->free);
244244 rb_erase(&e->u.rb, &ubi->free);
@@ -392,18 +392,18 @@ static bool need_wear_leveling(struct ubi_device *ubi) · 147 unmodified lines
392392 if (!e) {
393393 if (!ubi->free.rb_node)
394394 return false;
395− e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF, 0);
395+ e = find_wl_entry(ubi, &ubi->free, ubi->wl_free_max_diff, 0);
396396 ec = e->ec;
397397 } else {
398398 ec = e->ec;
399399 if (ubi->free.rb_node) {
400− e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF, 0);
400+ e = find_wl_entry(ubi, &ubi->free, ubi->wl_free_max_diff, 0);
401401 ec = max(ec, e->ec);
402402 }
403403 }
404404 e = rb_entry(rb_first(&ubi->used), struct ubi_wl_entry, u.rb);
405405
406− return ec - e->ec >= UBI_WL_THRESHOLD;
406+ return ec - e->ec >= ubi->wl_threshold;
407407 }
408408
409409 /* get_peb_for_wl - returns a PEB to be used internally by the WL sub-system.
drivers/mtd/ubi/fastmap.c+4−2
@@ -1526,7 +1526,8 @@ int ubi_update_fastmap(struct ubi_device *ubi) · 1525 unmodified lines
15261526
15271527 if (!tmp_e) {
15281528 if (old_fm && old_fm->e[i]) {
1529− ret = ubi_sync_erase(ubi, old_fm->e[i], 0);
1529+ ret = ubi_sync_erase(ubi, old_fm->e[i],
1530+ &old_fm->to_be_tortured[i]);
15301531 if (ret < 0) {
15311532 ubi_err(ubi, "could not erase old fastmap PEB");
15321533
@@ -1578,7 +1579,8 @@ int ubi_update_fastmap(struct ubi_device *ubi) · 45 unmodified lines
15781579 if (old_fm) {
15791580 /* no fresh anchor PEB was found, reuse the old one */
15801581 if (!tmp_e) {
1581− ret = ubi_sync_erase(ubi, old_fm->e[0], 0);
1582+ ret = ubi_sync_erase(ubi, old_fm->e[0],
1583+ &old_fm->to_be_tortured[0]);
15821584 if (ret < 0) {
15831585 ubi_err(ubi, "could not erase old anchor PEB");
15841586
drivers/mtd/ubi/io.c+7−4
@@ -519,8 +519,10 @@ error: · 518 unmodified lines
519519 /**
520520 * ubi_io_sync_erase - synchronously erase a physical eraseblock.
521521 * @ubi: UBI device description object
522− * @pnum: physical eraseblock number to erase
523− * @torture: if this physical eraseblock has to be tortured
522+ * @pnum: the physical eraseblock number to erase
523+ * @torture: if this physical eraseblock has to be tortured; cleared to zero
524+ * once the torture test has completed successfully so that a retry
525+ * of the erase does not torture the physical eraseblock again
524526 *
525527 * This function synchronously erases physical eraseblock @pnum. If @torture
526528 * flag is not zero, the physical eraseblock is checked by means of writing
@@ -532,7 +534,7 @@ error: · 5 unmodified lines
532534 * codes in case of other errors. Note, %-EIO means that the physical
533535 * eraseblock is bad.
534536 */
535−int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)
537+int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int *torture)
536538 {
537539 int err, ret = 0;
538540
@@ -560,10 +562,11 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture) · 21 unmodified lines
560562 return err;
561563 }
562564
563− if (torture) {
565+ if (*torture) {
564566 ret = torture_peb(ubi, pnum);
565567 if (ret < 0)
566568 return ret;
569+ *torture = 0;
567570 }
568571
569572 err = do_sync_erase(ubi, pnum);
drivers/mtd/ubi/ubi.h+22−3
@@ -516,6 +516,22 @@ struct ubi_debug_info { · 515 unmodified lines
516516 * @bgt_thread: background thread description object
517517 * @thread_enabled: if the background thread is enabled
518518 * @bgt_name: background thread name
519+ * @wl_threshold: Maximum difference between two erase counters. If this
520+ * threshold is exceeded, the WL sub-system starts moving
521+ * data from used physical eraseblocks with low erase
522+ * counter to free physical eraseblocks with high erase counter.
523+ * @wl_free_max_diff: When a physical eraseblock is moved, the WL sub-system
524+ * has to pick the target physical eraseblock to move to.
525+ * The simplest way would be just to pick the one with the
526+ * highest erase counter. But in certain workloads this
527+ * could lead to an unlimited wear of one or few physical
528+ * eraseblock. Indeed, imagine a situation when the picked
529+ * physical eraseblock is constantly erased after the
530+ * data is written to it. So, we have a constant which
531+ * limits the highest erase counter of the free physical
532+ * eraseblock to pick. Namely, the WL sub-system does not
533+ * pick eraseblocks with erase counter greater than the
534+ * lowest erase counter plus @wl_free_max_diff.
519535 *
520536 * @flash_size: underlying MTD device size (in bytes)
521537 * @peb_count: count of physical eraseblocks on the MTD device
@@ -623,6 +639,8 @@ struct ubi_device { · 101 unmodified lines
623639 struct task_struct *bgt_thread;
624640 int thread_enabled;
625641 char bgt_name[sizeof(UBI_BGT_NAME_PATTERN)+2];
642+ int wl_threshold;
643+ int wl_free_max_diff;
626644
627645 /* I/O sub-system's stuff */
628646 long long flash_size;
@@ -901,7 +919,7 @@ int self_check_eba(struct ubi_device *ubi, struct ubi_attach_info *ai_fastmap, · 272 unmodified lines
901919 struct ubi_attach_info *ai_scan);
902920
903921 /* wl.c */
904−int ubi_sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int torture);
922+int ubi_sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int *torture);
905923 int ubi_wl_get_peb(struct ubi_device *ubi);
906924 int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum,
907925 int pnum, int torture);
@@ -923,7 +941,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset, · 15 unmodified lines
923941 int len);
924942 int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
925943 int len);
926−int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture);
944+int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int *torture);
927945 int ubi_io_is_bad(const struct ubi_device *ubi, int pnum);
928946 int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum);
929947 int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
@@ -938,7 +956,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, · 8 unmodified lines
938956 /* build.c */
939957 int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
940958 int vid_hdr_offset, int max_beb_per1024,
941− bool disable_fm, bool need_resv_pool);
959+ bool disable_fm, bool need_resv_pool,
960+ int wl_threshold);
942961 int ubi_detach_mtd_dev(int ubi_num, int anyway);
943962 struct ubi_device *ubi_get_device(int ubi_num);
944963 void ubi_put_device(struct ubi_device *ubi);
drivers/mtd/ubi/wl.c+18−36
@@ -95,27 +95,6 @@ · 94 unmodified lines
9595 /* Number of physical eraseblocks reserved for wear-leveling purposes */
9696 #define WL_RESERVED_PEBS 1
9797
98−/*
99− * Maximum difference between two erase counters. If this threshold is
100− * exceeded, the WL sub-system starts moving data from used physical
101− * eraseblocks with low erase counter to free physical eraseblocks with high
102− * erase counter.
103− */
104−#define UBI_WL_THRESHOLD CONFIG_MTD_UBI_WL_THRESHOLD
105−
106−/*
107− * When a physical eraseblock is moved, the WL sub-system has to pick the target
108− * physical eraseblock to move to. The simplest way would be just to pick the
109− * one with the highest erase counter. But in certain workloads this could lead
110− * to an unlimited wear of one or few physical eraseblock. Indeed, imagine a
111− * situation when the picked physical eraseblock is constantly erased after the
112− * data is written to it. So, we have a constant which limits the highest erase
113− * counter of the free physical eraseblock to pick. Namely, the WL sub-system
114− * does not pick eraseblocks with erase counter greater than the lowest erase
115− * counter plus %WL_FREE_MAX_DIFF.
116− */
117−#define WL_FREE_MAX_DIFF (2*UBI_WL_THRESHOLD)
118−
11998 /*
12099 * Maximum number of consecutive background thread failures which is enough to
121100 * switch to read-only mode.
@@ -358,7 +337,7 @@ static struct ubi_wl_entry *find_wl_entry(struct ubi_device *ubi, · 236 unmodified lines
358337 *
359338 * This function looks for a wear leveling entry with medium erase counter,
360339 * but not greater or equivalent than the lowest erase counter plus
361− * %WL_FREE_MAX_DIFF/2.
340+ * @ubi->wl_free_max_diff/2.
362341 */
363342 static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi,
364343 struct rb_root *root)
@@ -368,7 +347,7 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi, · 3 unmodified lines
368347 first = rb_entry(rb_first(root), struct ubi_wl_entry, u.rb);
369348 last = rb_entry(rb_last(root), struct ubi_wl_entry, u.rb);
370349
371− if (last->ec - first->ec < WL_FREE_MAX_DIFF) {
350+ if (last->ec - first->ec < ubi->wl_free_max_diff) {
372351 e = rb_entry(root->rb_node, struct ubi_wl_entry, u.rb);
373352
374353 /*
@@ -379,7 +358,7 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi, · 4 unmodified lines
379358 */
380359 e = may_reserve_for_fm(ubi, e, root);
381360 } else
382− e = find_wl_entry(ubi, root, WL_FREE_MAX_DIFF/2, 0);
361+ e = find_wl_entry(ubi, root, ubi->wl_free_max_diff/2, 0);
383362
384363 return e;
385364 }
@@ -443,12 +422,14 @@ static int prot_queue_del(struct ubi_device *ubi, int pnum) · 57 unmodified lines
443422 * ubi_sync_erase - synchronously erase a physical eraseblock.
444423 * @ubi: UBI device description object
445424 * @e: the physical eraseblock to erase
446− * @torture: if the physical eraseblock has to be tortured
425+ * @torture: if the physical eraseblock has to be tortured; cleared to zero
426+ * once the torture test has completed successfully so that a retry
427+ * of the erase does not torture the physical eraseblock again
447428 *
448429 * This function returns zero in case of success and a negative error code in
449430 * case of failure.
450431 */
451−int ubi_sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int torture)
432+int ubi_sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int *torture)
452433 {
453434 int err;
454435 struct ubi_ec_hdr *ec_hdr;
@@ -706,7 +687,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, · 251 unmodified lines
706687 #ifdef CONFIG_MTD_UBI_FASTMAP
707688 e1 = find_anchor_wl_entry(&ubi->used);
708689 if (e1 && ubi->fm_anchor &&
709− (ubi->fm_anchor->ec - e1->ec >= UBI_WL_THRESHOLD)) {
690+ (ubi->fm_anchor->ec - e1->ec >= ubi->wl_threshold)) {
710691 ubi->fm_do_produce_anchor = 1;
711692 /*
712693 * fm_anchor is no longer considered a good anchor.
@@ -743,7 +724,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, · 30 unmodified lines
743724 if (!e2)
744725 goto out_cancel;
745726
746− if (!(e2->ec - e1->ec >= UBI_WL_THRESHOLD)) {
727+ if (!(e2->ec - e1->ec >= ubi->wl_threshold)) {
747728 dbg_wl("no WL needed: min used EC %d, max free EC %d",
748729 e1->ec, e2->ec);
749730
@@ -1056,12 +1037,12 @@ static int ensure_wear_leveling(struct ubi_device *ubi, int nested) · 306 unmodified lines
10561037 * We schedule wear-leveling only if the difference between the
10571038 * lowest erase counter of used physical eraseblocks and a high
10581039 * erase counter of free physical eraseblocks is greater than
1059− * %UBI_WL_THRESHOLD.
1040+ * @ubi->wl_threshold.
10601041 */
10611042 e1 = rb_entry(rb_first(&ubi->used), struct ubi_wl_entry, u.rb);
1062− e2 = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF, 0);
1043+ e2 = find_wl_entry(ubi, &ubi->free, ubi->wl_free_max_diff, 0);
10631044
1064− if (!(e2->ec - e1->ec >= UBI_WL_THRESHOLD))
1045+ if (!(e2->ec - e1->ec >= ubi->wl_threshold))
10651046 goto out_unlock;
10661047 #endif
10671048 dbg_wl("schedule wear-leveling");
@@ -1113,7 +1094,7 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk) · 45 unmodified lines
11131094 dbg_wl("erase PEB %d EC %d LEB %d:%d",
11141095 pnum, e->ec, wl_wrk->vol_id, wl_wrk->lnum);
11151096
1116− err = ubi_sync_erase(ubi, e, wl_wrk->torture);
1097+ err = ubi_sync_erase(ubi, e, &wl_wrk->torture);
11171098 if (!err) {
11181099 spin_lock(&ubi->wl_lock);
11191100
@@ -1150,7 +1131,8 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk) · 30 unmodified lines
11501131 int err1;
11511132
11521133 /* Re-schedule the LEB for erasure */
1153− err1 = schedule_erase(ubi, e, vol_id, lnum, 0, true);
1134+ err1 = schedule_erase(ubi, e, vol_id, lnum, wl_wrk->torture,
1135+ true);
11541136 if (err1) {
11551137 spin_lock(&ubi->wl_lock);
11561138 wl_entry_destroy(ubi, e);
@@ -1757,7 +1739,7 @@ static void shutdown_work(struct ubi_device *ubi) · 600 unmodified lines
17571739 static int erase_aeb(struct ubi_device *ubi, struct ubi_ainf_peb *aeb, bool sync)
17581740 {
17591741 struct ubi_wl_entry *e;
1760− int err;
1742+ int err, torture = 0;
17611743
17621744 e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL);
17631745 if (!e)
@@ -1768,7 +1750,7 @@ static int erase_aeb(struct ubi_device *ubi, struct ubi_ainf_peb *aeb, bool sync · 4 unmodified lines
17681750 ubi->lookuptbl[e->pnum] = e;
17691751
17701752 if (sync) {
1771− err = ubi_sync_erase(ubi, e, false);
1753+ err = ubi_sync_erase(ubi, e, &torture);
17721754 if (err)
17731755 goto out_free;
17741756
@@ -2090,7 +2072,7 @@ static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi) · 315 unmodified lines
20902072 {
20912073 struct ubi_wl_entry *e;
20922074
2093− e = find_wl_entry(ubi, &ubi->free, WL_FREE_MAX_DIFF, 0);
2075+ e = find_wl_entry(ubi, &ubi->free, ubi->wl_free_max_diff, 0);
20942076 self_check_in_wl_tree(ubi, e, &ubi->free);
20952077 ubi->free_count--;
20962078 ubi_assert(ubi->free_count >= 0);
fs/ubifs/auth.c+1−1
@@ -217,7 +217,7 @@ int ubifs_sb_verify_signature(struct ubifs_info *c, · 216 unmodified lines
217217
218218 signode = snod->node;
219219
220− if (le32_to_cpu(signode->len) > snod->len + sizeof(struct ubifs_sig_node)) {
220+ if (le32_to_cpu(signode->len) > snod->len - sizeof(struct ubifs_sig_node)) {
221221 ubifs_err(c, "invalid signature len %d", le32_to_cpu(signode->len));
222222 err = -EINVAL;
223223 goto out_destroy;
fs/ubifs/debug.h+2−2
@@ -26,7 +26,7 @@ typedef int (*dbg_znode_callback)(struct ubifs_info *c, · 25 unmodified lines
2626 #define UBIFS_DFS_DIR_LEN (3 + 1 + 2 + 3 + 1)
2727
2828 /**
29− * ubifs_debug_info - per-FS debugging information.
29+ * struct ubifs_debug_info - per-FS debugging information.
3030 * @old_zroot: old index root - used by 'dbg_check_old_index()'
3131 * @old_zroot_level: old index root level - used by 'dbg_check_old_index()'
3232 * @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()'
@@ -119,7 +119,7 @@ struct ubifs_debug_info { · 86 unmodified lines
119119 };
120120
121121 /**
122− * ubifs_global_debug_info - global (not per-FS) UBIFS debugging information.
122+ * struct ubifs_global_debug_info - global (not per-FS) UBIFS debugging information.
123123 *
124124 * @chk_gen: if general extra checks are enabled
125125 * @chk_index: if index xtra checks are enabled
fs/ubifs/key.h+1−1
@@ -33,7 +33,7 @@ · 32 unmodified lines
3333
3434 /**
3535 * key_mask_hash - mask a valid hash value.
36− * @val: value to be masked
36+ * @hash: value to be masked
3737 *
3838 * We use hash values as offset in directories, so values %0 and %1 are
3939 * reserved for "." and "..". %2 is reserved for "end of readdir" marker. This
fs/ubifs/ubifs.h+12−8
@@ -738,6 +738,7 @@ struct ubifs_jhead { · 737 unmodified lines
738738 * struct ubifs_zbranch - key/coordinate/length branch stored in znodes.
739739 * @key: key
740740 * @znode: znode address in memory
741+ * @leaf: leaf node
741742 * @lnum: LEB number of the target node (indexing node or data node)
742743 * @offs: target node offset within @lnum
743744 * @len: target node length
@@ -801,7 +802,7 @@ struct ubifs_znode { · 57 unmodified lines
801802 * @gc_seq: GC sequence number to detect races with GC
802803 * @cnt: number of data nodes for bulk read
803804 * @blk_cnt: number of data blocks including holes
804− * @oef: end of file reached
805+ * @eof: end of file reached
805806 */
806807 struct bu_info {
807808 union ubifs_key key;
@@ -985,7 +986,7 @@ struct ubifs_budg_info { · 177 unmodified lines
985986 };
986987
987988 /**
988− * ubifs_stats_info - per-FS statistics information.
989+ * struct ubifs_stats_info - per-FS statistics information.
989990 * @magic_errors: number of bad magic numbers (will be reset with a new mount).
990991 * @node_errors: number of bad nodes (will be reset with a new mount).
991992 * @crc_errors: number of bad crcs (will be reset with a new mount).
@@ -1051,6 +1052,7 @@ struct ubifs_debug_info; · 59 unmodified lines
10511052 * @rw_incompat: the media is not R/W compatible
10521053 * @assert_action: action to take when a ubifs_assert() fails
10531054 * @authenticated: flag indigating the FS is mounted in authenticated mode
1055+ * @superblock_need_write: superblock node needs to be written
10541056 *
10551057 * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
10561058 * @calc_idx_sz
@@ -1588,8 +1590,9 @@ int ubifs_prepare_auth_node(struct ubifs_info *c, void *node, · 531 unmodified lines
15881590 * @expected: first hash
15891591 * @got: second hash
15901592 *
1591− * Compare two hashes @expected and @got. Returns 0 when they are equal, a
1592− * negative error code otherwise.
1593+ * Compare two hashes @expected and @got.
1594+ *
1595+ * Returns: 0 when they are equal, a negative error code otherwise.
15931596 */
15941597 static inline int ubifs_check_hash(const struct ubifs_info *c,
15951598 const u8 *expected, const u8 *got)
@@ -1603,8 +1606,9 @@ static inline int ubifs_check_hash(const struct ubifs_info *c, · 7 unmodified lines
16031606 * @expected: first HMAC
16041607 * @got: second HMAC
16051608 *
1606− * Compare two hashes @expected and @got. Returns 0 when they are equal, a
1607− * negative error code otherwise.
1609+ * Compare two hashes @expected and @got.
1610+ *
1611+ * Returns: 0 when they are equal, a negative error code otherwise.
16081612 */
16091613 static inline int ubifs_check_hmac(const struct ubifs_info *c,
16101614 const u8 *expected, const u8 *got)
@@ -1644,7 +1648,7 @@ static inline void ubifs_exit_authentication(struct ubifs_info *c) · 33 unmodified lines
16441648 * @c: UBIFS file-system description object
16451649 * @br: branch to get the hash from
16461650 *
1647− * This returns a pointer to the hash of a branch. Since the key already is a
1651+ * Returns: a pointer to the hash of a branch. Since the key already is a
16481652 * dynamically sized object we cannot use a struct member here.
16491653 */
16501654 static inline u8 *ubifs_branch_hash(struct ubifs_info *c,
@@ -1694,7 +1698,7 @@ static inline int ubifs_node_verify_hmac(const struct ubifs_info *c, · 43 unmodified lines
16941698 * ubifs_auth_node_sz - returns the size of an authentication node
16951699 * @c: UBIFS file-system description object
16961700 *
1697− * This function returns the size of an authentication node which can
1701+ * Returns: the size of an authentication node which can
16981702 * be 0 for unauthenticated filesystems or the real size of an auth node
16991703 * authentication is enabled.
17001704 */
include/uapi/mtd/ubi-user.h+9−1
@@ -289,6 +289,13 @@ enum { · 288 unmodified lines
289289 * If @disable_fm is not zero, ubi doesn't create new fastmap even the module
290290 * param 'fm_autoconvert' is set, and existed old fastmap will be destroyed
291291 * after doing full scanning.
292+ *
293+ * The @wl_threshold defines the maximum difference between the highest and the
294+ * lowest erase counter value of eraseblocks of this UBI device. When this
295+ * threshold is exceeded, UBI starts performing wear leveling by means of
296+ * moving data from eraseblock with low erase counter to eraseblocks with high
297+ * erase counter. If @wl_threshold is zero, the default kernel value of
298+ * %CONFIG_MTD_UBI_WL_THRESHOLD is used. The accepted range is 2-65536.
292299 */
293300 struct ubi_attach_req {
294301 __s32 ubi_num;
@@ -297,7 +304,8 @@ struct ubi_attach_req { · 2 unmodified lines
297304 __s16 max_beb_per1024;
298305 __s8 disable_fm;
299306 __s8 need_resv_pool;
300− __s8 padding[8];
307+ __s32 wl_threshold;
308+ __s8 padding[4];
301309 };
302310
303311 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t