From a7878665d9c55d80b8c545ab8b777b7ff83633ea Mon Sep 17 00:00:00 2001 From: Frederic Weisbecker Date: Fri, 2 Dec 2011 14:12:54 +1100 Subject: [PATCH] reiserfs: don't lock root inode searching Nothing requires that we lock the filesystem until the root inode is provided. Also iget5_locked() triggers a warning because we are holding the filesystem lock while allocating the inode, which result in a lockdep suspicion that we have a lock inversion against the reclaim path: [ 1986.896979] ================================= [ 1986.896990] [ INFO: inconsistent lock state ] [ 1986.896997] 3.1.1-main #8 [ 1986.897001] --------------------------------- [ 1986.897007] inconsistent {RECLAIM_FS-ON-W} -> {IN-RECLAIM_FS-W} usage. [ 1986.897016] kswapd0/16 [HC0[0]:SC0[0]:HE1:SE1] takes: [ 1986.897023] (&REISERFS_SB(s)->lock){+.+.?.}, at: [] reiserfs_write_lock+0x20/0x2a [ 1986.897044] {RECLAIM_FS-ON-W} state was registered at: [ 1986.897050] [] mark_held_locks+0xae/0xd0 [ 1986.897060] [] lockdep_trace_alloc+0x7d/0x91 [ 1986.897068] [] kmem_cache_alloc+0x1a/0x93 [ 1986.897078] [] reiserfs_alloc_inode+0x13/0x3d [ 1986.897088] [] alloc_inode+0x14/0x5f [ 1986.897097] [] iget5_locked+0x62/0x13a [ 1986.897106] [] reiserfs_fill_super+0x410/0x8b9 [ 1986.897114] [] mount_bdev+0x10b/0x159 [ 1986.897123] [] get_super_block+0x10/0x12 [ 1986.897131] [] mount_fs+0x59/0x12d [ 1986.897138] [] vfs_kern_mount+0x45/0x7a [ 1986.897147] [] do_kern_mount+0x2f/0xb0 [ 1986.897155] [] do_mount+0x5c2/0x612 [ 1986.897163] [] sys_mount+0x61/0x8f [ 1986.897170] [] sysenter_do_call+0x12/0x32 [ 1986.897181] irq event stamp: 7509691 [ 1986.897186] hardirqs last enabled at (7509691): [] kmem_cache_alloc+0x6e/0x93 [ 1986.897197] hardirqs last disabled at (7509690): [] kmem_cache_alloc+0x24/0x93 [ 1986.897209] softirqs last enabled at (7508896): [] __do_softirq+0xee/0xfd [ 1986.897222] softirqs last disabled at (7508859): [] do_softirq+0x50/0x9d [ 1986.897234] [ 1986.897235] other info that might help us debug this: [ 1986.897242] Possible unsafe locking scenario: [ 1986.897244] [ 1986.897250] CPU0 [ 1986.897254] ---- [ 1986.897257] lock(&REISERFS_SB(s)->lock); [ 1986.897265] [ 1986.897269] lock(&REISERFS_SB(s)->lock); [ 1986.897276] [ 1986.897277] *** DEADLOCK *** [ 1986.897278] [ 1986.897286] no locks held by kswapd0/16. [ 1986.897291] [ 1986.897292] stack backtrace: [ 1986.897299] Pid: 16, comm: kswapd0 Not tainted 3.1.1-main #8 [ 1986.897306] Call Trace: [ 1986.897314] [] ? printk+0xf/0x11 [ 1986.897324] [] print_usage_bug+0x20e/0x21a [ 1986.897332] [] ? print_irq_inversion_bug+0x172/0x172 [ 1986.897341] [] mark_lock+0x27f/0x483 [ 1986.897349] [] __lock_acquire+0x628/0x1472 [ 1986.897358] [] lock_acquire+0x47/0x5e [ 1986.897366] [] ? reiserfs_write_lock+0x20/0x2a [ 1986.897384] [] ? reiserfs_write_lock+0x20/0x2a [ 1986.897397] [] mutex_lock_nested+0x35/0x26f [ 1986.897409] [] ? reiserfs_write_lock+0x20/0x2a [ 1986.897421] [] reiserfs_write_lock+0x20/0x2a [ 1986.897433] [] map_block_for_writepage+0xc9/0x590 [ 1986.897448] [] ? create_empty_buffers+0x33/0x8f [ 1986.897461] [] ? get_parent_ip+0xb/0x31 [ 1986.897472] [] ? sub_preempt_count+0x81/0x8e [ 1986.897485] [] ? _raw_spin_unlock+0x27/0x3d [ 1986.897496] [] ? get_parent_ip+0xb/0x31 [ 1986.897508] [] reiserfs_writepage+0x1b9/0x3e7 [ 1986.897521] [] ? clear_page_dirty_for_io+0xcb/0xde [ 1986.897533] [] ? trace_hardirqs_on_caller+0x108/0x138 [ 1986.897546] [] ? trace_hardirqs_on+0xb/0xd [ 1986.897559] [] shrink_page_list+0x34f/0x5e2 [ 1986.897572] [] shrink_inactive_list+0x172/0x22c [ 1986.897585] [] shrink_zone+0x303/0x3b1 [ 1986.897597] [] ? _raw_spin_unlock+0x27/0x3d [ 1986.897611] [] kswapd+0x3b7/0x5f2 The deadlock shouldn't happen since we are doing that allocation in the mount path, the filesystem is not available for any reclaim. Still the warning is annoying. To solve this, acquire the lock later only where we need it, right before calling reiserfs_read_locked_inode() that wants to lock to walk the tree. Reported-by: Knut Petersen Signed-off-by: Frederic Weisbecker Cc: Al Viro Cc: Christoph Hellwig Cc: Jeff Mahoney Signed-off-by: Andrew Morton --- fs/reiserfs/super.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c index b5f167c6a687..7cd93139e259 100644 --- a/fs/reiserfs/super.c +++ b/fs/reiserfs/super.c @@ -1428,9 +1428,7 @@ static int read_super_block(struct super_block *s, int offset) static int reread_meta_blocks(struct super_block *s) { ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s))); - reiserfs_write_unlock(s); wait_on_buffer(SB_BUFFER_WITH_SB(s)); - reiserfs_write_lock(s); if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) { reiserfs_warning(s, "reiserfs-2504", "error reading the super"); return 1; @@ -1738,24 +1736,14 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent) */ } - /* - * This path assumed to be called with the BKL in the old times. - * Now we have inherited the big reiserfs lock from it and many - * reiserfs helpers called in the mount path and elsewhere require - * this lock to be held even if it's not always necessary. Let's be - * conservative and hold it early. The window can be reduced after - * careful review of the code. - */ - reiserfs_write_lock(s); - if (reread_meta_blocks(s)) { SWARN(silent, s, "jmacd-9", "unable to reread meta blocks after journal init"); - goto error; + goto error_unlocked; } if (replay_only(s)) - goto error; + goto error_unlocked; if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) { SWARN(silent, s, "clm-7000", @@ -1769,9 +1757,19 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent) reiserfs_init_locked_inode, (void *)(&args)); if (!root_inode) { SWARN(silent, s, "jmacd-10", "get root inode failed"); - goto error; + goto error_unlocked; } + /* + * This path assumed to be called with the BKL in the old times. + * Now we have inherited the big reiserfs lock from it and many + * reiserfs helpers called in the mount path and elsewhere require + * this lock to be held even if it's not always necessary. Let's be + * conservative and hold it early. The window can be reduced after + * careful review of the code. + */ + reiserfs_write_lock(s); + if (root_inode->i_state & I_NEW) { reiserfs_read_locked_inode(root_inode, &args); unlock_new_inode(root_inode); -- 2.39.5