Skip to content

Commit

Permalink
Merge tag 'for-linus-5.17-rc1' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/rw/ubifs

Pull JFFS2, UBI and UBIFS updates from Richard Weinberger:
 "JFFS2:
   - Fix for a deadlock in jffs2_write_begin()

  UBI:
   - Fixes in comments

  UBIFS:
   - Expose error counters in sysfs
   - Many bugfixes found by Hulk Robot and others"

* tag 'for-linus-5.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs:
  jffs2: GC deadlock reading a page that is used in jffs2_write_begin()
  ubifs: read-only if LEB may always be taken in ubifs_garbage_collect
  ubifs: fix double return leb in ubifs_garbage_collect
  ubifs: fix slab-out-of-bounds in ubifs_change_lp
  ubifs: fix snprintf() length check
  ubifs: Document sysfs nodes
  ubifs: Export filesystem error counters
  ubifs: Error path in ubifs_remount_rw() seems to wrongly free write buffers
  ubifs: Make use of the helper macro kthread_run()
  ubi: Fix a mistake in comment
  ubifs: Fix spelling mistakes
  • Loading branch information
torvalds committed Jan 11, 2022
2 parents 3f67eae + aa39cc6 commit 5672cdf
Show file tree
Hide file tree
Showing 12 changed files with 309 additions and 28 deletions.
35 changes: 35 additions & 0 deletions Documentation/ABI/testing/sysfs-fs-ubifs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
What: /sys/fs/ubifsX_Y/error_magic
Date: October 2021
KernelVersion: 5.16
Contact: [email protected]
Description:
Exposes magic errors: every node starts with a magic number.

This counter keeps track of the number of accesses of nodes
with a corrupted magic number.

The counter is reset to 0 with a remount.

What: /sys/fs/ubifsX_Y/error_node
Date: October 2021
KernelVersion: 5.16
Contact: [email protected]
Description:
Exposes node errors. Every node embeds its type.

This counter keeps track of the number of accesses of nodes
with a corrupted node type.

The counter is reset to 0 with a remount.

What: /sys/fs/ubifsX_Y/error_crc
Date: October 2021
KernelVersion: 5.16
Contact: [email protected]
Description:
Exposes crc errors: every node embeds a crc checksum.

This counter keeps track of the number of accesses of nodes
with a bad crc checksum.

The counter is reset to 0 with a remount.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -19603,6 +19603,7 @@ S: Supported
W: http://www.linux-mtd.infradead.org/doc/ubifs.html
T: git git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs.git next
T: git git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs.git fixes
F: Documentation/ABI/testing/sysfs-fs-ubifs
F: Documentation/filesystems/ubifs-authentication.rst
F: Documentation/filesystems/ubifs.rst
F: fs/ubifs/
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/ubi/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
}

/**
* dbg_debug_exit_dev - free all debugfs files corresponding to device @ubi
* ubi_debugfs_exit_dev - free all debugfs files corresponding to device @ubi
* @ubi: UBI device description object
*/
void ubi_debugfs_exit_dev(struct ubi_device *ubi)
Expand Down
40 changes: 25 additions & 15 deletions fs/jffs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,15 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
struct page *pg;
struct inode *inode = mapping->host;
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
pgoff_t index = pos >> PAGE_SHIFT;
uint32_t pageofs = index << PAGE_SHIFT;
int ret = 0;

pg = grab_cache_page_write_begin(mapping, index, flags);
if (!pg)
return -ENOMEM;
*pagep = pg;

jffs2_dbg(1, "%s()\n", __func__);

if (pageofs > inode->i_size) {
/* Make new hole frag from old EOF to new page */
struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
struct jffs2_raw_inode ri;
struct jffs2_full_dnode *fn;
uint32_t alloc_len;
Expand All @@ -160,7 +155,7 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
ret = jffs2_reserve_space(c, sizeof(ri), &alloc_len,
ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
if (ret)
goto out_page;
goto out_err;

mutex_lock(&f->sem);
memset(&ri, 0, sizeof(ri));
Expand Down Expand Up @@ -190,7 +185,7 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
ret = PTR_ERR(fn);
jffs2_complete_reservation(c);
mutex_unlock(&f->sem);
goto out_page;
goto out_err;
}
ret = jffs2_add_full_dnode_to_inode(c, f, fn);
if (f->metadata) {
Expand All @@ -205,13 +200,26 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
jffs2_free_full_dnode(fn);
jffs2_complete_reservation(c);
mutex_unlock(&f->sem);
goto out_page;
goto out_err;
}
jffs2_complete_reservation(c);
inode->i_size = pageofs;
mutex_unlock(&f->sem);
}

/*
* While getting a page and reading data in, lock c->alloc_sem until
* the page is Uptodate. Otherwise GC task may attempt to read the same
* page in read_cache_page(), which causes a deadlock.
*/
mutex_lock(&c->alloc_sem);
pg = grab_cache_page_write_begin(mapping, index, flags);
if (!pg) {
ret = -ENOMEM;
goto release_sem;
}
*pagep = pg;

/*
* Read in the page if it wasn't already present. Cannot optimize away
* the whole page write case until jffs2_write_end can handle the
Expand All @@ -221,15 +229,17 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
mutex_lock(&f->sem);
ret = jffs2_do_readpage_nolock(inode, pg);
mutex_unlock(&f->sem);
if (ret)
goto out_page;
if (ret) {
unlock_page(pg);
put_page(pg);
goto release_sem;
}
}
jffs2_dbg(1, "end write_begin(). pg->flags %lx\n", pg->flags);
return ret;

out_page:
unlock_page(pg);
put_page(pg);
release_sem:
mutex_unlock(&c->alloc_sem);
out_err:
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion fs/ubifs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ubifs-y += shrinker.o journal.o file.o dir.o super.o sb.o io.o
ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o
ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o
ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o debug.o
ubifs-y += misc.o
ubifs-y += misc.o sysfs.o
ubifs-$(CONFIG_FS_ENCRYPTION) += crypto.o
ubifs-$(CONFIG_UBIFS_FS_XATTR) += xattr.o
ubifs-$(CONFIG_UBIFS_FS_AUTHENTICATION) += auth.o
4 changes: 2 additions & 2 deletions fs/ubifs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ static int ubifs_symlink(struct user_namespace *mnt_userns, struct inode *dir,
* @inode1: first inode
* @inode2: second inode
* @inode3: third inode
* @inode4: fouth inode
* @inode4: fourth inode
*
* This function is used for 'ubifs_rename()' and @inode1 may be the same as
* @inode2 whereas @inode3 and @inode4 may be %NULL.
Expand All @@ -1233,7 +1233,7 @@ static void lock_4_inodes(struct inode *inode1, struct inode *inode2,
* @inode1: first inode
* @inode2: second inode
* @inode3: third inode
* @inode4: fouth inode
* @inode4: fourth inode
*/
static void unlock_4_inodes(struct inode *inode1, struct inode *inode2,
struct inode *inode3, struct inode *inode4)
Expand Down
19 changes: 17 additions & 2 deletions fs/ubifs/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ int ubifs_garbage_collect(struct ubifs_info *c, int anyway)
for (i = 0; ; i++) {
int space_before, space_after;

/* Maybe continue after find and break before find */
lp.lnum = -1;

cond_resched();

/* Give the commit an opportunity to run */
Expand Down Expand Up @@ -753,8 +756,19 @@ int ubifs_garbage_collect(struct ubifs_info *c, int anyway)
* caller instead of the original '-EAGAIN'.
*/
err = ubifs_return_leb(c, lp.lnum);
if (err)
if (err) {
ret = err;
/*
* An LEB may always be "taken",
* so setting ubifs to read-only,
* and then executing sync wbuf will
* return -EROFS and enter the "out"
* error branch.
*/
ubifs_ro_mode(c, ret);
}
/* Maybe double return LEB if goto out */
lp.lnum = -1;
break;
}
goto out;
Expand Down Expand Up @@ -843,7 +857,8 @@ int ubifs_garbage_collect(struct ubifs_info *c, int anyway)
ubifs_wbuf_sync_nolock(wbuf);
ubifs_ro_mode(c, ret);
mutex_unlock(&wbuf->io_mutex);
ubifs_return_leb(c, lp.lnum);
if (lp.lnum != -1)
ubifs_return_leb(c, lp.lnum);
return ret;
}

Expand Down
21 changes: 21 additions & 0 deletions fs/ubifs/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,24 @@ int ubifs_is_mapped(const struct ubifs_info *c, int lnum)
return err;
}

static void record_magic_error(struct ubifs_stats_info *stats)
{
if (stats)
stats->magic_errors++;
}

static void record_node_error(struct ubifs_stats_info *stats)
{
if (stats)
stats->node_errors++;
}

static void record_crc_error(struct ubifs_stats_info *stats)
{
if (stats)
stats->crc_errors++;
}

/**
* ubifs_check_node - check node.
* @c: UBIFS file-system description object
Expand Down Expand Up @@ -238,6 +256,7 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,
if (!quiet)
ubifs_err(c, "bad magic %#08x, expected %#08x",
magic, UBIFS_NODE_MAGIC);
record_magic_error(c->stats);
err = -EUCLEAN;
goto out;
}
Expand All @@ -246,6 +265,7 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,
if (type < 0 || type >= UBIFS_NODE_TYPES_CNT) {
if (!quiet)
ubifs_err(c, "bad node type %d", type);
record_node_error(c->stats);
goto out;
}

Expand All @@ -270,6 +290,7 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,
if (!quiet)
ubifs_err(c, "bad CRC: calculated %#08x, read %#08x",
crc, node_crc);
record_crc_error(c->stats);
err = -EUCLEAN;
goto out;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/ubifs/replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static int set_bud_lprops(struct ubifs_info *c, struct bud_entry *b)
* property values should be @lp->free == @c->leb_size and
* @lp->dirty == 0, but that is not the case. The reason is that
* the LEB had been garbage collected before it became the bud,
* and there was not commit inbetween. The garbage collector
* and there was no commit in between. The garbage collector
* resets the free and dirty space without recording it
* anywhere except lprops, so if there was no commit then
* lprops does not have that information.
Expand Down
23 changes: 17 additions & 6 deletions fs/ubifs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,10 @@ static int mount_ubifs(struct ubifs_info *c)
if (err)
return err;

err = ubifs_sysfs_register(c);
if (err)
goto out_debugging;

err = check_volume_empty(c);
if (err)
goto out_free;
Expand Down Expand Up @@ -1367,15 +1371,14 @@ static int mount_ubifs(struct ubifs_info *c)
sprintf(c->bgt_name, BGT_NAME_PATTERN, c->vi.ubi_num, c->vi.vol_id);
if (!c->ro_mount) {
/* Create background thread */
c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name);
c->bgt = kthread_run(ubifs_bg_thread, c, "%s", c->bgt_name);
if (IS_ERR(c->bgt)) {
err = PTR_ERR(c->bgt);
c->bgt = NULL;
ubifs_err(c, "cannot spawn \"%s\", error %d",
c->bgt_name, err);
goto out_wbufs;
}
wake_up_process(c->bgt);
}

err = ubifs_read_master(c);
Expand Down Expand Up @@ -1641,6 +1644,8 @@ static int mount_ubifs(struct ubifs_info *c)
vfree(c->sbuf);
kfree(c->bottom_up_buf);
kfree(c->sup_node);
ubifs_sysfs_unregister(c);
out_debugging:
ubifs_debugging_exit(c);
return err;
}
Expand Down Expand Up @@ -1684,6 +1689,7 @@ static void ubifs_umount(struct ubifs_info *c)
kfree(c->bottom_up_buf);
kfree(c->sup_node);
ubifs_debugging_exit(c);
ubifs_sysfs_unregister(c);
}

/**
Expand Down Expand Up @@ -1780,15 +1786,14 @@ static int ubifs_remount_rw(struct ubifs_info *c)
goto out;

/* Create background thread */
c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name);
c->bgt = kthread_run(ubifs_bg_thread, c, "%s", c->bgt_name);
if (IS_ERR(c->bgt)) {
err = PTR_ERR(c->bgt);
c->bgt = NULL;
ubifs_err(c, "cannot spawn \"%s\", error %d",
c->bgt_name, err);
goto out;
}
wake_up_process(c->bgt);

c->orph_buf = vmalloc(c->leb_size);
if (!c->orph_buf) {
Expand Down Expand Up @@ -1853,7 +1858,6 @@ static int ubifs_remount_rw(struct ubifs_info *c)
kthread_stop(c->bgt);
c->bgt = NULL;
}
free_wbufs(c);
kfree(c->write_reserve_buf);
c->write_reserve_buf = NULL;
vfree(c->ileb_buf);
Expand Down Expand Up @@ -2436,14 +2440,20 @@ static int __init ubifs_init(void)

dbg_debugfs_init();

err = ubifs_sysfs_init();
if (err)
goto out_dbg;

err = register_filesystem(&ubifs_fs_type);
if (err) {
pr_err("UBIFS error (pid %d): cannot register file system, error %d",
current->pid, err);
goto out_dbg;
goto out_sysfs;
}
return 0;

out_sysfs:
ubifs_sysfs_exit();
out_dbg:
dbg_debugfs_exit();
ubifs_compressors_exit();
Expand All @@ -2462,6 +2472,7 @@ static void __exit ubifs_exit(void)
WARN_ON(atomic_long_read(&ubifs_clean_zn_cnt) != 0);

dbg_debugfs_exit();
ubifs_sysfs_exit();
ubifs_compressors_exit();
unregister_shrinker(&ubifs_shrinker_info);

Expand Down
Loading

0 comments on commit 5672cdf

Please sign in to comment.