BTRFS info (device loop4): using spread ssd allocation scheme
BTRFS info (device loop4): using free space tree
BTRFS info (device loop4): has skinny extents
print_req_error: I/O error, dev loop6, sector 512
======================================================
WARNING: possible circular locking dependency detected
4.14.305-syzkaller #0 Not tainted
------------------------------------------------------
kworker/u4:3/794 is trying to acquire lock:
 (sb_internal#2){.+.+}, at: [<ffffffff829ede7e>] sb_start_intwrite include/linux/fs.h:1598 [inline]
 (sb_internal#2){.+.+}, at: [<ffffffff829ede7e>] start_transaction+0x6de/0xf30 fs/btrfs/transaction.c:548

but task is already holding lock:
 ((&work->normal_work)){+.+.}, at: [<ffffffff81366116>] process_one_work+0x6e6/0x14a0 kernel/workqueue.c:2092

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #4 ((&work->normal_work)){+.+.}:
       process_one_work+0x736/0x14a0 kernel/workqueue.c:2093
       worker_thread+0x5cc/0xff0 kernel/workqueue.c:2251
       kthread+0x30d/0x420 kernel/kthread.c:232
       ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:406

-> #3 ("%s-%s""btrfs", name){+.+.}:
       flush_workqueue+0xfa/0x1310 kernel/workqueue.c:2625
       drain_workqueue+0x177/0x3e0 kernel/workqueue.c:2790
       destroy_workqueue+0x71/0x710 kernel/workqueue.c:4116
       __btrfs_destroy_workqueue fs/btrfs/async-thread.c:436 [inline]
       btrfs_destroy_workqueue+0xf8/0x630 fs/btrfs/async-thread.c:447
       scrub_workers_put+0x90/0x1a0 fs/btrfs/scrub.c:4075
       btrfs_scrub_dev+0x536/0xcd0 fs/btrfs/scrub.c:4219
       btrfs_ioctl_scrub fs/btrfs/ioctl.c:4451 [inline]
       btrfs_ioctl+0xba8/0x5b20 fs/btrfs/ioctl.c:5681
       vfs_ioctl fs/ioctl.c:46 [inline]
       file_ioctl fs/ioctl.c:500 [inline]
       do_vfs_ioctl+0x75a/0xff0 fs/ioctl.c:684
       SYSC_ioctl fs/ioctl.c:701 [inline]
       SyS_ioctl+0x7f/0xb0 fs/ioctl.c:692
       do_syscall_64+0x1d5/0x640 arch/x86/entry/common.c:292
       entry_SYSCALL_64_after_hwframe+0x5e/0xd3

-> #2 (&fs_info->scrub_lock){+.+.}:
       __mutex_lock_common kernel/locking/mutex.c:756 [inline]
       __mutex_lock+0xc4/0x1310 kernel/locking/mutex.c:893
       btrfs_scrub_dev+0x1f3/0xcd0 fs/btrfs/scrub.c:4150
       btrfs_ioctl_scrub fs/btrfs/ioctl.c:4451 [inline]
       btrfs_ioctl+0xba8/0x5b20 fs/btrfs/ioctl.c:5681
       vfs_ioctl fs/ioctl.c:46 [inline]
       file_ioctl fs/ioctl.c:500 [inline]
       do_vfs_ioctl+0x75a/0xff0 fs/ioctl.c:684
       SYSC_ioctl fs/ioctl.c:701 [inline]
       SyS_ioctl+0x7f/0xb0 fs/ioctl.c:692
       do_syscall_64+0x1d5/0x640 arch/x86/entry/common.c:292
       entry_SYSCALL_64_after_hwframe+0x5e/0xd3

-> #1 (&fs_devs->device_list_mutex){+.+.}:
       __mutex_lock_common kernel/locking/mutex.c:756 [inline]
       __mutex_lock+0xc4/0x1310 kernel/locking/mutex.c:893
       btrfs_finish_chunk_alloc+0x221/0xe90 fs/btrfs/volumes.c:4923
       btrfs_create_pending_block_groups+0x1fd/0x540 fs/btrfs/extent-tree.c:10388
       __btrfs_end_transaction+0x1f2/0xaa0 fs/btrfs/transaction.c:851
       flush_space+0x8de/0xde0 fs/btrfs/extent-tree.c:5046
       btrfs_async_reclaim_metadata_space+0x414/0xc20 fs/btrfs/extent-tree.c:5162
       process_one_work+0x793/0x14a0 kernel/workqueue.c:2117
       worker_thread+0x5cc/0xff0 kernel/workqueue.c:2251
       kthread+0x30d/0x420 kernel/kthread.c:232
       ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:406

-> #0 (sb_internal#2){.+.+}:
       lock_acquire+0x170/0x3f0 kernel/locking/lockdep.c:3998
       percpu_down_read_preempt_disable include/linux/percpu-rwsem.h:36 [inline]
       percpu_down_read include/linux/percpu-rwsem.h:59 [inline]
       __sb_start_write+0x64/0x260 fs/super.c:1342
       sb_start_intwrite include/linux/fs.h:1598 [inline]
       start_transaction+0x6de/0xf30 fs/btrfs/transaction.c:548
       btrfs_qgroup_rescan_worker+0x176/0x1060 fs/btrfs/qgroup.c:2632
       normal_work_helper+0x304/0x1330 fs/btrfs/async-thread.c:376
       process_one_work+0x793/0x14a0 kernel/workqueue.c:2117
       worker_thread+0x5cc/0xff0 kernel/workqueue.c:2251
       kthread+0x30d/0x420 kernel/kthread.c:232
       ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:406

other info that might help us debug this:

Chain exists of:
  sb_internal#2 --> "%s-%s""btrfs", name --> (&work->normal_work)

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock((&work->normal_work));
                               lock("%s-%s""btrfs", name);
                               lock((&work->normal_work));
  lock(sb_internal#2);

 *** DEADLOCK ***

2 locks held by kworker/u4:3/794:
 #0:  ("%s-%s""btrfs", name){+.+.}, at: [<ffffffff813660e0>] process_one_work+0x6b0/0x14a0 kernel/workqueue.c:2088
 #1:  ((&work->normal_work)){+.+.}, at: [<ffffffff81366116>] process_one_work+0x6e6/0x14a0 kernel/workqueue.c:2092

stack backtrace:
CPU: 1 PID: 794 Comm: kworker/u4:3 Not tainted 4.14.305-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/12/2023
Workqueue: btrfs-qgroup-rescan btrfs_qgroup_rescan_helper
Call Trace:
 __dump_stack lib/dump_stack.c:17 [inline]
 dump_stack+0x1b2/0x281 lib/dump_stack.c:58
 print_circular_bug.constprop.0.cold+0x2d7/0x41e kernel/locking/lockdep.c:1258
 check_prev_add kernel/locking/lockdep.c:1905 [inline]
 check_prevs_add kernel/locking/lockdep.c:2022 [inline]
 validate_chain kernel/locking/lockdep.c:2464 [inline]
 __lock_acquire+0x2e0e/0x3f20 kernel/locking/lockdep.c:3491
 lock_acquire+0x170/0x3f0 kernel/locking/lockdep.c:3998
 percpu_down_read_preempt_disable include/linux/percpu-rwsem.h:36 [inline]
 percpu_down_read include/linux/percpu-rwsem.h:59 [inline]
 __sb_start_write+0x64/0x260 fs/super.c:1342
 sb_start_intwrite include/linux/fs.h:1598 [inline]
 start_transaction+0x6de/0xf30 fs/btrfs/transaction.c:548
 btrfs_qgroup_rescan_worker+0x176/0x1060 fs/btrfs/qgroup.c:2632
 normal_work_helper+0x304/0x1330 fs/btrfs/async-thread.c:376
 process_one_work+0x793/0x14a0 kernel/workqueue.c:2117
 worker_thread+0x5cc/0xff0 kernel/workqueue.c:2251
 kthread+0x30d/0x420 kernel/kthread.c:232
 ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:406
BTRFS error (device loop4): fail to start transaction for status update: -28
BTRFS info (device loop5): enabling inode map caching
BTRFS info (device loop5): trying to use backup root at mount time
BTRFS info (device loop5): use zlib compression
BTRFS info (device loop5): enabling ssd optimizations
BTRFS info (device loop5): using spread ssd allocation scheme
BTRFS info (device loop5): using free space tree
BTRFS info (device loop5): has skinny extents
BTRFS error (device loop5): fail to start transaction for status update: -28
mmap: syz-executor.0 (11827) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.
BTRFS info (device loop5): enabling inode map caching
 loop3: p1 < > p3 < > p4
loop3: p4 start 16777216 is beyond EOD, truncated
BTRFS info (device loop5): trying to use backup root at mount time
BTRFS info (device loop5): use zlib compression
BTRFS info (device loop5): enabling ssd optimizations
BTRFS info (device loop5): using spread ssd allocation scheme
BTRFS info (device loop5): using free space tree
BTRFS info (device loop5): has skinny extents
 loop3: p1 < > p3 < > p4
loop3: p4 start 16777216 is beyond EOD, truncated
BTRFS error (device loop5): fail to start transaction for status update: -28
input: syz0 as /devices/virtual/input/input6
BTRFS info (device loop5): enabling inode map caching
BTRFS info (device loop5): trying to use backup root at mount time
BTRFS info (device loop5): use zlib compression
BTRFS info (device loop5): enabling ssd optimizations
BTRFS info (device loop5): using spread ssd allocation scheme
BTRFS info (device loop5): using free space tree
BTRFS info (device loop5): has skinny extents
BTRFS error (device loop5): fail to start transaction for status update: -28
EXT4-fs warning (device loop1): ext4_fill_super:3598: metadata_csum and uninit_bg are redundant flags; please run fsck.
EXT4-fs (loop1): VFS: Found ext4 filesystem with invalid superblock checksum.  Run e2fsck?
NILFS (loop1): segctord starting. Construction interval = 5 seconds, CP frequency < 30 seconds
REISERFS warning (device loop3): super-6502 reiserfs_getopt: unknown mount option "system."
NILFS (loop5): segctord starting. Construction interval = 5 seconds, CP frequency < 30 seconds
audit: type=1800 audit(1675773425.229:37): pid=12128 uid=0 auid=4294967295 ses=4294967295 op="collect_data" cause="failed(directio)" comm="syz-executor.5" name="bus" dev="loop5" ino=18 res=0
audit: type=1804 audit(1675773425.229:38): pid=12128 uid=0 auid=4294967295 ses=4294967295 op="invalid_pcr" cause="open_writers" comm="syz-executor.5" name="/root/syzkaller-testdir3233639086/syzkaller.jhrUQX/73/file0/bus" dev="loop5" ino=18 res=1
REISERFS warning (device loop3): super-6502 reiserfs_getopt: unknown mount option "system."
audit: type=1804 audit(1675773425.229:39): pid=12128 uid=0 auid=4294967295 ses=4294967295 op="invalid_pcr" cause="ToMToU" comm="syz-executor.5" name="/root/syzkaller-testdir3233639086/syzkaller.jhrUQX/73/file0/bus" dev="loop5" ino=18 res=1
REISERFS warning (device loop3): super-6502 reiserfs_getopt: unknown mount option "system."
audit: type=1804 audit(1675773425.229:40): pid=12128 uid=0 auid=4294967295 ses=4294967295 op="invalid_pcr" cause="open_writers" comm="syz-executor.5" name="/root/syzkaller-testdir3233639086/syzkaller.jhrUQX/73/file0/bus" dev="loop5" ino=18 res=1
NILFS (loop5): segctord starting. Construction interval = 5 seconds, CP frequency < 30 seconds
audit: type=1800 audit(1675773425.699:41): pid=12184 uid=0 auid=4294967295 ses=4294967295 op="collect_data" cause="failed(directio)" comm="syz-executor.5" name="bus" dev="loop5" ino=18 res=0
audit: type=1804 audit(1675773425.699:42): pid=12184 uid=0 auid=4294967295 ses=4294967295 op="invalid_pcr" cause="open_writers" comm="syz-executor.5" name="/root/syzkaller-testdir3233639086/syzkaller.jhrUQX/74/file0/bus" dev="loop5" ino=18 res=1
audit: type=1804 audit(1675773425.719:43): pid=12184 uid=0 auid=4294967295 ses=4294967295 op="invalid_pcr" cause="ToMToU" comm="syz-executor.5" name="/root/syzkaller-testdir3233639086/syzkaller.jhrUQX/74/file0/bus" dev="loop5" ino=18 res=1
audit: type=1804 audit(1675773425.719:44): pid=12184 uid=0 auid=4294967295 ses=4294967295 op="invalid_pcr" cause="open_writers" comm="syz-executor.5" name="/root/syzkaller-testdir3233639086/syzkaller.jhrUQX/74/file0/bus" dev="loop5" ino=18 res=1
BTRFS info (device loop2): using free space tree
BTRFS info (device loop2): has skinny extents
REISERFS warning (device loop3): super-6502 reiserfs_getopt: unknown mount option "system."
NILFS (loop5): segctord starting. Construction interval = 5 seconds, CP frequency < 30 seconds
audit: type=1800 audit(1675773426.269:45): pid=12232 uid=0 auid=4294967295 ses=4294967295 op="collect_data" cause="failed(directio)" comm="syz-executor.5" name="bus" dev="loop5" ino=18 res=0
audit: type=1800 audit(1675773426.289:46): pid=12234 uid=0 auid=4294967295 ses=4294967295 op="collect_data" cause="failed(directio)" comm="syz-executor.0" name="bus" dev="sda1" ino=14221 res=0
netlink: 24 bytes leftover after parsing attributes in process `syz-executor.1'.
BTRFS info (device loop4): using free space tree
BTRFS info (device loop4): has skinny extents
netlink: 24 bytes leftover after parsing attributes in process `syz-executor.1'.
print_req_error: I/O error, dev loop5, sector 0
NILFS (loop5): segctord starting. Construction interval = 5 seconds, CP frequency < 30 seconds
netlink: 24 bytes leftover after parsing attributes in process `syz-executor.1'.
netlink: 24 bytes leftover after parsing attributes in process `syz-executor.1'.
netlink: 24 bytes leftover after parsing attributes in process `syz-executor.5'.
netlink: 24 bytes leftover after parsing attributes in process `syz-executor.5'.
XFS (loop1): Mounting V4 Filesystem
XFS (loop1): Ending clean mount
BTRFS info (device loop4): using free space tree
BTRFS info (device loop4): has skinny extents
XFS (loop1): Unmounting Filesystem
netlink: 24 bytes leftover after parsing attributes in process `syz-executor.5'.