syzbot


possible deadlock in btrfs_dirty_inode (2)

Status: upstream: reported on 2024/12/16 02:12
Subsystems: btrfs
[Documentation on labels]
Reported-by: syzbot+415a049af48761105c01@syzkaller.appspotmail.com
First crash: 62d, last: 34d
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [btrfs?] possible deadlock in btrfs_dirty_inode (2) 0 (1) 2024/12/16 02:12
Similar bugs (4)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-5.15 possible deadlock in btrfs_dirty_inode (2) 2 243d 305d 0/3 auto-obsoleted due to no activity on 2024/09/22 15:54
linux-5.15 possible deadlock in btrfs_dirty_inode (3) origin:lts-only C inconclusive 4 21d 65d 0/3 upstream: reported C repro on 2024/12/09 11:33
linux-5.15 possible deadlock in btrfs_dirty_inode 3 602d 621d 0/3 auto-obsoleted due to no activity on 2023/09/28 23:24
upstream possible deadlock in btrfs_dirty_inode btrfs C error done 48 809d 821d 0/28 auto-obsoleted due to no activity on 2023/05/16 05:18

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.13.0-rc6-syzkaller-00046-g0b7958fa05d5 #0 Not tainted
------------------------------------------------------
syz.0.112/6421 is trying to acquire lock:
ffff88802ca3c610 (sb_internal#5){.+.+}-{0:0}, at: btrfs_dirty_inode+0xa5/0x1a0 fs/btrfs/inode.c:6055

but task is already holding lock:
ffff888078638ba0 (&mm->mmap_lock){++++}-{4:4}, at: mmap_write_lock_killable include/linux/mmap_lock.h:122 [inline]
ffff888078638ba0 (&mm->mmap_lock){++++}-{4:4}, at: vm_mmap_pgoff+0x17c/0x3d0 mm/util.c:573

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #8 (&mm->mmap_lock){++++}-{4:4}:
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       __might_fault+0xc6/0x120 mm/memory.c:6751
       _inline_copy_from_user include/linux/uaccess.h:162 [inline]
       _copy_from_user+0x2a/0xc0 lib/usercopy.c:18
       copy_from_user include/linux/uaccess.h:212 [inline]
       __blk_trace_setup kernel/trace/blktrace.c:626 [inline]
       blk_trace_ioctl+0x1ad/0x9a0 kernel/trace/blktrace.c:740
       blkdev_ioctl+0x40c/0x6a0 block/ioctl.c:682
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:906 [inline]
       __se_sys_ioctl+0xf7/0x170 fs/ioctl.c:892
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #7 (&q->debugfs_mutex){+.+.}-{4:4}:
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       __mutex_lock_common kernel/locking/mutex.c:585 [inline]
       __mutex_lock+0x1ac/0xee0 kernel/locking/mutex.c:735
       blk_mq_init_sched+0x3fa/0x830 block/blk-mq-sched.c:473
       elevator_init_mq+0x20e/0x320 block/elevator.c:610
       add_disk_fwnode+0x10d/0xf80 block/genhd.c:413
       sd_probe+0xba6/0x1100 drivers/scsi/sd.c:4024
       really_probe+0x2ba/0xad0 drivers/base/dd.c:658
       __driver_probe_device+0x1a2/0x390 drivers/base/dd.c:800
       driver_probe_device+0x50/0x430 drivers/base/dd.c:830
       __device_attach_driver+0x2d6/0x530 drivers/base/dd.c:958
       bus_for_each_drv+0x250/0x2e0 drivers/base/bus.c:459
       __device_attach_async_helper+0x22d/0x300 drivers/base/dd.c:987
       async_run_entry_fn+0xaa/0x420 kernel/async.c:129
       process_one_work kernel/workqueue.c:3229 [inline]
       process_scheduled_works+0xa68/0x1840 kernel/workqueue.c:3310
       worker_thread+0x870/0xd30 kernel/workqueue.c:3391
       kthread+0x2f2/0x390 kernel/kthread.c:389
       ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

-> #6 (&q->q_usage_counter(queue)#50){++++}-{0:0}:
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       blk_queue_enter+0xe1/0x600 block/blk-core.c:328
       blk_mq_alloc_request+0x4fa/0xaa0 block/blk-mq.c:652
       scsi_alloc_request drivers/scsi/scsi_lib.c:1222 [inline]
       scsi_execute_cmd+0x177/0x1090 drivers/scsi/scsi_lib.c:304
       read_capacity_16+0x2b4/0x1450 drivers/scsi/sd.c:2655
       sd_read_capacity drivers/scsi/sd.c:2824 [inline]
       sd_revalidate_disk+0x1013/0xbce0 drivers/scsi/sd.c:3734
       sd_probe+0x9fa/0x1100 drivers/scsi/sd.c:4010
       really_probe+0x2ba/0xad0 drivers/base/dd.c:658
       __driver_probe_device+0x1a2/0x390 drivers/base/dd.c:800
       driver_probe_device+0x50/0x430 drivers/base/dd.c:830
       __device_attach_driver+0x2d6/0x530 drivers/base/dd.c:958
       bus_for_each_drv+0x250/0x2e0 drivers/base/bus.c:459
       __device_attach_async_helper+0x22d/0x300 drivers/base/dd.c:987
       async_run_entry_fn+0xaa/0x420 kernel/async.c:129
       process_one_work kernel/workqueue.c:3229 [inline]
       process_scheduled_works+0xa68/0x1840 kernel/workqueue.c:3310
       worker_thread+0x870/0xd30 kernel/workqueue.c:3391
       kthread+0x2f2/0x390 kernel/kthread.c:389
       ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

-> #5 (
&q->limits_lock){+.+.}-{4:4}
:
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       __mutex_lock_common kernel/locking/mutex.c:585 [inline]
       __mutex_lock+0x1ac/0xee0 kernel/locking/mutex.c:735
       queue_limits_start_update include/linux/blkdev.h:947 [inline]
       loop_reconfigure_limits+0x43f/0x900 drivers/block/loop.c:998
       loop_set_block_size drivers/block/loop.c:1473 [inline]
       lo_simple_ioctl drivers/block/loop.c:1496 [inline]
       lo_ioctl+0x1351/0x1f50 drivers/block/loop.c:1559
       blkdev_ioctl+0x57f/0x6a0 block/ioctl.c:693
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:906 [inline]
       __se_sys_ioctl+0xf7/0x170 fs/ioctl.c:892
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #4 (
&q->q_usage_counter(io)#17
){++++}-{0:0}
:
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       bio_queue_enter block/blk.h:75 [inline]
       blk_mq_submit_bio+0x1536/0x2390 block/blk-mq.c:3090
       __submit_bio+0x2c6/0x560 block/blk-core.c:629
       __submit_bio_noacct_mq block/blk-core.c:710 [inline]
       submit_bio_noacct_nocheck+0x4d3/0xe30 block/blk-core.c:739
       btrfs_submit_chunk fs/btrfs/bio.c:763 [inline]
       btrfs_submit_bbio+0xf91/0x19c0 fs/btrfs/bio.c:792
       submit_eb_page fs/btrfs/extent_io.c:1931 [inline]
       btree_write_cache_pages+0xfa4/0x14b0 fs/btrfs/extent_io.c:1981
       do_writepages+0x361/0x880 mm/page-writeback.c:2702
       filemap_fdatawrite_wbc mm/filemap.c:388 [inline]
       __filemap_fdatawrite_range mm/filemap.c:421 [inline]
       filemap_fdatawrite_range+0x215/0x2c0 mm/filemap.c:439
       btrfs_write_marked_extents+0x27d/0x450 fs/btrfs/transaction.c:1149
       btrfs_write_and_wait_transaction fs/btrfs/transaction.c:1257 [inline]
       btrfs_commit_transaction+0x1dd9/0x3720 fs/btrfs/transaction.c:2519
       btrfs_rebuild_free_space_tree+0x1cb/0x490 fs/btrfs/free-space-tree.c:1360
       btrfs_start_pre_rw_mount+0xeed/0x1300 fs/btrfs/disk-io.c:2998
       open_ctree+0x24f5/0x2a30 fs/btrfs/disk-io.c:3543
       btrfs_fill_super fs/btrfs/super.c:972 [inline]
       btrfs_get_tree_super fs/btrfs/super.c:1898 [inline]
       btrfs_get_tree+0x12d8/0x1a30 fs/btrfs/super.c:2093
       vfs_get_tree+0x92/0x2b0 fs/super.c:1814
       fc_mount+0x1b/0xb0 fs/namespace.c:1231
       btrfs_get_tree_subvol fs/btrfs/super.c:2051 [inline]
       btrfs_get_tree+0x6b1/0x1a30 fs/btrfs/super.c:2094
       vfs_get_tree+0x92/0x2b0 fs/super.c:1814
       do_new_mount+0x2be/0xb40 fs/namespace.c:3513
       do_mount fs/namespace.c:3853 [inline]
       __do_sys_mount fs/namespace.c:4063 [inline]
       __se_sys_mount+0x2d6/0x3c0 fs/namespace.c:4040
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #3 (&fs_info->tree_log_mutex){+.+.}-{4:4}:
       reacquire_held_locks+0x3eb/0x690 kernel/locking/lockdep.c:5374
       __lock_release kernel/locking/lockdep.c:5563 [inline]
       lock_release+0x396/0xa30 kernel/locking/lockdep.c:5870
       btrfs_commit_transaction+0x1ce0/0x3720 fs/btrfs/transaction.c:2512
       btrfs_rebuild_free_space_tree+0x1cb/0x490 fs/btrfs/free-space-tree.c:1360
       btrfs_start_pre_rw_mount+0xeed/0x1300 fs/btrfs/disk-io.c:2998
       open_ctree+0x24f5/0x2a30 fs/btrfs/disk-io.c:3543
       btrfs_fill_super fs/btrfs/super.c:972 [inline]
       btrfs_get_tree_super fs/btrfs/super.c:1898 [inline]
       btrfs_get_tree+0x12d8/0x1a30 fs/btrfs/super.c:2093
       vfs_get_tree+0x92/0x2b0 fs/super.c:1814
       fc_mount+0x1b/0xb0 fs/namespace.c:1231
       btrfs_get_tree_subvol fs/btrfs/super.c:2051 [inline]
       btrfs_get_tree+0x6b1/0x1a30 fs/btrfs/super.c:2094
       vfs_get_tree+0x92/0x2b0 fs/super.c:1814
       do_new_mount+0x2be/0xb40 fs/namespace.c:3513
       do_mount fs/namespace.c:3853 [inline]
       __do_sys_mount fs/namespace.c:4063 [inline]
       __se_sys_mount+0x2d6/0x3c0 fs/namespace.c:4040
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #2 (btrfs_trans_super_committed){.+.+}-{0:0}:
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       btrfs_commit_transaction+0xe85/0x3720 fs/btrfs/transaction.c:2371
       btrfs_rebuild_free_space_tree+0x1cb/0x490 fs/btrfs/free-space-tree.c:1360
       btrfs_start_pre_rw_mount+0xeed/0x1300 fs/btrfs/disk-io.c:2998
       open_ctree+0x24f5/0x2a30 fs/btrfs/disk-io.c:3543
       btrfs_fill_super fs/btrfs/super.c:972 [inline]
       btrfs_get_tree_super fs/btrfs/super.c:1898 [inline]
       btrfs_get_tree+0x12d8/0x1a30 fs/btrfs/super.c:2093
       vfs_get_tree+0x92/0x2b0 fs/super.c:1814
       fc_mount+0x1b/0xb0 fs/namespace.c:1231
       btrfs_get_tree_subvol fs/btrfs/super.c:2051 [inline]
       btrfs_get_tree+0x6b1/0x1a30 fs/btrfs/super.c:2094
       vfs_get_tree+0x92/0x2b0 fs/super.c:1814
       do_new_mount+0x2be/0xb40 fs/namespace.c:3513
       do_mount fs/namespace.c:3853 [inline]
       __do_sys_mount fs/namespace.c:4063 [inline]
       __se_sys_mount+0x2d6/0x3c0 fs/namespace.c:4040
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (btrfs_trans_completed){.+.+}-{0:0}:
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       btrfs_commit_transaction+0xe59/0x3720 fs/btrfs/transaction.c:2370
       btrfs_rebuild_free_space_tree+0x1cb/0x490 fs/btrfs/free-space-tree.c:1360
       btrfs_start_pre_rw_mount+0xeed/0x1300 fs/btrfs/disk-io.c:2998
       open_ctree+0x24f5/0x2a30 fs/btrfs/disk-io.c:3543
       btrfs_fill_super fs/btrfs/super.c:972 [inline]
       btrfs_get_tree_super fs/btrfs/super.c:1898 [inline]
       btrfs_get_tree+0x12d8/0x1a30 fs/btrfs/super.c:2093
       vfs_get_tree+0x92/0x2b0 fs/super.c:1814
       fc_mount+0x1b/0xb0 fs/namespace.c:1231
       btrfs_get_tree_subvol fs/btrfs/super.c:2051 [inline]
       btrfs_get_tree+0x6b1/0x1a30 fs/btrfs/super.c:2094
       vfs_get_tree+0x92/0x2b0 fs/super.c:1814
       do_new_mount+0x2be/0xb40 fs/namespace.c:3513
       do_mount fs/namespace.c:3853 [inline]
       __do_sys_mount fs/namespace.c:4063 [inline]
       __se_sys_mount+0x2d6/0x3c0 fs/namespace.c:4040
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (sb_internal#5){.+.+}-{0:0}:
       check_prev_add kernel/locking/lockdep.c:3161 [inline]
       check_prevs_add kernel/locking/lockdep.c:3280 [inline]
       validate_chain+0x18ef/0x5920 kernel/locking/lockdep.c:3904
       __lock_acquire+0x1397/0x2100 kernel/locking/lockdep.c:5226
       lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
       percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
       __sb_start_write include/linux/fs.h:1725 [inline]
       sb_start_intwrite include/linux/fs.h:1908 [inline]
       start_transaction+0x8fd/0x1670 fs/btrfs/transaction.c:691
       btrfs_dirty_inode+0xa5/0x1a0 fs/btrfs/inode.c:6055
       inode_update_time fs/inode.c:2124 [inline]
       touch_atime+0x27f/0x690 fs/inode.c:2197
       file_accessed include/linux/fs.h:2539 [inline]
       btrfs_file_mmap+0xbd/0x120 fs/btrfs/file.c:1954
       call_mmap include/linux/fs.h:2183 [inline]
       mmap_file mm/internal.h:124 [inline]
       __mmap_new_file_vma mm/vma.c:2291 [inline]
       __mmap_new_vma mm/vma.c:2355 [inline]
       __mmap_region+0x2250/0x2d30 mm/vma.c:2456
       mmap_region+0x226/0x2c0 mm/mmap.c:1352
       do_mmap+0x97a/0x10d0 mm/mmap.c:500
       vm_mmap_pgoff+0x1dd/0x3d0 mm/util.c:575
       ksys_mmap_pgoff+0x4eb/0x720 mm/mmap.c:546
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  sb_internal#5 --> &q->debugfs_mutex --> &mm->mmap_lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&mm->mmap_lock);
                               lock(&q->debugfs_mutex);
                               lock(&mm->mmap_lock);
  rlock(sb_internal#5);

 *** DEADLOCK ***

2 locks held by syz.0.112/6421:
 #0: ffff888078638ba0 (&mm->mmap_lock){++++}-{4:4}, at: mmap_write_lock_killable include/linux/mmap_lock.h:122 [inline]
 #0: ffff888078638ba0 (&mm->mmap_lock){++++}-{4:4}, at: vm_mmap_pgoff+0x17c/0x3d0 mm/util.c:573
 #1: ffff88802ca3c420 (sb_writers#27){.+.+}-{0:0}, at: file_accessed include/linux/fs.h:2539 [inline]
 #1: ffff88802ca3c420 (sb_writers#27){.+.+}-{0:0}, at: btrfs_file_mmap+0xbd/0x120 fs/btrfs/file.c:1954

stack backtrace:
CPU: 0 UID: 0 PID: 6421 Comm: syz.0.112 Not tainted 6.13.0-rc6-syzkaller-00046-g0b7958fa05d5 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
 print_circular_bug+0x13a/0x1b0 kernel/locking/lockdep.c:2074
 check_noncircular+0x36a/0x4a0 kernel/locking/lockdep.c:2206
 check_prev_add kernel/locking/lockdep.c:3161 [inline]
 check_prevs_add kernel/locking/lockdep.c:3280 [inline]
 validate_chain+0x18ef/0x5920 kernel/locking/lockdep.c:3904
 __lock_acquire+0x1397/0x2100 kernel/locking/lockdep.c:5226
 lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5849
 percpu_down_read include/linux/percpu-rwsem.h:51 [inline]
 __sb_start_write include/linux/fs.h:1725 [inline]
 sb_start_intwrite include/linux/fs.h:1908 [inline]
 start_transaction+0x8fd/0x1670 fs/btrfs/transaction.c:691
 btrfs_dirty_inode+0xa5/0x1a0 fs/btrfs/inode.c:6055
 inode_update_time fs/inode.c:2124 [inline]
 touch_atime+0x27f/0x690 fs/inode.c:2197
 file_accessed include/linux/fs.h:2539 [inline]
 btrfs_file_mmap+0xbd/0x120 fs/btrfs/file.c:1954
 call_mmap include/linux/fs.h:2183 [inline]
 mmap_file mm/internal.h:124 [inline]
 __mmap_new_file_vma mm/vma.c:2291 [inline]
 __mmap_new_vma mm/vma.c:2355 [inline]
 __mmap_region+0x2250/0x2d30 mm/vma.c:2456
 mmap_region+0x226/0x2c0 mm/mmap.c:1352
 do_mmap+0x97a/0x10d0 mm/mmap.c:500
 vm_mmap_pgoff+0x1dd/0x3d0 mm/util.c:575
 ksys_mmap_pgoff+0x4eb/0x720 mm/mmap.c:546
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f78d4585d29
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f78d5448038 EFLAGS: 00000246 ORIG_RAX: 0000000000000009
RAX: ffffffffffffffda RBX: 00007f78d4776080 RCX: 00007f78d4585d29
RDX: 0000000000000002 RSI: 0000000000b36000 RDI: 0000000020000000
RBP: 00007f78d4601b08 R08: 0000000000000004 R09: 0000000000000000
R10: 0000000000028011 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000001 R14: 00007f78d4776080 R15: 00007ffca27a2918
 </TASK>

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/01/09 05:00 upstream 0b7958fa05d5 f3558dbf .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in btrfs_dirty_inode
2024/12/26 22:14 upstream d6ef8b40d075 d3ccff63 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in btrfs_dirty_inode
2024/12/12 02:06 upstream 231825b2e1ff ff949d25 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-badwrites-root possible deadlock in btrfs_dirty_inode
* Struck through repros no longer work on HEAD.