Skip to content

Commit ab0b2e5

Browse files
committed
Merge tag 'upstream-4.18-rc1' of git://git.infradead.org/linux-ubifs
Pull UBI and UBIFS updates from Richard Weinberger: - the UBI on-disk format header file is now dual licensed - new way to detect Fastmap problems during runtime - bugfix for Fastmap - minor updates for UBIFS (spelling, comments, vm_fault_t, ...) * tag 'upstream-4.18-rc1' of git://git.infradead.org/linux-ubifs: mtd: ubi: Update ubi-media.h to dual license ubi: fastmap: Detect EBA mismatches on-the-fly ubi: fastmap: Check each mapping only once ubi: fastmap: Correctly handle interrupted erasures in EBA ubi: fastmap: Cancel work upon detach ubifs: lpt: Fix wrong pnode number range in comment ubifs: gc: Fix typo ubifs: log: Some spelling fixes ubifs: Spelling fix someting -> something ubifs: journal: Remove wrong comment ubifs: remove set but never used variable ubifs, xattr: remove misguided quota flags fs: ubifs: Adding new return type vm_fault_t
2 parents 5f85942 + f5a926d commit ab0b2e5

File tree

16 files changed

+178
-46
lines changed

16 files changed

+178
-46
lines changed

drivers/mtd/ubi/build.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ void ubi_free_internal_volumes(struct ubi_device *ubi)
526526
for (i = ubi->vtbl_slots;
527527
i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
528528
ubi_eba_replace_table(ubi->volumes[i], NULL);
529+
ubi_fastmap_destroy_checkmap(ubi->volumes[i]);
529530
kfree(ubi->volumes[i]);
530531
}
531532
}
@@ -1091,6 +1092,9 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
10911092
if (ubi->bgt_thread)
10921093
kthread_stop(ubi->bgt_thread);
10931094

1095+
#ifdef CONFIG_MTD_UBI_FASTMAP
1096+
cancel_work_sync(&ubi->fm_work);
1097+
#endif
10941098
ubi_debugfs_exit_dev(ubi);
10951099
uif_close(ubi);
10961100

drivers/mtd/ubi/eba.c

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,103 @@ int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
490490
return err;
491491
}
492492

493+
#ifdef CONFIG_MTD_UBI_FASTMAP
494+
/**
495+
* check_mapping - check and fixup a mapping
496+
* @ubi: UBI device description object
497+
* @vol: volume description object
498+
* @lnum: logical eraseblock number
499+
* @pnum: physical eraseblock number
500+
*
501+
* Checks whether a given mapping is valid. Fastmap cannot track LEB unmap
502+
* operations, if such an operation is interrupted the mapping still looks
503+
* good, but upon first read an ECC is reported to the upper layer.
504+
* Normaly during the full-scan at attach time this is fixed, for Fastmap
505+
* we have to deal with it while reading.
506+
* If the PEB behind a LEB shows this symthom we change the mapping to
507+
* %UBI_LEB_UNMAPPED and schedule the PEB for erasure.
508+
*
509+
* Returns 0 on success, negative error code in case of failure.
510+
*/
511+
static int check_mapping(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
512+
int *pnum)
513+
{
514+
int err;
515+
struct ubi_vid_io_buf *vidb;
516+
struct ubi_vid_hdr *vid_hdr;
517+
518+
if (!ubi->fast_attach)
519+
return 0;
520+
521+
if (!vol->checkmap || test_bit(lnum, vol->checkmap))
522+
return 0;
523+
524+
vidb = ubi_alloc_vid_buf(ubi, GFP_NOFS);
525+
if (!vidb)
526+
return -ENOMEM;
527+
528+
err = ubi_io_read_vid_hdr(ubi, *pnum, vidb, 0);
529+
if (err > 0 && err != UBI_IO_BITFLIPS) {
530+
int torture = 0;
531+
532+
switch (err) {
533+
case UBI_IO_FF:
534+
case UBI_IO_FF_BITFLIPS:
535+
case UBI_IO_BAD_HDR:
536+
case UBI_IO_BAD_HDR_EBADMSG:
537+
break;
538+
default:
539+
ubi_assert(0);
540+
}
541+
542+
if (err == UBI_IO_BAD_HDR_EBADMSG || err == UBI_IO_FF_BITFLIPS)
543+
torture = 1;
544+
545+
down_read(&ubi->fm_eba_sem);
546+
vol->eba_tbl->entries[lnum].pnum = UBI_LEB_UNMAPPED;
547+
up_read(&ubi->fm_eba_sem);
548+
ubi_wl_put_peb(ubi, vol->vol_id, lnum, *pnum, torture);
549+
550+
*pnum = UBI_LEB_UNMAPPED;
551+
} else if (err < 0) {
552+
ubi_err(ubi, "unable to read VID header back from PEB %i: %i",
553+
*pnum, err);
554+
555+
goto out_free;
556+
} else {
557+
int found_vol_id, found_lnum;
558+
559+
ubi_assert(err == 0 || err == UBI_IO_BITFLIPS);
560+
561+
vid_hdr = ubi_get_vid_hdr(vidb);
562+
found_vol_id = be32_to_cpu(vid_hdr->vol_id);
563+
found_lnum = be32_to_cpu(vid_hdr->lnum);
564+
565+
if (found_lnum != lnum || found_vol_id != vol->vol_id) {
566+
ubi_err(ubi, "EBA mismatch! PEB %i is LEB %i:%i instead of LEB %i:%i",
567+
*pnum, found_vol_id, found_lnum, vol->vol_id, lnum);
568+
ubi_ro_mode(ubi);
569+
err = -EINVAL;
570+
goto out_free;
571+
}
572+
}
573+
574+
set_bit(lnum, vol->checkmap);
575+
err = 0;
576+
577+
out_free:
578+
ubi_free_vid_buf(vidb);
579+
580+
return err;
581+
}
582+
#else
583+
static int check_mapping(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
584+
int *pnum)
585+
{
586+
return 0;
587+
}
588+
#endif
589+
493590
/**
494591
* ubi_eba_read_leb - read data.
495592
* @ubi: UBI device description object
@@ -522,7 +619,13 @@ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
522619
return err;
523620

524621
pnum = vol->eba_tbl->entries[lnum].pnum;
525-
if (pnum < 0) {
622+
if (pnum >= 0) {
623+
err = check_mapping(ubi, vol, lnum, &pnum);
624+
if (err < 0)
625+
goto out_unlock;
626+
}
627+
628+
if (pnum == UBI_LEB_UNMAPPED) {
526629
/*
527630
* The logical eraseblock is not mapped, fill the whole buffer
528631
* with 0xFF bytes. The exception is static volumes for which
@@ -930,6 +1033,12 @@ int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
9301033
return err;
9311034

9321035
pnum = vol->eba_tbl->entries[lnum].pnum;
1036+
if (pnum >= 0) {
1037+
err = check_mapping(ubi, vol, lnum, &pnum);
1038+
if (err < 0)
1039+
goto out;
1040+
}
1041+
9331042
if (pnum >= 0) {
9341043
dbg_eba("write %d bytes at offset %d of LEB %d:%d, PEB %d",
9351044
len, offset, vol_id, lnum, pnum);

drivers/mtd/ubi/fastmap.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,26 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
11001100
goto out;
11011101
}
11021102

1103+
int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count)
1104+
{
1105+
struct ubi_device *ubi = vol->ubi;
1106+
1107+
if (!ubi->fast_attach)
1108+
return 0;
1109+
1110+
vol->checkmap = kcalloc(BITS_TO_LONGS(leb_count), sizeof(unsigned long),
1111+
GFP_KERNEL);
1112+
if (!vol->checkmap)
1113+
return -ENOMEM;
1114+
1115+
return 0;
1116+
}
1117+
1118+
void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol)
1119+
{
1120+
kfree(vol->checkmap);
1121+
}
1122+
11031123
/**
11041124
* ubi_write_fastmap - writes a fastmap.
11051125
* @ubi: UBI device object

drivers/mtd/ubi/ubi-media.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
1+
/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
12
/*
2-
* Copyright (c) International Business Machines Corp., 2006
3-
*
4-
* This program is free software; you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation; either version 2 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12-
* the GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program; if not, write to the Free Software
16-
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17-
*
3+
* Copyright (C) International Business Machines Corp., 2006
184
* Authors: Artem Bityutskiy (Битюцкий Артём)
195
* Thomas Gleixner
206
* Frank Haverkamp
217
* Oliver Lohmann
228
* Andreas Arnez
23-
*/
24-
25-
/*
9+
*
2610
* This file defines the layout of UBI headers and all the other UBI on-flash
2711
* data structures.
2812
*/

drivers/mtd/ubi/ubi.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ struct ubi_eba_leb_desc {
334334
* @changing_leb: %1 if the atomic LEB change ioctl command is in progress
335335
* @direct_writes: %1 if direct writes are enabled for this volume
336336
*
337+
* @checkmap: bitmap to remember which PEB->LEB mappings got checked,
338+
* protected by UBI LEB lock tree.
339+
*
337340
* The @corrupted field indicates that the volume's contents is corrupted.
338341
* Since UBI protects only static volumes, this field is not relevant to
339342
* dynamic volumes - it is user's responsibility to assure their data
@@ -377,6 +380,10 @@ struct ubi_volume {
377380
unsigned int updating:1;
378381
unsigned int changing_leb:1;
379382
unsigned int direct_writes:1;
383+
384+
#ifdef CONFIG_MTD_UBI_FASTMAP
385+
unsigned long *checkmap;
386+
#endif
380387
};
381388

382389
/**
@@ -965,8 +972,12 @@ size_t ubi_calc_fm_size(struct ubi_device *ubi);
965972
int ubi_update_fastmap(struct ubi_device *ubi);
966973
int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
967974
struct ubi_attach_info *scan_ai);
975+
int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count);
976+
void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol);
968977
#else
969978
static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; }
979+
int static inline ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count) { return 0; }
980+
static inline void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol) {}
970981
#endif
971982

972983
/* block.c */

drivers/mtd/ubi/vmt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static void vol_release(struct device *dev)
139139
struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
140140

141141
ubi_eba_replace_table(vol, NULL);
142+
ubi_fastmap_destroy_checkmap(vol);
142143
kfree(vol);
143144
}
144145

drivers/mtd/ubi/vtbl.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ static int init_volumes(struct ubi_device *ubi,
534534
const struct ubi_attach_info *ai,
535535
const struct ubi_vtbl_record *vtbl)
536536
{
537-
int i, reserved_pebs = 0;
537+
int i, err, reserved_pebs = 0;
538538
struct ubi_ainf_volume *av;
539539
struct ubi_volume *vol;
540540

@@ -620,6 +620,16 @@ static int init_volumes(struct ubi_device *ubi,
620620
(long long)(vol->used_ebs - 1) * vol->usable_leb_size;
621621
vol->used_bytes += av->last_data_size;
622622
vol->last_eb_bytes = av->last_data_size;
623+
624+
/*
625+
* We use ubi->peb_count and not vol->reserved_pebs because
626+
* we want to keep the code simple. Otherwise we'd have to
627+
* resize/check the bitmap upon volume resize too.
628+
* Allocating a few bytes more does not hurt.
629+
*/
630+
err = ubi_fastmap_init_checkmap(vol, ubi->peb_count);
631+
if (err)
632+
return err;
623633
}
624634

625635
/* And add the layout volume */
@@ -645,6 +655,9 @@ static int init_volumes(struct ubi_device *ubi,
645655
reserved_pebs += vol->reserved_pebs;
646656
ubi->vol_count += 1;
647657
vol->ubi = ubi;
658+
err = ubi_fastmap_init_checkmap(vol, UBI_LAYOUT_VOLUME_EBS);
659+
if (err)
660+
return err;
648661

649662
if (reserved_pebs > ubi->avail_pebs) {
650663
ubi_err(ubi, "not enough PEBs, required %d, available %d",
@@ -849,6 +862,7 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai)
849862
out_free:
850863
vfree(ubi->vtbl);
851864
for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
865+
ubi_fastmap_destroy_checkmap(ubi->volumes[i]);
852866
kfree(ubi->volumes[i]);
853867
ubi->volumes[i] = NULL;
854868
}

drivers/mtd/ubi/wl.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ int ubi_thread(void *u)
15051505
}
15061506

15071507
dbg_wl("background thread \"%s\" is killed", ubi->bgt_name);
1508+
ubi->thread_enabled = 0;
15081509
return 0;
15091510
}
15101511

@@ -1514,9 +1515,6 @@ int ubi_thread(void *u)
15141515
*/
15151516
static void shutdown_work(struct ubi_device *ubi)
15161517
{
1517-
#ifdef CONFIG_MTD_UBI_FASTMAP
1518-
flush_work(&ubi->fm_work);
1519-
#endif
15201518
while (!list_empty(&ubi->works)) {
15211519
struct ubi_work *wrk;
15221520

fs/ubifs/file.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ static int ubifs_releasepage(struct page *page, gfp_t unused_gfp_flags)
15131513
* mmap()d file has taken write protection fault and is being made writable.
15141514
* UBIFS must ensure page is budgeted for.
15151515
*/
1516-
static int ubifs_vm_page_mkwrite(struct vm_fault *vmf)
1516+
static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf)
15171517
{
15181518
struct page *page = vmf->page;
15191519
struct inode *inode = file_inode(vmf->vma->vm_file);
@@ -1567,8 +1567,7 @@ static int ubifs_vm_page_mkwrite(struct vm_fault *vmf)
15671567
if (unlikely(page->mapping != inode->i_mapping ||
15681568
page_offset(page) > i_size_read(inode))) {
15691569
/* Page got truncated out from underneath us */
1570-
err = -EINVAL;
1571-
goto out_unlock;
1570+
goto sigbus;
15721571
}
15731572

15741573
if (PagePrivate(page))
@@ -1597,12 +1596,10 @@ static int ubifs_vm_page_mkwrite(struct vm_fault *vmf)
15971596
wait_for_stable_page(page);
15981597
return VM_FAULT_LOCKED;
15991598

1600-
out_unlock:
1599+
sigbus:
16011600
unlock_page(page);
16021601
ubifs_release_budget(c, &req);
1603-
if (err)
1604-
err = VM_FAULT_SIGBUS;
1605-
return err;
1602+
return VM_FAULT_SIGBUS;
16061603
}
16071604

16081605
static const struct vm_operations_struct ubifs_file_vm_ops = {

fs/ubifs/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* maximum size. So dark watermark is the amount of free + dirty space in LEB
5050
* which are guaranteed to be reclaimable. If LEB has less space, the GC might
5151
* be unable to reclaim it. So, LEBs with free + dirty greater than dark
52-
* watermark are "good" LEBs from GC's point of few. The other LEBs are not so
52+
* watermark are "good" LEBs from GC's point of view. The other LEBs are not so
5353
* good, and GC takes extra care when moving them.
5454
*/
5555

fs/ubifs/journal.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ static inline void zero_trun_node_unused(struct ubifs_trun_node *trun)
9898
*
9999
* This function reserves space in journal head @head. If the reservation
100100
* succeeded, the journal head stays locked and later has to be unlocked using
101-
* 'release_head()'. 'write_node()' and 'write_head()' functions also unlock
102-
* it. Returns zero in case of success, %-EAGAIN if commit has to be done, and
103-
* other negative error codes in case of other failures.
101+
* 'release_head()'. Returns zero in case of success, %-EAGAIN if commit has to
102+
* be done, and other negative error codes in case of other failures.
104103
*/
105104
static int reserve_space(struct ubifs_info *c, int jhead, int len)
106105
{

fs/ubifs/log.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ void ubifs_add_bud(struct ubifs_info *c, struct ubifs_bud *bud)
167167
* @lnum: LEB number of the bud
168168
* @offs: starting offset of the bud
169169
*
170-
* This function writes reference node for the new bud LEB @lnum it to the log,
171-
* and adds it to the buds tress. It also makes sure that log size does not
170+
* This function writes a reference node for the new bud LEB @lnum to the log,
171+
* and adds it to the buds trees. It also makes sure that log size does not
172172
* exceed the 'c->max_bud_bytes' limit. Returns zero in case of success,
173-
* %-EAGAIN if commit is required, and a negative error codes in case of
173+
* %-EAGAIN if commit is required, and a negative error code in case of
174174
* failure.
175175
*/
176176
int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs)

fs/ubifs/lpt_commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static struct ubifs_pnode *next_pnode_to_dirty(struct ubifs_info *c,
619619
/**
620620
* pnode_lookup - lookup a pnode in the LPT.
621621
* @c: UBIFS file-system description object
622-
* @i: pnode number (0 to main_lebs - 1)
622+
* @i: pnode number (0 to (main_lebs - 1) / UBIFS_LPT_FANOUT))
623623
*
624624
* This function returns a pointer to the pnode on success or a negative
625625
* error code on failure.

0 commit comments

Comments
 (0)