possible deadlock in btrfs_search_slot (4)

Status: moderation: reported on 2026/12/01 12:53
Subsystems: nbd btrfs
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+54a0848c949a74f6cb0f@syzkaller.appspotmail.com
First crash: 1h40m, last: 1h40m
✨ AI cause bisection: introduced by (AI job) :
commit 9280e6edf65662b6aafc8b704ad065b54c08b519
Author: Deepanshu Kartikey <kartikey406@gmail.com>
Date: Sun Jun 21 23:52:55 2026 +0000

  nbd: don't warn when reclassifying a busy socket lock

✨ AI-generated root cause summary:

In drivers/block/nbd.c, nbd_reclassify_socket() is supposed to move attached sockets into NBD's dedicated sk_lock-AF_INET-NBD lockdep class, but because userspace retains the socket fd and can concurrently hold the socket lock (or softirq BH processing can hold sk_lock.slock), sock_allow_reclassification() can return false and cause nbd_reclassify_socket() to silently skip reclassification while still attaching the socket under the generic sk_lock-AF_INET class. Combined with shared global lockdep classes (&q->elevator_lock and set->srcu bridging loop8 and nbd, and sk_lock-AF_INET bridging NBD and regular tcp_sendmsg()) plus read_block_for_search() holding btrfs-tree-00 across btrfs_read_extent_buffer(), lockdep observes an 11-lock cycle back to btrfs-tree-01. Additionally, because NBD allows userspace to retain the socket fd, a CAP_SYS_ADMIN process can also trigger a real self-deadlock on sk_lock if it writes to the attached NBD socket from an mmap()ed buffer backed by that NBD device.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 19cc08c1a6a6:

Root Cause Analysis

The lockdep warning reports an 11-lock circular dependency cycle between btrfs-tree-01 and btrfs-tree-00 spanning Btrfs, the block layer, NBD, TCP sockets, and mm->mmap_lock. The primary defect causing this cycle is in drivers/block/nbd.c, where nbd_reclassify_socket() silently skips lockdep class reclassification when the user-supplied socket is busy, leaving it in the generic sk_lock-AF_INET class.

1. Silent bypass of socket lockdep reclassification in NBD (drivers/block/nbd.c)

To avoid lockdep cycles between block-layer I/O paths and normal userspace socket operations (sk_lock-AF_INET -> &mm->mmap_lock -> filesystem/block I/O), nbd_add_socket() (drivers/block/nbd.c:1299) and nbd_genl_reconnect_sock_cb() (drivers/block/nbd.c:1359) call nbd_reclassify_socket() (drivers/block/nbd.c:1245-1272) to move sock->sk->sk_lock to the NBD-specific sk_lock-AF_INET-NBD class (nbd_key[0]).

However, nbd_reclassify_socket() begins with:

if (!sock_allow_reclassification(sk))
    return;

where sock_allow_reclassification() (include/net/sock.h:1835-1841) checks !sock_owned_by_user_nocheck(sk) && !spin_is_locked(&sk->sk_lock.slock). Because nbd_get_socket() (drivers/block/nbd.c:1213-1239) obtains struct socket * via sockfd_lookup() from a userspace file descriptorβ€”and userspace retains that descriptorβ€”a concurrent syscall on the same fd or softirq BH packet processing (bh_lock_sock()) can hold the socket lock when nbd_reclassify_socket() runs. Instead of synchronizing or rejecting the busy socket, nbd_reclassify_socket() returns early and NBD attaches the socket while its sk_lock remains in the generic sk_lock-AF_INET lockdep class.

2. How the full lockdep cycle is formed

Once NBD uses an unreclassified sk_lock-AF_INET socket, lockdep connects the block/filesystem stack back to mm->mmap_lock and Btrfs:

  1. btrfs-tree-01 -> btrfs-tree-00 (#0): During openat() -> btrfs_lookup() -> btrfs_search_slot() (fs/btrfs/ctree.c:2224), Btrfs descends from a level-1 node (btrfs-tree-01) and read-locks a level-0 leaf (btrfs-tree-00) via btrfs_tree_read_lock() (fs/btrfs/locking.c:146).
  2. btrfs-tree-00 -> &q->q_usage_counter(io)#17 (#1): In read_block_for_search() (fs/btrfs/ctree.c:1518-1525, 1563-1569), Btrfs acquires btrfs_tree_read_lock(tmp) on the level-0 extent buffer (btrfs-tree-00), releases the parent path (btrfs_release_path(p)), and then performs synchronous metadata I/O via btrfs_read_extent_buffer() -> read_extent_buffer_pages() -> btrfs_submit_bbio() -> blk_mq_submit_bio() -> bio_queue_enter() (block/blk.h:90-100), which acquires q->io_lockdep_map (&q->q_usage_counter(io)#17).
  3. &q->q_usage_counter(io)#17 -> &q->elevator_lock (#2): elv_iosched_store() -> elevator_change() (block/elevator.c:668-681) freezes the queue (blk_mq_freeze_queue(q), acquiring q->io_lockdep_map as writer) and then acquires mutex_lock(&q->elevator_lock). Note that &q->elevator_lock shares a single static lockdep class across all request_queue instances, bridging loop8 (#17) and nbd.
  4. &q->elevator_lock -> set->srcu (#3): During nbd_dev_add() (drivers/block/nbd.c:2027) -> add_disk() -> blk_register_queue() -> elevator_set_default() -> elevator_change() -> elevator_switch() (block/elevator.c:576), blk_mq_quiesce_queue() calls synchronize_srcu(set->srcu) (block/blk-mq.c:284) while holding &q->elevator_lock. All BLK_MQ_F_BLOCKING tag sets initialized via blk_mq_alloc_tag_set() (block/blk-mq.c:4957) share the same set->srcu lockdep class.
  5. set->srcu -> &cmd->lock -> &nsock->tx_lock -> sk_lock-AF_INET (#4–#6):
    • blk_mq_run_work_fn() (block/blk-mq.c:2555) enters blk_mq_run_dispatch_ops() (srcu_read_lock(set->srcu), block/blk-mq.h:448) and dispatches via nbd_queue_rq() (drivers/block/nbd.c:1199), acquiring &cmd->lock.
    • nbd_handle_cmd() (drivers/block/nbd.c:1143) acquires &nsock->tx_lock.
    • recv_work() -> nbd_mark_nsock_dead() (drivers/block/nbd.c:1029-1030, 319) holds &nsock->tx_lock and calls kernel_sock_shutdown() -> inet_shutdown() -> lock_sock() (net/ipv4/af_inet.c:913), recording &nsock->tx_lock -> sk_lock-AF_INET because reclassification was skipped.
  6. sk_lock-AF_INET -> &mm->mmap_lock (#7): tcp_sendmsg_locked() (net/ipv4/tcp.c:1324) holds sk_lock-AF_INET while calling _copy_from_iter() -> __might_fault(), establishing sk_lock-AF_INET -> &mm->mmap_lock.
  7. &mm->mmap_lock -> btrfs_trans_num_writers -> btrfs_trans_num_extwriters -> btrfs-tree-01 (#8–#10):
    • mmap_region() holds &mm->mmap_lock and calls btrfs_file_mmap_prepare() (fs/btrfs/file.c:2010) -> file_accessed() -> touch_atime() -> btrfs_dirty_inode() (fs/btrfs/inode.c:6386, 6400), entering a Btrfs transaction (btrfs_trans_num_writers, btrfs_trans_num_extwriters) and releasing sb_end_intwrite() before the transaction lockdep maps in __btrfs_end_transaction() (fs/btrfs/transaction.c:1124, 1140-1141).
    • btrfs_fallocate() (fs/btrfs/file.c:3126, 3162) -> btrfs_wait_ordered_range() -> __cow_file_range_inline() (fs/btrfs/inode.c:624, 638) -> btrfs_drop_extents() -> btrfs_search_slot() locks btrfs-tree-01 (btrfs_read_lock_root_node()) while holding btrfs_trans_num_extwriters, completing the cycle.

3. Cross-device lockdep aliasing vs. single-socket shared-fd deadlock

In the reported trace, the cycle bridges unrelated block devices (loop8 and nbd) via &q->elevator_lock and set->srcu, and bridges an NBD socket with a regular TCP socket via the unreclassified sk_lock-AF_INET. However, because NBD does not take exclusive ownership of the user-supplied socket fd (both nbd_ioctl() and nbd_genl_connect() gate access with CAP_SYS_ADMIN, and userspace retains the fd), a privileged user can also construct a real single-socket deadlock by attaching a TCP socket fd to NBD and writing to that same fd from an mmap()ed buffer backed by a filesystem mounted on that NBD device.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
c6a2fb64 bisect-cause IsRelease: ❌ ❓ possible deadlock in btrfs_search_slot (4) 2026/12/01 12:49 2026/12/01 12:49 2026/12/01 13:43 ba8e13b2
04247e1b assessment-security DenialOfService: βœ… Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ possible deadlock in btrfs_search_slot (4) 2026/12/01 12:05 2026/12/01 12:05 2026/12/01 12:52 ba8e13b2
▶ ▼ Similar bugs (3)
Kernel Title Rank πŸ›ˆ Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream possible deadlock in btrfs_search_slot (2) btrfs 4 syz, C error 2 1197d 1193d 25/30 fixed on 2023/12/21 03:45
upstream possible deadlock in btrfs_search_slot btrfs 4 syz, C error done 188 1210d 1484d 23/30 fixed on 2023/08/10 11:21
upstream possible deadlock in btrfs_search_slot (3) btrfs 4 5 686d 729d 0/30 auto-obsoleted due to no activity on 2025/04/24 08:43

Sample crash report:
BTRFS info (device loop8): enabling ssd optimizations
BTRFS info (device loop8): turning on async discard
BTRFS info (device loop8): enabling free space tree
BTRFS info (device loop8): use zstd compression, level 3
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Tainted: G             L     
------------------------------------------------------
syz.8.6633/27696 is trying to acquire lock:
ffff8880847940f0 (btrfs-tree-00){++++}-{4:4}, at: btrfs_tree_read_lock_nested+0x45/0x250 fs/btrfs/locking.c:146

but task is already holding lock:
ffff888084795360 (btrfs-tree-01){++++}-{4:4}, at: btrfs_tree_read_lock_nested+0x45/0x250 fs/btrfs/locking.c:146

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #10 (btrfs-tree-01){++++}-{4:4}:
       down_read_nested+0x47/0x320 kernel/locking/rwsem.c:1709
       btrfs_tree_read_lock_nested+0x45/0x250 fs/btrfs/locking.c:146
       btrfs_tree_read_lock fs/btrfs/locking.h:188 [inline]
       btrfs_read_lock_root_node+0x3f/0xd0 fs/btrfs/locking.c:267
       btrfs_search_slot_get_root fs/btrfs/ctree.c:1740 [inline]
       btrfs_search_slot+0x66c/0x2d20 fs/btrfs/ctree.c:2070
       btrfs_lookup_file_extent+0xe6/0x140 fs/btrfs/file-item.c:265
       btrfs_drop_extents+0x444/0x29b0 fs/btrfs/file.c:170
       __cow_file_range_inline+0x270/0x1000 fs/btrfs/inode.c:638
       run_delalloc_inline fs/btrfs/inode.c:2354 [inline]
       btrfs_run_delalloc_range+0x1932/0x1e80 fs/btrfs/inode.c:2410
       writepage_delalloc+0x10a4/0x1c60 fs/btrfs/extent_io.c:1685
       extent_writepage fs/btrfs/extent_io.c:2081 [inline]
       extent_write_cache_pages fs/btrfs/extent_io.c:2834 [inline]
       btrfs_writepages+0x15df/0x2830 fs/btrfs/extent_io.c:2965
       do_writepages+0x338/0x560 mm/page-writeback.c:2562
       filemap_writeback mm/filemap.c:386 [inline]
       filemap_fdatawrite_range+0x1ef/0x2f0 mm/filemap.c:411
       btrfs_fdatawrite_range+0x54/0xf0 fs/btrfs/file.c:3872
       btrfs_wait_ordered_range+0x59/0x260 fs/btrfs/ordered-data.c:910
       btrfs_fallocate+0xbc8/0x1df0 fs/btrfs/file.c:3162
       vfs_fallocate+0x65a/0x7e0 fs/open.c:338
       ksys_fallocate fs/open.c:362 [inline]
       __do_sys_fallocate fs/open.c:367 [inline]
       __se_sys_fallocate fs/open.c:365 [inline]
       __x64_sys_fallocate+0xbf/0x110 fs/open.c:365
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #9 (btrfs_trans_num_extwriters){++++}-{0:0}:
       join_transaction+0x180/0x1030 fs/btrfs/transaction.c:346
       start_transaction+0x731/0x1830 fs/btrfs/transaction.c:753
       btrfs_dirty_inode+0x9f/0x190 fs/btrfs/inode.c:6386
       file_update_time_flags+0x285/0x440 fs/inode.c:2502
       btrfs_fallocate+0x79a/0x1df0 fs/btrfs/file.c:3126
       vfs_fallocate+0x65a/0x7e0 fs/open.c:338
       ksys_fallocate fs/open.c:362 [inline]
       __do_sys_fallocate fs/open.c:367 [inline]
       __se_sys_fallocate fs/open.c:365 [inline]
       __x64_sys_fallocate+0xbf/0x110 fs/open.c:365
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #8 (btrfs_trans_num_writers){++++}-{0:0}:
       __lock_release kernel/locking/lockdep.c:5627 [inline]
       lock_release+0x1a3/0x3c0 kernel/locking/lockdep.c:5964
       percpu_up_read include/linux/percpu-rwsem.h:114 [inline]
       __sb_end_write include/linux/fs/super.h:14 [inline]
       sb_end_intwrite+0x26/0x190 include/linux/fs/super.h:101
       __btrfs_end_transaction+0x237/0x640 fs/btrfs/transaction.c:1124
       btrfs_dirty_inode+0x14c/0x190 fs/btrfs/inode.c:6400
       touch_atime+0x2f8/0x670 fs/inode.c:2347
       file_accessed include/linux/fs.h:2286 [inline]
       btrfs_file_mmap_prepare+0x172/0x1f0 fs/btrfs/file.c:2010
       vfs_mmap_prepare include/linux/fs.h:2076 [inline]
       call_mmap_prepare mm/vma.c:2986 [inline]
       __mmap_region mm/vma.c:3103 [inline]
       mmap_region+0x1191/0x2820 mm/vma.c:3201
       do_mmap+0xe0a/0x1300 mm/mmap.c:573
       vm_mmap_pgoff+0x27a/0x520 mm/util.c:581
       ksys_mmap_pgoff+0x4dc/0x760 mm/mmap.c:619
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #7 (&mm->mmap_lock){++++}-{4:4}:
       __might_fault+0xcb/0x130 mm/memory.c:7607
       _copy_from_iter+0x100/0x1680 lib/iov_iter.c:271
       copy_from_iter include/linux/uio.h:236 [inline]
       copy_from_iter_full include/linux/uio.h:253 [inline]
       skb_do_copy_data_nocache include/net/sock.h:2345 [inline]
       skb_copy_to_page_nocache include/net/sock.h:2371 [inline]
       tcp_sendmsg_locked+0x244e/0x57c0 net/ipv4/tcp.c:1324
       tcp_sendmsg+0x2f/0x50 net/ipv4/tcp.c:1467
       sock_sendmsg_nosec+0x10f/0x190 net/socket.c:801
       __sock_sendmsg net/socket.c:818 [inline]
       sock_write_iter+0x2de/0x3e0 net/socket.c:1269
       new_sync_write fs/read_write.c:575 [inline]
       vfs_write+0x612/0xba0 fs/read_write.c:667
       ksys_write+0x150/0x270 fs/read_write.c:719
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #6 (sk_lock-AF_INET){+.+.}-{0:0}:
       lock_sock_nested+0x41/0x100 net/core/sock.c:3909
       lock_sock include/net/sock.h:1717 [inline]
       inet_shutdown+0x6a/0x390 net/ipv4/af_inet.c:913
       nbd_mark_nsock_dead+0x2cb/0x550 drivers/block/nbd.c:319
       recv_work+0x1d14/0x1e30 drivers/block/nbd.c:1030
       process_one_work kernel/workqueue.c:3497 [inline]
       process_scheduled_works+0xc5d/0x1650 kernel/workqueue.c:3580
       worker_thread+0xa47/0xfb0 kernel/workqueue.c:3661
       kthread+0x38b/0x480 kernel/kthread.c:436
       ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

-> #5 (&nsock->tx_lock){+.+.}-{4:4}:
       __mutex_lock_common kernel/locking/mutex.c:646 [inline]
       __mutex_lock+0x197/0x15a0 kernel/locking/mutex.c:821
       nbd_handle_cmd drivers/block/nbd.c:1143 [inline]
       nbd_queue_rq+0x373/0xff0 drivers/block/nbd.c:1207
       blk_mq_dispatch_rq_list+0x499/0x1990 block/blk-mq.c:2141
       __blk_mq_do_dispatch_sched block/blk-mq-sched.c:168 [inline]
       blk_mq_do_dispatch_sched block/blk-mq-sched.c:182 [inline]
       __blk_mq_sched_dispatch_requests+0xd36/0x1580 block/blk-mq-sched.c:307
       blk_mq_sched_dispatch_requests+0xd7/0x190 block/blk-mq-sched.c:329
       blk_mq_run_work_fn+0x167/0x2f0 block/blk-mq.c:2556
       process_one_work kernel/workqueue.c:3497 [inline]
       process_scheduled_works+0xc5d/0x1650 kernel/workqueue.c:3580
       worker_thread+0xa47/0xfb0 kernel/workqueue.c:3661
       kthread+0x38b/0x480 kernel/kthread.c:436
       ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

-> #4 (&cmd->lock){+.+.}-{4:4}:
       __mutex_lock_common kernel/locking/mutex.c:646 [inline]
       __mutex_lock+0x197/0x15a0 kernel/locking/mutex.c:821
       nbd_queue_rq+0xc1/0xff0 drivers/block/nbd.c:1199
       blk_mq_dispatch_rq_list+0x499/0x1990 block/blk-mq.c:2141
       __blk_mq_do_dispatch_sched block/blk-mq-sched.c:168 [inline]
       blk_mq_do_dispatch_sched block/blk-mq-sched.c:182 [inline]
       __blk_mq_sched_dispatch_requests+0xd36/0x1580 block/blk-mq-sched.c:307
       blk_mq_sched_dispatch_requests+0xd7/0x190 block/blk-mq-sched.c:329
       blk_mq_run_work_fn+0x167/0x2f0 block/blk-mq.c:2556
       process_one_work kernel/workqueue.c:3497 [inline]
       process_scheduled_works+0xc5d/0x1650 kernel/workqueue.c:3580
       worker_thread+0xa47/0xfb0 kernel/workqueue.c:3661
       kthread+0x38b/0x480 kernel/kthread.c:436
       ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

-> #3 (set->srcu){.+.+}-{0:0}:
       srcu_lock_sync include/linux/srcu.h:261 [inline]
       __synchronize_srcu+0xca/0x2f0 kernel/rcu/srcutree.c:1662
       elevator_switch+0x1e8/0x7b0 block/elevator.c:576
       elevator_change+0x2fa/0x480 block/elevator.c:681
       elevator_set_default+0x375/0x440 block/elevator.c:754
       blk_register_queue+0x404/0x4f0 block/blk-sysfs.c:992
       __add_disk+0x6b8/0xdb0 block/genhd.c:531
       add_disk_fwnode+0x100/0x3a0 block/genhd.c:600
       add_disk include/linux/blkdev.h:799 [inline]
       nbd_dev_add+0x733/0xb60 drivers/block/nbd.c:2027
       nbd_init+0x168/0x1f0 drivers/block/nbd.c:2744
       do_one_initcall+0x250/0x870 init/main.c:1432
       do_initcall_level+0x10a/0x1a0 init/main.c:1494
       do_initcalls+0x59/0xa0 init/main.c:1510
       kernel_init_freeable+0x29d/0x3e0 init/main.c:1745
       kernel_init+0x22/0x1d0 init/main.c:1635
       ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

-> #2 (&q->elevator_lock){+.+.}-{4:4}:
       __mutex_lock_common kernel/locking/mutex.c:646 [inline]
       __mutex_lock+0x197/0x15a0 kernel/locking/mutex.c:821
       elevator_change+0x1af/0x480 block/elevator.c:679
       elv_iosched_store+0x50e/0x630 block/elevator.c:831
       queue_attr_store+0x207/0x2b0 block/blk-sysfs.c:906
       kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
       iter_file_splice_write+0x9f9/0x11c0 fs/splice.c:660
       do_splice_from fs/splice.c:863 [inline]
       direct_splice_actor+0x101/0x160 fs/splice.c:1114
       splice_direct_to_actor+0x57b/0xcb0 fs/splice.c:1023
       do_splice_direct_actor fs/splice.c:1157 [inline]
       do_splice_direct+0x195/0x290 fs/splice.c:1183
       do_sendfile+0x52e/0x7c0 fs/read_write.c:1351
       __do_sys_sendfile64 fs/read_write.c:1412 [inline]
       __se_sys_sendfile64+0x144/0x1a0 fs/read_write.c:1398
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (&q->q_usage_counter(io)#17){++++}-{0:0}:
       bio_queue_enter block/blk.h:95 [inline]
       blk_mq_submit_bio+0x7c6/0x2eb0 block/blk-mq.c:3149
       __submit_bio_noacct_mq block/blk-core.c:755 [inline]
       submit_bio_noacct_nocheck+0x2fe/0xb80 block/blk-core.c:789
       btrfs_submit_chunk fs/btrfs/bio.c:823 [inline]
       btrfs_submit_bbio+0x132d/0x1ee0 fs/btrfs/bio.c:882
       read_extent_buffer_pages_nowait+0x747/0x860 fs/btrfs/extent_io.c:4381
       read_extent_buffer_pages+0x22/0x100 fs/btrfs/extent_io.c:4390
       btrfs_read_extent_buffer+0x9d/0x730 fs/btrfs/disk-io.c:236
       read_block_for_search+0x67e/0xa40 fs/btrfs/ctree.c:1569
       btrfs_search_slot+0x147a/0x2d20 fs/btrfs/ctree.c:2198
       btrfs_init_root_free_objectid+0xf5/0x290 fs/btrfs/disk-io.c:5058
       btrfs_init_fs_root+0x204/0x3b0 fs/btrfs/disk-io.c:1114
       btrfs_get_root_ref+0x3c8/0x890 fs/btrfs/disk-io.c:1365
       btrfs_get_fs_root fs/btrfs/disk-io.c:1417 [inline]
       open_ctree+0x2d07/0x4140 fs/btrfs/disk-io.c:3805
       btrfs_fill_super fs/btrfs/super.c:971 [inline]
       btrfs_get_tree_super fs/btrfs/super.c:1956 [inline]
       btrfs_get_tree_subvol fs/btrfs/super.c:2099 [inline]
       btrfs_get_tree+0x10cf/0x1a00 fs/btrfs/super.c:2133
       vfs_get_tree+0x92/0x2a0 fs/super.c:1881
       fc_mount fs/namespace.c:1282 [inline]
       do_new_mount_fc fs/namespace.c:3910 [inline]
       do_new_mount+0x325/0xb00 fs/namespace.c:3986
       do_mount fs/namespace.c:4350 [inline]
       __do_sys_mount fs/namespace.c:4563 [inline]
       __se_sys_mount+0x31d/0x420 fs/namespace.c:4540
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #0 (btrfs-tree-00){++++}-{4:4}:
       check_prev_add kernel/locking/lockdep.c:3209 [inline]
       check_prevs_add kernel/locking/lockdep.c:3328 [inline]
       validate_chain kernel/locking/lockdep.c:3952 [inline]
       __lock_acquire+0x164c/0x2de0 kernel/locking/lockdep.c:5288
       lock_acquire+0x115/0x350 kernel/locking/lockdep.c:5942
       down_read_nested+0x47/0x320 kernel/locking/rwsem.c:1709
       btrfs_tree_read_lock_nested+0x45/0x250 fs/btrfs/locking.c:146
       btrfs_tree_read_lock fs/btrfs/locking.h:188 [inline]
       btrfs_search_slot+0x15e1/0x2d20 fs/btrfs/ctree.c:2224
       btrfs_lookup_match_dir fs/btrfs/dir-item.c:196 [inline]
       btrfs_lookup_dir_item+0x154/0x280 fs/btrfs/dir-item.c:234
       btrfs_inode_by_name fs/btrfs/inode.c:5726 [inline]
       btrfs_lookup_dentry+0x269/0x1390 fs/btrfs/inode.c:6018
       btrfs_lookup+0x1d/0x40 fs/btrfs/inode.c:6091
       lookup_open+0xa54/0x1ae0 fs/namei.c:4536
       open_last_lookups fs/namei.c:4774 [inline]
       path_openat+0x70c/0x20f0 fs/namei.c:5013
       do_file_open+0x23e/0x4a0 fs/namei.c:5045
       do_sys_openat2+0x115/0x200 fs/open.c:1443
       do_sys_open fs/open.c:1449 [inline]
       __do_sys_openat fs/open.c:1465 [inline]
       __se_sys_openat fs/open.c:1460 [inline]
       __x64_sys_openat+0x138/0x170 fs/open.c:1460
       do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
       do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  btrfs-tree-00 --> btrfs_trans_num_extwriters --> btrfs-tree-01

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  rlock(btrfs-tree-01);
                               lock(btrfs_trans_num_extwriters);
                               lock(btrfs-tree-01);
  rlock(btrfs-tree-00);

 *** DEADLOCK ***

locks held by syz.8.6633/27696: 4, on CPU#1:
 #0: ffff8880845de478 (sb_writers#14){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:531
 #1: ffff888053a7a610 (&type->i_mutex_dir_key#11){++++}-{4:4}, at: inode_lock_shared include/linux/fs.h:1042 [inline]
 #1: ffff888053a7a610 (&type->i_mutex_dir_key#11){++++}-{4:4}, at: lookup_open+0x221/0x1ae0 fs/namei.c:4466
 #2: ffff888077541ca0 (DCACHE_PAR_LOOKUP#17){+.+.}-{0:0}, at: rcu_lock_acquire include/linux/rcupdate.h:309 [inline]
 #2: ffff888077541ca0 (DCACHE_PAR_LOOKUP#17){+.+.}-{0:0}, at: rcu_read_lock include/linux/rcupdate.h:849 [inline]
 #2: ffff888077541ca0 (DCACHE_PAR_LOOKUP#17){+.+.}-{0:0}, at: __d_alloc_parallel+0x39e/0x1700 fs/dcache.c:2919
 #3: ffff888084795360 (btrfs-tree-01){++++}-{4:4}, at: btrfs_tree_read_lock_nested+0x45/0x250 fs/btrfs/locking.c:146

stack backtrace:
CPU: 1 UID: 0 PID: 27696 Comm: syz.8.6633 Tainted: G             L      syzkaller #0 PREEMPT(full) 
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
Call Trace:
 <TASK>
 dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
 print_circular_bug+0x2e2/0x300 kernel/locking/lockdep.c:2087
 check_noncircular+0x12f/0x150 kernel/locking/lockdep.c:2219
 check_prev_add kernel/locking/lockdep.c:3209 [inline]
 check_prevs_add kernel/locking/lockdep.c:3328 [inline]
 validate_chain kernel/locking/lockdep.c:3952 [inline]
 __lock_acquire+0x164c/0x2de0 kernel/locking/lockdep.c:5288
 lock_acquire+0x115/0x350 kernel/locking/lockdep.c:5942
 down_read_nested+0x47/0x320 kernel/locking/rwsem.c:1709
 btrfs_tree_read_lock_nested+0x45/0x250 fs/btrfs/locking.c:146
 btrfs_tree_read_lock fs/btrfs/locking.h:188 [inline]
 btrfs_search_slot+0x15e1/0x2d20 fs/btrfs/ctree.c:2224
 btrfs_lookup_match_dir fs/btrfs/dir-item.c:196 [inline]
 btrfs_lookup_dir_item+0x154/0x280 fs/btrfs/dir-item.c:234
 btrfs_inode_by_name fs/btrfs/inode.c:5726 [inline]
 btrfs_lookup_dentry+0x269/0x1390 fs/btrfs/inode.c:6018
 btrfs_lookup+0x1d/0x40 fs/btrfs/inode.c:6091
 lookup_open+0xa54/0x1ae0 fs/namei.c:4536
 open_last_lookups fs/namei.c:4774 [inline]
 path_openat+0x70c/0x20f0 fs/namei.c:5013
 do_file_open+0x23e/0x4a0 fs/namei.c:5045
 do_sys_openat2+0x115/0x200 fs/open.c:1443
 do_sys_open fs/open.c:1449 [inline]
 __do_sys_openat fs/open.c:1465 [inline]
 __se_sys_openat fs/open.c:1460 [inline]
 __x64_sys_openat+0x138/0x170 fs/open.c:1460
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f2fae9a9c99
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 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 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f2faf7d3028 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 00007f2faec35fa0 RCX: 00007f2fae9a9c99
RDX: 0000000000000002 RSI: 000020000000de80 RDI: ffffffffffffff9c
RBP: 00007f2faea3b18b R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f2faec36038 R14: 00007f2faec35fa0 R15: 00007ffdd78f3be8
 </TASK>

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/12/01 12:05 upstream 19cc08c1a6a6 90414683 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in btrfs_search_slot
* Struck through repros no longer work on HEAD.