possible deadlock in btrfs_inode_lock

Status: moderation: reported on 2026/12/01 12:46
Subsystems: nbd
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+8c9aaebf716d628c8061@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_add_socket() and nbd_genl_reconnect_sock_cb() accept a userspace socket fd via sockfd_lookup() and call nbd_reclassify_socket() to move sk->sk_lock to an NBD-specific lockdep class. However, nbd_reclassify_socket() silently aborts if sock_allow_reclassification(sk) returns false (e.g., if userspace or softirq concurrently holds the socket lock), leaving the NBD socket in the generic sk_lock-AF_INET class. This bridges the block I/O path (btrfs_inode::i_mmap_lock -> btrfs-tree-* -> blk-mq -> nbd cmd->lock -> nsock->tx_lock -> sk_lock-AF_INET) with userspace socket I/O (sk_lock-AF_INET -> mm->mmap_lock -> sb_pagefaults -> btrfs_inode::i_mmap_lock), and also permits a real same-socket deadlock because userspace retains access to the NBD socket fd.

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

Technical Root Cause Analysis

The circular locking dependency reported by lockdep involves two main issues in drivers/block/nbd.c when a filesystem (here btrfs) is mounted on an NBD device backed by an AF_INET TCP socket:

1. Silent failure of nbd_reclassify_socket() (drivers/block/nbd.c)

When a socket file descriptor is attached to an NBD device via NBD_SET_SOCK (nbd_add_socket() at drivers/block/nbd.c:1277) or reconnected via netlink (nbd_genl_reconnect_sock_cb() at drivers/block/nbd.c:1348), nbd_get_socket() (drivers/block/nbd.c:1213) looks up the socket using sockfd_lookup() and then calls nbd_reclassify_socket(sock) (drivers/block/nbd.c:1245).

nbd_reclassify_socket() is intended to move the socket's sk->sk_lock and sk->sk_lock.slock into NBD-specific lockdep classes ("sk_lock-AF_INET-NBD" / &nbd_key[0], etc.) via sock_lock_init_class_and_name(). However, it performs an unlocked check:

if (!sock_allow_reclassification(sk))
    return;

(drivers/block/nbd.c:1249, where sock_allow_reclassification() in include/net/sock.h:1835 checks !sock_owned_by_user_nocheck(sk) && !spin_is_locked(&sk->sk_lock.slock)).

Because the socket originates from userspace and userspace still holds the file descriptor, another thread calling a socket syscall (e.g., sendmsg, recvmsg, setsockopt, connect, shutdown) or softirq processing incoming packets via bh_lock_sock(sk) can concurrently hold sk->sk_lock or sk->sk_lock.slock when nbd_reclassify_socket() runs. When that occurs, nbd_reclassify_socket() silently returns without reclassifying the socket and without failing nbd_add_socket()/nbd_genl_reconnect_sock_cb(), leaving nsock->sock->sk in the generic sk_lock-AF_INET lockdep class.

2. Resulting dependency cycle (and same-socket deadlock exposure)

With the NBD socket remaining in sk_lock-AF_INET (or when userspace continues operating on the same NBD socket fd), lockdep records the following cycle:

  1. &ei->i_mmap_lock → btrfs-tree-01 → btrfs-tree-00 → &q->q_usage_counter(io):

    • btrfs_fallocate() (fs/btrfs/file.c:3118) calls btrfs_inode_lock(BTRFS_I(inode), BTRFS_ILOCK_MMAP), acquiring down_write(&ei->i_mmap_lock) (fs/btrfs/inode.c:368).
    • While holding i_mmap_lock, it calls file_modified() (fs/btrfs/file.c:3126) → file_remove_privs_flags() → security_inode_need_killpriv() → btrfs_xattr_handler_get_security() → btrfs_getxattr() → btrfs_lookup_xattr() → btrfs_search_slot() → btrfs_read_lock_root_node(), acquiring btrfs-tree-01 (btrfs_tree_read_lock_nested(), fs/btrfs/locking.c:146).
    • Reading child tree blocks in read_block_for_search() (fs/btrfs/ctree.c:1563–1569) acquires btrfs-tree-00 and submits metadata I/O via btrfs_read_extent_buffer() → btrfs_submit_bbio() → blk_mq_submit_bio(), entering &q->q_usage_counter(io).
  2. &q->q_usage_counter(io) → &q->elevator_lock → set->srcu → &cmd->lock → &nsock->tx_lock → sk_lock-AF_INET:

    • Block queue reconfiguration (elevator_change() / elevator_switch() in block/elevator.c:576, 668–681) nests queue freeze (q_usage_counter) → &q->elevator_lock → blk_mq_quiesce_queue() (set->srcu).
    • blk_mq_dispatch_rq_list() invokes nbd_queue_rq() (drivers/block/nbd.c:1184), which acquires &cmd->lock → &nsock->tx_lock (nbd_handle_cmd(), drivers/block/nbd.c:1143).
    • Under &nsock->tx_lock, NBD acquires sk->sk_lock both in nbd_send_cmd() → sock_sendmsg() (drivers/block/nbd.c:585) and in recv_work() → nbd_mark_nsock_dead() → kernel_sock_shutdown(nsock->sock, SHUT_RDWR) → inet_shutdown() → lock_sock() (drivers/block/nbd.c:319, 1030), recorded against sk_lock-AF_INET (link #7).
  3. sk_lock-AF_INET → &mm->mmap_lock → sb_pagefaults → &ei->i_mmap_lock:

    • Userspace TCP I/O holds lock_sock(sk) (sk_lock-AF_INET) across user-memory copies that can fault: tcp_sendmsg_locked() (net/ipv4/tcp.c:1324) calls skb_copy_to_page_nocache() → _copy_from_iter() → __might_fault() (mm/memory.c:7607), and tcp_recvmsg() (net/ipv4/tcp.c:2956) holds lock_sock(sk) across skb_copy_datagram_msg() (net/ipv4/tcp.c:2853).
    • A page write fault against an mmap()ed file on the btrfs-on-NBD filesystem enters do_page_mkwrite() → btrfs_page_mkwrite() (fs/btrfs/file.c:1844, 1889), acquiring sb_start_pagefault() (sb_pagefaults) and down_read(&inode->i_mmap_lock) (&ei->i_mmap_lock), closing the cycle.

Note also that because nbd_get_socket() only borrows a struct file reference via sockfd_lookup() and leaves the socket file descriptor open in userspace, a task can also issue recvmsg()/read() directly on the NBD socket fd into an mmap()ed page backed by a file on /dev/nbdX, creating a real AB-BA lock inversion on the exact same sk->sk_lock and ei->i_mmap_lock instances even without lockdep class sharing.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
83e90d5d bisect-cause IsRelease: ❌ ❓ possible deadlock in btrfs_inode_lock 2026/12/01 13:07 2026/12/01 13:07 2026/12/01 13:36 ba8e13b2
16778413 assessment-security DenialOfService: ✅ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ possible deadlock in btrfs_inode_lock 2026/12/01 12:04 2026/12/01 12:05 2026/12/01 12:45 ba8e13b2

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Tainted: G             L     
------------------------------------------------------
syz.0.1970/12965 is trying to acquire lock:
ffff888056f4c4a0 (btrfs-tree-01){++++}-{4:4}, at: btrfs_tree_read_lock_nested+0x45/0x250 fs/btrfs/locking.c:146

but task is already holding lock:
ffff888052ec3d98 (&ei->i_mmap_lock){++++}-{4:4}, at: btrfs_inode_lock+0xcb/0xe0 fs/btrfs/inode.c:368

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #10 (&ei->i_mmap_lock){++++}-{4:4}:
       down_read+0x45/0x320 kernel/locking/rwsem.c:1574
       btrfs_page_mkwrite+0x607/0x1a30 fs/btrfs/file.c:1889
       do_page_mkwrite+0x147/0x310 mm/memory.c:3908
       wp_page_shared mm/memory.c:4317 [inline]
       do_wp_page+0x1a7c/0x4c40 mm/memory.c:4540
       handle_pte_fault mm/memory.c:6724 [inline]
       __handle_mm_fault mm/memory.c:6849 [inline]
       handle_mm_fault+0x19c9/0x2f80 mm/memory.c:7016
       do_user_addr_fault+0x7f6/0x1480 arch/x86/mm/fault.c:1394
       handle_page_fault arch/x86/mm/fault.c:1483 [inline]
       exc_page_fault+0x6a/0xc0 arch/x86/mm/fault.c:1536
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:595
       copy_user_generic arch/x86/include/asm/uaccess_64.h:126 [inline]
       raw_copy_to_user arch/x86/include/asm/uaccess_64.h:147 [inline]
       _inline_copy_to_user include/linux/uaccess.h:202 [inline]
       _copy_to_user+0x85/0xb0 lib/usercopy.c:24
       copy_to_user include/linux/uaccess.h:230 [inline]
       rng_dev_read+0x3ee/0x830 drivers/char/hw_random/core.c:287
       vfs_read+0x213/0xa80 fs/read_write.c:552
       ksys_read+0x150/0x270 fs/read_write.c:696
       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 (sb_pagefaults#4){++++}-{0:0}:
       percpu_down_read_internal include/linux/percpu-rwsem.h:53 [inline]
       percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
       __sb_start_write include/linux/fs/super.h:19 [inline]
       sb_start_pagefault include/linux/fs/super.h:159 [inline]
       btrfs_page_mkwrite+0x2fe/0x1a30 fs/btrfs/file.c:1844
       do_page_mkwrite+0x147/0x310 mm/memory.c:3908
       wp_page_shared mm/memory.c:4317 [inline]
       do_wp_page+0x1a7c/0x4c40 mm/memory.c:4540
       handle_pte_fault mm/memory.c:6724 [inline]
       __handle_mm_fault mm/memory.c:6849 [inline]
       handle_mm_fault+0x19c9/0x2f80 mm/memory.c:7016
       do_user_addr_fault+0x7f6/0x1480 arch/x86/mm/fault.c:1394
       handle_page_fault arch/x86/mm/fault.c:1483 [inline]
       exc_page_fault+0x6a/0xc0 arch/x86/mm/fault.c:1536
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:595
       copy_user_generic arch/x86/include/asm/uaccess_64.h:126 [inline]
       raw_copy_to_user arch/x86/include/asm/uaccess_64.h:147 [inline]
       _inline_copy_to_user include/linux/uaccess.h:202 [inline]
       _copy_to_user+0x85/0xb0 lib/usercopy.c:24
       copy_to_user include/linux/uaccess.h:230 [inline]
       rng_dev_read+0x3ee/0x830 drivers/char/hw_random/core.c:287
       vfs_read+0x213/0xa80 fs/read_write.c:552
       ksys_read+0x150/0x270 fs/read_write.c:696
       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 (&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

-> #7 (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

-> #6 (&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

-> #5 (&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

-> #4 (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

-> #3 (&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
       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

-> #2 (&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

-> #1 (btrfs-tree-00){++++}-{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]
       read_block_for_search+0x617/0xa40 fs/btrfs/ctree.c:1563
       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-01){++++}-{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_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_match_dir fs/btrfs/dir-item.c:196 [inline]
       btrfs_lookup_xattr+0xff/0x1e0 fs/btrfs/dir-item.c:369
       btrfs_getxattr+0x97/0x1b0 fs/btrfs/xattr.c:41
       btrfs_xattr_handler_get_security+0xd0/0x130 fs/btrfs/xattr.c:398
       __vfs_getxattr+0x412/0x440 fs/xattr.c:446
       cap_inode_need_killpriv+0x45/0x60 security/commoncap.c:331
       security_inode_need_killpriv+0x85/0x240 security/security.c:2209
       dentry_needs_remove_privs fs/inode.c:2372 [inline]
       file_remove_privs_flags+0x277/0x610 fs/inode.c:2403
       file_modified_flags fs/inode.c:2552 [inline]
       file_modified+0x18/0x50 fs/inode.c:2571
       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

other info that might help us debug this:

Chain exists of:
  btrfs-tree-01 --> sb_pagefaults#4 --> &ei->i_mmap_lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&ei->i_mmap_lock);
                               lock(sb_pagefaults#4);
                               lock(&ei->i_mmap_lock);
  rlock(btrfs-tree-01);

 *** DEADLOCK ***

locks held by syz.0.1970/12965: 3, on CPU#0:
 #0: ffff88805558c478 (sb_writers#12){++++}-{0:0}, at: file_start_write include/linux/fs.h:2765 [inline]
 #0: ffff88805558c478 (sb_writers#12){++++}-{0:0}, at: vfs_fallocate+0x5e0/0x7e0 fs/open.c:337
 #1: ffff888052ec3f00 (&sb->s_type->i_mutex_key#24){++++}-{4:4}, at: inode_lock include/linux/fs.h:1027 [inline]
 #1: ffff888052ec3f00 (&sb->s_type->i_mutex_key#24){++++}-{4:4}, at: btrfs_inode_lock+0x51/0xe0 fs/btrfs/inode.c:365
 #2: ffff888052ec3d98 (&ei->i_mmap_lock){++++}-{4:4}, at: btrfs_inode_lock+0xcb/0xe0 fs/btrfs/inode.c:368

stack backtrace:
CPU: 0 UID: 0 PID: 12965 Comm: syz.0.1970 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_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_match_dir fs/btrfs/dir-item.c:196 [inline]
 btrfs_lookup_xattr+0xff/0x1e0 fs/btrfs/dir-item.c:369
 btrfs_getxattr+0x97/0x1b0 fs/btrfs/xattr.c:41
 btrfs_xattr_handler_get_security+0xd0/0x130 fs/btrfs/xattr.c:398
 __vfs_getxattr+0x412/0x440 fs/xattr.c:446
 cap_inode_need_killpriv+0x45/0x60 security/commoncap.c:331
 security_inode_need_killpriv+0x85/0x240 security/security.c:2209
 dentry_needs_remove_privs fs/inode.c:2372 [inline]
 file_remove_privs_flags+0x277/0x610 fs/inode.c:2403
 file_modified_flags fs/inode.c:2552 [inline]
 file_modified+0x18/0x50 fs/inode.c:2571
 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
RIP: 0033:0x7f81335a9c99
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:00007f81344d8028 EFLAGS: 00000246 ORIG_RAX: 000000000000011d
RAX: ffffffffffffffda RBX: 00007f8133835fa0 RCX: 00007f81335a9c99
RDX: 0000000000000006 RSI: 0000000000000000 RDI: 0000000000000004
RBP: 00007f813363b18b R08: 0000000000000000 R09: 0000000000000000
R10: 000000000000ffff R11: 0000000000000246 R12: 0000000000000000
R13: 00007f8133836038 R14: 00007f8133835fa0 R15: 00007ffe47c43d78
 </TASK>

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