On Tue, May 12, 2020 at 04:15:46PM +0200, David Sterba wrote:
> [ 5174.283784] -> #1 (&fs_info->chunk_mutex){+.+.}-{3:3}:
> [ 5174.286134] __lock_acquire+0x581/0xae0
> [ 5174.287563] lock_acquire+0xa3/0x400
> [ 5174.289033] __mutex_lock+0xa0/0xaf0
> [ 5174.290488] btrfs_init_new_device+0x316/0x12f0 [btrfs]
> [ 5174.292209] btrfs_ioctl+0xc3c/0x2590 [btrfs]
ioctl called
> [ 5174.293673] ksys_ioctl+0x68/0xa0
> [ 5174.294883] __x64_sys_ioctl+0x16/0x20
> [ 5174.296231] do_syscall_64+0x50/0x210
> [ 5174.297548] entry_SYSCALL_64_after_hwframe+0x49/0xb3
> [ 5174.299278]
> [ 5174.299278] -> #0 (&fs_devs->device_list_mutex){+.+.}-{3:3}:
> [ 5174.301760] check_prev_add+0x98/0xa20
> [ 5174.303219] validate_chain+0xa6c/0x29e0
> [ 5174.304770] __lock_acquire+0x581/0xae0
> [ 5174.306274] lock_acquire+0xa3/0x400
> [ 5174.307716] __mutex_lock+0xa0/0xaf0
> [ 5174.309145] clone_fs_devices+0x3f/0x170 [btrfs]
> [ 5174.310757] read_one_dev+0xc4/0x500 [btrfs]
> [ 5174.312293] btrfs_read_chunk_tree+0x202/0x2a0 [btrfs]
> [ 5174.313946] open_ctree+0x7a3/0x10db [btrfs]
... while the filesystem is being set up. This is actually possible
because this is with enabled seeding, so the mounted filesystem accesses
the seeding filesystem's structures when cloning the devices.
Should be fixed by lifting the device_list_mutex from clone_fs_devices
to some of it's callers. In btrfs_read_chunk_tree it's between the uuid
mutex and chunk mutex, in btrfs_init_new_device lock device_list_mutex
before "if (seeding_dev)".
> [ 5174.315411] btrfs_mount_root.cold+0xe/0xcc [btrfs]
> [ 5174.317122] legacy_get_tree+0x2d/0x60
> [ 5174.318543] vfs_get_tree+0x1d/0xb0
> [ 5174.319844] fc_mount+0xe/0x40
> [ 5174.321122] vfs_kern_mount.part.0+0x71/0x90
> [ 5174.322688] btrfs_mount+0x147/0x3e0 [btrfs]
> [ 5174.324250] legacy_get_tree+0x2d/0x60
> [ 5174.325644] vfs_get_tree+0x1d/0xb0
> [ 5174.326978] do_mount+0x7d5/0xa40
> [ 5174.328294] __x64_sys_mount+0x8e/0xd0
> [ 5174.329829] do_syscall_64+0x50/0x210
> [ 5174.331260] entry_SYSCALL_64_after_hwframe+0x49/0xb3