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
Unified · Split
| @@ -771,7 +771,7 @@ void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av) · 770 unmodified lines | ||
| 771 | 771 | static int early_erase_peb(struct ubi_device *ubi, |
| 772 | 772 | const struct ubi_attach_info *ai, int pnum, int ec) |
| 773 | 773 | { |
| 774 | − int err; | |
| 774 | + int err, torture = 0; | |
| 775 | 775 | struct ubi_ec_hdr *ec_hdr; |
| 776 | 776 | |
| 777 | 777 | if ((long long)ec >= UBI_MAX_ERASECOUNTER) { |
| @@ -790,7 +790,7 @@ static int early_erase_peb(struct ubi_device *ubi, · 12 unmodified lines | ||
| 790 | 790 | |
| 791 | 791 | ec_hdr->ec = cpu_to_be64(ec); |
| 792 | 792 | |
| 793 | − err = ubi_io_sync_erase(ubi, pnum, 0); | |
| 793 | + err = ubi_io_sync_erase(ubi, pnum, &torture); | |
| 794 | 794 | if (err < 0) |
| 795 | 795 | goto out_free; |
| 796 | 796 | |
| @@ -36,7 +36,7 @@ · 35 unmodified lines | ||
| 36 | 36 | #define MTD_PARAM_LEN_MAX 64 |
| 37 | 37 | |
| 38 | 38 | /* Maximum number of comma-separated items in the 'mtd=' parameter */ |
| 39 | −#define MTD_PARAM_MAX_COUNT 6 | |
| 39 | +#define MTD_PARAM_MAX_COUNT 7 | |
| 40 | 40 | |
| 41 | 41 | /* Maximum value for the number of bad PEBs per 1024 PEBs */ |
| 42 | 42 | #define MAX_MTD_UBI_BEB_LIMIT 768 |
| @@ -56,6 +56,7 @@ · 13 unmodified lines | ||
| 56 | 56 | * @max_beb_per1024: maximum expected number of bad PEBs per 1024 PEBs |
| 57 | 57 | * @enable_fm: enable fastmap when value is non-zero |
| 58 | 58 | * @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 | |
| 59 | 60 | */ |
| 60 | 61 | struct mtd_dev_param { |
| 61 | 62 | char name[MTD_PARAM_LEN_MAX]; |
| @@ -64,6 +65,7 @@ struct mtd_dev_param { · 2 unmodified lines | ||
| 64 | 65 | int max_beb_per1024; |
| 65 | 66 | int enable_fm; |
| 66 | 67 | int need_resv_pool; |
| 68 | + int wl_threshold; | |
| 67 | 69 | }; |
| 68 | 70 | |
| 69 | 71 | /* 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 | ||
| 832 | 834 | * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs |
| 833 | 835 | * @disable_fm: whether disable fastmap |
| 834 | 836 | * @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 | |
| 835 | 839 | * |
| 836 | 840 | * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number |
| 837 | 841 | * 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 | ||
| 848 | 852 | */ |
| 849 | 853 | int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, |
| 850 | 854 | int vid_hdr_offset, int max_beb_per1024, bool disable_fm, |
| 851 | − bool need_resv_pool) | |
| 855 | + bool need_resv_pool, int wl_threshold) | |
| 852 | 856 | { |
| 853 | 857 | struct ubi_device *ubi; |
| 854 | 858 | int i, err; |
| @@ -859,6 +863,15 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, · 4 unmodified lines | ||
| 859 | 863 | if (!max_beb_per1024) |
| 860 | 864 | max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT; |
| 861 | 865 | |
| 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 | + | |
| 862 | 875 | /* |
| 863 | 876 | * Check if we already have the same MTD device attached. |
| 864 | 877 | * |
| @@ -944,6 +957,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, · 79 unmodified lines | ||
| 944 | 957 | ubi->ubi_num = ubi_num; |
| 945 | 958 | ubi->vid_hdr_offset = vid_hdr_offset; |
| 946 | 959 | ubi->autoresize_vol_id = -1; |
| 960 | + ubi->wl_threshold = wl_threshold; | |
| 961 | + ubi->wl_free_max_diff = wl_threshold * 2; | |
| 947 | 962 | |
| 948 | 963 | #ifdef CONFIG_MTD_UBI_FASTMAP |
| 949 | 964 | 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 | ||
| 1044 | 1059 | ubi->vol_count - UBI_INT_VOL_COUNT, UBI_INT_VOL_COUNT, |
| 1045 | 1060 | ubi->vtbl_slots); |
| 1046 | 1061 | 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, | |
| 1048 | 1063 | ubi->image_seq); |
| 1049 | 1064 | ubi_msg(ubi, "available PEBs: %d, total reserved PEBs: %d, PEBs reserved for bad PEB handling: %d", |
| 1050 | 1065 | 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 | ||
| 1105 | 1120 | ubi->ref_count -= 1; |
| 1106 | 1121 | if (ubi->ref_count) { |
| 1107 | 1122 | if (!anyway) { |
| 1123 | + put_device(&ubi->dev); | |
| 1108 | 1124 | spin_unlock(&ubi_devices_lock); |
| 1109 | 1125 | return -EBUSY; |
| 1110 | 1126 | } |
| @@ -1247,7 +1263,7 @@ static void ubi_notify_add(struct mtd_info *mtd) · 136 unmodified lines | ||
| 1247 | 1263 | |
| 1248 | 1264 | /* called while holding mtd_table_mutex */ |
| 1249 | 1265 | 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); | |
| 1251 | 1267 | mutex_unlock(&ubi_devices_mutex); |
| 1252 | 1268 | if (err < 0) |
| 1253 | 1269 | __put_mtd_device(mtd); |
| @@ -1289,7 +1305,8 @@ static int __init ubi_init_attach(void) · 35 unmodified lines | ||
| 1289 | 1305 | err = ubi_attach_mtd_dev(mtd, p->ubi_num, |
| 1290 | 1306 | p->vid_hdr_offs, p->max_beb_per1024, |
| 1291 | 1307 | p->enable_fm == 0, |
| 1292 | − p->need_resv_pool != 0); | |
| 1308 | + p->need_resv_pool != 0, | |
| 1309 | + p->wl_threshold); | |
| 1293 | 1310 | mutex_unlock(&ubi_devices_mutex); |
| 1294 | 1311 | if (err < 0) { |
| 1295 | 1312 | pr_err("UBI error: cannot attach mtd%d\n", |
| @@ -1317,10 +1334,10 @@ static int __init ubi_init_attach(void) · 21 unmodified lines | ||
| 1317 | 1334 | return 0; |
| 1318 | 1335 | |
| 1319 | 1336 | out_detach: |
| 1320 | − for (k = 0; k < i; k++) | |
| 1337 | + for (k = 0; k < UBI_MAX_DEVICES; k++) | |
| 1321 | 1338 | if (ubi_devices[k]) { |
| 1322 | 1339 | mutex_lock(&ubi_devices_mutex); |
| 1323 | − ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1); | |
| 1340 | + ubi_detach_mtd_dev(k, 1); | |
| 1324 | 1341 | mutex_unlock(&ubi_devices_mutex); |
| 1325 | 1342 | } |
| 1326 | 1343 | return err; |
| @@ -1569,12 +1586,24 @@ static int ubi_mtd_param_parse(const char *val, const struct kernel_param *kp) · 242 unmodified lines | ||
| 1569 | 1586 | } else |
| 1570 | 1587 | p->need_resv_pool = 0; |
| 1571 | 1588 | |
| 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 | + | |
| 1572 | 1601 | mtd_devs += 1; |
| 1573 | 1602 | return 0; |
| 1574 | 1603 | } |
| 1575 | 1604 | |
| 1576 | 1605 | 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" | |
| 1578 | 1607 | "Multiple \"mtd\" parameters may be specified.\n" |
| 1579 | 1608 | "MTD devices may be specified by their number, name, or path to the MTD character device node.\n" |
| 1580 | 1609 | "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 | ||
| 1587 | 1616 | "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n" |
| 1588 | 1617 | "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" |
| 1589 | 1618 | "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" | |
| 1590 | 1620 | "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" |
| 1591 | 1621 | "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"); | |
| 1593 | 1623 | #ifdef CONFIG_MTD_UBI_FASTMAP |
| 1594 | 1624 | module_param(fm_autoconvert, bool, 0644); |
| 1595 | 1625 | MODULE_PARM_DESC(fm_autoconvert, "Set this parameter to enable fastmap automatically on images without a fastmap."); |
| @@ -1112,7 +1112,7 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd, · 1111 unmodified lines | ||
| 1112 | 1112 | mutex_lock(&ubi_devices_mutex); |
| 1113 | 1113 | err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset, |
| 1114 | 1114 | req.max_beb_per1024, !!req.disable_fm, |
| 1115 | − !!req.need_resv_pool); | |
| 1115 | + !!req.need_resv_pool, req.wl_threshold); | |
| 1116 | 1116 | mutex_unlock(&ubi_devices_mutex); |
| 1117 | 1117 | if (err < 0) |
| 1118 | 1118 | put_mtd_device(mtd); |
| @@ -238,7 +238,7 @@ void ubi_refill_pools_and_lock(struct ubi_device *ubi) · 237 unmodified lines | ||
| 238 | 238 | if (left_free <= 0) |
| 239 | 239 | break; |
| 240 | 240 | |
| 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, | |
| 242 | 242 | !can_fill_pools(ubi, left_free)); |
| 243 | 243 | self_check_in_wl_tree(ubi, e, &ubi->free); |
| 244 | 244 | rb_erase(&e->u.rb, &ubi->free); |
| @@ -392,18 +392,18 @@ static bool need_wear_leveling(struct ubi_device *ubi) · 147 unmodified lines | ||
| 392 | 392 | if (!e) { |
| 393 | 393 | if (!ubi->free.rb_node) |
| 394 | 394 | 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); | |
| 396 | 396 | ec = e->ec; |
| 397 | 397 | } else { |
| 398 | 398 | ec = e->ec; |
| 399 | 399 | 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); | |
| 401 | 401 | ec = max(ec, e->ec); |
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | e = rb_entry(rb_first(&ubi->used), struct ubi_wl_entry, u.rb); |
| 405 | 405 | |
| 406 | − return ec - e->ec >= UBI_WL_THRESHOLD; | |
| 406 | + return ec - e->ec >= ubi->wl_threshold; | |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /* get_peb_for_wl - returns a PEB to be used internally by the WL sub-system. |
| @@ -1526,7 +1526,8 @@ int ubi_update_fastmap(struct ubi_device *ubi) · 1525 unmodified lines | ||
| 1526 | 1526 | |
| 1527 | 1527 | if (!tmp_e) { |
| 1528 | 1528 | 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]); | |
| 1530 | 1531 | if (ret < 0) { |
| 1531 | 1532 | ubi_err(ubi, "could not erase old fastmap PEB"); |
| 1532 | 1533 | |
| @@ -1578,7 +1579,8 @@ int ubi_update_fastmap(struct ubi_device *ubi) · 45 unmodified lines | ||
| 1578 | 1579 | if (old_fm) { |
| 1579 | 1580 | /* no fresh anchor PEB was found, reuse the old one */ |
| 1580 | 1581 | 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]); | |
| 1582 | 1584 | if (ret < 0) { |
| 1583 | 1585 | ubi_err(ubi, "could not erase old anchor PEB"); |
| 1584 | 1586 | |
| @@ -519,8 +519,10 @@ error: · 518 unmodified lines | ||
| 519 | 519 | /** |
| 520 | 520 | * ubi_io_sync_erase - synchronously erase a physical eraseblock. |
| 521 | 521 | * @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 | |
| 524 | 526 | * |
| 525 | 527 | * This function synchronously erases physical eraseblock @pnum. If @torture |
| 526 | 528 | * flag is not zero, the physical eraseblock is checked by means of writing |
| @@ -532,7 +534,7 @@ error: · 5 unmodified lines | ||
| 532 | 534 | * codes in case of other errors. Note, %-EIO means that the physical |
| 533 | 535 | * eraseblock is bad. |
| 534 | 536 | */ |
| 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) | |
| 536 | 538 | { |
| 537 | 539 | int err, ret = 0; |
| 538 | 540 | |
| @@ -560,10 +562,11 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture) · 21 unmodified lines | ||
| 560 | 562 | return err; |
| 561 | 563 | } |
| 562 | 564 | |
| 563 | − if (torture) { | |
| 565 | + if (*torture) { | |
| 564 | 566 | ret = torture_peb(ubi, pnum); |
| 565 | 567 | if (ret < 0) |
| 566 | 568 | return ret; |
| 569 | + *torture = 0; | |
| 567 | 570 | } |
| 568 | 571 | |
| 569 | 572 | err = do_sync_erase(ubi, pnum); |
| @@ -516,6 +516,22 @@ struct ubi_debug_info { · 515 unmodified lines | ||
| 516 | 516 | * @bgt_thread: background thread description object |
| 517 | 517 | * @thread_enabled: if the background thread is enabled |
| 518 | 518 | * @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. | |
| 519 | 535 | * |
| 520 | 536 | * @flash_size: underlying MTD device size (in bytes) |
| 521 | 537 | * @peb_count: count of physical eraseblocks on the MTD device |
| @@ -623,6 +639,8 @@ struct ubi_device { · 101 unmodified lines | ||
| 623 | 639 | struct task_struct *bgt_thread; |
| 624 | 640 | int thread_enabled; |
| 625 | 641 | char bgt_name[sizeof(UBI_BGT_NAME_PATTERN)+2]; |
| 642 | + int wl_threshold; | |
| 643 | + int wl_free_max_diff; | |
| 626 | 644 | |
| 627 | 645 | /* I/O sub-system's stuff */ |
| 628 | 646 | 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 | ||
| 901 | 919 | struct ubi_attach_info *ai_scan); |
| 902 | 920 | |
| 903 | 921 | /* 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); | |
| 905 | 923 | int ubi_wl_get_peb(struct ubi_device *ubi); |
| 906 | 924 | int ubi_wl_put_peb(struct ubi_device *ubi, int vol_id, int lnum, |
| 907 | 925 | 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 | ||
| 923 | 941 | int len); |
| 924 | 942 | int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, |
| 925 | 943 | 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); | |
| 927 | 945 | int ubi_io_is_bad(const struct ubi_device *ubi, int pnum); |
| 928 | 946 | int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum); |
| 929 | 947 | 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 | ||
| 938 | 956 | /* build.c */ |
| 939 | 957 | int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, |
| 940 | 958 | 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); | |
| 942 | 961 | int ubi_detach_mtd_dev(int ubi_num, int anyway); |
| 943 | 962 | struct ubi_device *ubi_get_device(int ubi_num); |
| 944 | 963 | void ubi_put_device(struct ubi_device *ubi); |
| @@ -95,27 +95,6 @@ · 94 unmodified lines | ||
| 95 | 95 | /* Number of physical eraseblocks reserved for wear-leveling purposes */ |
| 96 | 96 | #define WL_RESERVED_PEBS 1 |
| 97 | 97 | |
| 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 | − | |
| 119 | 98 | /* |
| 120 | 99 | * Maximum number of consecutive background thread failures which is enough to |
| 121 | 100 | * switch to read-only mode. |
| @@ -358,7 +337,7 @@ static struct ubi_wl_entry *find_wl_entry(struct ubi_device *ubi, · 236 unmodified lines | ||
| 358 | 337 | * |
| 359 | 338 | * This function looks for a wear leveling entry with medium erase counter, |
| 360 | 339 | * but not greater or equivalent than the lowest erase counter plus |
| 361 | − * %WL_FREE_MAX_DIFF/2. | |
| 340 | + * @ubi->wl_free_max_diff/2. | |
| 362 | 341 | */ |
| 363 | 342 | static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi, |
| 364 | 343 | struct rb_root *root) |
| @@ -368,7 +347,7 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi, · 3 unmodified lines | ||
| 368 | 347 | first = rb_entry(rb_first(root), struct ubi_wl_entry, u.rb); |
| 369 | 348 | last = rb_entry(rb_last(root), struct ubi_wl_entry, u.rb); |
| 370 | 349 | |
| 371 | − if (last->ec - first->ec < WL_FREE_MAX_DIFF) { | |
| 350 | + if (last->ec - first->ec < ubi->wl_free_max_diff) { | |
| 372 | 351 | e = rb_entry(root->rb_node, struct ubi_wl_entry, u.rb); |
| 373 | 352 | |
| 374 | 353 | /* |
| @@ -379,7 +358,7 @@ static struct ubi_wl_entry *find_mean_wl_entry(struct ubi_device *ubi, · 4 unmodified lines | ||
| 379 | 358 | */ |
| 380 | 359 | e = may_reserve_for_fm(ubi, e, root); |
| 381 | 360 | } 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); | |
| 383 | 362 | |
| 384 | 363 | return e; |
| 385 | 364 | } |
| @@ -443,12 +422,14 @@ static int prot_queue_del(struct ubi_device *ubi, int pnum) · 57 unmodified lines | ||
| 443 | 422 | * ubi_sync_erase - synchronously erase a physical eraseblock. |
| 444 | 423 | * @ubi: UBI device description object |
| 445 | 424 | * @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 | |
| 447 | 428 | * |
| 448 | 429 | * This function returns zero in case of success and a negative error code in |
| 449 | 430 | * case of failure. |
| 450 | 431 | */ |
| 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) | |
| 452 | 433 | { |
| 453 | 434 | int err; |
| 454 | 435 | 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 | ||
| 706 | 687 | #ifdef CONFIG_MTD_UBI_FASTMAP |
| 707 | 688 | e1 = find_anchor_wl_entry(&ubi->used); |
| 708 | 689 | 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)) { | |
| 710 | 691 | ubi->fm_do_produce_anchor = 1; |
| 711 | 692 | /* |
| 712 | 693 | * 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 | ||
| 743 | 724 | if (!e2) |
| 744 | 725 | goto out_cancel; |
| 745 | 726 | |
| 746 | − if (!(e2->ec - e1->ec >= UBI_WL_THRESHOLD)) { | |
| 727 | + if (!(e2->ec - e1->ec >= ubi->wl_threshold)) { | |
| 747 | 728 | dbg_wl("no WL needed: min used EC %d, max free EC %d", |
| 748 | 729 | e1->ec, e2->ec); |
| 749 | 730 | |
| @@ -1056,12 +1037,12 @@ static int ensure_wear_leveling(struct ubi_device *ubi, int nested) · 306 unmodified lines | ||
| 1056 | 1037 | * We schedule wear-leveling only if the difference between the |
| 1057 | 1038 | * lowest erase counter of used physical eraseblocks and a high |
| 1058 | 1039 | * erase counter of free physical eraseblocks is greater than |
| 1059 | − * %UBI_WL_THRESHOLD. | |
| 1040 | + * @ubi->wl_threshold. | |
| 1060 | 1041 | */ |
| 1061 | 1042 | 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); | |
| 1063 | 1044 | |
| 1064 | − if (!(e2->ec - e1->ec >= UBI_WL_THRESHOLD)) | |
| 1045 | + if (!(e2->ec - e1->ec >= ubi->wl_threshold)) | |
| 1065 | 1046 | goto out_unlock; |
| 1066 | 1047 | #endif |
| 1067 | 1048 | 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 | ||
| 1113 | 1094 | dbg_wl("erase PEB %d EC %d LEB %d:%d", |
| 1114 | 1095 | pnum, e->ec, wl_wrk->vol_id, wl_wrk->lnum); |
| 1115 | 1096 | |
| 1116 | − err = ubi_sync_erase(ubi, e, wl_wrk->torture); | |
| 1097 | + err = ubi_sync_erase(ubi, e, &wl_wrk->torture); | |
| 1117 | 1098 | if (!err) { |
| 1118 | 1099 | spin_lock(&ubi->wl_lock); |
| 1119 | 1100 | |
| @@ -1150,7 +1131,8 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk) · 30 unmodified lines | ||
| 1150 | 1131 | int err1; |
| 1151 | 1132 | |
| 1152 | 1133 | /* 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); | |
| 1154 | 1136 | if (err1) { |
| 1155 | 1137 | spin_lock(&ubi->wl_lock); |
| 1156 | 1138 | wl_entry_destroy(ubi, e); |
| @@ -1757,7 +1739,7 @@ static void shutdown_work(struct ubi_device *ubi) · 600 unmodified lines | ||
| 1757 | 1739 | static int erase_aeb(struct ubi_device *ubi, struct ubi_ainf_peb *aeb, bool sync) |
| 1758 | 1740 | { |
| 1759 | 1741 | struct ubi_wl_entry *e; |
| 1760 | − int err; | |
| 1742 | + int err, torture = 0; | |
| 1761 | 1743 | |
| 1762 | 1744 | e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL); |
| 1763 | 1745 | if (!e) |
| @@ -1768,7 +1750,7 @@ static int erase_aeb(struct ubi_device *ubi, struct ubi_ainf_peb *aeb, bool sync · 4 unmodified lines | ||
| 1768 | 1750 | ubi->lookuptbl[e->pnum] = e; |
| 1769 | 1751 | |
| 1770 | 1752 | if (sync) { |
| 1771 | − err = ubi_sync_erase(ubi, e, false); | |
| 1753 | + err = ubi_sync_erase(ubi, e, &torture); | |
| 1772 | 1754 | if (err) |
| 1773 | 1755 | goto out_free; |
| 1774 | 1756 | |
| @@ -2090,7 +2072,7 @@ static struct ubi_wl_entry *get_peb_for_wl(struct ubi_device *ubi) · 315 unmodified lines | ||
| 2090 | 2072 | { |
| 2091 | 2073 | struct ubi_wl_entry *e; |
| 2092 | 2074 | |
| 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); | |
| 2094 | 2076 | self_check_in_wl_tree(ubi, e, &ubi->free); |
| 2095 | 2077 | ubi->free_count--; |
| 2096 | 2078 | ubi_assert(ubi->free_count >= 0); |
| @@ -217,7 +217,7 @@ int ubifs_sb_verify_signature(struct ubifs_info *c, · 216 unmodified lines | ||
| 217 | 217 | |
| 218 | 218 | signode = snod->node; |
| 219 | 219 | |
| 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)) { | |
| 221 | 221 | ubifs_err(c, "invalid signature len %d", le32_to_cpu(signode->len)); |
| 222 | 222 | err = -EINVAL; |
| 223 | 223 | goto out_destroy; |
| @@ -26,7 +26,7 @@ typedef int (*dbg_znode_callback)(struct ubifs_info *c, · 25 unmodified lines | ||
| 26 | 26 | #define UBIFS_DFS_DIR_LEN (3 + 1 + 2 + 3 + 1) |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | − * ubifs_debug_info - per-FS debugging information. | |
| 29 | + * struct ubifs_debug_info - per-FS debugging information. | |
| 30 | 30 | * @old_zroot: old index root - used by 'dbg_check_old_index()' |
| 31 | 31 | * @old_zroot_level: old index root level - used by 'dbg_check_old_index()' |
| 32 | 32 | * @old_zroot_sqnum: old index root sqnum - used by 'dbg_check_old_index()' |
| @@ -119,7 +119,7 @@ struct ubifs_debug_info { · 86 unmodified lines | ||
| 119 | 119 | }; |
| 120 | 120 | |
| 121 | 121 | /** |
| 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. | |
| 123 | 123 | * |
| 124 | 124 | * @chk_gen: if general extra checks are enabled |
| 125 | 125 | * @chk_index: if index xtra checks are enabled |
| @@ -33,7 +33,7 @@ · 32 unmodified lines | ||
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * key_mask_hash - mask a valid hash value. |
| 36 | − * @val: value to be masked | |
| 36 | + * @hash: value to be masked | |
| 37 | 37 | * |
| 38 | 38 | * We use hash values as offset in directories, so values %0 and %1 are |
| 39 | 39 | * reserved for "." and "..". %2 is reserved for "end of readdir" marker. This |
| @@ -738,6 +738,7 @@ struct ubifs_jhead { · 737 unmodified lines | ||
| 738 | 738 | * struct ubifs_zbranch - key/coordinate/length branch stored in znodes. |
| 739 | 739 | * @key: key |
| 740 | 740 | * @znode: znode address in memory |
| 741 | + * @leaf: leaf node | |
| 741 | 742 | * @lnum: LEB number of the target node (indexing node or data node) |
| 742 | 743 | * @offs: target node offset within @lnum |
| 743 | 744 | * @len: target node length |
| @@ -801,7 +802,7 @@ struct ubifs_znode { · 57 unmodified lines | ||
| 801 | 802 | * @gc_seq: GC sequence number to detect races with GC |
| 802 | 803 | * @cnt: number of data nodes for bulk read |
| 803 | 804 | * @blk_cnt: number of data blocks including holes |
| 804 | − * @oef: end of file reached | |
| 805 | + * @eof: end of file reached | |
| 805 | 806 | */ |
| 806 | 807 | struct bu_info { |
| 807 | 808 | union ubifs_key key; |
| @@ -985,7 +986,7 @@ struct ubifs_budg_info { · 177 unmodified lines | ||
| 985 | 986 | }; |
| 986 | 987 | |
| 987 | 988 | /** |
| 988 | − * ubifs_stats_info - per-FS statistics information. | |
| 989 | + * struct ubifs_stats_info - per-FS statistics information. | |
| 989 | 990 | * @magic_errors: number of bad magic numbers (will be reset with a new mount). |
| 990 | 991 | * @node_errors: number of bad nodes (will be reset with a new mount). |
| 991 | 992 | * @crc_errors: number of bad crcs (will be reset with a new mount). |
| @@ -1051,6 +1052,7 @@ struct ubifs_debug_info; · 59 unmodified lines | ||
| 1051 | 1052 | * @rw_incompat: the media is not R/W compatible |
| 1052 | 1053 | * @assert_action: action to take when a ubifs_assert() fails |
| 1053 | 1054 | * @authenticated: flag indigating the FS is mounted in authenticated mode |
| 1055 | + * @superblock_need_write: superblock node needs to be written | |
| 1054 | 1056 | * |
| 1055 | 1057 | * @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and |
| 1056 | 1058 | * @calc_idx_sz |
| @@ -1588,8 +1590,9 @@ int ubifs_prepare_auth_node(struct ubifs_info *c, void *node, · 531 unmodified lines | ||
| 1588 | 1590 | * @expected: first hash |
| 1589 | 1591 | * @got: second hash |
| 1590 | 1592 | * |
| 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. | |
| 1593 | 1596 | */ |
| 1594 | 1597 | static inline int ubifs_check_hash(const struct ubifs_info *c, |
| 1595 | 1598 | const u8 *expected, const u8 *got) |
| @@ -1603,8 +1606,9 @@ static inline int ubifs_check_hash(const struct ubifs_info *c, · 7 unmodified lines | ||
| 1603 | 1606 | * @expected: first HMAC |
| 1604 | 1607 | * @got: second HMAC |
| 1605 | 1608 | * |
| 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. | |
| 1608 | 1612 | */ |
| 1609 | 1613 | static inline int ubifs_check_hmac(const struct ubifs_info *c, |
| 1610 | 1614 | const u8 *expected, const u8 *got) |
| @@ -1644,7 +1648,7 @@ static inline void ubifs_exit_authentication(struct ubifs_info *c) · 33 unmodified lines | ||
| 1644 | 1648 | * @c: UBIFS file-system description object |
| 1645 | 1649 | * @br: branch to get the hash from |
| 1646 | 1650 | * |
| 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 | |
| 1648 | 1652 | * dynamically sized object we cannot use a struct member here. |
| 1649 | 1653 | */ |
| 1650 | 1654 | 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 | ||
| 1694 | 1698 | * ubifs_auth_node_sz - returns the size of an authentication node |
| 1695 | 1699 | * @c: UBIFS file-system description object |
| 1696 | 1700 | * |
| 1697 | − * This function returns the size of an authentication node which can | |
| 1701 | + * Returns: the size of an authentication node which can | |
| 1698 | 1702 | * be 0 for unauthenticated filesystems or the real size of an auth node |
| 1699 | 1703 | * authentication is enabled. |
| 1700 | 1704 | */ |
| @@ -289,6 +289,13 @@ enum { · 288 unmodified lines | ||
| 289 | 289 | * If @disable_fm is not zero, ubi doesn't create new fastmap even the module |
| 290 | 290 | * param 'fm_autoconvert' is set, and existed old fastmap will be destroyed |
| 291 | 291 | * 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. | |
| 292 | 299 | */ |
| 293 | 300 | struct ubi_attach_req { |
| 294 | 301 | __s32 ubi_num; |
| @@ -297,7 +304,8 @@ struct ubi_attach_req { · 2 unmodified lines | ||
| 297 | 304 | __s16 max_beb_per1024; |
| 298 | 305 | __s8 disable_fm; |
| 299 | 306 | __s8 need_resv_pool; |
| 300 | − __s8 padding[8]; | |
| 307 | + __s32 wl_threshold; | |
| 308 | + __s8 padding[4]; | |
| 301 | 309 | }; |
| 302 | 310 | |
| 303 | 311 | /* |