Josef Bacik
339f26ffdf
btrfs: fix lockdep splat in btrfs_recover_relocation
...
commit fb286100974e7239af243bc2255a52f29442f9c8 upstream.
While testing the error paths of relocation I hit the following lockdep
splat:
======================================================
WARNING: possible circular locking dependency detected
5.10.0-rc6+ #217 Not tainted
------------------------------------------------------
mount/779 is trying to acquire lock:
ffffa0e676945418 (&fs_info->balance_mutex){+.+.}-{3:3}, at: btrfs_recover_balance+0x2f0/0x340
but task is already holding lock:
ffffa0e60ee31da8 (btrfs-root-00){++++}-{3:3}, at: __btrfs_tree_read_lock+0x27/0x100
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (btrfs-root-00){++++}-{3:3}:
down_read_nested+0x43/0x130
__btrfs_tree_read_lock+0x27/0x100
btrfs_read_lock_root_node+0x31/0x40
btrfs_search_slot+0x462/0x8f0
btrfs_update_root+0x55/0x2b0
btrfs_drop_snapshot+0x398/0x750
clean_dirty_subvols+0xdf/0x120
btrfs_recover_relocation+0x534/0x5a0
btrfs_start_pre_rw_mount+0xcb/0x170
open_ctree+0x151f/0x1726
btrfs_mount_root.cold+0x12/0xea
legacy_get_tree+0x30/0x50
vfs_get_tree+0x28/0xc0
vfs_kern_mount.part.0+0x71/0xb0
btrfs_mount+0x10d/0x380
legacy_get_tree+0x30/0x50
vfs_get_tree+0x28/0xc0
path_mount+0x433/0xc10
__x64_sys_mount+0xe3/0x120
do_syscall_64+0x33/0x40
entry_SYSCALL_64_after_hwframe+0x44/0xa9
-> #1 (sb_internal#2){.+.+}-{0:0}:
start_transaction+0x444/0x700
insert_balance_item.isra.0+0x37/0x320
btrfs_balance+0x354/0xf40
btrfs_ioctl_balance+0x2cf/0x380
__x64_sys_ioctl+0x83/0xb0
do_syscall_64+0x33/0x40
entry_SYSCALL_64_after_hwframe+0x44/0xa9
-> #0 (&fs_info->balance_mutex){+.+.}-{3:3}:
__lock_acquire+0x1120/0x1e10
lock_acquire+0x116/0x370
__mutex_lock+0x7e/0x7b0
btrfs_recover_balance+0x2f0/0x340
open_ctree+0x1095/0x1726
btrfs_mount_root.cold+0x12/0xea
legacy_get_tree+0x30/0x50
vfs_get_tree+0x28/0xc0
vfs_kern_mount.part.0+0x71/0xb0
btrfs_mount+0x10d/0x380
legacy_get_tree+0x30/0x50
vfs_get_tree+0x28/0xc0
path_mount+0x433/0xc10
__x64_sys_mount+0xe3/0x120
do_syscall_64+0x33/0x40
entry_SYSCALL_64_after_hwframe+0x44/0xa9
other info that might help us debug this:
Chain exists of:
&fs_info->balance_mutex --> sb_internal#2 --> btrfs-root-00
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(btrfs-root-00);
lock(sb_internal#2);
lock(btrfs-root-00);
lock(&fs_info->balance_mutex);
*** DEADLOCK ***
2 locks held by mount/779:
#0 : ffffa0e60dc040e0 (&type->s_umount_key#47/1){+.+.}-{3:3}, at: alloc_super+0xb5/0x380
#1 : ffffa0e60ee31da8 (btrfs-root-00){++++}-{3:3}, at: __btrfs_tree_read_lock+0x27/0x100
stack backtrace:
CPU: 0 PID: 779 Comm: mount Not tainted 5.10.0-rc6+ #217
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
Call Trace:
dump_stack+0x8b/0xb0
check_noncircular+0xcf/0xf0
? trace_call_bpf+0x139/0x260
__lock_acquire+0x1120/0x1e10
lock_acquire+0x116/0x370
? btrfs_recover_balance+0x2f0/0x340
__mutex_lock+0x7e/0x7b0
? btrfs_recover_balance+0x2f0/0x340
? btrfs_recover_balance+0x2f0/0x340
? rcu_read_lock_sched_held+0x3f/0x80
? kmem_cache_alloc_trace+0x2c4/0x2f0
? btrfs_get_64+0x5e/0x100
btrfs_recover_balance+0x2f0/0x340
open_ctree+0x1095/0x1726
btrfs_mount_root.cold+0x12/0xea
? rcu_read_lock_sched_held+0x3f/0x80
legacy_get_tree+0x30/0x50
vfs_get_tree+0x28/0xc0
vfs_kern_mount.part.0+0x71/0xb0
btrfs_mount+0x10d/0x380
? __kmalloc_track_caller+0x2f2/0x320
legacy_get_tree+0x30/0x50
vfs_get_tree+0x28/0xc0
? capable+0x3a/0x60
path_mount+0x433/0xc10
__x64_sys_mount+0xe3/0x120
do_syscall_64+0x33/0x40
entry_SYSCALL_64_after_hwframe+0x44/0xa9
This is straightforward to fix, simply release the path before we setup
the balance_ctl.
CC: stable@vger.kernel.org # 4.4+
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-01-27 11:05:35 +01:00
..
2020-11-05 11:08:53 +01:00
2019-08-06 19:06:49 +02:00
2020-09-09 19:04:30 +02:00
2020-08-26 10:31:05 +02:00
2019-12-13 08:51:01 +01:00
2018-12-01 09:37:27 +01:00
2021-01-27 11:05:35 +01:00
2020-11-05 11:08:54 +01:00
2020-12-30 11:26:13 +01:00
2020-12-30 11:26:13 +01:00
2019-08-06 19:06:51 +02:00
2020-05-27 17:37:32 +02:00
2018-11-13 11:08:55 -08:00
2021-01-06 14:44:58 +01:00
2019-05-08 07:21:48 +02:00
2019-03-23 20:09:59 +01:00
2020-10-30 10:38:28 +01:00
2020-02-28 16:38:59 +01:00
2020-12-02 08:48:12 +01:00
2019-12-05 09:20:32 +01:00
2020-01-27 14:50:02 +01:00
2020-09-09 19:04:28 +02:00
2021-01-19 18:22:38 +01:00
2021-01-06 14:44:58 +01:00
2020-06-22 09:05:08 +02:00
2018-12-17 09:24:40 +01:00
2020-11-05 11:08:34 +01:00
2020-12-11 13:25:04 +01:00
2019-12-01 09:17:10 +01:00
2020-04-17 10:48:52 +02:00
2018-08-17 16:20:28 -07:00
2018-08-25 12:42:33 -07:00
2019-05-22 07:37:40 +02:00
2018-08-21 11:37:41 +02:00
2020-09-03 11:24:24 +02:00
2020-12-30 11:26:13 +01:00
2020-12-30 11:26:13 +01:00
2019-12-13 08:52:43 +01:00
2020-12-30 11:25:59 +01:00
2020-08-21 11:05:38 +02:00
2021-01-19 18:22:37 +01:00
2020-12-30 11:26:02 +01:00
2021-01-23 15:49:55 +01:00
2020-06-22 09:05:03 +02:00
2020-06-30 23:17:00 -04:00
2020-10-30 10:38:28 +01:00
2020-11-18 19:18:49 +01:00
2020-02-24 08:34:53 +01:00
2020-07-22 09:32:10 +02:00
2021-01-12 20:10:17 +01:00
2020-08-19 08:15:04 +02:00
2021-01-06 14:45:01 +01:00
2020-10-30 10:38:21 +01:00
2021-01-06 14:45:00 +01:00
2020-08-26 10:30:59 +02:00
2018-08-18 11:44:53 -07:00
2018-12-17 09:24:30 +01:00
2021-01-06 14:44:59 +01:00
2020-11-05 11:08:50 +01:00
2020-08-21 11:05:38 +02:00
2020-11-24 13:27:23 +01:00
2020-06-22 09:05:01 +02:00
2020-06-03 08:19:41 +02:00
2019-07-03 13:14:44 +02:00
2019-11-06 13:05:37 +01:00
2020-10-01 13:14:42 +02:00
2020-11-05 11:08:46 +01:00
2020-01-14 20:06:57 +01:00
2020-01-09 10:19:07 +01:00
2020-05-14 07:57:21 +02:00
2020-03-05 16:42:12 +01:00
2020-11-05 11:08:35 +01:00
2019-03-05 17:58:50 +01:00
2020-01-12 12:17:20 +01:00
2020-02-11 04:34:08 -08:00
2020-10-07 08:00:09 +02:00
2020-11-05 11:08:38 +01:00
2021-01-06 14:45:00 +01:00
2018-08-21 18:19:09 -07:00
2020-05-27 17:37:29 +02:00
2020-04-17 10:48:51 +02:00
2020-09-03 11:24:28 +02:00
2020-03-25 08:06:14 +01:00
2019-05-31 06:46:05 -07:00
2018-11-21 09:19:14 +01:00
2019-12-13 08:52:56 +01:00
2020-11-24 13:27:23 +01:00
2020-01-09 10:19:00 +01:00
2018-08-17 16:20:29 -07:00
2020-03-05 16:42:20 +01:00
2020-04-29 16:31:26 +02:00
2019-05-25 18:23:26 +02:00
2020-03-18 07:14:21 +01:00
2019-05-04 09:20:11 +02:00
2020-05-02 17:26:01 +02:00
2019-12-01 09:17:04 +01:00
2020-01-04 19:13:26 +01:00
2019-08-25 10:47:43 +02:00
2020-08-26 10:31:02 +02:00
2019-12-17 20:35:43 +01:00
2019-10-11 18:21:39 +02:00
2020-11-24 13:27:20 +01:00
2018-08-13 20:56:23 -07:00
2020-01-04 19:13:18 +01:00
2020-08-11 15:32:34 +02:00