| 0/0 |
2026/11/28 09:26 |
flow |
bisect-cause |
41m
Results: map[BisectReasoning:### Root Cause
Lockdep reports a circular locking dependency:
`fs_reclaim --> sk_lock-AF_INET6 --> k-sk_lock-AF_INET6 --> fs_reclaim`
Breaking down the chain:
1. **`k-sk_lock-AF_INET6` β `fs_reclaim`** (`#0`): `rds_tcp_recv_path()` (`net/rds/tcp_recv.c`) acquires `lock_sock(sock->sk)` on a kernel socket (`k-sk_lock-AF_INET6`) and allocates memory with `GFP_KERNEL` in `rds_tcp_data_recv()`.
2. **`sk_lock-AF_INET6` β `k-sk_lock-AF_INET6`** (`#7`): `mptcp_setsockopt_first_sf_only()` (`net/mptcp/sockopt.c`) holds `lock_sock(sk)` on a user MPTCP socket (`sk_lock-AF_INET6`) and calls `do_tcp_setsockopt()` on the subflow kernel socket (`k-sk_lock-AF_INET6`).
3. **`fs_reclaim` β `sk_lock-AF_INET6`** (`#1`β`#6`): Through the block layer and NBD (`&q->q_usage_counter(io)` β `&q->elevator_lock` β `set->srcu` β `&cmd->lock` β `&nsock->tx_lock`), `nbd_genl_connect()` β `nbd_config_put()` β `nbd_clear_sock()` β `sock_shutdown()` β `nbd_mark_nsock_dead()` calls `inet_shutdown()` β `lock_sock()`, acquiring the generic user socket class `sk_lock-AF_INET6` instead of NBD's dedicated `sk_lock-AF_INET6-NBD` class.
Normally, `fs_reclaim` must never depend on the generic user `sk_lock-AF_INET6` lock class. NBD sockets are supposed to be reclassified to `sk_lock-AF_INET6-NBD` by `nbd_reclassify_socket()` when added via `nbd_add_socket()`.
However, in `drivers/block/nbd.c`, `nbd_reclassify_socket()` checks `if (!sock_allow_reclassification(sk)) return;` and silently skips reclassification if the socket lock (`sk->sk_lock` or `sk->sk_lock.slock`) is concurrently held (for example, by a concurrent userspace syscall on the same fd or softirq BH processing). `nbd_add_socket()` still proceeds to attach the socket with its original `sk_lock-AF_INET6` class, directly re-introducing the `fs_reclaim` β `sk_lock-AF_INET6` dependency when NBD later locks the socket under `&nsock->tx_lock`.
### Bisection History
- **`70041088e3b9` / `2da43c4a1b51`** (`net/rds/tcp_recv.c`) and **`d3d429047cc6` / `caea64675d8b`** (`net/mptcp/sockopt.c`): Old code from 2009β2022; `k-sk_lock-AF_INET6 -> fs_reclaim` and `sk_lock-AF_INET6 -> k-sk_lock-AF_INET6` are normal outside block/reclaim paths. Ruled out.
- **`ffa1e7ada456`** (`block: Make request_queue lockdep splats show up earlier`): Only added lockdep priming between `fs_reclaim` and `q->io_lockdep_map` in `blk_alloc_queue()`. Ruled out.
- **`d532cddb6c60`** (`nbd: Reclassify sockets to avoid lockdep circular dependency`): Introduced `nbd_reclassify_socket()` to move NBD sockets into `sk_lock-AF_INET*-NBD` classes, guarded with `if (WARN_ON_ONCE(!sock_allow_reclassification(sk))) return;`. Under this commit, racing socket activity against `NBD_CMD_CONNECT` triggered the `WARN_ON_ONCE` instead of silently leaving the socket unclassified.
- **`9280e6edf656`** (`nbd: don't warn when reclassifying a busy socket lock`): Changed `if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))` to `if (!sock_allow_reclassification(sk)) return;`, assuming that *"Reclassification is a lockdep-only annotation, so skipping it in the rare racing case is harmless."* Because `nbd_add_socket()` does not reject or retry when reclassification is skipped, this commit allows an unreclassified `sk_lock-AF_INET6` socket to be attached to NBD, producing the reported circular locking dependency.
- **`553d28925fde`** (`nbd: Reclassify sockets in the reconnect path`): Later follow-up adding `nbd_reclassify_socket()` to `nbd_genl_reconnect_sock_cb()`, unrelated to `nbd_genl_connect()` (`nbd_add_socket()`). Ruled out.
### Conclusion
The bug was introduced by commit **`9280e6edf65662b6aafc8b704ad065b54c08b519`** (`nbd: don't warn when reclassifying a busy socket lock`). Commits:[map[AuthorEmail:kartikey406@gmail.com AuthorName:Deepanshu Kartikey Date:2026-06-22T05:22:55+05:30 Hash:9280e6edf65662b6aafc8b704ad065b54c08b519 Recipients:[map[Email:axboe@kernel.dk Name: To:true] map[Email:edumazet@google.com Name: To:true] map[Email:kartikey406@gmail.com Name: To:true]] Title:nbd: don't warn when reclassifying a busy socket lock]] IsRelease:false KernelCommit:28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f]
|
| 1/1 |
2026/11/28 09:26 |
action |
use-crash-commit |
0m
Results: map[KernelCommit:28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f]
|
| 2/1 |
2026/11/28 09:26 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 3/1 |
2026/11/28 09:26 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/2ae4d7fdd1dd8aff00476e0039272088237994f2/data]
|
| 4/1 |
2026/11/28 09:26 |
action |
kernel-builder |
19m
Results: map[KernelObj:/app/workdir/cache/build/2bc0422f3324e6dfd9821245ba5461153b707bf2/data]
|
| 5/1 |
2026/11/28 09:45 |
action |
codesearch-prepare |
14m
Results: map[Index:codesearch-index]
|
| 6/1 |
2026/11/28 10:00 |
agent |
cause-finder |
6m
Model:
Results: map[CandidateCommits:[9280e6edf65662b6aafc8b704ad065b54c08b519]]
Instruction:
You are an experienced Linux kernel developer tasked with identifying the commit
that introduced a kernel bug (cause bisection).
Your investigation strategy:
1. Establish the root cause first.
Analyze the crash report and the code it points to (stack traces, allocation/free stacks,
the involved functions and structs) until you understand the exact invariant that is
violated and the exact execution sequence that leads to the crash.
Identify the specific functions, structs, invariants, or lines of code where the buggy
logic resides.
2. Use git tools (git-blame, git-log, git-show) to trace the history
of the affected functions and lines.
3. Trace past pure refactorings, code movements, formatting changes, or variable renames
to find the commit that actually introduced the buggy logic or broke an existing invariant.
4. Do NOT blame commits that merely added debugging or sanitizer checks (WARN_ON, BUG_ON,
KASAN/KMSAN/LOCKDEP annotations) that exposed an older bug, unless the check itself is
incorrect and is the bug.
5. Do NOT return a merge commit unless the bug was introduced by the merge conflict
resolution itself; otherwise identify the underlying non-merge commit.
6. Verify your hypothesis by inspecting the full commit diff with git-show and
confirming how the change introduced the exact condition described in the root cause.
Output rules:
- Returning a SINGLE commit in CandidateCommits (a 1-element list) is the expected norm
and is strongly preferred. A single commit gives maintainers a clear, directly actionable
result, whereas returning extra commits dilutes the report and notifies additional commit
authors unnecessarily.
- Once you identify the primary commit that introduced (or fixed) the bug, return ONLY that
commit in CandidateCommits. Do NOT include secondary or "contributing" commits such as
earlier background/foundation commits, preparatory or follow-up commits in the same
series, later refactorings, incomplete fix attempts, or commits that merely exposed or
enabled the code path (e.g. new callers, default config changes, or sanitizer/debug checks).
Mention those related commits in your text reply for context instead.
- Returning more than one commit (at most 3) is the rare exception, not the norm. Only return
multiple commits when:
1. There is genuine, unresolvable ambiguity between 2-3 equally plausible candidates after
thorough investigation, OR
2. The bug was strictly and inseparably introduced (or fixed) by 2-3 commits together, with
no single primary commit.
In those rare cases, order CandidateCommits by relevance with the most important/likely
commit FIRST.
- If you cannot determine the commit with confidence, return an empty CandidateCommits list
rather than guessing.
- Your text reply must provide a clear bisection log explaining the root cause of the bug,
the git history you traced, the commits you examined (with their hashes and titles), why
you ruled out other commits, and how you reached your conclusion.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
During execution, you may receive periodic guidance in <supervisor_advice> tags;
use it to refine your investigation or wrap up once you have sufficient evidence.
Prompt:
The crash is:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
kworker/u8:11/3383 is trying to acquire lock:
ffffffff902954c0 (fs_reclaim){+.+.}-{0:0}, at: might_alloc include/linux/sched/mm.h:316 [inline]
ffffffff902954c0 (fs_reclaim){+.+.}-{0:0}, at: slab_pre_alloc_hook mm/slub.c:4673 [inline]
ffffffff902954c0 (fs_reclaim){+.+.}-{0:0}, at: slab_alloc_node mm/slub.c:5011 [inline]
ffffffff902954c0 (fs_reclaim){+.+.}-{0:0}, at: kmem_cache_alloc_noprof+0x5f/0x600 mm/slub.c:5047
but task is already holding lock:
ffff88807d634720 (k-sk_lock-AF_INET6){+.+.}-{0:0}, at: lock_sock include/net/sock.h:1717 [inline]
ffff88807d634720 (k-sk_lock-AF_INET6){+.+.}-{0:0}, at: rds_tcp_recv_path+0xfe/0x340 net/rds/tcp_recv.c:304
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #7 (k-sk_lock-AF_INET6){+.+.}-{0:0}:
lock_sock_nested+0x41/0x100 net/core/sock.c:3909
do_tcp_setsockopt+0x8ec/0x1f70 net/ipv4/tcp.c:3977
mptcp_setsockopt_first_sf_only net/mptcp/sockopt.c:804 [inline]
mptcp_setsockopt_sol_tcp net/mptcp/sockopt.c:852 [inline]
mptcp_setsockopt+0x1165/0x3550 net/mptcp/sockopt.c:940
do_sock_setsockopt+0x17c/0x1b0 net/socket.c:2399
__sys_setsockopt net/socket.c:2424 [inline]
__do_sys_setsockopt net/socket.c:2430 [inline]
__se_sys_setsockopt net/socket.c:2427 [inline]
__x64_sys_setsockopt+0x13d/0x1b0 net/socket.c:2427
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_INET6){+.+.}-{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
sock_shutdown+0x15e/0x260 drivers/block/nbd.c:420
nbd_clear_sock+0x24/0x170 drivers/block/nbd.c:1464
nbd_config_put+0x477/0x7e0 drivers/block/nbd.c:1493
nbd_genl_connect+0x19b8/0x1cd0 drivers/block/nbd.c:2320
genl_family_rcv_msg_doit+0x233/0x340 net/netlink/genetlink.c:1114
genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
genl_rcv_msg+0x614/0x7a0 net/netlink/genetlink.c:1209
netlink_rcv_skb+0x226/0x4a0 net/netlink/af_netlink.c:2585
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
netlink_unicast_kernel net/netlink/af_netlink.c:1336 [inline]
netlink_unicast+0x8ef/0xa80 net/netlink/af_netlink.c:1362
netlink_sendmsg+0x7f0/0xb20 net/netlink/af_netlink.c:1921
sock_sendmsg_nosec+0x14e/0x190 net/socket.c:800
__sock_sendmsg net/socket.c:818 [inline]
____sys_sendmsg+0x49f/0x790 net/socket.c:2713
___sys_sendmsg+0x2f8/0x3d0 net/socket.c:2770
__sys_sendmsg net/socket.c:2802 [inline]
__do_sys_sendmsg net/socket.c:2807 [inline]
__se_sys_sendmsg net/socket.c:2805 [inline]
__x64_sys_sendmsg+0x1b1/0x290 net/socket.c:2805
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
-> #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
elevator_set_none+0xb5/0x140 block/elevator.c:769
blk_mq_elv_switch_none block/blk-mq.c:5171 [inline]
__blk_mq_update_nr_hw_queues block/blk-mq.c:5216 [inline]
blk_mq_update_nr_hw_queues+0x60b/0x1b70 block/blk-mq.c:5284
nbd_start_device+0x189/0xb30 drivers/block/nbd.c:1531
nbd_genl_connect+0x167d/0x1cd0 drivers/block/nbd.c:2311
genl_family_rcv_msg_doit+0x233/0x340 net/netlink/genetlink.c:1114
genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
genl_rcv_msg+0x614/0x7a0 net/netlink/genetlink.c:1209
netlink_rcv_skb+0x226/0x4a0 net/netlink/af_netlink.c:2585
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
netlink_unicast_kernel net/netlink/af_netlink.c:1336 [inline]
netlink_unicast+0x8ef/0xa80 net/netlink/af_netlink.c:1362
netlink_sendmsg+0x7f0/0xb20 net/netlink/af_netlink.c:1921
sock_sendmsg_nosec+0x14e/0x190 net/socket.c:800
__sock_sendmsg net/socket.c:818 [inline]
____sys_sendmsg+0x49f/0x790 net/socket.c:2713
___sys_sendmsg+0x2f8/0x3d0 net/socket.c:2770
__sys_sendmsg net/socket.c:2802 [inline]
__do_sys_sendmsg net/socket.c:2807 [inline]
__se_sys_sendmsg net/socket.c:2805 [inline]
__x64_sys_sendmsg+0x1b1/0x290 net/socket.c:2805
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)#51){++++}-{0:0}:
blk_alloc_queue+0x544/0x690 block/blk-core.c:503
blk_mq_alloc_queue block/blk-mq.c:4471 [inline]
__blk_mq_alloc_disk+0x194/0x390 block/blk-mq.c:4518
nbd_dev_add+0x494/0xb60 drivers/block/nbd.c:1997
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
-> #0 (fs_reclaim){+.+.}-{0:0}:
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
__fs_reclaim_acquire mm/page_alloc.c:4388 [inline]
fs_reclaim_acquire+0x71/0x100 mm/page_alloc.c:4402
might_alloc include/linux/sched/mm.h:316 [inline]
slab_pre_alloc_hook mm/slub.c:4673 [inline]
slab_alloc_node mm/slub.c:5011 [inline]
kmem_cache_alloc_noprof+0x5f/0x600 mm/slub.c:5047
rds_tcp_data_recv+0x174/0xa00 net/rds/tcp_recv.c:174
__tcp_read_sock+0x18d/0x970 net/ipv4/tcp.c:1706
rds_tcp_read_sock net/rds/tcp_recv.c:277 [inline]
rds_tcp_recv_path+0x200/0x340 net/rds/tcp_recv.c:305
rds_tcp_conn_path_shutdown+0x29b/0xac0 net/rds/tcp_connect.c:269
rds_conn_shutdown+0x46d/0xb20 net/rds/connection.c:440
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
other info that might help us debug this:
Chain exists of:
fs_reclaim --> sk_lock-AF_INET6 --> k-sk_lock-AF_INET6
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(k-sk_lock-AF_INET6);
lock(sk_lock-AF_INET6);
lock(k-sk_lock-AF_INET6);
lock(fs_reclaim);
*** DEADLOCK ***
locks held by kworker/u8:11/3383: 3, on CPU#0:
#0: ffff888079cbd948 ((wq_completion)krds_cp_wq#11/2){+.+.}-{0:0}, at: rcu_lock_acquire include/linux/rcupdate.h:309 [inline]
#0: ffff888079cbd948 ((wq_completion)krds_cp_wq#11/2){+.+.}-{0:0}, at: rcu_read_lock include/linux/rcupdate.h:849 [inline]
#0: ffff888079cbd948 ((wq_completion)krds_cp_wq#11/2){+.+.}-{0:0}, at: process_one_work kernel/workqueue.c:3462 [inline]
#0: ffff888079cbd948 ((wq_completion)krds_cp_wq#11/2){+.+.}-{0:0}, at: process_scheduled_works+0x99a/0x1650 kernel/workqueue.c:3580
#1: ffffc9000ecf7c40 ((work_completion)(&cp->cp_down_w)){+.+.}-{0:0}, at: rcu_lock_acquire include/linux/rcupdate.h:309 [inline]
#1: ffffc9000ecf7c40 ((work_completion)(&cp->cp_down_w)){+.+.}-{0:0}, at: rcu_read_lock include/linux/rcupdate.h:849 [inline]
#1: ffffc9000ecf7c40 ((work_completion)(&cp->cp_down_w)){+.+.}-{0:0}, at: process_one_work kernel/workqueue.c:3462 [inline]
#1: ffffc9000ecf7c40 ((work_completion)(&cp->cp_down_w)){+.+.}-{0:0}, at: process_scheduled_works+0x99a/0x1650 kernel/workqueue.c:3580
#2: ffff88807d634720 (k-sk_lock-AF_INET6){+.+.}-{0:0}, at: lock_sock include/net/sock.h:1717 [inline]
#2: ffff88807d634720 (k-sk_lock-AF_INET6){+.+.}-{0:0}, at: rds_tcp_recv_path+0xfe/0x340 net/rds/tcp_recv.c:304
stack backtrace:
CPU: 0 UID: 0 PID: 3383 Comm: kworker/u8:11 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
Workqueue: krds_cp_wq#11/2 rds_shutdown_worker
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
__fs_reclaim_acquire mm/page_alloc.c:4388 [inline]
fs_reclaim_acquire+0x71/0x100 mm/page_alloc.c:4402
might_alloc include/linux/sched/mm.h:316 [inline]
slab_pre_alloc_hook mm/slub.c:4673 [inline]
slab_alloc_node mm/slub.c:5011 [inline]
kmem_cache_alloc_noprof+0x5f/0x600 mm/slub.c:5047
rds_tcp_data_recv+0x174/0xa00 net/rds/tcp_recv.c:174
__tcp_read_sock+0x18d/0x970 net/ipv4/tcp.c:1706
rds_tcp_read_sock net/rds/tcp_recv.c:277 [inline]
rds_tcp_recv_path+0x200/0x340 net/rds/tcp_recv.c:305
rds_tcp_conn_path_shutdown+0x29b/0xac0 net/rds/tcp_connect.c:269
rds_conn_shutdown+0x46d/0xb20 net/rds/connection.c:440
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
</TASK>
Search for the commit that introduced this bug.
Reply: ### Root Cause
Lockdep reports a circular locking dependency:
`fs_reclaim --> sk_lock-AF_INET6 --> k-sk_lock-AF_INET6 --> fs_reclaim`
Breaking down the chain:
1. **`k-sk_lock-AF_INET6` β `fs_reclaim`** (`#0`): `rds_tcp_recv_path()` (`net/rds/tcp_recv.c`) acquires `lock_sock(sock->sk)` on a kernel socket (`k-sk_lock-AF_INET6`) and allocates memory with `GFP_KERNEL` in `rds_tcp_data_recv()`.
2. **`sk_lock-AF_INET6` β `k-sk_lock-AF_INET6`** (`#7`): `mptcp_setsockopt_first_sf_only()` (`net/mptcp/sockopt.c`) holds `lock_sock(sk)` on a user MPTCP socket (`sk_lock-AF_INET6`) and calls `do_tcp_setsockopt()` on the subflow kernel socket (`k-sk_lock-AF_INET6`).
3. **`fs_reclaim` β `sk_lock-AF_INET6`** (`#1`β`#6`): Through the block layer and NBD (`&q->q_usage_counter(io)` β `&q->elevator_lock` β `set->srcu` β `&cmd->lock` β `&nsock->tx_lock`), `nbd_genl_connect()` β `nbd_config_put()` β `nbd_clear_sock()` β `sock_shutdown()` β `nbd_mark_nsock_dead()` calls `inet_shutdown()` β `lock_sock()`, acquiring the generic user socket class `sk_lock-AF_INET6` instead of NBD's dedicated `sk_lock-AF_INET6-NBD` class.
Normally, `fs_reclaim` must never depend on the generic user `sk_lock-AF_INET6` lock class. NBD sockets are supposed to be reclassified to `sk_lock-AF_INET6-NBD` by `nbd_reclassify_socket()` when added via `nbd_add_socket()`.
However, in `drivers/block/nbd.c`, `nbd_reclassify_socket()` checks `if (!sock_allow_reclassification(sk)) return;` and silently skips reclassification if the socket lock (`sk->sk_lock` or `sk->sk_lock.slock`) is concurrently held (for example, by a concurrent userspace syscall on the same fd or softirq BH processing). `nbd_add_socket()` still proceeds to attach the socket with its original `sk_lock-AF_INET6` class, directly re-introducing the `fs_reclaim` β `sk_lock-AF_INET6` dependency when NBD later locks the socket under `&nsock->tx_lock`.
### Bisection History
- **`70041088e3b9` / `2da43c4a1b51`** (`net/rds/tcp_recv.c`) and **`d3d429047cc6` / `caea64675d8b`** (`net/mptcp/sockopt.c`): Old code from 2009β2022; `k-sk_lock-AF_INET6 -> fs_reclaim` and `sk_lock-AF_INET6 -> k-sk_lock-AF_INET6` are normal outside block/reclaim paths. Ruled out.
- **`ffa1e7ada456`** (`block: Make request_queue lockdep splats show up earlier`): Only added lockdep priming between `fs_reclaim` and `q->io_lockdep_map` in `blk_alloc_queue()`. Ruled out.
- **`d532cddb6c60`** (`nbd: Reclassify sockets to avoid lockdep circular dependency`): Introduced `nbd_reclassify_socket()` to move NBD sockets into `sk_lock-AF_INET*-NBD` classes, guarded with `if (WARN_ON_ONCE(!sock_allow_reclassification(sk))) return;`. Under this commit, racing socket activity against `NBD_CMD_CONNECT` triggered the `WARN_ON_ONCE` instead of silently leaving the socket unclassified.
- **`9280e6edf656`** (`nbd: don't warn when reclassifying a busy socket lock`): Changed `if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))` to `if (!sock_allow_reclassification(sk)) return;`, assuming that *"Reclassification is a lockdep-only annotation, so skipping it in the rare racing case is harmless."* Because `nbd_add_socket()` does not reject or retry when reclassification is skipped, this commit allows an unreclassified `sk_lock-AF_INET6` socket to be attached to NBD, producing the reported circular locking dependency.
- **`553d28925fde`** (`nbd: Reclassify sockets in the reconnect path`): Later follow-up adding `nbd_reclassify_socket()` to `nbd_genl_reconnect_sock_cb()`, unrelated to `nbd_genl_connect()` (`nbd_add_socket()`). Ruled out.
### Conclusion
The bug was introduced by commit **`9280e6edf65662b6aafc8b704ad065b54c08b519`** (`nbd: don't warn when reclassifying a busy socket lock`).
|
| 7/2 |
2026/11/28 10:00 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 11211
output: 202
thoughts: 702
Thoughts: **Unraveling a Complex Locking Deadlock**
My immediate focus is to meticulously dissect this `lockdep` splat. It's screaming about a circular locking dependency, and I need to understand *precisely* where the choke point is. The core of the issue, as I see it, is this: `kworker/u8:11/3383` is attempting to acquire the `fs_reclaim` lock while already holding `k-sk_lock-AF_INET6`. This acquisition attempt originates from `rds_tcp_recv_path` at line 304 in `net/rds/tcp_recv.c`.
The allocation call stack leading to this problematic state is also critical. It points to `rds_tcp_data_recv` at `net/rds/tcp_recv.c:174`, which then calls `__tcp_read_sock` in `net/ipv4/tcp.c:1706`, followed by `rds_tcp_read_sock` in `net/rds/tcp_recv.c:277`, and finally returning to `rds_tcp_recv_path` at `net/rds/tcp_recv.c:305`.
But the story doesn't end there; the *entire* dependency chain needs to be understood. Let's trace it out:
1. The `fs_reclaim` lock is held under `k-sk_lock-AF_INET6` within the `rds_tcp_recv_path` and `rds_tcp_data_recv` context.
2. From `fs_reclaim`, the dependency goes to `&q->q_usage_counter(io)#51` at the `blk_alloc_queue` call.
3. Next, `&q->q_usage_counter(io)#51` leads to `&q->elevator_lock` during `blk_mq_update_nr_hw_queues`.
4. The chain continues from `&q->elevator_lock` to `set->srcu` within `elevator_switch`.
5. Then, `set->srcu` leads to `&cmd->lock` in `nbd_queue_rq`.
6. From `&cmd->lock`, we move to `&nsock->tx_lock` in `nbd_handle_cmd`.
7. Crucially, `&nsock->tx_lock` then points back to `sk_lock-AF_INET6` via `nbd_mark_nsock_dead` and `inet_shutdown`.
8. And finally, `sk_lock-AF_INET6` itself leads to `k-sk_lock-AF_INET6` through `mptcp_setsockopt_first_sf_only` and `do_tcp_setsockopt`.
Now, the critical question emerges: where is the *actual* bug lurking? Is it within `rds_tcp_data_recv` itself, perhaps due to a `GFP_KERNEL` allocation occurring while `lock_sock` is held (or `rds_tcp_recv_path` is holding `lock_sock` without proper `sk_allocation` / `memalloc_nofs_save`, or incorrectly using `GFP_ATOMIC` / `GFP_NOFS`)? Or is the root cause in `nbd`, `mptcp`, or another part of the `rds` subsystem? To get to the bottom of this, I need to dive deep into the source code. My next step is to carefully review `net/rds/tcp_recv.c`, `net/rds/tcp_connect.c`, `drivers/block/nbd.c`, `net/mptcp/sockopt.c`, and `block/blk-mq.c`.
|
| 8/2 |
2026/11/28 10:00 |
tool |
read-file |
0m
Args: map[File:net/rds/tcp_recv.c FirstLine:140 LineCount:100]
Results: map[Contents: 140: if (map_off == PAGE_SIZE) {
141: map_off = 0;
142: map_page++;
143: }
144: }
145: }
146:
147: rds_cong_map_updated(map, ~(u64) 0);
148: }
149:
150: struct rds_tcp_desc_arg {
151: struct rds_conn_path *conn_path;
152: gfp_t gfp;
153: };
154:
155: static int rds_tcp_data_recv(read_descriptor_t *desc, struct sk_buff *skb,
156: unsigned int offset, size_t len)
157: {
158: struct rds_tcp_desc_arg *arg = desc->arg.data;
159: struct rds_conn_path *cp = arg->conn_path;
160: struct rds_tcp_connection *tc = cp->cp_transport_data;
161: struct rds_tcp_incoming *tinc = tc->t_tinc;
162: struct sk_buff *clone;
163: size_t left = len, to_copy;
164:
165: rdsdebug("tcp data tc %p skb %p offset %u len %zu\n", tc, skb, offset,
166: len);
167:
168: /*
169: * tcp_read_sock() interprets partial progress as an indication to stop
170: * processing.
171: */
172: while (left) {
173: if (!tinc) {
174: tinc = kmem_cache_alloc(rds_tcp_incoming_slab,
175: arg->gfp);
176: if (!tinc) {
177: desc->error = -ENOMEM;
178: goto out;
179: }
180: tc->t_tinc = tinc;
181: rdsdebug("allocated tinc %p\n", tinc);
182: rds_inc_path_init(&tinc->ti_inc, cp,
183: &cp->cp_conn->c_faddr);
184: tinc->ti_inc.i_rx_lat_trace[RDS_MSG_RX_HDR] =
185: local_clock();
186:
187: /*
188: * XXX * we might be able to use the __ variants when
189: * we've already serialized at a higher level.
190: */
191: skb_queue_head_init(&tinc->ti_skb_list);
192: }
193:
194: if (left && tc->t_tinc_hdr_rem) {
195: to_copy = min(tc->t_tinc_hdr_rem, left);
196: rdsdebug("copying %zu header from skb %p\n", to_copy,
197: skb);
198: skb_copy_bits(skb, offset,
199: (char *)&tinc->ti_inc.i_hdr +
200: sizeof(struct rds_header) -
201: tc->t_tinc_hdr_rem,
202: to_copy);
203: tc->t_tinc_hdr_rem -= to_copy;
204: left -= to_copy;
205: offset += to_copy;
206:
207: if (tc->t_tinc_hdr_rem == 0) {
208: /* could be 0 for a 0 len message */
209: tc->t_tinc_data_rem =
210: be32_to_cpu(tinc->ti_inc.i_hdr.h_len);
211: tinc->ti_inc.i_rx_lat_trace[RDS_MSG_RX_START] =
212: local_clock();
213: }
214: }
215:
216: if (left && tc->t_tinc_data_rem) {
217: to_copy = min(tc->t_tinc_data_rem, left);
218:
219: clone = pskb_extract(skb, offset, to_copy, arg->gfp);
220: if (!clone) {
221: desc->error = -ENOMEM;
222: goto out;
223: }
224:
225: skb_queue_tail(&tinc->ti_skb_list, clone);
226:
227: rdsdebug("skb %p data %p len %d off %u to_copy %zu -> "
228: "clone %p data %p len %d\n",
229: skb, skb->data, skb->len, offset, to_copy,
230: clone, clone->data, clone->len);
231:
232: tc->t_tinc_data_rem -= to_copy;
233: left -= to_copy;
234: offset += to_copy;
235: }
236:
237: if (tc->t_tinc_hdr_rem == 0 && tc->t_tinc_data_rem == 0) {
238: struct rds_connection *conn = cp->cp_conn;
239:
]
|
| 9/2 |
2026/11/28 10:00 |
tool |
read-file |
0m
Args: map[File:net/rds/tcp_recv.c FirstLine:240 LineCount:100]
Results: map[Contents: 240: if (tinc->ti_inc.i_hdr.h_flags == RDS_FLAG_CONG_BITMAP)
241: rds_tcp_cong_recv(conn, tinc);
242: else
243: rds_recv_incoming(conn, &conn->c_faddr,
244: &conn->c_laddr,
245: &tinc->ti_inc,
246: arg->gfp);
247:
248: tc->t_tinc_hdr_rem = sizeof(struct rds_header);
249: tc->t_tinc_data_rem = 0;
250: tc->t_tinc = NULL;
251: rds_inc_put(&tinc->ti_inc);
252: tinc = NULL;
253: }
254: }
255: out:
256: rdsdebug("returning len %zu left %zu skb len %d rx queue depth %d\n",
257: len, left, skb->len,
258: skb_queue_len(&tc->t_sock->sk->sk_receive_queue));
259: return len - left;
260: }
261:
262: /* the caller has to hold the sock lock */
263: static int rds_tcp_read_sock(struct rds_conn_path *cp, gfp_t gfp)
264: {
265: struct rds_tcp_connection *tc = cp->cp_transport_data;
266: struct socket *sock = tc->t_sock;
267: read_descriptor_t desc;
268: struct rds_tcp_desc_arg arg;
269:
270: /* It's like glib in the kernel! */
271: arg.conn_path = cp;
272: arg.gfp = gfp;
273: desc.arg.data = &arg;
274: desc.error = 0;
275: desc.count = 1; /* give more than one skb per call */
276:
277: tcp_read_sock(sock->sk, &desc, rds_tcp_data_recv);
278: rdsdebug("tcp_read_sock for tc %p gfp %pGg returned %d\n", tc, &gfp,
279: desc.error);
280:
281: if (skb_queue_empty_lockless(&sock->sk->sk_receive_queue) &&
282: wq_has_sleeper(&tc->t_recv_done_waitq))
283: wake_up(&tc->t_recv_done_waitq);
284:
285: return desc.error;
286: }
287:
288: /*
289: * We hold the sock lock to serialize our rds_tcp_recv->tcp_read_sock from
290: * data_ready.
291: *
292: * if we fail to allocate we're in trouble.. blindly wait some time before
293: * trying again to see if the VM can free up something for us.
294: */
295: int rds_tcp_recv_path(struct rds_conn_path *cp)
296: {
297: struct rds_tcp_connection *tc = cp->cp_transport_data;
298: struct socket *sock = tc->t_sock;
299: int ret = 0;
300:
301: rdsdebug("recv worker path [%d] tc %p sock %p\n",
302: cp->cp_index, tc, sock);
303:
304: lock_sock(sock->sk);
305: ret = rds_tcp_read_sock(cp, GFP_KERNEL);
306: release_sock(sock->sk);
307:
308: return ret;
309: }
310:
311: void rds_tcp_data_ready(struct sock *sk)
312: {
313: void (*ready)(struct sock *sk);
314: struct rds_conn_path *cp;
315: struct rds_tcp_connection *tc;
316:
317: trace_sk_data_ready(sk);
318: rdsdebug("data ready sk %p\n", sk);
319:
320: read_lock_bh(&sk->sk_callback_lock);
321: cp = sk->sk_user_data;
322: if (!cp) { /* check for teardown race */
323: ready = sk->sk_data_ready;
324: goto out;
325: }
326:
327: tc = cp->cp_transport_data;
328: ready = tc->t_orig_data_ready;
329: rds_tcp_stats_inc(s_tcp_data_ready_calls);
330:
331: if (rds_tcp_read_sock(cp, GFP_ATOMIC) == -ENOMEM) {
332: rcu_read_lock();
333: if (!rds_destroy_pending(cp->cp_conn))
334: queue_delayed_work(cp->cp_wq, &cp->cp_recv_w, 0);
335: rcu_read_unlock();
336: }
337: out:
338: read_unlock_bh(&sk->sk_callback_lock);
339: ready(sk);
]
|
| 10/2 |
2026/11/28 10:00 |
tool |
read-file |
0m
Args: map[File:net/rds/tcp_connect.c FirstLine:240 LineCount:60]
Results: map[Contents: 240: rdsdebug("shutting down conn %p tc %p sock %p\n",
241: cp->cp_conn, tc, sock);
242:
243: if (sock) {
244: sk = sock->sk;
245: if (rds_destroy_pending(cp->cp_conn))
246: sock_no_linger(sk);
247:
248: sock->ops->shutdown(sock, SHUT_WR);
249:
250: /* after sending FIN,
251: * wait until we processed all incoming messages
252: * and we're sure that there won't be any more:
253: * i.e. state CLOSING, TIME_WAIT, CLOSE_WAIT,
254: * LAST_ACK, or CLOSE (RFC 793).
255: *
256: * Give up waiting after 5 seconds and allow messages
257: * to theoretically get dropped, if the TCP transition
258: * didn't happen.
259: */
260: rounds = 0;
261: do {
262: /* we need to ensure messages are dequeued here
263: * since "rds_recv_worker" only dispatches messages
264: * while the connection is still in RDS_CONN_UP
265: * and there is no guarantee that "rds_tcp_data_ready"
266: * was called nor that "sk_data_ready" still points to
267: * it.
268: */
269: rds_tcp_recv_path(cp);
270: } while (!wait_event_timeout(tc->t_recv_done_waitq,
271: (sk->sk_state == TCP_CLOSING ||
272: sk->sk_state == TCP_TIME_WAIT ||
273: sk->sk_state == TCP_CLOSE_WAIT ||
274: sk->sk_state == TCP_LAST_ACK ||
275: sk->sk_state == TCP_CLOSE) &&
276: skb_queue_empty_lockless(&sk->sk_receive_queue),
277: msecs_to_jiffies(100)) &&
278: ++rounds < 50);
279: lock_sock(sk);
280:
281: /* discard messages that the peer received already */
282: tc->t_last_seen_una = rds_tcp_snd_una(tc);
283: rds_send_path_drop_acked(cp, rds_tcp_snd_una(tc),
284: rds_tcp_is_acked);
285:
286: rds_tcp_restore_callbacks(sock, tc); /* tc->tc_sock = NULL */
287:
288: release_sock(sk);
289: sock_release(sock);
290: }
291:
292: if (tc->t_tinc) {
293: rds_inc_put(&tc->t_tinc->ti_inc);
294: tc->t_tinc = NULL;
295: }
296: tc->t_tinc_hdr_rem = sizeof(struct rds_header);
297: tc->t_tinc_data_rem = 0;
298: }
]
|
| 11/2 |
2026/11/28 10:00 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:1450 LineCount:100]
Results: map[Contents:1450:
1451: static int nbd_disconnect(struct nbd_device *nbd)
1452: {
1453: struct nbd_config *config = nbd->config;
1454:
1455: dev_info(disk_to_dev(nbd->disk), "NBD_DISCONNECT\n");
1456: set_bit(NBD_RT_DISCONNECT_REQUESTED, &config->runtime_flags);
1457: set_bit(NBD_DISCONNECT_REQUESTED, &nbd->flags);
1458: send_disconnects(nbd);
1459: return 0;
1460: }
1461:
1462: static void nbd_clear_sock(struct nbd_device *nbd)
1463: {
1464: sock_shutdown(nbd);
1465: nbd_clear_que(nbd);
1466: nbd->task_setup = NULL;
1467: }
1468:
1469: static void nbd_config_put(struct nbd_device *nbd)
1470: {
1471: if (refcount_dec_and_mutex_lock(&nbd->config_refs,
1472: &nbd->config_lock)) {
1473: struct nbd_config *config = nbd->config;
1474: struct queue_limits lim;
1475: nbd_dev_dbg_close(nbd);
1476: invalidate_disk(nbd->disk);
1477: /* reset queue limits to default */
1478: lim = queue_limits_start_update(nbd->disk->queue);
1479: nbd_apply_limits(&lim, 0);
1480: queue_limits_commit_update(nbd->disk->queue, &lim);
1481: if (nbd->config->bytesize)
1482: kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
1483: if (test_and_clear_bit(NBD_RT_HAS_PID_FILE,
1484: &config->runtime_flags))
1485: device_remove_file(disk_to_dev(nbd->disk), &pid_attr);
1486: nbd->pid = 0;
1487: if (test_and_clear_bit(NBD_RT_HAS_BACKEND_FILE,
1488: &config->runtime_flags)) {
1489: device_remove_file(disk_to_dev(nbd->disk), &backend_attr);
1490: kfree(nbd->backend);
1491: nbd->backend = NULL;
1492: }
1493: nbd_clear_sock(nbd);
1494: if (config->num_connections) {
1495: int i;
1496: for (i = 0; i < config->num_connections; i++) {
1497: sockfd_put(config->socks[i]->sock);
1498: kfree(config->socks[i]);
1499: }
1500: kfree(config->socks);
1501: }
1502: kfree(nbd->config);
1503: nbd->config = NULL;
1504:
1505: nbd->tag_set.timeout = 0;
1506:
1507: mutex_unlock(&nbd->config_lock);
1508: nbd_put(nbd);
1509: module_put(THIS_MODULE);
1510: }
1511: }
1512:
1513: static int nbd_start_device(struct nbd_device *nbd)
1514: {
1515: struct nbd_config *config = nbd->config;
1516: int num_connections = config->num_connections;
1517: int error = 0, i;
1518:
1519: if (nbd->pid)
1520: return -EBUSY;
1521: if (!config->socks)
1522: return -EINVAL;
1523: if (num_connections > 1 &&
1524: !(config->flags & NBD_FLAG_CAN_MULTI_CONN)) {
1525: dev_err(disk_to_dev(nbd->disk), "server does not support multiple connections per device.\n");
1526: return -EINVAL;
1527: }
1528:
1529: retry:
1530: mutex_unlock(&nbd->config_lock);
1531: blk_mq_update_nr_hw_queues(&nbd->tag_set, num_connections);
1532: mutex_lock(&nbd->config_lock);
1533:
1534: /* if another code path updated nr_hw_queues, retry until succeed */
1535: if (num_connections != config->num_connections) {
1536: num_connections = config->num_connections;
1537: goto retry;
1538: }
1539:
1540: nbd->pid = task_pid_nr(current);
1541:
1542: nbd_parse_flags(nbd);
1543:
1544: error = device_create_file(disk_to_dev(nbd->disk), &pid_attr);
1545: if (error) {
1546: dev_err(disk_to_dev(nbd->disk), "device_create_file failed for pid!\n");
1547: return error;
1548: }
1549: set_bit(NBD_RT_HAS_PID_FILE, &config->runtime_flags);
]
|
| 12/2 |
2026/11/28 10:00 |
tool |
read-file |
0m
Args: map[File:net/mptcp/sockopt.c FirstLine:790 LineCount:80]
Results: map[Contents: 790: sockptr_t optval, unsigned int optlen)
791: {
792: struct sock *sk = (struct sock *)msk;
793: struct sock *ssk;
794: int ret;
795:
796: /* Limit to first subflow, before the connection establishment */
797: lock_sock(sk);
798: ssk = __mptcp_nmpc_sk(msk);
799: if (IS_ERR(ssk)) {
800: ret = PTR_ERR(ssk);
801: goto unlock;
802: }
803:
804: ret = tcp_setsockopt(ssk, level, optname, optval, optlen);
805:
806: unlock:
807: release_sock(sk);
808: return ret;
809: }
810:
811: static int mptcp_setsockopt_all_sf(struct mptcp_sock *msk, int level,
812: int optname, sockptr_t optval,
813: unsigned int optlen)
814: {
815: struct mptcp_subflow_context *subflow;
816: int ret = 0;
817:
818: mptcp_for_each_subflow(msk, subflow) {
819: struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
820: int err;
821:
822: err = tcp_setsockopt(ssk, level, optname, optval, optlen);
823: if (err < 0 && ret == 0)
824: ret = err;
825: }
826:
827: if (!ret)
828: sockopt_seq_inc(msk);
829:
830: return ret;
831: }
832:
833: static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
834: sockptr_t optval, unsigned int optlen)
835: {
836: struct sock *sk = (void *)msk;
837: int ret, val;
838:
839: switch (optname) {
840: case TCP_ULP:
841: return -EOPNOTSUPP;
842: case TCP_CONGESTION:
843: return mptcp_setsockopt_sol_tcp_congestion(msk, optval, optlen);
844: case TCP_DEFER_ACCEPT:
845: /* See tcp.c: TCP_DEFER_ACCEPT does not fail */
846: mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname, optval, optlen);
847: return 0;
848: case TCP_FASTOPEN:
849: case TCP_FASTOPEN_CONNECT:
850: case TCP_FASTOPEN_KEY:
851: case TCP_FASTOPEN_NO_COOKIE:
852: return mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname,
853: optval, optlen);
854: }
855:
856: ret = mptcp_get_int_option(msk, optval, optlen, &val);
857: if (ret)
858: return ret;
859:
860: lock_sock(sk);
861: switch (optname) {
862: case TCP_INQ:
863: if (val < 0 || val > 1)
864: ret = -EINVAL;
865: else
866: msk->recvmsg_inq = !!val;
867: break;
868: case TCP_NOTSENT_LOWAT:
869: WRITE_ONCE(msk->notsent_lowat, val);
]
|
| 13/2 |
2026/11/28 10:00 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 19097
output: 195
thoughts: 1460
Thoughts: **Tracing a Complex Locking Deadlock**
My primary focus has been on dissecting a rather intricate locking problem, and I believe I've finally pinpointed the core of the issue by meticulously examining several key areas within the kernel's networking and block layer subsystems.
Initially, I was drawn to the `lockdep` chain, specifically looking at its output in conjunction with `rds_tcp_recv_path` and how socket allocation (`sk_allocation`) interacted with different lock classes like `sk_lock-AF_INET6`, `k-sk_lock-AF_INET6`, and `fs_reclaim`.
A crucial point of confusion, and therefore investigation, arose when I noticed `k-sk_lock-AF_INET6` appearing in both `rds_tcp_recv_path` and `mptcp_setsockopt_first_sf_only`. This overlap suggested a potential interaction point for a deadlock.
Let's break down the path within `rds_tcp_recv_path`: it locks the underlying kernel TCP socket (`sock->sk`), which has the lock class `k-sk_lock-AF_INET6`. Then, it proceeds to call `rds_tcp_read_sock(cp, GFP_KERNEL)`. Inside this, `kmem_cache_alloc` is invoked with `GFP_KERNEL`. This immediately raised a flag: can `GFP_KERNEL` allocations actually occur while holding `lock_sock` on a kernel socket? Normally, for user sockets (`sk_lock-AF_INET6`), `GFP_KERNEL` allocations are permissible, as seen in operations like `sk_stream_alloc_skb` or `tcp_sendmsg`. However, the lock class here is `k-sk_lock-AF_INET6`, and the subsequent entry into `fs_reclaim` within the `lockdep` chain created a concern. The sequence `k-sk_lock-AF_INET6` -> `fs_reclaim` or `fs_reclaim` -> `sk_lock-AF_INET6` -> `k-sk_lock-AF_INET6` seemed problematic.
To resolve this, I decided to analyze both sides of the potential cycle in the `lockdep` output.
On "Side A" (referring to the `#0` lock in the chain), we have `k-sk_lock-AF_INET6` leading to `fs_reclaim`. This occurs within `rds_tcp_recv_path` when it calls `rds_tcp_read_sock` with `GFP_KERNEL` while holding `lock_sock(sock->sk)`. The question was whether this combination, specifically `k-sk_lock-AF_INET6` influencing `fs_reclaim`, was inherently problematic. My previous thought was that this shouldn't be an issue, given the normal behavior with user sockets. However, the `lockdep` output showing `k-sk_lock-AF_INET6` acquiring *after* `sk_lock-AF_INET6` was a strong indicator of an inversion.
Then I turned my attention to the chain starting from `#7` and going down. In `mptcp_setsockopt_first_sf_only`, a `lock_sock(sk)` is called on the MPTCP socket (class `sk_lock-AF_INET6`). Subsequently, it calls `tcp_setsockopt` on a subflow socket (`ssk`), which is a kernel-created TCP socket with the lock class `k-sk_lock-AF_INET6`. This establishes the sequence: `sk_lock-AF_INET6` -> `k-sk_lock-AF_INET6`.
Next, I examined the chain from `#6` down to `#1`. This appears to originate in the `nbd` driver.
* `#6 sk_lock-AF_INET6` is acquired while holding `#5 &nsock->tx_lock`. This happens in `nbd_mark_nsock_dead` calling `inet_shutdown`.
* `#5 &nsock->tx_lock` is acquired while holding `#4 &cmd->lock`. This is in `nbd_queue_rq` calling `nbd_handle_cmd`.
* `#4 &cmd->lock` is acquired while holding `#3 set->srcu`. This occurs in `blk_mq_dispatch_rq_list` calling `nbd_queue_rq`.
* `#3 set->srcu` is acquired while holding `#2 &q->elevator_lock`. This is in `elevator_change` calling `elevator_switch` and `__synchronize_srcu`.
* `#2 &q->elevator_lock` is acquired while holding `#1 &q->q_usage_counter(io)#51`. This is in `blk_mq_update_nr_hw_queues` calling `blk_mq_elv_switch_none`, `elevator_set_none`, and `elevator_change`.
* The critical part is `#1 &q->q_usage_counter(io)#51` being acquired while holding `#0 fs_reclaim`. This is where the initial confusion was. I'm trying to understand if `blk_alloc_queue` leads to `q_usage_counter` -> `fs_reclaim`, or vice-versa. The `lockdep` output seems to indicate `fs_reclaim` is acquired first, and then `q_usage_counter`.
The core of my investigation is now centered on understanding the exact lock acquisition order in `blk_alloc_queue` concerning `q_usage_counter` and `fs_reclaim`, and how this sequence, when combined with the MPTCP and RDS paths, creates the observed deadlock. I've been reviewing `block/blk-core.c`, `block/blk-mq.c`, `drivers/block/nbd.c`, `net/mptcp/subflow.c` (or `sockopt.c`), and the git history for relevant changes in `rds/tcp_recv.c`, `drivers/block/nbd.c`, `net/mptcp/`, and `block/blk-mq.c` to clarify these interactions.
|
| 14/2 |
2026/11/28 10:00 |
tool |
read-file |
0m
Args: map[File:block/blk-core.c FirstLine:475 LineCount:50]
Results: map[Contents: 475: mutex_init(&q->sysfs_lock);
476: mutex_init(&q->limits_lock);
477: mutex_init(&q->rq_qos_mutex);
478: spin_lock_init(&q->queue_lock);
479:
480: init_waitqueue_head(&q->mq_freeze_wq);
481: mutex_init(&q->mq_freeze_lock);
482:
483: blkg_init_queue(q);
484:
485: /*
486: * Init percpu_ref in atomic mode so that it's faster to shutdown.
487: * See blk_register_queue() for details.
488: */
489: error = percpu_ref_init(&q->q_usage_counter,
490: blk_queue_usage_counter_release,
491: PERCPU_REF_INIT_ATOMIC, GFP_KERNEL);
492: if (error)
493: goto fail_stats;
494: lockdep_register_key(&q->io_lock_cls_key);
495: lockdep_register_key(&q->q_lock_cls_key);
496: lockdep_init_map(&q->io_lockdep_map, "&q->q_usage_counter(io)",
497: &q->io_lock_cls_key, 0);
498: lockdep_init_map(&q->q_lockdep_map, "&q->q_usage_counter(queue)",
499: &q->q_lock_cls_key, 0);
500:
501: /* Teach lockdep about lock ordering (reclaim WRT queue freeze lock). */
502: fs_reclaim_acquire(GFP_KERNEL);
503: rwsem_acquire_read(&q->io_lockdep_map, 0, 0, _RET_IP_);
504: rwsem_release(&q->io_lockdep_map, _RET_IP_);
505: fs_reclaim_release(GFP_KERNEL);
506:
507: q->nr_requests = BLKDEV_DEFAULT_RQ;
508: q->async_depth = BLKDEV_DEFAULT_RQ;
509:
510: return q;
511:
512: fail_stats:
513: blk_free_queue_stats(q->stats);
514: fail_id:
515: ida_free(&blk_queue_ida, q->id);
516: fail_q:
517: kmem_cache_free(blk_requestq_cachep, q);
518: return ERR_PTR(error);
519: }
520:
521: /**
522: * blk_get_queue - increment the request_queue refcount
523: * @q: the request_queue structure to increment the refcount for
524: *
]
|
| 15/2 |
2026/11/28 10:01 |
tool |
read-file |
0m
Args: map[File:block/blk-mq.c FirstLine:5155 LineCount:90]
Results: map[Contents:5155: ctx->name = q->elevator->type->elevator_name;
5156:
5157: /*
5158: * Before we switch elevator to 'none', take a reference to
5159: * the elevator module so that while nr_hw_queue update is
5160: * running, no one can remove elevator module. We'd put the
5161: * reference to elevator module later when we switch back
5162: * elevator.
5163: */
5164: __elevator_get(q->elevator->type);
5165:
5166: /*
5167: * Store elevator type so that we can release the reference
5168: * taken above later.
5169: */
5170: ctx->type = q->elevator->type;
5171: elevator_set_none(q);
5172: }
5173: return 0;
5174: }
5175:
5176: static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
5177: int nr_hw_queues)
5178: {
5179: struct request_queue *q;
5180: int prev_nr_hw_queues = set->nr_hw_queues;
5181: unsigned int memflags;
5182: int i;
5183: struct xarray elv_tbl;
5184: struct blk_mq_tags **new_tags;
5185: bool queues_frozen = false;
5186:
5187: lockdep_assert_held(&set->tag_list_lock);
5188:
5189: if (set->nr_maps == 1 && nr_hw_queues > nr_cpu_ids)
5190: nr_hw_queues = nr_cpu_ids;
5191: if (nr_hw_queues < 1)
5192: return;
5193: if (set->nr_maps == 1 && nr_hw_queues == set->nr_hw_queues)
5194: return;
5195:
5196: memflags = memalloc_noio_save();
5197:
5198: xa_init(&elv_tbl);
5199: if (blk_mq_alloc_sched_ctx_batch(&elv_tbl, set) < 0)
5200: goto out_free_ctx;
5201:
5202: if (blk_mq_alloc_sched_res_batch(&elv_tbl, set, nr_hw_queues) < 0)
5203: goto out_free_ctx;
5204:
5205: list_for_each_entry(q, &set->tag_list, tag_set_list) {
5206: blk_mq_debugfs_unregister_hctxs(q);
5207: blk_mq_sysfs_unregister_hctxs(q);
5208: }
5209:
5210: /*
5211: * Switch IO scheduler to 'none', cleaning up the data associated
5212: * with the previous scheduler. We will switch back once we are done
5213: * updating the new sw to hw queue mappings.
5214: */
5215: list_for_each_entry(q, &set->tag_list, tag_set_list)
5216: if (blk_mq_elv_switch_none(q, &elv_tbl))
5217: goto switch_back;
5218:
5219: new_tags = blk_mq_prealloc_tag_set_tags(set, nr_hw_queues);
5220: if (IS_ERR(new_tags))
5221: goto switch_back;
5222:
5223: list_for_each_entry(q, &set->tag_list, tag_set_list)
5224: blk_mq_freeze_queue_nomemsave(q);
5225: queues_frozen = true;
5226: if (new_tags) {
5227: kfree(set->tags);
5228: set->tags = new_tags;
5229: }
5230: set->nr_hw_queues = nr_hw_queues;
5231:
5232: fallback:
5233: blk_mq_update_queue_map(set);
5234: list_for_each_entry(q, &set->tag_list, tag_set_list) {
5235: __blk_mq_realloc_hw_ctxs(set, q);
5236:
5237: if (q->nr_hw_queues != set->nr_hw_queues) {
5238: int i = prev_nr_hw_queues;
5239:
5240: pr_warn("Increasing nr_hw_queues to %d fails, fallback to %d\n",
5241: nr_hw_queues, prev_nr_hw_queues);
5242: for (; i < set->nr_hw_queues; i++)
5243: __blk_mq_free_map_and_rqs(set, i);
5244:
]
|
| 16/2 |
2026/11/28 10:01 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:300 LineCount:60]
Results: map[Contents: 300: static int nbd_disconnected(struct nbd_config *config)
301: {
302: return test_bit(NBD_RT_DISCONNECTED, &config->runtime_flags) ||
303: test_bit(NBD_RT_DISCONNECT_REQUESTED, &config->runtime_flags);
304: }
305:
306: static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock,
307: int notify)
308: {
309: if (!nsock->dead && notify && !nbd_disconnected(nbd->config)) {
310: struct link_dead_args *args;
311: args = kmalloc_obj(struct link_dead_args, GFP_NOIO);
312: if (args) {
313: INIT_WORK(&args->work, nbd_dead_link_work);
314: args->index = nbd->index;
315: queue_work(system_percpu_wq, &args->work);
316: }
317: }
318: if (!nsock->dead) {
319: kernel_sock_shutdown(nsock->sock, SHUT_RDWR);
320: if (atomic_dec_return(&nbd->config->live_connections) == 0) {
321: if (test_and_clear_bit(NBD_RT_DISCONNECT_REQUESTED,
322: &nbd->config->runtime_flags)) {
323: set_bit(NBD_RT_DISCONNECTED,
324: &nbd->config->runtime_flags);
325: dev_info(nbd_to_dev(nbd),
326: "Disconnected due to user request.\n");
327: }
328: }
329: }
330: nsock->dead = true;
331: nsock->pending = NULL;
332: nsock->sent = 0;
333: }
334:
335: static void nbd_apply_limits(struct queue_limits *lim, u32 flags)
336: {
337: lim->features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA | BLK_FEAT_ROTATIONAL);
338: lim->max_hw_discard_sectors = 0;
339: lim->max_write_zeroes_sectors = 0;
340:
341: if (flags & NBD_FLAG_SEND_TRIM)
342: lim->max_hw_discard_sectors = UINT_MAX >> SECTOR_SHIFT;
343: if (flags & NBD_FLAG_SEND_FLUSH) {
344: lim->features |= BLK_FEAT_WRITE_CACHE;
345: if (flags & NBD_FLAG_SEND_FUA)
346: lim->features |= BLK_FEAT_FUA;
347: }
348:
349: if (flags & NBD_FLAG_ROTATIONAL)
350: lim->features |= BLK_FEAT_ROTATIONAL;
351: if (flags & NBD_FLAG_SEND_WRITE_ZEROES)
352: lim->max_write_zeroes_sectors = UINT_MAX >> SECTOR_SHIFT;
353: }
354:
355: static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, loff_t blksize)
356: {
357: struct queue_limits lim;
358: int error;
359:
]
|
| 17/2 |
2026/11/28 10:01 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:1185 LineCount:50]
Results: map[Contents:1185: const struct blk_mq_queue_data *bd)
1186: {
1187: struct nbd_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
1188: blk_status_t ret;
1189:
1190: /*
1191: * Since we look at the bio's to send the request over the network we
1192: * need to make sure the completion work doesn't mark this request done
1193: * before we are done doing our send. This keeps us from dereferencing
1194: * freed data if we have particularly fast completions (ie we get the
1195: * completion before we exit sock_xmit on the last bvec) or in the case
1196: * that the server is misbehaving (or there was an error) before we're
1197: * done sending everything over the wire.
1198: */
1199: mutex_lock(&cmd->lock);
1200: clear_bit(NBD_CMD_REQUEUED, &cmd->flags);
1201:
1202: /* We can be called directly from the user space process, which means we
1203: * could possibly have signals pending so our sendmsg will fail. In
1204: * this case we need to return that we are busy, otherwise error out as
1205: * appropriate.
1206: */
1207: ret = nbd_handle_cmd(cmd, hctx->queue_num);
1208: mutex_unlock(&cmd->lock);
1209:
1210: return ret;
1211: }
1212:
1213: static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
1214: int *err)
1215: {
1216: struct socket *sock;
1217:
1218: *err = 0;
1219: sock = sockfd_lookup(fd, err);
1220: if (!sock)
1221: return NULL;
1222:
1223: if (!sk_is_tcp(sock->sk) &&
1224: !sk_is_stream_unix(sock->sk)) {
1225: dev_err(disk_to_dev(nbd->disk), "Unsupported socket: should be TCP or UNIX.\n");
1226: *err = -EINVAL;
1227: sockfd_put(sock);
1228: return NULL;
1229: }
1230:
1231: if (sock->ops->shutdown == sock_no_shutdown) {
1232: dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
1233: *err = -EINVAL;
1234: sockfd_put(sock);
]
|
| 18/2 |
2026/11/28 10:01 |
tool |
read-file |
0m
Args: map[File:net/rds/tcp_recv.c FirstLine:290 LineCount:35]
Results: map[Contents: 290: * data_ready.
291: *
292: * if we fail to allocate we're in trouble.. blindly wait some time before
293: * trying again to see if the VM can free up something for us.
294: */
295: int rds_tcp_recv_path(struct rds_conn_path *cp)
296: {
297: struct rds_tcp_connection *tc = cp->cp_transport_data;
298: struct socket *sock = tc->t_sock;
299: int ret = 0;
300:
301: rdsdebug("recv worker path [%d] tc %p sock %p\n",
302: cp->cp_index, tc, sock);
303:
304: lock_sock(sock->sk);
305: ret = rds_tcp_read_sock(cp, GFP_KERNEL);
306: release_sock(sock->sk);
307:
308: return ret;
309: }
310:
311: void rds_tcp_data_ready(struct sock *sk)
312: {
313: void (*ready)(struct sock *sk);
314: struct rds_conn_path *cp;
315: struct rds_tcp_connection *tc;
316:
317: trace_sk_data_ready(sk);
318: rdsdebug("data ready sk %p\n", sk);
319:
320: read_lock_bh(&sk->sk_callback_lock);
321: cp = sk->sk_user_data;
322: if (!cp) { /* check for teardown race */
323: ready = sk->sk_data_ready;
324: goto out;
]
|
| 19/2 |
2026/11/28 10:01 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 25443
output: 173
thoughts: 1221
Thoughts: **Analyzing the Interconnectedness of Block I/O and Network Socket Locking**
My current line of thinking is laser-focused on understanding the intricate dependencies between block I/O operations and network socket locking mechanisms, specifically in the context of `fs_reclaim`. I've been meticulously tracing a chain of lock acquisitions to identify potential deadlocks or forbidden operations during memory reclamation.
Here's my thought process:
1. **The Starting Point: `fs_reclaim` and Block I/O:** I've identified that `fs_reclaim`, which is crucial for freeing memory (think pageout, swapout, writeback), can lead to block I/O submission. This is evident when `fs_reclaim_acquire` is called, which in turn acquires the read lock on `q->io_lockdep_map`. The implication here is profound: anything happening *while* `q->q_usage_counter(io)` is held β a state associated with block I/O submission β must *not* attempt `fs_reclaim`. This means we must use `GFP_NOIO` and absolutely avoid `GFP_KERNEL` allocations within such contexts.
2. **Connecting Block I/O to Elevator Locking:** My next step was to understand how `q->q_usage_counter(io)` relates to other locks. I found that during updates to the number of hardware queues (`blk_mq_update_nr_hw_queues`), specifically within `blk_mq_elv_switch_none` and subsequently `elevator_change`, the `q->q_usage_counter(io)` is acquired. This is a critical point. I'm scrutinizing the sequence: `blk_mq_update_nr_hw_queues` appears to freeze the queue *after* calling `blk_mq_elv_switch_none`. This raises a question about the precise ordering: is `q->q_usage_counter(io)` acquired *before* `&q->elevator_lock` in the `elevator_change` path, or does `blk_mq_update_nr_hw_queues` itself establish this dependency? I need to dig deeper into `elevator_change` to confirm where `q->q_usage_counter(io)` is actually being acquired.
3. **From Elevator Lock to SRCU:** The chain continues. I see that `&q->elevator_lock` is acquired during `elevator_change`, which then leads to `elevator_switch` and ultimately `__synchronize_srcu`, thus acquiring `set->srcu`.
4. **SRCU to Command Lock:** From `set->srcu`, the path extends to `&cmd->lock` via `blk_mq_dispatch_rq_list` and `nbd_queue_rq`. This means that within the context of dispatching requests, specifically for `nbd`, we're acquiring the command lock.
5. **Command Lock to Network Socket Lock:** The dependency progresses further to `&nsock->tx_lock` when `nbd_queue_rq` calls `nbd_handle_cmd`. This is where the block I/O context starts to intersect with network socket operations.
6. **The Critical Juncture: Network Socket Lock and `fs_reclaim`:** This is the moment of "WAIT A MINUTE!" I've discovered that `nbd` (a block device driver) is involved in calling `kernel_sock_shutdown`, which ultimately acquires `sk_lock-AF_INET6`. The sequence is: `fs_reclaim` -> ... -> `nbd_queue_rq` -> `nbd_handle_cmd` -> `&nsock->tx_lock` -> `kernel_sock_shutdown` -> `lock_sock` -> `sk_lock-AF_INET6`.
My immediate concern is: *why* is `nbd` calling `kernel_sock_shutdown` while holding `&nsock->tx_lock`? Or, more precisely, why does `sock_shutdown` (called within `nbd_clear_sock` or `nbd_mark_nsock_dead`) acquire `sk_lock-AF_INET6`?
Even if `nbd_handle_cmd` only acquires `&nsock->tx_lock`, and `sock_shutdown` then acquires `&nsock->tx_lock` before `nbd_mark_nsock_dead` calls `kernel_sock_shutdown` to acquire `sk_lock-AF_INET6`, the core issue remains: we have a path from `fs_reclaim` that leads to `sk_lock-AF_INET6`.
Normally, acquiring `sk_lock` (associated with user sockets, specifically `sk_lock-AF_INET6` here) *is permitted* to perform `GFP_KERNEL` allocations. These allocations are common in network operations like `tcp_sendmsg` or `sk_stream_alloc_skb`. If `sk_lock-AF_INET6` is already *below* `fs_reclaim` in the lock dependency graph, then any operation that proceeds from `sk_lock-AF_INET6` and *then* tries to invoke `fs_reclaim` would lead to a deadlock.
This leads me to ask: *why* doesn't `sk_lock-AF_INET6` -> `fs_reclaim` normally occur, or, more importantly, *why isn't lockdep flagging this potential deadlock*?
To answer this, I believe I need to conduct a thorough review of the git history for `nbd`, `mptcp`, `rds`, and `block/blk-mq.c`, specifically focusing on the areas of `block/elevator.c`, `net/mptcp/`, `net/rds/tcp_recv.c`, and `drivers/block/nbd.c`. This historical context will be crucial to understanding how these dependencies were introduced and, perhaps, how potential issues were mitigated or overlooked.
|
| 20/2 |
2026/11/28 10:01 |
tool |
read-file |
0m
Args: map[File:block/elevator.c FirstLine:560 LineCount:135]
Results: map[Contents: 560: * to restore the old io scheduler, so leaving the io scheduler being none.
561: */
562: static int elevator_switch(struct request_queue *q, struct elv_change_ctx *ctx)
563: {
564: struct elevator_type *new_e = NULL;
565: int ret = 0;
566:
567: WARN_ON_ONCE(q->mq_freeze_depth == 0);
568: lockdep_assert_held(&q->elevator_lock);
569:
570: if (strncmp(ctx->name, "none", 4)) {
571: new_e = elevator_find_get(ctx->name);
572: if (!new_e)
573: return -EINVAL;
574: }
575:
576: blk_mq_quiesce_queue(q);
577:
578: if (q->elevator) {
579: ctx->old = q->elevator;
580: elevator_exit(q);
581: }
582:
583: if (new_e) {
584: ret = blk_mq_init_sched(q, new_e, &ctx->res);
585: if (ret)
586: goto out_unfreeze;
587: ctx->new = q->elevator;
588: } else {
589: blk_queue_flag_clear(QUEUE_FLAG_SQ_SCHED, q);
590: q->elevator = NULL;
591: q->nr_requests = q->tag_set->queue_depth;
592: q->async_depth = q->tag_set->queue_depth;
593: }
594: blk_add_trace_msg(q, "elv switch: %s", ctx->name);
595:
596: out_unfreeze:
597: blk_mq_unquiesce_queue(q);
598:
599: if (ret) {
600: pr_warn("elv: switch to \"%s\" failed, falling back to \"none\"\n",
601: new_e->elevator_name);
602: }
603:
604: if (new_e)
605: elevator_put(new_e);
606: return ret;
607: }
608:
609: static void elv_exit_and_release(struct elv_change_ctx *ctx,
610: struct request_queue *q)
611: {
612: struct elevator_queue *e;
613: unsigned memflags;
614:
615: memflags = blk_mq_freeze_queue(q);
616: mutex_lock(&q->elevator_lock);
617: e = q->elevator;
618: elevator_exit(q);
619: mutex_unlock(&q->elevator_lock);
620: blk_mq_unfreeze_queue(q, memflags);
621: if (e) {
622: blk_mq_free_sched_res(&ctx->res, ctx->type, q->tag_set);
623: kobject_put(&e->kobj);
624: }
625: }
626:
627: static int elevator_change_done(struct request_queue *q,
628: struct elv_change_ctx *ctx)
629: {
630: int ret = 0;
631:
632: if (ctx->old) {
633: struct elevator_resources res = {
634: .et = ctx->old->et,
635: .data = ctx->old->elevator_data
636: };
637:
638: elv_unregister_queue(q, ctx->old);
639: blk_mq_free_sched_res(&res, ctx->old->type, q->tag_set);
640: kobject_put(&ctx->old->kobj);
641: }
642: if (ctx->new) {
643: ret = elv_register_queue(q, ctx->new, !ctx->no_uevent);
644: if (ret)
645: elv_exit_and_release(ctx, q);
646: }
647: return ret;
648: }
649:
650: /*
651: * Switch this queue to the given IO scheduler.
652: */
653: static int elevator_change(struct request_queue *q, struct elv_change_ctx *ctx)
654: {
655: unsigned int memflags;
656: struct blk_mq_tag_set *set = q->tag_set;
657: int ret = 0;
658:
659: lockdep_assert_held(&set->update_nr_hwq_lock);
]
|
| 21/2 |
2026/11/28 10:01 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:400 LineCount:40]
Results: map[Contents: 400:
401: blk_mq_end_request(req, cmd->status);
402: }
403:
404: /*
405: * Forcibly shutdown the socket causing all listeners to error
406: */
407: static void sock_shutdown(struct nbd_device *nbd)
408: {
409: struct nbd_config *config = nbd->config;
410: int i;
411:
412: if (config->num_connections == 0)
413: return;
414: if (test_and_set_bit(NBD_RT_DISCONNECTED, &config->runtime_flags))
415: return;
416:
417: for (i = 0; i < config->num_connections; i++) {
418: struct nbd_sock *nsock = config->socks[i];
419: mutex_lock(&nsock->tx_lock);
420: nbd_mark_nsock_dead(nbd, nsock, 0);
421: mutex_unlock(&nsock->tx_lock);
422: }
423: dev_warn(disk_to_dev(nbd->disk), "shutting down sockets\n");
424: }
425:
426: static u32 req_to_nbd_cmd_type(struct request *req)
427: {
428: switch (req_op(req)) {
429: case REQ_OP_DISCARD:
430: return NBD_CMD_TRIM;
431: case REQ_OP_FLUSH:
432: return NBD_CMD_FLUSH;
433: case REQ_OP_WRITE:
434: return NBD_CMD_WRITE;
435: case REQ_OP_READ:
436: return NBD_CMD_READ;
437: case REQ_OP_WRITE_ZEROES:
438: return NBD_CMD_WRITE_ZEROES;
439: default:
]
|
| 22/2 |
2026/11/28 10:01 |
tool |
git-log |
0m
Args: map[Count:15 PathPrefix:drivers/block/nbd.c]
Results: map[Output:553d28925fde nbd: Reclassify sockets in the reconnect path
326d49039c10 nbd: add pre_defined_connections module parameter for pre-created devices
a9d414b4a15c nbd: remove queue freeze for newly created nbd from netlink path
f8d21c590e55 nbd: factor out a nbd_genl_foreach_sock
db285268df79 nbd: skip queue freeze when setting size at device startup
285908f554fe nbd: remove queue freeze in nbd_add_socket
0fdee7c5fa88 nbd: clear queue limits on disconnect
04d8fb23e520 nbd: disallow NBD_SET_SOCK on an active device
fe247030f1ce nbd: simplify find_fallback() by removing redundant logic
9280e6edf656 nbd: don't warn when reclassifying a busy socket lock
d532cddb6c60 nbd: Reclassify sockets to avoid lockdep circular dependency
b040a1a4523d block: switch numa_node to int in blk_mq_hw_ctx and init_request
bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
1649714b930f nbd: defer config unlock in nbd_genl_connect
]
|
| 23/2 |
2026/11/28 10:01 |
tool |
git-log |
0m
Args: map[Count:15 PathPrefix:net/rds/tcp_recv.c]
Results: map[Output:3f9941462015 net/rds: use special gfp_t format specifier
826c1004d4ae net/rds: rds_tcp_conn_path_shutdown must not discard messages
d327e2e74aed net/rds: Add per cp work queue
9f1f70dd8500 rds:Simplify the allocation of slab caches
40e0b0908142 net/sock: Introduce trace_sk_data_ready()
379aecbce08f rds: Fix spelling mistakes
eee2fa6ab322 rds: Changing IP address internal representation to struct in6_addr
ebeeb1ad9b8a rds: tcp: use rds_destroy_pending() to synchronize netns/module teardown and rds connection/workq management
3db6e0d172c9 rds: use RCU to synchronize work-enqueue with connection teardown
3289025aedc0 RDS: add receive message trace used by application
2da43c4a1b51 RDS: TCP: make receive path use the rds_conn_path
ea3b1ea53930 RDS: TCP: make ->sk_user_data point to a rds_conn_path
5c3da57d70f1 net: rds: fix coding style issues
0cb43965d42a RDS: split out connection specific state from rds_connection to rds_conn_path
38036629cded rds: tcp: block BH in TCP callbacks
]
|
| 24/2 |
2026/11/28 10:01 |
tool |
git-log |
0m
Args: map[Count:15 PathPrefix:net/mptcp/sockopt.c]
Results: map[Output:7690137e70ab mptcp: sockopt: set sockopt on all subflows
57132affbc89 mptcp: sockopt: check timestamping ret value
3a543ae0e209 mptcp: update window_clamp on subflows when SO_RCVBUF is set
70ece9d7021c mptcp: sockopt: increase seq in mptcp_setsockopt_all_sf
b5c52908d52c mptcp: fix scheduling with atomic in timestamp sockopt
5f95c21fc23a mptcp: sockopt: set timestamp flags on subflow socket, not msk
f88191c7f361 mptcp: pm: in-kernel: record fullmesh endp nb
539f6b9de39e mptcp: pm: in-kernel: add laminar endpoints
e7757b6d3a62 mptcp: pm: in-kernel: rename 'local_addr_max' to 'endp_subflow_max'
37712d84dfc2 mptcp: pm: in-kernel: rename 'add_addr_accept_max' to 'limit_add_addr_accepted'
45cae570664d mptcp: pm: in-kernel: rename 'add_addr_signal_max' to 'endp_signal_max'
3eb3c9a9596a mptcp: pm: in-kernel: rename 'subflows_max' to 'limit_extra_subflows'
c5273f6ca166 mptcp: pm: rename 'subflows' to 'extra_subflows'
648de37416b3 mptcp: sockopt: make sync_socket_options propagate SOCK_KEEPOPEN
51c5fd09e1b4 mptcp: add TCP_MAXSEG sockopt support
]
|
| 25/2 |
2026/11/28 10:01 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 30186
output: 140
thoughts: 203
Thoughts: **Sudden Realization and Urgent Investigation of NBD Socket Handling**
Whoa, hold up a second! I just did a `git log` on `drivers/block/nbd.c` and I need to dive into these commits *immediately*. It looks like there's been some significant churn around how sockets are handled, especially in the reconnect path.
Specifically, I'm seeing:
* `553d28925fde nbd: Reclassify sockets in the reconnect path`
* `d532cddb6c60 nbd: Reclassify sockets to avoid lockdep circular dependency`
* `9280e6edf656 nbd: don't warn when reclassifying a busy socket lock`
These three entries, in particular, scream "potential race condition" or "locking issue" to me. The fact that they're explicitly addressing reclassifying sockets to *avoid* lockdep circular dependencies suggests some complex interactions that could easily lead to bugs if not handled perfectly. I need to understand the exact state transitions and locking mechanisms involved here. Why was a circular dependency happening? What states are these sockets transitioning through, and what are the implications of reclassifying them? And the "don't warn" commit implies a scenario where reclassifying a busy socket was previously a problematic (or at least noisy) situation β what was that scenario, and has it been fully mitigated?
Beyond the socket reclassification, I also noticed:
* `a9d414b4a15c nbd: remove queue freeze for newly created nbd from netlink path`
* `326d49039c10 nbd: add pre_defined_connections module parameter for pre-created devices`
* `0fdee7c5fa88 nbd: clear queue limits on disconnect`
The removal of the queue freeze for netlink-created NBDs is interesting. My immediate thought is: does this introduce any new race conditions or performance regressions when a device is rapidly created and then potentially used? Why was the freeze there in the first place?
The `pre_defined_connections` parameter sounds like an enhancement to simplify setup, but I'll need to check how it interacts with the existing connection management and socket handling logic to ensure it doesn't inadvertently create edge cases.
Finally, clearing queue limits on disconnect seems like good hygiene, but I'll want to confirm that it's done at the right time and doesn't leave any lingering state that could affect subsequent connections or operations.
Given the density of changes around socket management and connection lifecycles in `nbd.c`, I'm also going to pull in the `nbd_genl_connect` function into my immediate investigation. This is likely the entry point for many of these connection and socket operations, and understanding how it interacts with the changes I've just seen in the `git log` is critical. I suspect the core of the problem, or at least the context for these fixes, lies within that function. I need to trace the data flow and state management from `nbd_genl_connect` through these socket operations.
|
| 26/2 |
2026/11/28 10:01 |
tool |
git-show |
0m
Args:
Results: map[Output:commit d532cddb6c6049ced414d64d83c6ce7149a6421a
Author: Eric Dumazet <edumazet@kernel.org>
Date: Sat Jun 13 04:26:19 2026 +0000
nbd: Reclassify sockets to avoid lockdep circular dependency
syzbot reported a possible circular locking dependency in udp_sendmsg()
where fs_reclaim can be triggered while holding sk_lock, and fs_reclaim
can eventually depend on another sk_lock (e.g., if NBD is used for swap
or writeback and NBD uses TLS/TCP which acquires sk_lock).
Since the UDP socket and the NBD TCP/TLS socket are different, this is a
false positive. Fix this by reclassifying NBD sockets to a separate lock
class when they are added to the NBD device.
This is similar to what nvme-tcp and other network block devices do.
Fixes: ffa1e7ada456 ("block: Make request_queue lockdep splats show up earlier")
Reported-by: syzbot+607cdcf978b3e79da878@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/6a2cdafe.428ffe26.258b27.0161.GAE@google.com/T/#u
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260613042619.1108126-1-edumazet@google.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index e2fe9e3308fc..3a585a0c882a 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1238,6 +1238,42 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
return sock;
}
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+static struct lock_class_key nbd_key[3];
+static struct lock_class_key nbd_slock_key[3];
+
+static void nbd_reclassify_socket(struct socket *sock)
+{
+ struct sock *sk = sock->sk;
+
+ if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
+ return;
+
+ switch (sk->sk_family) {
+ case AF_INET:
+ sock_lock_init_class_and_name(sk, "slock-AF_INET-NBD",
+ &nbd_slock_key[0],
+ "sk_lock-AF_INET-NBD",
+ &nbd_key[0]);
+ break;
+ case AF_INET6:
+ sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD",
+ &nbd_slock_key[1],
+ "sk_lock-AF_INET6-NBD",
+ &nbd_key[1]);
+ break;
+ case AF_UNIX:
+ sock_lock_init_class_and_name(sk, "slock-AF_UNIX-NBD",
+ &nbd_slock_key[2],
+ "sk_lock-AF_UNIX-NBD",
+ &nbd_key[2]);
+ break;
+ }
+}
+#else
+static inline void nbd_reclassify_socket(struct socket *sock) {}
+#endif
+
static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
bool netlink)
{
@@ -1254,6 +1290,7 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
sock = nbd_get_socket(nbd, arg, &err);
if (!sock)
return err;
+ nbd_reclassify_socket(sock);
/*
* We need to make sure we don't get any errant requests while we're
]
|
| 27/2 |
2026/11/28 10:01 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 9280e6edf65662b6aafc8b704ad065b54c08b519
Author: Deepanshu Kartikey <kartikey406@gmail.com>
Date: Mon Jun 22 05:22:55 2026 +0530
nbd: don't warn when reclassifying a busy socket lock
nbd_reclassify_socket() warns via WARN_ON_ONCE() if the socket lock is
held at the point of reclassification. That assertion was copied from
nvme-tcp, where the socket is created internally by the kernel
(sock_create_kern()) and is never visible to user space, so the lock
is guaranteed to be free.
NBD is different: the socket is looked up from a user-supplied fd in
nbd_get_socket(), and user space retains that fd. A concurrent syscall
on the same socket (or softirq processing taking bh_lock_sock() on a
connected TCP socket) can legitimately hold the lock at the instant
NBD reclassifies it. sock_allow_reclassification() then returns false
and the WARN_ON_ONCE() fires, which turns into a crash under
panic_on_warn. This is reachable by simply racing NBD_CMD_CONNECT
against socket activity on the same fd, as reported by syzbot.
Hitting a held lock here is expected for an externally owned socket and
is not a kernel bug, so skip reclassification silently instead of
warning. Reclassification is a lockdep-only annotation, so skipping it
in the rare racing case is harmless.
Reported-by: syzbot+6b85d1e39a5b8ed9a954@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6b85d1e39a5b8ed9a954
Fixes: d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular dependency")
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260621235255.66015-1-kartikey406@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 3a585a0c882a..8f10762e90ef 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1246,7 +1246,7 @@ static void nbd_reclassify_socket(struct socket *sock)
{
struct sock *sk = sock->sk;
- if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
+ if (!sock_allow_reclassification(sk))
return;
switch (sk->sk_family) {
]
|
| 28/2 |
2026/11/28 10:01 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 553d28925fdea4044bad4ae1e2bf9484ad21f758
Author: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
Date: Thu Nov 12 07:59:39 2026 -0300
nbd: Reclassify sockets in the reconnect path
Commit d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular
dependency") introduced nbd_reclassify_socket() to prevent lockdep false
positives when NBD sockets are used in memory reclaim paths. While
nbd_add_socket() reclassifies newly added sockets,
nbd_genl_reconnect_sock_cb() omitted this call when replacing dead
sockets during reconnection. Consequently, reconnected sockets retain
the generic socket lockdep class and trigger false-positive lockdep
reports.
Fix this by reclassifying the replacement socket in
nbd_genl_reconnect_sock_cb().
Fixes: d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular dependency")
Reported-by: syzbot+d7d72f3d467710442af0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=d7d72f3d467710442af0
Signed-off-by: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Link: https://patch.msgid.link/20261112105939.260856-1-trintaeoitogc@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index ffce519bf008..b2b27f90a7ed 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1356,6 +1356,7 @@ static int nbd_genl_reconnect_sock_cb(struct nbd_device *nbd, unsigned long arg)
sock = nbd_get_socket(nbd, arg, &err);
if (!sock)
return err;
+ nbd_reclassify_socket(sock);
args = kzalloc_obj(*args);
if (!args) {
]
|
| 29/2 |
2026/11/28 10:01 |
tool |
git-show |
0m
Args:
Results: map[Output:commit a9d414b4a15c69b5389da3ec08f23e9f2926c52a
Author: Yang Erkun <yangerkun@huawei.com>
Date: Wed Aug 5 20:29:29 2026 +0800
nbd: remove queue freeze for newly created nbd from netlink path
Previous commits has removed the queue freeze in nbd_add_socket and
nbd_set_size during nbd device setup. However, a queue freeze can still
occur when nbd_start_device calls blk_mq_update_nr_hw_queues if the
socket connection count does not match nbd->tag_set->nr_hw_queues.
The nbd_start_device function can be invoked through either the ioctl or
netlink paths. The ioctl path only allows reusing an existing inactivate
nbd device, there is nothing more we can do to prevent the queue freeze
since the old nbd->tag_set->nr_hw_queues may not match the new socket
connection count. Similarly, the netlink path can reuse a preferred
inactivate nbd device, and again, we cannot do more in this scenario.
However, the netlink path can also add a new nbd device using
nbd_dev_add. In this case, we can obtain the new number of socket
connections, and by adding a new argument representing the expected
nr_hw_queues in nbd_dev_add, we can ensure the queue freeze is avoided
for this situation.
Reviewed-by: Yu Kuai <yukuai@fygo.io>
Signed-off-by: Yang Erkun <yangerkun@huawei.com>
Link: https://patch.msgid.link/20260805122930.57647-8-yangerkun@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 192c80aa738c..6c4aa19ea11a 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1944,7 +1944,8 @@ static const struct blk_mq_ops nbd_mq_ops = {
.timeout = nbd_xmit_timeout,
};
-static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
+static struct nbd_device *nbd_dev_add(int index, unsigned int refs,
+ int nr_hw_queues)
{
struct queue_limits lim = {
.max_hw_sectors = 65536,
@@ -1961,7 +1962,7 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
goto out;
nbd->tag_set.ops = &nbd_mq_ops;
- nbd->tag_set.nr_hw_queues = 1;
+ nbd->tag_set.nr_hw_queues = nr_hw_queues;
nbd->tag_set.queue_depth = 128;
nbd->tag_set.numa_node = NUMA_NO_NODE;
nbd->tag_set.cmd_size = sizeof(struct nbd_cmd);
@@ -2214,7 +2215,11 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
mutex_unlock(&nbd_index_mutex);
if (!nbd) {
- nbd = nbd_dev_add(index, 2);
+ ret = nbd_genl_foreach_sock(info, NULL, NULL);
+ if (ret < 0)
+ return ret;
+
+ nbd = nbd_dev_add(index, 2, ret > 0 ? ret : 1);
if (IS_ERR(nbd)) {
pr_err("failed to add new device\n");
return PTR_ERR(nbd);
@@ -2724,7 +2729,7 @@ static int __init nbd_init(void)
nbd_dbg_init();
for (i = 0; i < nbds_max; i++)
- nbd_dev_add(i, 1);
+ nbd_dev_add(i, 1, 1);
return 0;
}
]
|
| 30/2 |
2026/11/28 10:01 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 0fdee7c5fa886554503001cecea049f053237381
Author: Yang Erkun <yangerkun@huawei.com>
Date: Wed Aug 5 20:29:25 2026 +0800
nbd: clear queue limits on disconnect
An inactive nbd device may refuse any I/O operations. The nbd_config_put
function calls invalidate_disk, which sets the device capacity to zero
to reject all read and write I/O. For zero-sector flush I/O requests
from blkdev_issue_flush, if the write cache is disabled, the zero-sector
flush I/O immediately returns 0 in submit_bio_noacct. However, since
nbd_config_put does not clear the write cache state, an inactive nbd
device might still have the write cache enabled. In this situation,
zero-sector flush I/O will return -EIO because there is no active socket.
Additionally, BLK_FEAT_FUA and BLK_FEAT_ROTATIONAL flags may also remain
stale, resetting all of them ensures consistent behavior.
The limits update uses queue_limits_commit_update() (the non-freezing
variant) because config_refs == 0 here means every fd is closed and recv
threads have drained, so no in-flight I/O can read q->limits concurrently.
Reviewed-by: Yu Kuai <yukuai@fygo.io>
Signed-off-by: Yang Erkun <yangerkun@huawei.com>
Link: https://patch.msgid.link/20260805122930.57647-4-yangerkun@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 7ec85f94f742..78df6f459da6 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -331,6 +331,26 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock,
nsock->sent = 0;
}
+static void nbd_apply_limits(struct queue_limits *lim, u32 flags)
+{
+ lim->features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA | BLK_FEAT_ROTATIONAL);
+ lim->max_hw_discard_sectors = 0;
+ lim->max_write_zeroes_sectors = 0;
+
+ if (flags & NBD_FLAG_SEND_TRIM)
+ lim->max_hw_discard_sectors = UINT_MAX >> SECTOR_SHIFT;
+ if (flags & NBD_FLAG_SEND_FLUSH) {
+ lim->features |= BLK_FEAT_WRITE_CACHE;
+ if (flags & NBD_FLAG_SEND_FUA)
+ lim->features |= BLK_FEAT_FUA;
+ }
+
+ if (flags & NBD_FLAG_ROTATIONAL)
+ lim->features |= BLK_FEAT_ROTATIONAL;
+ if (flags & NBD_FLAG_SEND_WRITE_ZEROES)
+ lim->max_write_zeroes_sectors = UINT_MAX >> SECTOR_SHIFT;
+}
+
static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, loff_t blksize)
{
struct queue_limits lim;
@@ -352,23 +372,7 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, loff_t blksize)
return 0;
lim = queue_limits_start_update(nbd->disk->queue);
- if (nbd->config->flags & NBD_FLAG_SEND_TRIM)
- lim.max_hw_discard_sectors = UINT_MAX >> SECTOR_SHIFT;
- else
- lim.max_hw_discard_sectors = 0;
- if (!(nbd->config->flags & NBD_FLAG_SEND_FLUSH)) {
- lim.features &= ~(BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA);
- } else if (nbd->config->flags & NBD_FLAG_SEND_FUA) {
- lim.features |= BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA;
- } else {
- lim.features |= BLK_FEAT_WRITE_CACHE;
- lim.features &= ~BLK_FEAT_FUA;
- }
- if (nbd->config->flags & NBD_FLAG_ROTATIONAL)
- lim.features |= BLK_FEAT_ROTATIONAL;
- if (nbd->config->flags & NBD_FLAG_SEND_WRITE_ZEROES)
- lim.max_write_zeroes_sectors = UINT_MAX >> SECTOR_SHIFT;
-
+ nbd_apply_limits(&lim, nbd->config->flags);
lim.logical_block_size = blksize;
lim.physical_block_size = blksize;
error = queue_limits_commit_update_frozen(nbd->disk->queue, &lim);
@@ -1469,8 +1473,13 @@ static void nbd_config_put(struct nbd_device *nbd)
if (refcount_dec_and_mutex_lock(&nbd->config_refs,
&nbd->config_lock)) {
struct nbd_config *config = nbd->config;
+ struct queue_limits lim;
nbd_dev_dbg_close(nbd);
invalidate_disk(nbd->disk);
+ /* reset queue limits to default */
+ lim = queue_limits_start_update(nbd->disk->queue);
+ nbd_apply_limits(&lim, 0);
+ queue_limits_commit_update(nbd->disk->queue, &lim);
if (nbd->config->bytesize)
kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
if (test_and_clear_bit(NBD_RT_HAS_PID_FILE,
]
|
| 31/2 |
2026/11/28 10:01 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 35928
output: 141
thoughts: 795
Thoughts: **My Revelation on the NBD Socket Lock Order**
WHOA! Hold everything! I've just had a major realization about the NBD socket reclassification and a critical lockdep splat in our bug report. It seems like the issue stems from how sockets are being classified, specifically around `sk_lock-AF_INET6`.
I've been looking at `d532cddb6c60` and `9280e6edf656`, and a specific detail in `d532cddb6c60` ("nbd: Reclassify sockets to avoid lockdep circular dependency") jumped out at me: `nbd_reclassify_socket()` is supposed to reclassify sockets to `sk_lock-AF_INET-NBD`, `sk_lock-AF_INET6-NBD`, or `sk_lock-AF_UNIX-NBD`.
But then I looked *again* at the lockdep splat from our bug report: it shows `-> #6 (sk_lock-AF_INET6){+.+.}-{0:0}:`. My immediate thought is: **WHY is it `(sk_lock-AF_INET6)` and not `(sk_lock-AF_INET6-NBD)`?!** This is the crux of the problem.
This discrepancy makes me question a few things:
1. **Why was the NBD socket still classified as `sk_lock-AF_INET6`?**
* Could it be that `nbd_genl_connect` is passing an MPTCP socket? I need to investigate if `nbd_get_socket` actually allows MPTCP sockets, so I'll be checking `sk_is_tcp(sock->sk)`.
* Alternatively, did `nbd_reclassify_socket` skip the reclassification due to the check `if (!sock_allow_reclassification(sk))` introduced in `9280e6edf656`? This seems like a plausible bypass.
* Or, is it because `nbd_genl_connect` adds sockets through `nbd_add_socket`? I need to carefully examine `nbd_genl_connect`, `sk_is_tcp`, and `sock_allow_reclassification` together to understand the flow.
2. **This also leads me to look at `rds_tcp_recv_path`.** It's using `GFP_KERNEL` while holding `lock_sock` (`k-sk_lock-AF_INET6`). This, combined with the NBD socket still being `sk_lock-AF_INET6`, feels like a related issue or a symptom of the same underlying problem.
I'm going to dive into all of these right now: I need to meticulously read `nbd_genl_connect`, `nbd_add_socket`, `sk_is_tcp`, `sock_allow_reclassification`, and also consider the implications of `mptcp` in this context. I'm convinced the answer lies within the interplay of these functions and the socket classification logic.
|
| 32/2 |
2026/11/28 10:01 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:1235 LineCount:100]
Results: map[Contents:1235: return NULL;
1236: }
1237:
1238: return sock;
1239: }
1240:
1241: #ifdef CONFIG_DEBUG_LOCK_ALLOC
1242: static struct lock_class_key nbd_key[3];
1243: static struct lock_class_key nbd_slock_key[3];
1244:
1245: static void nbd_reclassify_socket(struct socket *sock)
1246: {
1247: struct sock *sk = sock->sk;
1248:
1249: if (!sock_allow_reclassification(sk))
1250: return;
1251:
1252: switch (sk->sk_family) {
1253: case AF_INET:
1254: sock_lock_init_class_and_name(sk, "slock-AF_INET-NBD",
1255: &nbd_slock_key[0],
1256: "sk_lock-AF_INET-NBD",
1257: &nbd_key[0]);
1258: break;
1259: case AF_INET6:
1260: sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD",
1261: &nbd_slock_key[1],
1262: "sk_lock-AF_INET6-NBD",
1263: &nbd_key[1]);
1264: break;
1265: case AF_UNIX:
1266: sock_lock_init_class_and_name(sk, "slock-AF_UNIX-NBD",
1267: &nbd_slock_key[2],
1268: "sk_lock-AF_UNIX-NBD",
1269: &nbd_key[2]);
1270: break;
1271: }
1272: }
1273: #else
1274: static inline void nbd_reclassify_socket(struct socket *sock) {}
1275: #endif
1276:
1277: static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
1278: bool netlink)
1279: {
1280: struct nbd_config *config = nbd->config;
1281: struct socket *sock;
1282: struct nbd_sock **socks;
1283: struct nbd_sock *nsock;
1284: int err;
1285:
1286: /* Arg will be cast to int, check it to avoid overflow */
1287: if (arg > INT_MAX)
1288: return -EINVAL;
1289:
1290: if (nbd->pid) {
1291: dev_err(disk_to_dev(nbd->disk),
1292: "Cannot add socket to a running device\n");
1293: return -EBUSY;
1294: }
1295:
1296: sock = nbd_get_socket(nbd, arg, &err);
1297: if (!sock)
1298: return err;
1299: nbd_reclassify_socket(sock);
1300:
1301: if (!netlink && !nbd->task_setup &&
1302: !test_bit(NBD_RT_BOUND, &config->runtime_flags))
1303: nbd->task_setup = current;
1304:
1305: if (!netlink &&
1306: (nbd->task_setup != current ||
1307: test_bit(NBD_RT_BOUND, &config->runtime_flags))) {
1308: dev_err(disk_to_dev(nbd->disk),
1309: "Device being setup by another task");
1310: err = -EBUSY;
1311: goto put_socket;
1312: }
1313:
1314: nsock = kzalloc_obj(*nsock);
1315: if (!nsock) {
1316: err = -ENOMEM;
1317: goto put_socket;
1318: }
1319:
1320: socks = krealloc(config->socks, (config->num_connections + 1) *
1321: sizeof(struct nbd_sock *), GFP_KERNEL);
1322: if (!socks) {
1323: kfree(nsock);
1324: err = -ENOMEM;
1325: goto put_socket;
1326: }
1327:
1328: config->socks = socks;
1329:
1330: nsock->fallback_index = -1;
1331: nsock->dead = false;
1332: mutex_init(&nsock->tx_lock);
1333: nsock->sock = sock;
1334: nsock->pending = NULL;
]
|
| 33/2 |
2026/11/28 10:01 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:2230 LineCount:110]
Results: map[Contents:2230:
2231: mutex_lock(&nbd->config_lock);
2232: if (refcount_read(&nbd->config_refs)) {
2233: mutex_unlock(&nbd->config_lock);
2234: nbd_put(nbd);
2235: if (index == -1)
2236: goto again;
2237: pr_err("nbd%d already in use\n", index);
2238: return -EBUSY;
2239: }
2240:
2241: ret = nbd_alloc_and_init_config(nbd);
2242: if (ret) {
2243: mutex_unlock(&nbd->config_lock);
2244: nbd_put(nbd);
2245: pr_err("couldn't allocate config\n");
2246: return ret;
2247: }
2248:
2249: config = nbd->config;
2250: set_bit(NBD_RT_BOUND, &config->runtime_flags);
2251: ret = nbd_genl_size_set(info, nbd);
2252: if (ret)
2253: goto out;
2254:
2255: if (info->attrs[NBD_ATTR_TIMEOUT])
2256: nbd_set_cmd_timeout(nbd,
2257: nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]));
2258: if (info->attrs[NBD_ATTR_DEAD_CONN_TIMEOUT]) {
2259: config->dead_conn_timeout =
2260: nla_get_u64(info->attrs[NBD_ATTR_DEAD_CONN_TIMEOUT]);
2261: config->dead_conn_timeout *= HZ;
2262: }
2263: if (info->attrs[NBD_ATTR_SERVER_FLAGS])
2264: config->flags =
2265: nla_get_u64(info->attrs[NBD_ATTR_SERVER_FLAGS]);
2266: if (info->attrs[NBD_ATTR_CLIENT_FLAGS]) {
2267: u64 flags = nla_get_u64(info->attrs[NBD_ATTR_CLIENT_FLAGS]);
2268: if (flags & NBD_CFLAG_DESTROY_ON_DISCONNECT) {
2269: /*
2270: * We have 1 ref to keep the device around, and then 1
2271: * ref for our current operation here, which will be
2272: * inherited by the config. If we already have
2273: * DESTROY_ON_DISCONNECT set then we know we don't have
2274: * that extra ref already held so we don't need the
2275: * put_dev.
2276: */
2277: if (!test_and_set_bit(NBD_DESTROY_ON_DISCONNECT,
2278: &nbd->flags))
2279: put_dev = true;
2280: } else {
2281: if (test_and_clear_bit(NBD_DESTROY_ON_DISCONNECT,
2282: &nbd->flags))
2283: refcount_inc(&nbd->refs);
2284: }
2285: if (flags & NBD_CFLAG_DISCONNECT_ON_CLOSE) {
2286: set_bit(NBD_RT_DISCONNECT_ON_CLOSE,
2287: &config->runtime_flags);
2288: }
2289: }
2290:
2291: ret = nbd_genl_foreach_sock(info, nbd_genl_connect_sock_cb, nbd);
2292: if (ret < 0)
2293: goto out;
2294:
2295: if (info->attrs[NBD_ATTR_BACKEND_IDENTIFIER]) {
2296: nbd->backend = nla_strdup(info->attrs[NBD_ATTR_BACKEND_IDENTIFIER],
2297: GFP_KERNEL);
2298: if (!nbd->backend) {
2299: ret = -ENOMEM;
2300: goto out;
2301: }
2302: }
2303: ret = device_create_file(disk_to_dev(nbd->disk), &backend_attr);
2304: if (ret) {
2305: dev_err(disk_to_dev(nbd->disk),
2306: "device_create_file failed for backend!\n");
2307: goto out;
2308: }
2309: set_bit(NBD_RT_HAS_BACKEND_FILE, &config->runtime_flags);
2310:
2311: ret = nbd_start_device(nbd);
2312: out:
2313: if (!ret) {
2314: set_bit(NBD_RT_HAS_CONFIG_REF, &config->runtime_flags);
2315: refcount_inc(&nbd->config_refs);
2316: nbd_connect_reply(info, nbd->index);
2317: }
2318: mutex_unlock(&nbd->config_lock);
2319:
2320: nbd_config_put(nbd);
2321: if (put_dev)
2322: nbd_put(nbd);
2323: return ret;
2324: }
2325:
2326: static void nbd_disconnect_and_put(struct nbd_device *nbd)
2327: {
2328: mutex_lock(&nbd->config_lock);
2329: nbd_disconnect(nbd);
]
|
| 34/2 |
2026/11/28 10:01 |
tool |
grepper |
0m
Args: map[Expression:sk_is_tcp|sock_allow_reclassification]
Results: map[Output:
Full output is too long, showing 200 out of 339 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (31 files in total):
drivers/block/nbd.c:2
drivers/infiniband/sw/rxe/rxe_net.c:1
drivers/infiniband/sw/rxe/rxe_qp.c:1
drivers/infiniband/sw/siw/siw_cm.c:1
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c:3
drivers/nvme/host/tcp.c:1
drivers/scsi/iscsi_tcp.c:1
fs/smb/client/connect.c:2
include/net/ip.h:1
include/net/sock.h:2
include/net/tcp.h:2
net/bluetooth/af_bluetooth.c:1
net/core/filter.c:4
net/core/skbuff.c:3
net/core/skmsg.c:1
net/core/sock.c:10
net/core/sock_map.c:6
net/core/sock_reuseport.c:1
net/ipv4/ip_output.c:1
net/ipv4/tcp_bpf.c:1
net/ipv6/ip6_output.c:1
net/kcm/kcmsock.c:1
net/mptcp/bpf.c:1
net/psp/psp_nl.c:1
net/sched/sch_fq.c:1
net/sunrpc/svcsock.c:1
net/sunrpc/xprtsock.c:1
security/apparmor/lsm.c:1
security/landlock/net.c:3
security/selinux/hooks.c:1
tools/testing/selftests/bpf/progs/setget_sockopt.c:2
drivers/block/nbd.c=1213=static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
--
drivers/block/nbd.c-1222-
drivers/block/nbd.c:1223: if (!sk_is_tcp(sock->sk) &&
drivers/block/nbd.c-1224- !sk_is_stream_unix(sock->sk)) {
--
drivers/block/nbd.c=1245=static void nbd_reclassify_socket(struct socket *sock)
--
drivers/block/nbd.c-1248-
drivers/block/nbd.c:1249: if (!sock_allow_reclassification(sk))
drivers/block/nbd.c-1250- return;
--
drivers/infiniband/sw/rxe/rxe_net.c=45=static inline void rxe_reclassify_recv_socket(struct socket *sock)
--
drivers/infiniband/sw/rxe/rxe_net.c-49-
drivers/infiniband/sw/rxe/rxe_net.c:50: if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
drivers/infiniband/sw/rxe/rxe_net.c-51- return;
--
drivers/infiniband/sw/rxe/rxe_qp.c=37=static inline void rxe_reclassify_send_socket(struct socket *sock)
--
drivers/infiniband/sw/rxe/rxe_qp.c-41-
drivers/infiniband/sw/rxe/rxe_qp.c:42: if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
drivers/infiniband/sw/rxe/rxe_qp.c-43- return;
--
drivers/infiniband/sw/siw/siw_cm.c=62=static inline void siw_reclassify_socket(struct socket *sock)
--
drivers/infiniband/sw/siw/siw_cm.c-66-
drivers/infiniband/sw/siw/siw_cm.c:67: if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
drivers/infiniband/sw/siw/siw_cm.c-68- return;
--
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c=16=static bool dr_mask_is_l3_base_set(struct mlx5dr_match_spec *spec)
--
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c-21-
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c:22:static bool dr_mask_is_tcp_udp_base_set(struct mlx5dr_match_spec *spec)
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c-23-{
--
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c=33=static bool dr_mask_is_ipv4_5_tuple_set(struct mlx5dr_match_spec *spec)
--
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c-35- return (dr_mask_is_l3_base_set(spec) ||
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c:36: dr_mask_is_tcp_udp_base_set(spec) ||
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c-37- dr_mask_is_ipv4_set(spec));
--
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c=50=static bool dr_mask_is_ipv4_ihl_set(struct mlx5dr_match_spec *spec)
--
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c-66- dr_mask_is_l3_base_set(&(_spec)) || \
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c:67: dr_mask_is_tcp_udp_base_set(&(_spec)) || \
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_matcher.c-68- dr_mask_is_ttl_set(&(_spec)) || \
--
drivers/nvme/host/tcp.c=228=static void nvme_tcp_reclassify_socket(struct socket *sock)
--
drivers/nvme/host/tcp.c-231-
drivers/nvme/host/tcp.c:232: if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
drivers/nvme/host/tcp.c-233- return;
--
drivers/scsi/iscsi_tcp.c=664=iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
--
drivers/scsi/iscsi_tcp.c-683- err = -EINVAL;
drivers/scsi/iscsi_tcp.c:684: if (!sk_is_tcp(sock->sk))
drivers/scsi/iscsi_tcp.c-685- goto free_socket;
--
fs/smb/client/connect.c=3144=cifs_reclassify_socket4(struct socket *sock)
--
fs/smb/client/connect.c-3147-
fs/smb/client/connect.c:3148: BUG_ON(!sock_allow_reclassification(sk));
fs/smb/client/connect.c-3149- sock_lock_init_class_and_name(sk, "slock-AF_INET-CIFS",
--
fs/smb/client/connect.c=3154=cifs_reclassify_socket6(struct socket *sock)
--
fs/smb/client/connect.c-3157-
fs/smb/client/connect.c:3158: BUG_ON(!sock_allow_reclassification(sk));
fs/smb/client/connect.c-3159- sock_lock_init_class_and_name(sk, "slock-AF_INET6-CIFS",
--
include/net/ip.h=564=static inline void ip_select_ident_segs(struct net *net, struct sk_buff *skb,
--
include/net/ip.h-584- */
include/net/ip.h:585: if (sk_is_tcp(sk)) {
include/net/ip.h-586- sock_owned_by_me(sk);
--
include/net/sock.h=1825=static inline void sock_release_ownership(struct sock *sk)
--
include/net/sock.h-1834-/* no reclassification while locks are held */
include/net/sock.h:1835:static inline bool sock_allow_reclassification(const struct sock *csk)
include/net/sock.h-1836-{
--
include/net/sock.h=2976=static inline bool sk_is_inet(const struct sock *sk)
--
include/net/sock.h-2982-
include/net/sock.h:2983:static inline bool sk_is_tcp(const struct sock *sk)
include/net/sock.h-2984-{
--
include/net/tcp.h=802=static inline void tcp_set_nospace(struct sock *sk)
include/net/tcp.h-803-{
include/net/tcp.h:804: if (sk_is_tcp(sk)) {
include/net/tcp.h-805- /* pairs with smp_mb__before_atomic() in tcp_clear_nospace() */
--
include/net/tcp.h=812=static inline void tcp_clear_nospace(struct sock *sk)
include/net/tcp.h-813-{
include/net/tcp.h:814: if (sk_is_tcp(sk) && !sk_is_mptcp(sk)) {
include/net/tcp.h-815- WRITE_ONCE(tcp_sk(sk)->tcp_nospace, 0);
--
net/bluetooth/af_bluetooth.c=71=void bt_sock_reclassify_lock(struct sock *sk, int proto)
--
net/bluetooth/af_bluetooth.c-73- BUG_ON(!sk);
net/bluetooth/af_bluetooth.c:74: BUG_ON(!sock_allow_reclassification(sk));
net/bluetooth/af_bluetooth.c-75-
--
net/core/filter.c=5732=static int sol_tcp_sockopt(struct sock *sk, int optname,
--
net/core/filter.c-5735-{
net/core/filter.c:5736: if (!sk_is_tcp(sk))
net/core/filter.c-5737- return -EINVAL;
--
net/core/filter.c=7849=BPF_CALL_1(bpf_tcp_sock, struct sock *, sk)
net/core/filter.c-7850-{
net/core/filter.c:7851: if (sk_fullsock(sk) && sk_is_tcp(sk))
net/core/filter.c-7852- return (unsigned long)sk;
--
net/core/filter.c=12102=BPF_CALL_3(bpf_sk_lookup_assign, struct bpf_sk_lookup_kern *, ctx,
--
net/core/filter.c-12109- return -ESOCKTNOSUPPORT; /* reject non-RCU freed sockets */
net/core/filter.c:12110: if (unlikely(sk && sk_is_tcp(sk) && sk->sk_state != TCP_LISTEN))
net/core/filter.c-12111- return -ESOCKTNOSUPPORT; /* only accept TCP socket in LISTEN */
--
net/core/filter.c=12343=BPF_CALL_1(bpf_skc_to_tcp_sock, struct sock *, sk)
net/core/filter.c-12344-{
net/core/filter.c:12345: if (sk && sk_fullsock(sk) && sk_is_tcp(sk))
net/core/filter.c-12346- return (unsigned long)sk;
--
net/core/skbuff.c=3334=static int __skb_send_sock(struct sock *sk, struct sk_buff *skb, int offset,
--
net/core/skbuff.c-3336-{
net/core/skbuff.c:3337: int more_hint = sk_is_tcp(sk) ? MSG_MORE : 0;
net/core/skbuff.c-3338- unsigned int orig_len = len;
--
net/core/skbuff.c=5693=static void __skb_complete_tx_timestamp(struct sk_buff *skb,
--
net/core/skbuff.c-5711- serr->ee.ee_data = skb_shinfo(skb)->tskey;
net/core/skbuff.c:5712: if (sk_is_tcp(sk))
net/core/skbuff.c-5713- serr->ee.ee_data -= atomic_read(&sk->sk_tskey);
--
net/core/skbuff.c=5820=void __skb_tstamp_tx(struct sk_buff *orig_skb,
--
net/core/skbuff.c-5850- if ((tsflags & SOF_TIMESTAMPING_OPT_STATS) &&
net/core/skbuff.c:5851: sk_is_tcp(sk)) {
net/core/skbuff.c-5852- skb = tcp_get_timestamping_opt_stats(sk, orig_skb,
--
net/core/skmsg.c=1158=int sk_psock_init_strp(struct sock *sk, struct sk_psock *psock)
--
net/core/skmsg.c-1171-
net/core/skmsg.c:1172: if (sk_is_tcp(sk)) {
net/core/skmsg.c-1173- psock->strp.cb.read_sock = tcp_bpf_strp_read_sock;
--
net/core/sock.c=894=int sock_set_timestamping(struct sock *sk, int optname,
--
net/core/sock.c-908- !(sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID)) {
net/core/sock.c:909: if (sk_is_tcp(sk)) {
net/core/sock.c-910- if ((1 << sk->sk_state) &
--
net/core/sock.c=1033=static int sock_reserve_memory(struct sock *sk, int bytes)
--
net/core/sock.c-1038-
net/core/sock.c:1039: if (!mem_cgroup_sk_enabled(sk) || !sk_is_tcp(sk))
net/core/sock.c-1040- return -EOPNOTSUPP;
--
net/core/sock.c=1089=sock_devmem_dontneed(struct sock *sk, sockptr_t optval, unsigned int optlen)
--
net/core/sock.c-1095-
net/core/sock.c:1096: if (!sk_is_tcp(sk))
net/core/sock.c-1097- return -EBADF;
--
net/core/sock.c=1196=int sk_setsockopt(struct sock *sk, int level, int optname,
--
net/core/sock.c-1276- case SO_TXREHASH:
net/core/sock.c:1277: if (!sk_is_tcp(sk))
net/core/sock.c-1278- return -EOPNOTSUPP;
--
net/core/sock.c-1468-
net/core/sock.c:1469: if (sk_is_tcp(sk) &&
net/core/sock.c-1470- !sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
--
net/core/sock.c-1606- if (sk->sk_family == PF_INET || sk->sk_family == PF_INET6) {
net/core/sock.c:1607: if (!(sk_is_tcp(sk) ||
net/core/sock.c-1608- (sk->sk_type == SOCK_DGRAM &&
--
net/core/sock.c=1786=int sk_getsockopt(struct sock *sk, int level, int optname,
--
net/core/sock.c-2186- case SO_TXREHASH:
net/core/sock.c:2187: if (!sk_is_tcp(sk))
net/core/sock.c-2188- return -EOPNOTSUPP;
--
net/core/sock.c=2654=static u32 sk_dst_gso_max_size(struct sock *sk, const struct net_device *dev)
--
net/core/sock.c-2665- READ_ONCE(dev->gso_ipv4_max_size);
net/core/sock.c:2666: if (max_size > GSO_LEGACY_MAX_SIZE && !sk_is_tcp(sk))
net/core/sock.c-2667- max_size = GSO_LEGACY_MAX_SIZE;
--
net/core/sock.c=2672=void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
--
net/core/sock.c-2679- sk->sk_route_caps = dev->features;
net/core/sock.c:2680: if (sk_is_tcp(sk)) {
]
|
| 35/2 |
2026/11/28 10:01 |
tool |
git-show |
0m
Args: map[Commit:ffa1e7ada456 Stat:true]
Results: map[Output:commit ffa1e7ada456087c2402b37cd6b2863ced29aff0
Author: Thomas HellstrΓΆm <thomas.hellstrom@linux.intel.com>
Date: Tue Mar 18 10:55:48 2025 +0100
block: Make request_queue lockdep splats show up earlier
In recent kernels, there are lockdep splats around the
struct request_queue::io_lockdep_map, similar to [1], but they
typically don't show up until reclaim with writeback happens.
Having multiple kernel versions released with a known risc of kernel
deadlock during reclaim writeback should IMHO be addressed and
backported to -stable with the highest priority.
In order to have these lockdep splats show up earlier,
preferrably during system initialization, prime the
struct request_queue::io_lockdep_map as GFP_KERNEL reclaim-
tainted. This will instead lead to lockdep splats looking similar
to [2], but without the need for reclaim + writeback
happening.
[1]:
[ 189.762244] ======================================================
[ 189.762432] WARNING: possible circular locking dependency detected
[ 189.762441] 6.14.0-rc6-xe+ #6 Tainted: G U
[ 189.762450] ------------------------------------------------------
[ 189.762459] kswapd0/119 is trying to acquire lock:
[ 189.762467] ffff888110ceb710 (&q->q_usage_counter(io)#26){++++}-{0:0}, at: __submit_bio+0x76/0x230
[ 189.762485]
but task is already holding lock:
[ 189.762494] ffffffff834c97c0 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0xbe/0xb00
[ 189.762507]
which lock already depends on the new lock.
[ 189.762519]
the existing dependency chain (in reverse order) is:
[ 189.762529]
-> #2 (fs_reclaim){+.+.}-{0:0}:
[ 189.762540] fs_reclaim_acquire+0xc5/0x100
[ 189.762548] kmem_cache_alloc_lru_noprof+0x4a/0x480
[ 189.762558] alloc_inode+0xaa/0xe0
[ 189.762566] iget_locked+0x157/0x330
[ 189.762573] kernfs_get_inode+0x1b/0x110
[ 189.762582] kernfs_get_tree+0x1b0/0x2e0
[ 189.762590] sysfs_get_tree+0x1f/0x60
[ 189.762597] vfs_get_tree+0x2a/0xf0
[ 189.762605] path_mount+0x4cd/0xc00
[ 189.762613] __x64_sys_mount+0x119/0x150
[ 189.762621] x64_sys_call+0x14f2/0x2310
[ 189.762630] do_syscall_64+0x91/0x180
[ 189.762637] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 189.762647]
-> #1 (&root->kernfs_rwsem){++++}-{3:3}:
[ 189.762659] down_write+0x3e/0xf0
[ 189.762667] kernfs_remove+0x32/0x60
[ 189.762676] sysfs_remove_dir+0x4f/0x60
[ 189.762685] __kobject_del+0x33/0xa0
[ 189.762709] kobject_del+0x13/0x30
[ 189.762716] elv_unregister_queue+0x52/0x80
[ 189.762725] elevator_switch+0x68/0x360
[ 189.762733] elv_iosched_store+0x14b/0x1b0
[ 189.762756] queue_attr_store+0x181/0x1e0
[ 189.762765] sysfs_kf_write+0x49/0x80
[ 189.762773] kernfs_fop_write_iter+0x17d/0x250
[ 189.762781] vfs_write+0x281/0x540
[ 189.762790] ksys_write+0x72/0xf0
[ 189.762798] __x64_sys_write+0x19/0x30
[ 189.762807] x64_sys_call+0x2a3/0x2310
[ 189.762815] do_syscall_64+0x91/0x180
[ 189.762823] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 189.762833]
-> #0 (&q->q_usage_counter(io)#26){++++}-{0:0}:
[ 189.762845] __lock_acquire+0x1525/0x2760
[ 189.762854] lock_acquire+0xca/0x310
[ 189.762861] blk_mq_submit_bio+0x8a2/0xba0
[ 189.762870] __submit_bio+0x76/0x230
[ 189.762878] submit_bio_noacct_nocheck+0x323/0x430
[ 189.762888] submit_bio_noacct+0x2cc/0x620
[ 189.762896] submit_bio+0x38/0x110
[ 189.762904] __swap_writepage+0xf5/0x380
[ 189.762912] swap_writepage+0x3c7/0x600
[ 189.762920] shmem_writepage+0x3da/0x4f0
[ 189.762929] pageout+0x13f/0x310
[ 189.762937] shrink_folio_list+0x61c/0xf60
[ 189.763261] evict_folios+0x378/0xcd0
[ 189.763584] try_to_shrink_lruvec+0x1b0/0x360
[ 189.763946] shrink_one+0x10e/0x200
[ 189.764266] shrink_node+0xc02/0x1490
[ 189.764586] balance_pgdat+0x563/0xb00
[ 189.764934] kswapd+0x1e8/0x430
[ 189.765249] kthread+0x10b/0x260
[ 189.765559] ret_from_fork+0x44/0x70
[ 189.765889] ret_from_fork_asm+0x1a/0x30
[ 189.766198]
other info that might help us debug this:
[ 189.767089] Chain exists of:
&q->q_usage_counter(io)#26 --> &root->kernfs_rwsem --> fs_reclaim
[ 189.767971] Possible unsafe locking scenario:
[ 189.768555] CPU0 CPU1
[ 189.768849] ---- ----
[ 189.769136] lock(fs_reclaim);
[ 189.769421] lock(&root->kernfs_rwsem);
[ 189.769714] lock(fs_reclaim);
[ 189.770016] rlock(&q->q_usage_counter(io)#26);
[ 189.770305]
*** DEADLOCK ***
[ 189.771167] 1 lock held by kswapd0/119:
[ 189.771453] #0: ffffffff834c97c0 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0xbe/0xb00
[ 189.771770]
stack backtrace:
[ 189.772351] CPU: 4 UID: 0 PID: 119 Comm: kswapd0 Tainted: G U 6.14.0-rc6-xe+ #6
[ 189.772353] Tainted: [U]=USER
[ 189.772354] Hardware name: ASUS System Product Name/PRIME B560M-A AC, BIOS 2001 02/01/2023
[ 189.772354] Call Trace:
[ 189.772355] <TASK>
[ 189.772356] dump_stack_lvl+0x6e/0xa0
[ 189.772359] dump_stack+0x10/0x18
[ 189.772360] print_circular_bug.cold+0x17a/0x1b7
[ 189.772363] check_noncircular+0x13a/0x150
[ 189.772365] ? __pfx_stack_trace_consume_entry+0x10/0x10
[ 189.772368] __lock_acquire+0x1525/0x2760
[ 189.772368] ? ret_from_fork_asm+0x1a/0x30
[ 189.772371] lock_acquire+0xca/0x310
[ 189.772372] ? __submit_bio+0x76/0x230
[ 189.772375] ? lock_release+0xd5/0x2c0
[ 189.772376] blk_mq_submit_bio+0x8a2/0xba0
[ 189.772378] ? __submit_bio+0x76/0x230
[ 189.772380] __submit_bio+0x76/0x230
[ 189.772382] ? trace_hardirqs_on+0x1e/0xe0
[ 189.772384] submit_bio_noacct_nocheck+0x323/0x430
[ 189.772386] ? submit_bio_noacct_nocheck+0x323/0x430
[ 189.772387] ? __might_sleep+0x58/0xa0
[ 189.772390] submit_bio_noacct+0x2cc/0x620
[ 189.772391] ? count_memcg_events+0x68/0x90
[ 189.772393] submit_bio+0x38/0x110
[ 189.772395] __swap_writepage+0xf5/0x380
[ 189.772396] swap_writepage+0x3c7/0x600
[ 189.772397] shmem_writepage+0x3da/0x4f0
[ 189.772401] pageout+0x13f/0x310
[ 189.772406] shrink_folio_list+0x61c/0xf60
[ 189.772409] ? isolate_folios+0xe80/0x16b0
[ 189.772410] ? mark_held_locks+0x46/0x90
[ 189.772412] evict_folios+0x378/0xcd0
[ 189.772414] ? evict_folios+0x34a/0xcd0
[ 189.772415] ? lock_is_held_type+0xa3/0x130
[ 189.772417] try_to_shrink_lruvec+0x1b0/0x360
[ 189.772420] shrink_one+0x10e/0x200
[ 189.772421] shrink_node+0xc02/0x1490
[ 189.772423] ? shrink_node+0xa08/0x1490
[ 189.772424] ? shrink_node+0xbd8/0x1490
[ 189.772425] ? mem_cgroup_iter+0x366/0x480
[ 189.772427] balance_pgdat+0x563/0xb00
[ 189.772428] ? balance_pgdat+0x563/0xb00
[ 189.772430] ? trace_hardirqs_on+0x1e/0xe0
[ 189.772431] ? finish_task_switch.isra.0+0xcb/0x330
[ 189.772433] ? __switch_to_asm+0x33/0x70
[ 189.772437] kswapd+0x1e8/0x430
[ 189.772438] ? __pfx_autoremove_wake_function+0x10/0x10
[ 189.772440] ? __pfx_kswapd+0x10/0x10
[ 189.772441] kthread+0x10b/0x260
[ 189.772443] ? __pfx_kthread+0x10/0x10
[ 189.772444] ret_from_fork+0x44/0x70
[ 189.772446] ? __pfx_kthread+0x10/0x10
[ 189.772447] ret_from_fork_asm+0x1a/0x30
[ 189.772450] </TASK>
[2]:
[ 8.760253] ======================================================
[ 8.760254] WARNING: possible circular locking dependency detected
[ 8.760255] 6.14.0-rc6-xe+ #7 Tainted: G U
[ 8.760256] ------------------------------------------------------
[ 8.760257] (udev-worker)/674 is trying to acquire lock:
[ 8.760259] ffff888100e39148 (&root->kernfs_rwsem){++++}-{3:3}, at: kernfs_remove+0x32/0x60
[ 8.760265]
but task is already holding lock:
[ 8.760266] ffff888110dc7680 (&q->q_usage_counter(io)#27){++++}-{0:0}, at: blk_mq_freeze_queue_nomemsave+0x12/0x30
[ 8.760272]
which lock already depends on the new lock.
[ 8.760272]
the existing dependency chain (in reverse order) is:
[ 8.760273]
-> #2 (&q->q_usage_counter(io)#27){++++}-{0:0}:
[ 8.760276] blk_alloc_queue+0x30a/0x350
[ 8.760279] blk_mq_alloc_queue+0x6b/0xe0
[ 8.760281] scsi_alloc_sdev+0x276/0x3c0
[ 8.760284] scsi_probe_and_add_lun+0x22a/0x440
[ 8.760286] __scsi_scan_target+0x109/0x230
[ 8.760288] scsi_scan_channel+0x65/0xc0
[ 8.760290] scsi_scan_host_selected+0xff/0x140
[ 8.760292] do_scsi_scan_host+0xa7/0xc0
[ 8.760293] do_scan_async+0x1c/0x160
[ 8.760295] async_run_entry_fn+0x32/0x150
[ 8.760299] process_one_work+0x224/0x5f0
[ 8.760302] worker_thread+0x1d4/0x3e0
[ 8.760304] kthread+0x10b/0x260
[ 8.760306] ret_from_fork+0x44/0x70
[ 8.760309] ret_from_fork_asm+0x1a/0x30
[ 8.760312]
-> #1 (fs_reclaim){+.+.}-{0:0}:
[ 8.760315] fs_reclaim_acquire+0xc5/0x100
[ 8.760317] kmem_cache_alloc_lru_noprof+0x4a/0x480
[ 8.760319] alloc_inode+0xaa/0xe0
[ 8.760322] iget_locked+0x157/0x330
[ 8.760323] kernfs_get_inode+0x1b/0x110
[ 8.760325] kernfs_get_tree+0x1b0/0x2e0
[ 8.760327] sysfs_get_tree+0x1f/0x60
[ 8.760329] vfs_get_tree+0x2a/0xf0
[ 8.760332] path_mount+0x4cd/0xc00
[ 8.760334] __x64_sys_mount+0x119/0x150
[ 8.760336] x64_sys_call+0x14f2/0x2310
[ 8.760338] do_syscall_64+0x91/0x180
[ 8.760340] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 8.760342]
-> #0 (&root->kernfs_rwsem){++++}-{3:3}:
[ 8.760345] __lock_acquire+0x1525/0x2760
[ 8.760347] lock_acquire+0xca/0x310
[ 8.760348] down_write+0x3e/0xf0
[ 8.760350] kernfs_remove+0x32/0x60
[ 8.760351] sysfs_remove_dir+0x4f/0x60
[ 8.760353] __kobject_del+0x33/0xa0
[ 8.760355] kobject_del+0x13/0x30
[ 8.760356] elv_unregister_queue+0x52/0x80
[ 8.760358] elevator_switch+0x68/0x360
[ 8.760360] elv_iosched_store+0x14b/0x1b0
[ 8.760362] queue_attr_store+0x181/0x1e0
[ 8.760364] sysfs_kf_write+0x49/0x80
[ 8.760366] kernfs_fop_write_iter+0x17d/0x250
[ 8.760367] vfs_write+0x281/0x540
[ 8.760370] ksys_write+0x72/0xf0
[ 8.760372] __x64_sys_write+0x19/0x30
[ 8.760374] x64_sys_call+0x2a3/0x2310
[ 8.760376] do_syscall_64+0x91/0x180
[ 8.760377] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 8.760380]
other info that might help us debug this:
[ 8.760380] Chain exists of:
&root->kernfs_rwsem --> fs_reclaim --> &q->q_usage_counter(io)#27
[ 8.760384] Possible unsafe locking scenario:
[ 8.760384] CPU0 CPU1
[ 8.760385] ---- ----
[ 8.760385] lock(&q->q_usage_counter(io)#27);
[ 8.760387] lock(fs_reclaim);
[ 8.760388] lock(&q->q_usage_counter(io)#27);
[ 8.760390] lock(&root->kernfs_rwsem);
[ 8.760391]
*** DEADLOCK ***
[ 8.760391] 6 locks held by (udev-worker)/674:
[ 8.760392] #0: ffff8881209ac420 (sb_writers#4){.+.+}-{0:0}, at: ksys_write+0x72/0xf0
[ 8.760398] #1: ffff88810c80f488 (&of->mutex#2){+.+.}-{3:3}, at: kernfs_fop_write_iter+0x136/0x250
[ 8.760402] #2: ffff888125d1d330 (kn->active#101){.+.+}-{0:0}, at: kernfs_fop_write_iter+0x13f/0x250
[ 8.760406] #3: ffff888110dc7bb0 (&q->sysfs_lock){+.+.}-{3:3}, at: queue_attr_store+0x148/0x1e0
[ 8.760411] #4: ffff888110dc7680 (&q->q_usage_counter(io)#27){++++}-{0:0}, at: blk_mq_freeze_queue_nomemsave+0x12/0x30
[ 8.760416] #5: ffff888110dc76b8 (&q->q_usage_counter(queue)#27){++++}-{0:0}, at: blk_mq_freeze_queue_nomemsave+0x12/0x30
[ 8.760421]
stack backtrace:
[ 8.760422] CPU: 7 UID: 0 PID: 674 Comm: (udev-worker) Tainted: G U 6.14.0-rc6-xe+ #7
[ 8.760424] Tainted: [U]=USER
[ 8.760425] Hardware name: ASUS System Product Name/PRIME B560M-A AC, BIOS 2001 02/01/2023
[ 8.760426] Call Trace:
[ 8.760427] <TASK>
[ 8.760428] dump_stack_lvl+0x6e/0xa0
[ 8.760431] dump_stack+0x10/0x18
[ 8.760433] print_circular_bug.cold+0x17a/0x1b7
[ 8.760437] check_noncircular+0x13a/0x150
[ 8.760441] ? save_trace+0x54/0x360
[ 8.760445] __lock_acquire+0x1525/0x2760
[ 8.760446] ? irqentry_exit+0x3a/0xb0
[ 8.760448] ? sysvec_apic_timer_interrupt+0x57/0xc0
[ 8.760452] lock_acquire+0xca/0x310
[ 8.760453] ? kernfs_remove+0x32/0x60
[ 8.760457] down_write+0x3e/0xf0
[ 8.760459] ? kernfs_remove+0x32/0x60
[ 8.760460] kernfs_remove+0x32/0x60
[ 8.760462] sysfs_remove_dir+0x4f/0x60
[ 8.760464] __kobject_del+0x33/0xa0
[ 8.760466] kobject_del+0x13/0x30
[ 8.760467] elv_unregister_queue+0x52/0x80
[ 8.760470] elevator_switch+0x68/0x360
[ 8.760472] elv_iosched_store+0x14b/0x1b0
[ 8.760475] queue_attr_store+0x181/0x1e0
[ 8.760479] ? lock_acquire+0xca/0x310
[ 8.760480] ? kernfs_fop_write_iter+0x13f/0x250
[ 8.760482] ? lock_is_held_type+0xa3/0x130
[ 8.760485] sysfs_kf_write+0x49/0x80
[ 8.760487] kernfs_fop_write_iter+0x17d/0x250
[ 8.760489] vfs_write+0x281/0x540
[ 8.760494] ksys_write+0x72/0xf0
[ 8.760497] __x64_sys_write+0x19/0x30
[ 8.760499] x64_sys_call+0x2a3/0x2310
[ 8.760502] do_syscall_64+0x91/0x180
[ 8.760504] ? trace_hardirqs_off+0x5d/0xe0
[ 8.760506] ? handle_softirqs+0x479/0x4d0
[ 8.760508] ? hrtimer_interrupt+0x13f/0x280
[ 8.760511] ? irqentry_exit_to_user_mode+0x8b/0x260
[ 8.760513] ? clear_bhb_loop+0x15/0x70
[ 8.760515] ? clear_bhb_loop+0x15/0x70
[ 8.760516] ? clear_bhb_loop+0x15/0x70
[ 8.760518] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 8.760520] RIP: 0033:0x7aa3bf2f5504
[ 8.760522] Code: c7 00 16 00 00 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 80 3d c5 8b 10 00 00 74 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 55 48 89 e5 48 83 ec 20 48 89
[ 8.760523] RSP: 002b:00007ffc1e3697d8 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
[ 8.760526] RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007aa3bf2f5504
[ 8.760527] RDX: 0000000000000003 RSI: 00007ffc1e369ae0 RDI: 000000000000001c
[ 8.760528] RBP: 00007ffc1e369800 R08: 00007aa3bf3f51c8 R09: 00007ffc1e3698b0
[ 8.760528] R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000003
[ 8.760529] R13: 00007ffc1e369ae0 R14: 0000613ccf21f2f0 R15: 00007aa3bf3f4e80
[ 8.760533] </TASK>
v2:
- Update a code comment to increase readability (Ming Lei).
Cc: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Thomas HellstrΓΆm <thomas.hellstrom@linux.intel.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250318095548.5187-1-thomas.hellstrom@linux.intel.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-core.c | 6 ++++++
1 file changed, 6 insertions(+)
]
|
| 36/2 |
2026/11/28 10:01 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 53864
output: 163
thoughts: 464
Thoughts: **Deconstructing the NBD Socket Reclassification Puzzle**
My immediate thought upon seeing the commits `d532cddb6c60` and `9280e6edf656` related to NBD socket reclassification, and the mention of `sk_is_tcp`, is one of profound suspicion and a need for immediate, deep investigation. There's a palpable sense of something not quite adding up, a potential disconnect that needs to be unearthed.
My primary line of inquiry immediately splits into several critical threads that demand simultaneous examination. First and foremost, I need to understand the precise definition and behavior of `sk_is_tcp`. My immediate question is: does `sk_is_tcp` return true for MPTCP sockets, specifically those identified by `IPPROTO_MPTCP`? I'll be diving into `include/net/sock.h` at line 2975 to get a definitive answer. This is crucial because it dictates how TCP-specific logic, which might be interacting with the socket reclassification, will behave.
Concurrently, I need to meticulously examine the `nbd_genl_connect_sock_cb` function within `drivers/block/nbd.c`. This is the core of the NBD's socket handling logic, and understanding its flow, especially around how it receives and processes socket information, is paramount.
Then, Iβll scrutinize commit `9280e6edf656`. My understanding from a quick glance is that if `nbd_reclassify_socket` encounters a situation where `!sock_allow_reclassification(sk)` is true, it will exit without actually performing the reclassification. This leaves the socket in its existing state, which I suspect might be `sk_lock-AF_INET6` in some scenarios. This is a critical branching point that could lead to the observed issues.
Digging further into `nbd_reclassify_socket` itself is another immediate priority. Specifically, I need to ascertain how it handles MPTCP sockets. When an MPTCP socket is presented to NBD, its `sk->sk_family` will likely be `AF_INET6`, but its `sk->sk_protocol` will be `IPPROTO_MPTCP`. This distinction is vital, and again, my focus will be on whether `sk_is_tcp` correctly accounts for this `IPPROTO_MPTCP` protocol within the context of MPTCP.
Finally, and perhaps most broadly, I need to consider the implications for `rds_tcp_recv_path`. The question becomes: is the observed issue stemming from a flaw in `rds_tcp_recv_path` itself? Or is the problem with the NBD logic, potentially introduced or highlighted by `9280e6edf656`? Alternatively, could there be an underlying issue within MPTCP itself that is surfacing through this NBD interaction? This is a process of elimination and dependency mapping.
To resolve these questions, I'm preparing to immerse myself in the source code. I'll be poring over `include/net/sock.h`, meticulously dissecting `drivers/block/nbd.c` in the vicinity of `nbd_genl_connect_sock_cb` and `nbd_reclassify_socket`, and also delving into the MPTCP-specific code within `net/mptcp/`. My goal is to trace the execution paths, understand the locking mechanisms, and identify the exact point of divergence that leads to the observed behavior.
|
| 37/2 |
2026/11/28 10:02 |
tool |
read-file |
0m
Args: map[File:include/net/sock.h FirstLine:2975 LineCount:35]
Results: map[Contents:2975:
2976: static inline bool sk_is_inet(const struct sock *sk)
2977: {
2978: int family = READ_ONCE(sk->sk_family);
2979:
2980: return family == AF_INET || family == AF_INET6;
2981: }
2982:
2983: static inline bool sk_is_tcp(const struct sock *sk)
2984: {
2985: return sk_is_inet(sk) &&
2986: sk->sk_type == SOCK_STREAM &&
2987: sk->sk_protocol == IPPROTO_TCP;
2988: }
2989:
2990: static inline bool sk_is_udp(const struct sock *sk)
2991: {
2992: return sk_is_inet(sk) &&
2993: sk->sk_type == SOCK_DGRAM &&
2994: sk->sk_protocol == IPPROTO_UDP;
2995: }
2996:
2997: static inline bool sk_is_unix(const struct sock *sk)
2998: {
2999: return sk->sk_family == AF_UNIX;
3000: }
3001:
3002: static inline bool sk_is_stream_unix(const struct sock *sk)
3003: {
3004: return sk_is_unix(sk) && sk->sk_type == SOCK_STREAM;
3005: }
3006:
3007: static inline bool sk_is_vsock(const struct sock *sk)
3008: {
3009: return sk->sk_family == AF_VSOCK;
]
|
| 38/2 |
2026/11/28 10:02 |
tool |
read-file |
0m
Args: map[File:include/net/sock.h FirstLine:1830 LineCount:25]
Results: map[Contents:1830: /* The sk_lock has mutex_unlock() semantics: */
1831: mutex_release(&sk->sk_lock.dep_map, _RET_IP_);
1832: }
1833:
1834: /* no reclassification while locks are held */
1835: static inline bool sock_allow_reclassification(const struct sock *csk)
1836: {
1837: struct sock *sk = (struct sock *)csk;
1838:
1839: return !sock_owned_by_user_nocheck(sk) &&
1840: !spin_is_locked(&sk->sk_lock.slock);
1841: }
1842:
1843: struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
1844: struct proto *prot, int kern);
1845: void sk_free(struct sock *sk);
1846: void sk_net_refcnt_upgrade(struct sock *sk);
1847: void sk_destruct(struct sock *sk);
1848: struct sock *sk_clone(const struct sock *sk, const gfp_t priority, bool lock);
1849:
1850: static inline struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
1851: {
1852: return sk_clone(sk, priority, true);
1853: }
1854:
]
|
| 39/2 |
2026/11/28 10:02 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:2150 LineCount:90]
Results: map[Contents:2150:
2151: count++;
2152: if (cb) {
2153: ret = cb(nbd, (int)nla_get_u32(socks[NBD_SOCK_FD]));
2154: if (ret > 0)
2155: return count;
2156: if (ret < 0)
2157: return ret;
2158: }
2159: }
2160: return count;
2161: }
2162:
2163: static int nbd_genl_connect_sock_cb(struct nbd_device *nbd, unsigned long fd)
2164: {
2165: return nbd_add_socket(nbd, fd, true);
2166: }
2167:
2168: static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
2169: {
2170: struct nbd_device *nbd;
2171: struct nbd_config *config;
2172: int index = -1;
2173: int ret;
2174: bool put_dev = false;
2175:
2176: if (!netlink_capable(skb, CAP_SYS_ADMIN))
2177: return -EPERM;
2178:
2179: if (info->attrs[NBD_ATTR_INDEX]) {
2180: index = nla_get_u32(info->attrs[NBD_ATTR_INDEX]);
2181:
2182: /*
2183: * Too big first_minor can cause duplicate creation of
2184: * sysfs files/links, since index << part_shift might overflow, or
2185: * MKDEV() expect that the max bits of first_minor is 20.
2186: */
2187: if (index < 0 || index > MINORMASK >> part_shift) {
2188: pr_err("illegal input index %d\n", index);
2189: return -EINVAL;
2190: }
2191: }
2192: if (GENL_REQ_ATTR_CHECK(info, NBD_ATTR_SOCKETS)) {
2193: pr_err("must specify at least one socket\n");
2194: return -EINVAL;
2195: }
2196: if (GENL_REQ_ATTR_CHECK(info, NBD_ATTR_SIZE_BYTES)) {
2197: pr_err("must specify a size in bytes for the device\n");
2198: return -EINVAL;
2199: }
2200: again:
2201: mutex_lock(&nbd_index_mutex);
2202: if (index == -1) {
2203: nbd = nbd_find_get_unused();
2204: } else {
2205: nbd = idr_find(&nbd_index_idr, index);
2206: if (nbd) {
2207: if ((test_bit(NBD_DESTROY_ON_DISCONNECT, &nbd->flags) &&
2208: test_bit(NBD_DISCONNECT_REQUESTED, &nbd->flags)) ||
2209: !refcount_inc_not_zero(&nbd->refs)) {
2210: mutex_unlock(&nbd_index_mutex);
2211: pr_err("device at index %d is going down\n",
2212: index);
2213: return -EINVAL;
2214: }
2215: }
2216: }
2217: mutex_unlock(&nbd_index_mutex);
2218:
2219: if (!nbd) {
2220: ret = nbd_genl_foreach_sock(info, NULL, NULL);
2221: if (ret < 0)
2222: return ret;
2223:
2224: nbd = nbd_dev_add(index, 2, ret > 0 ? ret : 1);
2225: if (IS_ERR(nbd)) {
2226: pr_err("failed to add new device\n");
2227: return PTR_ERR(nbd);
2228: }
2229: }
2230:
2231: mutex_lock(&nbd->config_lock);
2232: if (refcount_read(&nbd->config_refs)) {
2233: mutex_unlock(&nbd->config_lock);
2234: nbd_put(nbd);
2235: if (index == -1)
2236: goto again;
2237: pr_err("nbd%d already in use\n", index);
2238: return -EBUSY;
2239: }
]
|
| 40/2 |
2026/11/28 10:02 |
tool |
grepper |
0m
Args: map[Expression:nbd_reclassify_socket|nbd_add_socket PathPrefixes:[drivers/block/nbd.c]]
Results: map[Output:drivers/block/nbd.c=1243=static struct lock_class_key nbd_slock_key[3];
drivers/block/nbd.c-1244-
drivers/block/nbd.c:1245:static void nbd_reclassify_socket(struct socket *sock)
drivers/block/nbd.c-1246-{
--
drivers/block/nbd.c-1273-#else
drivers/block/nbd.c:1274:static inline void nbd_reclassify_socket(struct socket *sock) {}
drivers/block/nbd.c-1275-#endif
drivers/block/nbd.c-1276-
drivers/block/nbd.c:1277:static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
drivers/block/nbd.c-1278- bool netlink)
--
drivers/block/nbd.c-1298- return err;
drivers/block/nbd.c:1299: nbd_reclassify_socket(sock);
drivers/block/nbd.c-1300-
--
drivers/block/nbd.c=1348=static int nbd_genl_reconnect_sock_cb(struct nbd_device *nbd, unsigned long arg)
--
drivers/block/nbd.c-1358- return err;
drivers/block/nbd.c:1359: nbd_reclassify_socket(sock);
drivers/block/nbd.c-1360-
--
drivers/block/nbd.c=1635=static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
--
drivers/block/nbd.c-1647- case NBD_SET_SOCK:
drivers/block/nbd.c:1648: return nbd_add_socket(nbd, arg, false);
drivers/block/nbd.c-1649- case NBD_SET_BLKSIZE:
--
drivers/block/nbd.c=2163=static int nbd_genl_connect_sock_cb(struct nbd_device *nbd, unsigned long fd)
drivers/block/nbd.c-2164-{
drivers/block/nbd.c:2165: return nbd_add_socket(nbd, fd, true);
drivers/block/nbd.c-2166-}
]
|
| 41/2 |
2026/11/28 10:02 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 57431
output: 69
thoughts: 4338
Thoughts: **Summary of my Thought Process**
Okay, hold on a second. I've been looking at this crash report and trying to piece together exactly what happened, and it seems like I'm stumbling upon a pretty fundamental locking issue.
First, I'm looking at this `nbd_reclassify_socket(sock)` function. It seems designed to change the lockdep class of a socket when NBD starts using it. But there's this check: `if (!sock_allow_reclassification(sk)) return;`. Now, I remember commit `9280e6edf656` which introduced this. The rationale was that NBD gets sockets from user file descriptors, and it's possible for userspace to be concurrently operating on that same socket (e.g., making another syscall or processing in a softirq). In those cases, `sock_allow_reclassify()` correctly returns false, and crucially, `nbd_reclassify_socket()` just silently *skips* the reclassification.
And *that's* where my alarm bells are ringing. If `nbd_reclassify_socket()` skips reclassification because the socket is busy, then the socket *retains its original lock class*, which in this crash report is `sk_lock-AF_INET6`.
Now, let's trace what happens next. The crash report shows a path through `nbd_genl_connect` -> `nbd_config_put` -> `nbd_clear_sock` -> `sock_shutdown` -> `nbd_mark_nsock_dead` -> `kernel_sock_shutdown` -> `inet_shutdown` -> `lock_sock(sk)`. The critical part is that `nbd_mark_nsock_dead` (at frame `#6`) is locking this socket, and it's still showing up as `sk_lock-AF_INET6`.
Why did `nbd_genl_connect` end up calling `nbd_config_put` and then `nbd_clear_sock` and `nbd_mark_nsock_dead`? Well, looking at `nbd_genl_connect`, line 2291 calls `nbd_genl_foreach_sock`, which in turn calls `nbd_add_socket`. *This is where `nbd_reclassify_socket(sock)` is called*. If `nbd_start_device` (or something like `device_create_file`) failed later on, then the `out:` label would be taken at line 2320, leading to `nbd_config_put(nbd)`. Since `config_refs` wouldn't have been incremented properly in the error path, `nbd_config_put` would drop the reference count to zero and then call `nbd_clear_sock`, eventually leading to `nbd_mark_nsock_dead`.
So, the key question becomes: why was the socket still `sk_lock-AF_INET6` and not `sk_lock-AF_INET6-NBD` at the point of `nbd_mark_nsock_dead`? This brings me back to `9280e6edf656`. If `nbd_reclassify_socket` was skipped because `sock_allow_reclassify()` returned false, it means the socket was busy. This is exactly what `9280e6edf656` was designed to handle by *silently skipping* reclassification.
But is skipping reclassification "harmless"? It seems not! If the reclassification is skipped, `nsock->sock->sk` retains its original `sk_lock-AF_INET6` class. Then, when NBD uses that socket later, for instance in `nbd_mark_nsock_dead` while holding `nsock->tx_lock`, lockdep starts seeing a dependency that it shouldn't.
Let's think about the broader implications. The crash report shows other lock classes involved: `rds_tcp_recv_path` (`#0`) and `mptcp_setsockopt_first_sf_only` (`#7`). Frame `#0` involves `kmem_cache_alloc(..., GFP_KERNEL)` while holding `lock_sock(sock->sk)` (which is `k-sk_lock-AF_INET6` in this context). Frame `#7` shows `sk_lock-AF_INET6` leading to `k-sk_lock-AF_INET6`.
This is starting to paint a picture of a circular dependency. If `nbd` doesn't reclassify its socket, it retains `sk_lock-AF_INET6`. This can then lead to a dependency like `fs_reclaim -> sk_lock-AF_INET6`. Now, if we also have `sk_lock-AF_INET6 -> k-sk_lock-AF_INET6` (as seen in MPTCP) and `k-sk_lock-AF_INET6 -> fs_reclaim` (as seen in RDS when allocating memory), we've created a full circle!
This exactly mirrors the scenario described in `d532cddb6c60`. That commit was concerned about `fs_reclaim` being triggered while holding `sk_lock`, and how that could lead to a circular dependency if another socket (like an NBD socket using TLS/TCP) was also involved. The fix proposed there was to reclassify NBD sockets to a separate lock class.
So, my current hypothesis is that commit `9280e6edf656`, while trying to prevent a warning in a race condition, has inadvertently introduced a way for NBD sockets to retain their generic `sk_lock-AF_INET6` class. This, in turn, allows lockdep to build a dependency chain that can conflict with other network protocols (like RDS or MPTCP) that also acquire locks while performing memory allocations, leading to the observed circular locking.
I need to systematically check all possibilities, though. Could `rds_tcp_recv_path` itself be the problem, doing `GFP_KERNEL` under `lock_sock`? Or is it `blk_mq_update_nr_hw_queues` or something in `mptcp` that's interacting poorly? I'm going to dive deeper into the interaction between `nbd`, `blk-mq`, `mptcp`, and `rds`, and specifically re-examine `nbd_reclassify_socket` and the commit messages for `9280e6edf656`, `d532cddb6c60`, `553d28925fde`, and how `nbd_mark_nsock_dead` interacts with the socket's lock class. I need to be absolutely sure I haven't missed any other potential cause for the socket retaining the `sk_lock-AF_INET6` class.
|
| 42/2 |
2026/11/28 10:02 |
tool |
grepper |
0m
Args: map[Expression:sock_lock_init_class_and_name]
Results: map[Output:drivers/block/nbd.c=1245=static void nbd_reclassify_socket(struct socket *sock)
--
drivers/block/nbd.c-1253- case AF_INET:
drivers/block/nbd.c:1254: sock_lock_init_class_and_name(sk, "slock-AF_INET-NBD",
drivers/block/nbd.c-1255- &nbd_slock_key[0],
--
drivers/block/nbd.c-1259- case AF_INET6:
drivers/block/nbd.c:1260: sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD",
drivers/block/nbd.c-1261- &nbd_slock_key[1],
--
drivers/block/nbd.c-1265- case AF_UNIX:
drivers/block/nbd.c:1266: sock_lock_init_class_and_name(sk, "slock-AF_UNIX-NBD",
drivers/block/nbd.c-1267- &nbd_slock_key[2],
--
drivers/infiniband/sw/rxe/rxe_net.c=45=static inline void rxe_reclassify_recv_socket(struct socket *sock)
--
drivers/infiniband/sw/rxe/rxe_net.c-54- case AF_INET:
drivers/infiniband/sw/rxe/rxe_net.c:55: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/rxe/rxe_net.c-56- "slock-AF_INET-RDMA-RXE-RECV",
--
drivers/infiniband/sw/rxe/rxe_net.c-61- case AF_INET6:
drivers/infiniband/sw/rxe/rxe_net.c:62: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/rxe/rxe_net.c-63- "slock-AF_INET6-RDMA-RXE-RECV",
--
drivers/infiniband/sw/rxe/rxe_net.c-72- /*
drivers/infiniband/sw/rxe/rxe_net.c:73: * sock_lock_init_class_and_name() calls
drivers/infiniband/sw/rxe/rxe_net.c-74- * sk_owner_set(sk, THIS_MODULE); in order
--
drivers/infiniband/sw/rxe/rxe_qp.c=37=static inline void rxe_reclassify_send_socket(struct socket *sock)
--
drivers/infiniband/sw/rxe/rxe_qp.c-46- case AF_INET:
drivers/infiniband/sw/rxe/rxe_qp.c:47: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/rxe/rxe_qp.c-48- "slock-AF_INET-RDMA-RXE-SEND",
--
drivers/infiniband/sw/rxe/rxe_qp.c-53- case AF_INET6:
drivers/infiniband/sw/rxe/rxe_qp.c:54: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/rxe/rxe_qp.c-55- "slock-AF_INET6-RDMA-RXE-SEND",
--
drivers/infiniband/sw/siw/siw_cm.c=62=static inline void siw_reclassify_socket(struct socket *sock)
--
drivers/infiniband/sw/siw/siw_cm.c-71- case AF_INET:
drivers/infiniband/sw/siw/siw_cm.c:72: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/siw/siw_cm.c-73- "slock-AF_INET-RDMA-SIW",
--
drivers/infiniband/sw/siw/siw_cm.c-78- case AF_INET6:
drivers/infiniband/sw/siw/siw_cm.c:79: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/siw/siw_cm.c-80- "slock-AF_INET6-RDMA-SIW",
--
drivers/nvme/host/tcp.c=228=static void nvme_tcp_reclassify_socket(struct socket *sock)
--
drivers/nvme/host/tcp.c-236- case AF_INET:
drivers/nvme/host/tcp.c:237: sock_lock_init_class_and_name(sk, "slock-AF_INET-NVME",
drivers/nvme/host/tcp.c-238- &nvme_tcp_slock_key[0],
--
drivers/nvme/host/tcp.c-242- case AF_INET6:
drivers/nvme/host/tcp.c:243: sock_lock_init_class_and_name(sk, "slock-AF_INET6-NVME",
drivers/nvme/host/tcp.c-244- &nvme_tcp_slock_key[1],
--
fs/smb/client/connect.c=3144=cifs_reclassify_socket4(struct socket *sock)
--
fs/smb/client/connect.c-3148- BUG_ON(!sock_allow_reclassification(sk));
fs/smb/client/connect.c:3149: sock_lock_init_class_and_name(sk, "slock-AF_INET-CIFS",
fs/smb/client/connect.c-3150- &cifs_slock_key[0], "sk_lock-AF_INET-CIFS", &cifs_key[0]);
--
fs/smb/client/connect.c=3154=cifs_reclassify_socket6(struct socket *sock)
--
fs/smb/client/connect.c-3158- BUG_ON(!sock_allow_reclassification(sk));
fs/smb/client/connect.c:3159: sock_lock_init_class_and_name(sk, "slock-AF_INET6-CIFS",
fs/smb/client/connect.c-3160- &cifs_slock_key[1], "sk_lock-AF_INET6-CIFS", &cifs_key[1]);
--
include/net/sock.h=242=struct sk_filter;
--
include/net/sock.h-363- * @sk_owner: reference to the real owner of the socket that calls
include/net/sock.h:364: * sock_lock_init_class_and_name().
include/net/sock.h-365- */
--
include/net/sock.h=1683=static inline void sk_owner_put(struct sock *sk)
--
include/net/sock.h-1693- */
include/net/sock.h:1694:#define sock_lock_init_class_and_name(sk, sname, skey, name, key) \
include/net/sock.h-1695-do { \
--
net/bluetooth/af_bluetooth.c=71=void bt_sock_reclassify_lock(struct sock *sk, int proto)
--
net/bluetooth/af_bluetooth.c-75-
net/bluetooth/af_bluetooth.c:76: sock_lock_init_class_and_name(sk,
net/bluetooth/af_bluetooth.c-77- bt_slock_key_strings[proto], &bt_slock_key[proto],
--
net/core/sock.c=2216=static inline void sock_lock_init(struct sock *sk)
--
net/core/sock.c-2220- if (sk->sk_kern_sock)
net/core/sock.c:2221: sock_lock_init_class_and_name(
net/core/sock.c-2222- sk,
--
net/core/sock.c-2227- else
net/core/sock.c:2228: sock_lock_init_class_and_name(
net/core/sock.c-2229- sk,
--
net/mptcp/pm_kernel.c=852=static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
--
net/mptcp/pm_kernel.c-876- */
net/mptcp/pm_kernel.c:877: sock_lock_init_class_and_name(newsk,
net/mptcp/pm_kernel.c-878- is_ipv6 ? "mlock-AF_INET6" : "mlock-AF_INET",
--
net/smc/af_smc.c=395=void smc_sk_init(struct net *net, struct sock *sk, int protocol)
--
net/smc/af_smc.c-407- INIT_LIST_HEAD(&smc->accept_q);
net/smc/af_smc.c:408: sock_lock_init_class_and_name(sk, "slock-AF_SMC", &smc_slock_key,
net/smc/af_smc.c-409- "sk_lock-AF_SMC", &smc_key);
--
net/sunrpc/svcsock.c=95=static void svc_reclassify_socket(struct socket *sock)
--
net/sunrpc/svcsock.c-103- case AF_INET:
net/sunrpc/svcsock.c:104: sock_lock_init_class_and_name(sk, "slock-AF_INET-NFSD",
net/sunrpc/svcsock.c-105- &svc_slock_key[0],
--
net/sunrpc/svcsock.c-110- case AF_INET6:
net/sunrpc/svcsock.c:111: sock_lock_init_class_and_name(sk, "slock-AF_INET6-NFSD",
net/sunrpc/svcsock.c-112- &svc_slock_key[1],
--
net/sunrpc/xprtsock.c=1891=static inline void xs_reclassify_socketu(struct socket *sock)
--
net/sunrpc/xprtsock.c-1894-
net/sunrpc/xprtsock.c:1895: sock_lock_init_class_and_name(sk, "slock-AF_LOCAL-RPC",
net/sunrpc/xprtsock.c-1896- &xs_slock_key[0], "sk_lock-AF_LOCAL-RPC", &xs_key[0]);
--
net/sunrpc/xprtsock.c=1899=static inline void xs_reclassify_socket4(struct socket *sock)
--
net/sunrpc/xprtsock.c-1902-
net/sunrpc/xprtsock.c:1903: sock_lock_init_class_and_name(sk, "slock-AF_INET-RPC",
net/sunrpc/xprtsock.c-1904- &xs_slock_key[1], "sk_lock-AF_INET-RPC", &xs_key[1]);
--
net/sunrpc/xprtsock.c=1907=static inline void xs_reclassify_socket6(struct socket *sock)
--
net/sunrpc/xprtsock.c-1910-
net/sunrpc/xprtsock.c:1911: sock_lock_init_class_and_name(sk, "slock-AF_INET6-RPC",
net/sunrpc/xprtsock.c-1912- &xs_slock_key[2], "sk_lock-AF_INET6-RPC", &xs_key[2]);
]
|
| 43/2 |
2026/11/28 10:02 |
tool |
read-file |
0m
Args: map[File:net/core/sock.c FirstLine:3450 LineCount:50]
Results: map[Contents:3450: /* Guarantee minimum buffer size under pressure (either global
3451: * or memcg) to make sure features described in RFC 7323 (TCP
3452: * Extensions for High Performance) work properly.
3453: *
3454: * This rule does NOT stand when exceeds global or memcg's hard
3455: * limit, or else a DoS attack can be taken place by spawning
3456: * lots of sockets whose usage are under minimum buffer size.
3457: */
3458: if (kind == SK_MEM_RECV) {
3459: if (atomic_read(&sk->sk_rmem_alloc) < sk_get_rmem0(sk, prot))
3460: return 1;
3461:
3462: } else { /* SK_MEM_SEND */
3463: int wmem0 = sk_get_wmem0(sk, prot);
3464:
3465: if (sk->sk_type == SOCK_STREAM) {
3466: if (sk->sk_wmem_queued < wmem0)
3467: return 1;
3468: } else if (refcount_read(&sk->sk_wmem_alloc) < wmem0) {
3469: return 1;
3470: }
3471: }
3472:
3473: if (sk_has_memory_pressure(sk)) {
3474: u64 alloc;
3475:
3476: /* The following 'average' heuristic is within the
3477: * scope of global accounting, so it only makes
3478: * sense for global memory pressure.
3479: */
3480: if (!sk_under_global_memory_pressure(sk))
3481: return 1;
3482:
3483: /* Try to be fair among all the sockets under global
3484: * pressure by allowing the ones that below average
3485: * usage to raise.
3486: */
3487: alloc = sk_sockets_allocated_read_positive(sk);
3488: if (sk_prot_mem_limits(sk, 2) > alloc *
3489: sk_mem_pages(sk->sk_wmem_queued +
3490: atomic_read(&sk->sk_rmem_alloc) +
3491: sk->sk_forward_alloc))
3492: return 1;
3493: }
3494:
3495: suppress_allocation:
3496:
3497: if (kind == SK_MEM_SEND && sk->sk_type == SOCK_STREAM) {
3498: sk_stream_moderate_sndbuf(sk);
3499:
]
|
| 44/2 |
2026/11/28 10:02 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 65777
output: 145
thoughts: 871
Thoughts: **Lockdown: Unraveling the NBD Socket Reclassification Conundrum**
I've been deep-diving into a tricky locking issue, and it all seems to hinge on how NBD sockets are being reclassified, particularly in conjunction with block device queue management. My initial alarm bells started ringing when I looked at `net/sunrpc/svcsock.c`, `drivers/block/nbd.c`, and `net/core/sock.c`. The functions `nbd_reclassify_socket`, `svc_reclassify_socket`, and `sock_allow_reclassification` immediately caught my eye as potential points of interaction and, thus, contention.
I then expanded my investigation to related NBD operations: `nbd_genl_connect`, `nbd_add_socket`, `nbd_config_put`, and the crucial `blk_mq_update_nr_hw_queues`. It felt like these were all interconnected pieces of the puzzle.
The real breakthrough, however, came when I meticulously examined both parts of the NBD trace in the lockdep report.
Looking at Part 1, specifically trace `#3`, I saw a sequence involving `srcu_lock_sync`, `__synchronize_srcu`, and then calls into the block layer: `elevator_switch`, `elevator_change`, `elevator_set_default`, `blk_register_queue`, and finally `__add_disk` and `nbd_dev_add`. This path clearly shows the block queue being set up and registered, with SR-CU synchronization happening along the way.
But then, when I looked at Part 2, trace `#2`, things got really interesting. This trace shows a path leading to `nbd_start_device` and `nbd_genl_connect`, and critically, it involves `blk_mq_update_nr_hw_queues`. What caught my attention was the lock acquisition: `elevator_change` is called, and it appears to be acquiring `&q->elevator_lock`. The lockdep trace directly links `q->q_usage_counter(io)` within `blk_mq_update_nr_hw_queues` to this `&q->elevator_lock`. This is where I paused, thinking, "How exactly is the usage counter being tied to the elevator lock in this context?"
This led me back to `elevator_change` in `block/elevator.c`, specifically lines 650-780. I need to scrutinize the logic there, how it interacts with the queue's usage counter and the elevator lock, especially when `blk_mq_update_nr_hw_queues` is invoked.
Furthermore, I've also decided to cast a wider net and review the history of `net/rds/tcp_recv.c` and `net/mptcp/sockopt.c`. While they might seem tangentially related, sometimes subtle changes in network socket handling can have cascading effects, and I want to ensure no other network-related socket reclassification or locking mechanisms are indirectly influencing this NBD behavior. My hunch is that the interaction between the network socket's reclassification and the block device queue's structural changes, particularly around elevator management and queue updates, is the root cause of this locking issue.
|
| 45/2 |
2026/11/28 10:02 |
tool |
read-file |
0m
Args: map[File:block/elevator.c FirstLine:650 LineCount:130]
Results: map[Contents: 650: /*
651: * Switch this queue to the given IO scheduler.
652: */
653: static int elevator_change(struct request_queue *q, struct elv_change_ctx *ctx)
654: {
655: unsigned int memflags;
656: struct blk_mq_tag_set *set = q->tag_set;
657: int ret = 0;
658:
659: lockdep_assert_held(&set->update_nr_hwq_lock);
660:
661: if (strncmp(ctx->name, "none", 4)) {
662: ret = blk_mq_alloc_sched_res(q, ctx->type, &ctx->res,
663: set->nr_hw_queues);
664: if (ret)
665: return ret;
666: }
667:
668: memflags = blk_mq_freeze_queue(q);
669: /*
670: * May be called before adding disk, when there isn't any FS I/O,
671: * so freezing queue plus canceling dispatch work is enough to
672: * drain any dispatch activities originated from passthrough
673: * requests, then no need to quiesce queue which may add long boot
674: * latency, especially when lots of disks are involved.
675: *
676: * Disk isn't added yet, so verifying queue lock only manually.
677: */
678: blk_mq_cancel_work_sync(q);
679: mutex_lock(&q->elevator_lock);
680: if (!(q->elevator && elevator_match(q->elevator->type, ctx->name)))
681: ret = elevator_switch(q, ctx);
682: mutex_unlock(&q->elevator_lock);
683: blk_mq_unfreeze_queue(q, memflags);
684: if (!ret)
685: ret = elevator_change_done(q, ctx);
686:
687: /*
688: * Free sched resource if it's allocated but we couldn't switch elevator.
689: */
690: if (!ctx->new)
691: blk_mq_free_sched_res(&ctx->res, ctx->type, set);
692:
693: return ret;
694: }
695:
696: /*
697: * The I/O scheduler depends on the number of hardware queues, this forces a
698: * reattachment when nr_hw_queues changes.
699: */
700: void elv_update_nr_hw_queues(struct request_queue *q,
701: struct elv_change_ctx *ctx)
702: {
703: struct blk_mq_tag_set *set = q->tag_set;
704: int ret = -ENODEV;
705:
706: WARN_ON_ONCE(q->mq_freeze_depth == 0);
707:
708: if (ctx->type && !blk_queue_dying(q) && blk_queue_registered(q)) {
709: mutex_lock(&q->elevator_lock);
710: /* force to reattach elevator after nr_hw_queue is updated */
711: ret = elevator_switch(q, ctx);
712: mutex_unlock(&q->elevator_lock);
713: }
714: blk_mq_unfreeze_queue_nomemrestore(q);
715: if (!ret)
716: WARN_ON_ONCE(elevator_change_done(q, ctx));
717:
718: /*
719: * Free sched resource if it's allocated but we couldn't switch elevator.
720: */
721: if (!ctx->new)
722: blk_mq_free_sched_res(&ctx->res, ctx->type, set);
723: }
724:
725: /*
726: * Use the default elevator settings. If the chosen elevator initialization
727: * fails, fall back to the "none" elevator (no elevator).
728: */
729: void elevator_set_default(struct request_queue *q)
730: {
731: struct elv_change_ctx ctx = {
732: .name = "mq-deadline",
733: .no_uevent = true,
734: };
735: int err;
736:
737: /* now we allow to switch elevator */
738: blk_queue_flag_clear(QUEUE_FLAG_NO_ELV_SWITCH, q);
739:
740: if (q->tag_set->flags & BLK_MQ_F_NO_SCHED_BY_DEFAULT)
741: return;
742:
743: /*
744: * For single queue devices, default to using mq-deadline. If we
745: * have multiple queues or mq-deadline is not available, default
746: * to "none".
747: */
748: ctx.type = elevator_find_get(ctx.name);
749: if (!ctx.type)
]
|
| 46/2 |
2026/11/28 10:02 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 7690137e70ab0fb1f8b5a30e6f087f8ee908b680
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Date: Tue Jun 2 22:14:15 2026 +1000
mptcp: sockopt: set sockopt on all subflows
The mptcp_setsockopt_all_sf(), currently used only with TCP_MAXSEG,
stopped when one subflow returned an error.
Even if it is not wrong, this is different from the other helpers trying
to set the option on all subflows, and then returning an error if at
least one of them had an issue.
Follow this behaviour, for a question of uniformity.
Fixes: 51c5fd09e1b4 ("mptcp: add TCP_MAXSEG sockopt support")
Cc: stable@vger.kernel.org
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20260602-net-mptcp-misc-fixes-7-1-rc7-v2-8-856831229976@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 91aa57f1d0fd..fcf6feb2a9eb 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -817,10 +817,11 @@ static int mptcp_setsockopt_all_sf(struct mptcp_sock *msk, int level,
mptcp_for_each_subflow(msk, subflow) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+ int err;
- ret = tcp_setsockopt(ssk, level, optname, optval, optlen);
- if (ret)
- break;
+ err = tcp_setsockopt(ssk, level, optname, optval, optlen);
+ if (err < 0 && ret == 0)
+ ret = err;
}
if (!ret)
]
|
| 47/2 |
2026/11/28 10:03 |
tool |
git-log |
0m
Args: map[CodeRegexp:mptcp_setsockopt_first_sf_only PathPrefix:net/mptcp/]
Results: map[Output:caea64675d8b mptcp: sockopt: use new helper for TCP_DEFER_ACCEPT
d3d429047cc6 mptcp: sockopt: make 'tcp_fastopen_connect' generic
]
|
| 48/2 |
2026/11/28 10:03 |
tool |
git-log |
0m
Args: map[Count:10 PathPrefix:block/blk-mq.c Since:1 year]
Results: map[Output:495f22c5a99a blk-mq: take quiesce_lock when removing a queue from the tag set
894e4e608492 blk-mq: fix out-of-bounds read in blk_mq_free_rqs
d734b6433b2f block: only fail dma-buf bios that need block layer PI
e67cb6ed40e7 blk-mq: end the request if getting a keyslot fails
4fcc499ea9bc blk-mq: set up a queue under tag_list_lock
89a2381482d8 blk-mq: exit the hctxs of a queue under tag_list_lock
71ec3c7d6db8 blk-mq: quiesce a queue that joins a quiesced tag set
0db9f8968a89 blk-mq: don't forget a timer the driver has restarted
9531230ee1fc blk-mq: don't bring back flags of a completed request
620cfc7a6642 blk-mq: keep sharing tags fairly after a queue update
]
|
| 49/2 |
2026/11/28 10:03 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 69327
output: 104
thoughts: 3092
Thoughts: **Tracing a Potential Lockdep Circular Dependency**
My analysis has led me down a rabbit hole, attempting to untangle a complex locking scenario that appears to be manifesting as a potential lockdep circular dependency, specifically around file system reclaim (`fs_reclaim`). I've been meticulously tracing the lock acquisition chain, starting from the `block/elevator.c` file.
Here's how I've broken it down:
Initially, I observed the following lock acquisitions in `block/elevator.c`:
* `blk_mq_freeze_queue(q)` at line 668 acquires `&q->q_usage_counter(io)`.
* `mutex_lock(&q->elevator_lock)` at line 679 acquires `&q->elevator_lock`.
* Within `elevator_switch` at line 681, `blk_mq_quiesce_queue(q)` is called, which eventually leads to `__synchronize_srcu(&set->srcu)`.
Now, to understand the *entire* picture, I've laid out the lock chain as I perceive it, noting the dependencies:
1. **`fs_reclaim` -> `&q->q_usage_counter(io)#51`**: This is a standard rule in the block layer, reinforced by commit `ffa1e7ada456`. The fundamental principle here is that `fs_reclaim` operations are disallowed while the queue is frozen or during bio submission, which is precisely when `q->q_usage_counter(io)` is held.
2. **`&q->q_usage_counter(io)#51` -> `&q->elevator_lock`**: This dependency is standard during an `elevator_change` operation.
3. **`&q->elevator_lock` -> `set->srcu`**: This is also standard, occurring during an `elevator_switch` which calls `blk_mq_quiesce_queue`.
4. **`set->srcu` -> `&cmd->lock`**: This is a typical path found in `blk_mq_dispatch_rq_list` when handling an `nbd_queue_rq`.
5. **`&cmd->lock` -> `&nsock->tx_lock`**: Again, standard within `nbd_queue_rq` when transitioning to `nbd_handle_cmd`.
6. **`&nsock->tx_lock` -> `sk_lock-AF_INET6`**: This is where things get interesting. In `nbd_mark_nsock_dead` (called by `sock_shutdown`), `kernel_sock_shutdown` and `inet_shutdown` lead to `lock_sock(sk)`. The critical observation here is that NBD sockets are block devices. Because NBD holds `nsock->tx_lock` during `nbd_queue_rq` (which is transitively under `fs_reclaim` via the chain above), *any* lock acquired under `nsock->tx_lock` becomes implicitly subordinate to `fs_reclaim`. Specifically, the socket lock of `nsock->sock->sk` (`sk->sk_lock`) is acquired under `nsock->tx_lock`. This means `sk->sk_lock` *must not* share the same lockdep class as regular user sockets (`sk_lock-AF_INET6`), because regular user sockets *can* trigger `fs_reclaim` while holding `sk_lock-AF_INET6`.
This initial chain led me to question the implications for other socket types.
7. **`sk_lock-AF_INET6` -> `k-sk_lock-AF_INET6`**: This transition occurs, for instance, in `mptcp_setsockopt_first_sf_only`, where `lock_sock(sk)` on a user socket (`sk_lock-AF_INET6`) is followed by `tcp_setsockopt` on a subflow socket (`ssk`), which is a kernel socket (`k-sk_lock-AF_INET6`).
8. **`k-sk_lock-AF_INET6` -> `fs_reclaim`**: This is observed in paths like `rds_tcp_recv_path`, where `lock_sock(sock->sk)` on a kernel socket (`k-sk_lock-AF_INET6`) is followed by `kmem_cache_alloc(..., GFP_KERNEL)` within `rds_tcp_data_recv`.
At this point, I had two critical questions to resolve:
**Question A: The `GFP_KERNEL` Allocation Under `k-sk_lock-AF_INET6`**
I needed to ascertain whether `rds_tcp_recv_path` is *supposed* to avoid `GFP_KERNEL` allocations while holding `lock_sock(sock->sk)` (i.e., `k-sk_lock-AF_INET6`), or if `k-sk_lock-AF_INET6` is inherently allowed to perform `GFP_KERNEL` allocations.
My investigation confirmed that *all* sockets, both user (`sk_lock-AF_INET6`) and kernel (`k-sk_lock-AF_INET6`), can indeed perform `GFP_KERNEL` allocations while holding `lock_sock` unless their allocation behavior is explicitly restricted (e.g., `GFP_NOIO`/`GFP_NOFS`) or they are reclassified. I verified this by checking how `k-sk_lock-AF_INET6` is used β it's applied to any kernel socket created with `sock_create_kern()` that hasn't been reclassified. This means the sequence `sk_lock-AF_INET6` -> `k-sk_lock-AF_INET6` -> `fs_reclaim` is, in general, valid. This is because user sockets and kernel sockets like MPTCP subflows or RDS sockets *are* permitted to allocate with `GFP_KERNEL` while holding `lock_sock`. I also considered the scenario of RDS being used for swap/writeback, but concluded that RDS sockets themselves are `k-sk_lock-AF_INET6`, not NBD sockets. Finally, I questioned if `rds_tcp_recv_path` performing `GFP_KERNEL` under `lock_sock` might be a bug, prompting a look at `git blame` for `net/rds/tcp_recv.c`.
**Question B: The NBD Socket Reclassification Issue**
This was the core of my concern: why was `nbd_mark_nsock_dead` acquiring `sk_lock-AF_INET6` instead of the intended `sk_lock-AF_INET6-NBD` class? I revisited commit `d532cddb6c60` ("nbd: Reclassify sockets to avoid lockdep circular dependency") and related commits (`9280e6edf656`, `553d28925fde`).
Commit `d532cddb6c60` introduced `nbd_reclassify_socket(sock)` to assign NBD sockets the `sk_lock-AF_INET6-NBD` class, specifically to prevent false positives from lockdep when NBD might be used for swap/writeback and interact with other `sk_lock`-held sockets. However, subsequent commit `9280e6edf656` modified the check within this reclassification logic. Originally, `d532cddb6c60` had:
if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
return;
And `9280e6edf656` changed it to:
if (!sock_allow_reclassification(sk))
return;
This change, *without* fixing the underlying issue, meant that if `sock_allow_reclassification(sk)` returned false, the function would now silently return *without* reclassifying the socket, leaving it with the default `sk_lock-AF_INET6` class.
This led me to investigate the conditions under which `sock_allow_reclassification(sk)` would be false. Looking at `include/net/sock.h`, the function returns false if `sock_owned_by_user_nocheck(sk)` (meaning `lock_sock(sk)` is already held by another thread) or if `spin_is_locked(&sk->sk_lock.slock)` (meaning `bh_lock_sock(sk)` is held, perhaps by an incoming TCP packet). Crucially, in both these scenarios, the socket *is still attached to the NBD device*, but it fails to be reclassified.
This situation is problematic because, as observed in my trace (`#6`), `nbd_genl_connect` -> `nbd_config_put` -> `nbd_clear_sock` -> `sock_shutdown` -> `nbd_mark_nsock_dead`, the `sock` *was* attached and ultimately had its `nsock->sock->sk` locked with the `sk_lock-AF_INET6` class, rather than the intended `sk_lock-AF_INET6-NBD`.
I then considered other ways NBD sockets are added:
1. `nbd_add_socket`: This function calls `nbd_reclassify_socket`. If `!sock_allow_reclassification(sk)`, it returns early *without reclassifying*. The logic in `nbd_add_socket` suggests that if `nbd_reclassify_socket` returns early, the socket might still be added but without the correct class. My trace specifically follows `nbd_genl_connect`, implying the socket *was* added.
2. `nbd_genl_reconnect_sock_cb`: This path was reportedly fixed in `553d28925fde`, but my current trace is not from a reconnect scenario.
3. The possibility of `sk->sk_family == AF_INET6` and `sk` being a TCP socket where `sock_allow_reclassification(sk)` is false. This ties back to the conditions mentioned above: `lock_sock` or `bh_lock_sock` already being held.
Finally, I pondered if `nbd_reclassify_socket` itself, or perhaps `rds_tcp_recv_path` in some unusual interaction, could be a factor. This prompted a final check of `git blame` on the relevant files and a review of recent commits in the kernel repository for any related changes.
|
| 50/2 |
2026/11/28 10:03 |
tool |
git-blame |
0m
Args: map[End:315 File:net/rds/tcp_recv.c Start:260]
Results: map[Output:70041088e3b97 260) }
70041088e3b97 261)
70041088e3b97 262) /* the caller has to hold the sock lock */
2da43c4a1b517 263) static int rds_tcp_read_sock(struct rds_conn_path *cp, gfp_t gfp)
70041088e3b97 264) {
2da43c4a1b517 265) struct rds_tcp_connection *tc = cp->cp_transport_data;
70041088e3b97 266) struct socket *sock = tc->t_sock;
70041088e3b97 267) read_descriptor_t desc;
70041088e3b97 268) struct rds_tcp_desc_arg arg;
70041088e3b97 269)
70041088e3b97 270) /* It's like glib in the kernel! */
2da43c4a1b517 271) arg.conn_path = cp;
70041088e3b97 272) arg.gfp = gfp;
70041088e3b97 273) desc.arg.data = &arg;
70041088e3b97 274) desc.error = 0;
70041088e3b97 275) desc.count = 1; /* give more than one skb per call */
70041088e3b97 276)
70041088e3b97 277) tcp_read_sock(sock->sk, &desc, rds_tcp_data_recv);
3f99414620156 278) rdsdebug("tcp_read_sock for tc %p gfp %pGg returned %d\n", tc, &gfp,
70041088e3b97 279) desc.error);
70041088e3b97 280)
826c1004d4aea 281) if (skb_queue_empty_lockless(&sock->sk->sk_receive_queue) &&
826c1004d4aea 282) wq_has_sleeper(&tc->t_recv_done_waitq))
826c1004d4aea 283) wake_up(&tc->t_recv_done_waitq);
826c1004d4aea 284)
70041088e3b97 285) return desc.error;
70041088e3b97 286) }
70041088e3b97 287)
70041088e3b97 288) /*
70041088e3b97 289) * We hold the sock lock to serialize our rds_tcp_recv->tcp_read_sock from
70041088e3b97 290) * data_ready.
70041088e3b97 291) *
70041088e3b97 292) * if we fail to allocate we're in trouble.. blindly wait some time before
70041088e3b97 293) * trying again to see if the VM can free up something for us.
70041088e3b97 294) */
2da43c4a1b517 295) int rds_tcp_recv_path(struct rds_conn_path *cp)
70041088e3b97 296) {
2da43c4a1b517 297) struct rds_tcp_connection *tc = cp->cp_transport_data;
70041088e3b97 298) struct socket *sock = tc->t_sock;
70041088e3b97 299) int ret = 0;
70041088e3b97 300)
2da43c4a1b517 301) rdsdebug("recv worker path [%d] tc %p sock %p\n",
2da43c4a1b517 302) cp->cp_index, tc, sock);
70041088e3b97 303)
70041088e3b97 304) lock_sock(sock->sk);
2da43c4a1b517 305) ret = rds_tcp_read_sock(cp, GFP_KERNEL);
70041088e3b97 306) release_sock(sock->sk);
70041088e3b97 307)
70041088e3b97 308) return ret;
70041088e3b97 309) }
70041088e3b97 310)
676d23690fb62 311) void rds_tcp_data_ready(struct sock *sk)
70041088e3b97 312) {
676d23690fb62 313) void (*ready)(struct sock *sk);
ea3b1ea539308 314) struct rds_conn_path *cp;
70041088e3b97 315) struct rds_tcp_connection *tc;
]
|
| 51/2 |
2026/11/28 10:03 |
tool |
git-blame |
0m
Args: map[End:185 File:net/rds/tcp_recv.c Start:155]
Results: map[Output:70041088e3b97 155) static int rds_tcp_data_recv(read_descriptor_t *desc, struct sk_buff *skb,
70041088e3b97 156) unsigned int offset, size_t len)
70041088e3b97 157) {
70041088e3b97 158) struct rds_tcp_desc_arg *arg = desc->arg.data;
2da43c4a1b517 159) struct rds_conn_path *cp = arg->conn_path;
2da43c4a1b517 160) struct rds_tcp_connection *tc = cp->cp_transport_data;
70041088e3b97 161) struct rds_tcp_incoming *tinc = tc->t_tinc;
70041088e3b97 162) struct sk_buff *clone;
70041088e3b97 163) size_t left = len, to_copy;
70041088e3b97 164)
70041088e3b97 165) rdsdebug("tcp data tc %p skb %p offset %u len %zu\n", tc, skb, offset,
70041088e3b97 166) len);
70041088e3b97 167)
70041088e3b97 168) /*
70041088e3b97 169) * tcp_read_sock() interprets partial progress as an indication to stop
70041088e3b97 170) * processing.
70041088e3b97 171) */
70041088e3b97 172) while (left) {
8690bfa17aea4 173) if (!tinc) {
70041088e3b97 174) tinc = kmem_cache_alloc(rds_tcp_incoming_slab,
5c3da57d70f1e 175) arg->gfp);
8690bfa17aea4 176) if (!tinc) {
70041088e3b97 177) desc->error = -ENOMEM;
70041088e3b97 178) goto out;
70041088e3b97 179) }
70041088e3b97 180) tc->t_tinc = tinc;
379aecbce08f7 181) rdsdebug("allocated tinc %p\n", tinc);
2da43c4a1b517 182) rds_inc_path_init(&tinc->ti_inc, cp,
eee2fa6ab3225 183) &cp->cp_conn->c_faddr);
3289025aedc01 184) tinc->ti_inc.i_rx_lat_trace[RDS_MSG_RX_HDR] =
3289025aedc01 185) local_clock();
]
|
| 52/2 |
2026/11/28 10:03 |
tool |
git-log |
0m
Error:
Args: map[Count:20 Since:2 months]
Results:
|
| 53/2 |
2026/11/28 10:03 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 75131
output: 143
thoughts: 69
Thoughts: **My Thinking Process**
Alright, so the first thing on my mind is to get a clear picture of the current state of the kernel. I'm going to start by inspecting the commit history. Specifically, I want to see what the latest kernel version is and when it was committed. The most direct way for me to do that is to use `git log HEAD` to see the commit history up to the current head, and then `git show HEAD` will give me the details of that very latest commit, which should include the relevant versioning and timestamp information.
Simultaneously, I need to understand the NBD (Network Block Device) subsystem's current operational parameters and how it's handling connections and configurations. My immediate focus is on a few key functions:
* `nbd_genl_connect`: I need to see how connections are being initiated and established within the NBD framework. What are the parameters being passed? Are there any potential bottlenecks or errors I can spot here right away?
* `nbd_config_put`: This function is likely involved in setting or updating NBD configurations. I want to understand what kind of configurations are being persisted or modified, and whether there are any implications for device behavior or performance.
* `nbd_reclassify_socket`: This sounds like it's related to how the underlying network socket is being treated or categorized within the NBD context. I'm curious about the conditions under which a socket might be reclassified and what that means for data flow or error handling.
Finally, I need to look at `elevator_change`. This function is critical for I/O scheduling. I want to understand how the I/O scheduler is being managed or potentially modified for NBD devices. Is it being explicitly changed? What are the implications of any changes for read/write performance and latency?
By examining these specific functions and the kernel version/date, I aim to build a comprehensive understanding of the current NBD and I/O scheduling environment I'm dealing with.
|
| 54/2 |
2026/11/28 10:03 |
tool |
git-show |
0m
Args: map[Commit:HEAD Stat:true]
Results: map[Output:commit 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f
Author: Ido Schimmel <idosch@nvidia.com>
Date: Sun Nov 22 09:25:04 2026 +0200
selftests: bridge_mdb: Test failed source list replace
Add a test case for the issues that were fixed in "bridge: mcast: Fix
source list rollback on failure". Check that a failed replace of a
(*, G) entry does not change its source list, with one of the existing
sources specified twice and a new source.
Output without the fix:
# ./bridge_mdb.sh
[...]
TEST: IPv4 (*, G) port group entries configuration tests [FAIL]
(S, G) entry for source 192.0.2.1 deleted after failed replace
TEST: IPv6 (*, G) port group entries configuration tests [FAIL]
(S, G) entry for source 2001:db8:1::1 deleted after failed replace
[...]
Output with the fix:
# ./bridge_mdb.sh
[...]
TEST: IPv4 (*, G) port group entries configuration tests [ OK ]
TEST: IPv6 (*, G) port group entries configuration tests [ OK ]
[...]
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
Link: https://patch.msgid.link/20261122072504.2623702-2-idosch@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
.../testing/selftests/net/forwarding/bridge_mdb.sh | 23 ++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
]
|
| 55/2 |
2026/11/28 10:03 |
tool |
git-log |
0m
Args: map[CodeRegexp:nbd_reclassify_socket PathPrefix:drivers/block/nbd.c]
Results: map[Output:553d28925fde nbd: Reclassify sockets in the reconnect path
d532cddb6c60 nbd: Reclassify sockets to avoid lockdep circular dependency
]
|
| 56/2 |
2026/11/28 10:03 |
tool |
git-blame |
0m
Args: map[End:1310 File:drivers/block/nbd.c Start:1240]
Results: map[Output:cf1b2326b7348 1240)
d532cddb6c604 1241) #ifdef CONFIG_DEBUG_LOCK_ALLOC
d532cddb6c604 1242) static struct lock_class_key nbd_key[3];
d532cddb6c604 1243) static struct lock_class_key nbd_slock_key[3];
d532cddb6c604 1244)
d532cddb6c604 1245) static void nbd_reclassify_socket(struct socket *sock)
d532cddb6c604 1246) {
d532cddb6c604 1247) struct sock *sk = sock->sk;
d532cddb6c604 1248)
9280e6edf6566 1249) if (!sock_allow_reclassification(sk))
d532cddb6c604 1250) return;
d532cddb6c604 1251)
d532cddb6c604 1252) switch (sk->sk_family) {
d532cddb6c604 1253) case AF_INET:
d532cddb6c604 1254) sock_lock_init_class_and_name(sk, "slock-AF_INET-NBD",
d532cddb6c604 1255) &nbd_slock_key[0],
d532cddb6c604 1256) "sk_lock-AF_INET-NBD",
d532cddb6c604 1257) &nbd_key[0]);
d532cddb6c604 1258) break;
d532cddb6c604 1259) case AF_INET6:
d532cddb6c604 1260) sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD",
d532cddb6c604 1261) &nbd_slock_key[1],
d532cddb6c604 1262) "sk_lock-AF_INET6-NBD",
d532cddb6c604 1263) &nbd_key[1]);
d532cddb6c604 1264) break;
d532cddb6c604 1265) case AF_UNIX:
d532cddb6c604 1266) sock_lock_init_class_and_name(sk, "slock-AF_UNIX-NBD",
d532cddb6c604 1267) &nbd_slock_key[2],
d532cddb6c604 1268) "sk_lock-AF_UNIX-NBD",
d532cddb6c604 1269) &nbd_key[2]);
d532cddb6c604 1270) break;
d532cddb6c604 1271) }
d532cddb6c604 1272) }
d532cddb6c604 1273) #else
d532cddb6c604 1274) static inline void nbd_reclassify_socket(struct socket *sock) {}
d532cddb6c604 1275) #endif
d532cddb6c604 1276)
e46c7287b1c27 1277) static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
e46c7287b1c27 1278) bool netlink)
23272a6754b81 1279) {
5ea8d10802ec4 1280) struct nbd_config *config = nbd->config;
9442b739207aa 1281) struct socket *sock;
9561a7ade0c20 1282) struct nbd_sock **socks;
9561a7ade0c20 1283) struct nbd_sock *nsock;
9442b739207aa 1284) int err;
9442b739207aa 1285)
55793ea54d777 1286) /* Arg will be cast to int, check it to avoid overflow */
55793ea54d777 1287) if (arg > INT_MAX)
55793ea54d777 1288) return -EINVAL;
04d8fb23e5204 1289)
04d8fb23e5204 1290) if (nbd->pid) {
04d8fb23e5204 1291) dev_err(disk_to_dev(nbd->disk),
04d8fb23e5204 1292) "Cannot add socket to a running device\n");
04d8fb23e5204 1293) return -EBUSY;
04d8fb23e5204 1294) }
04d8fb23e5204 1295)
cf1b2326b7348 1296) sock = nbd_get_socket(nbd, arg, &err);
9442b739207aa 1297) if (!sock)
9442b739207aa 1298) return err;
d532cddb6c604 1299) nbd_reclassify_socket(sock);
23272a6754b81 1300)
e46c7287b1c27 1301) if (!netlink && !nbd->task_setup &&
ec76a7b922e42 1302) !test_bit(NBD_RT_BOUND, &config->runtime_flags))
9561a7ade0c20 1303) nbd->task_setup = current;
e46c7287b1c27 1304)
e46c7287b1c27 1305) if (!netlink &&
e46c7287b1c27 1306) (nbd->task_setup != current ||
ec76a7b922e42 1307) test_bit(NBD_RT_BOUND, &config->runtime_flags))) {
9561a7ade0c20 1308) dev_err(disk_to_dev(nbd->disk),
9561a7ade0c20 1309) "Device being setup by another task");
579dd91ab3a54 1310) err = -EBUSY;
]
|
| 57/2 |
2026/11/28 10:03 |
tool |
git-blame |
0m
Args: map[End:1515 File:drivers/block/nbd.c Start:1460]
Results: map[Output:9442b739207aa 1460) }
9442b739207aa 1461)
29eaadc036494 1462) static void nbd_clear_sock(struct nbd_device *nbd)
1a2ad21128bb4 1463) {
9442b739207aa 1464) sock_shutdown(nbd);
9442b739207aa 1465) nbd_clear_que(nbd);
5ea8d10802ec4 1466) nbd->task_setup = NULL;
5ea8d10802ec4 1467) }
5ea8d10802ec4 1468)
5ea8d10802ec4 1469) static void nbd_config_put(struct nbd_device *nbd)
5ea8d10802ec4 1470) {
5ea8d10802ec4 1471) if (refcount_dec_and_mutex_lock(&nbd->config_refs,
5ea8d10802ec4 1472) &nbd->config_lock)) {
5ea8d10802ec4 1473) struct nbd_config *config = nbd->config;
0fdee7c5fa886 1474) struct queue_limits lim;
5ea8d10802ec4 1475) nbd_dev_dbg_close(nbd);
435c2acb307f1 1476) invalidate_disk(nbd->disk);
0fdee7c5fa886 1477) /* reset queue limits to default */
0fdee7c5fa886 1478) lim = queue_limits_start_update(nbd->disk->queue);
0fdee7c5fa886 1479) nbd_apply_limits(&lim, 0);
0fdee7c5fa886 1480) queue_limits_commit_update(nbd->disk->queue, &lim);
435c2acb307f1 1481) if (nbd->config->bytesize)
435c2acb307f1 1482) kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
ec76a7b922e42 1483) if (test_and_clear_bit(NBD_RT_HAS_PID_FILE,
5ea8d10802ec4 1484) &config->runtime_flags))
5ea8d10802ec4 1485) device_remove_file(disk_to_dev(nbd->disk), &pid_attr);
0c98057be9efa 1486) nbd->pid = 0;
6497ef8df568a 1487) if (test_and_clear_bit(NBD_RT_HAS_BACKEND_FILE,
6497ef8df568a 1488) &config->runtime_flags)) {
6497ef8df568a 1489) device_remove_file(disk_to_dev(nbd->disk), &backend_attr);
6497ef8df568a 1490) kfree(nbd->backend);
6497ef8df568a 1491) nbd->backend = NULL;
6497ef8df568a 1492) }
29eaadc036494 1493) nbd_clear_sock(nbd);
5ea8d10802ec4 1494) if (config->num_connections) {
5ea8d10802ec4 1495) int i;
5ea8d10802ec4 1496) for (i = 0; i < config->num_connections; i++) {
5ea8d10802ec4 1497) sockfd_put(config->socks[i]->sock);
5ea8d10802ec4 1498) kfree(config->socks[i]);
5ea8d10802ec4 1499) }
5ea8d10802ec4 1500) kfree(config->socks);
5ea8d10802ec4 1501) }
fa9765323a934 1502) kfree(nbd->config);
af622b8666588 1503) nbd->config = NULL;
af622b8666588 1504)
af622b8666588 1505) nbd->tag_set.timeout = 0;
a2c97909f97ef 1506)
5ea8d10802ec4 1507) mutex_unlock(&nbd->config_lock);
c6a4759ea0c9a 1508) nbd_put(nbd);
5ea8d10802ec4 1509) module_put(THIS_MODULE);
5ea8d10802ec4 1510) }
9442b739207aa 1511) }
9442b739207aa 1512)
e46c7287b1c27 1513) static int nbd_start_device(struct nbd_device *nbd)
9442b739207aa 1514) {
5ea8d10802ec4 1515) struct nbd_config *config = nbd->config;
]
|
| 58/2 |
2026/11/28 10:03 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 79565
output: 133
thoughts: 444
Thoughts: **My In-Depth Analysis of the Potential Issue**
Hold on a moment. Before I jump to any conclusions, I need to pause and meticulously examine *all* the candidates involved here. I'm going to scrutinize the two pieces of evidence we've already uncovered and, critically, consider if there's a *third* element at play that we might have overlooked.
My approach is to break down the entire chain of events and verify the origin and logic of each link.
Here's the chain I'm currently evaluating:
* **Link `#0` (`fs_reclaim` under `k-sk_lock-AF_INET6`):**
This path originates with `rds_tcp_recv_path`, which calls `lock_sock(sock->sk)`, then `rds_tcp_read_sock(cp, GFP_KERNEL)`, leading to `rds_tcp_data_recv`, and finally `kmem_cache_alloc(rds_tcp_incoming_slab, GFP_KERNEL)`.
I'm looking closely at the relevant code in `net/rds/tcp_recv.c`, specifically the commits `70041088e3b97` (from 2009!) and `2da43c4a1b517` (from 2016).
Now, a crucial question arises: why has `rds_tcp_recv_path` *never* triggered this specific path before? My hypothesis is that either `k-sk_lock-AF_INET6` was not previously linked below `sk_lock-AF_INET6`, or, conversely, `sk_lock-AF_INET6` was not linked below `fs_reclaim`. This suggests a structural change in the locking hierarchy.
To pinpoint the exact timing of this change, I need to investigate when `mptcp_setsockopt_first_sf_only` (identified as `#7` in some context) was introduced. Furthermore, I need to cross-reference this with the introduction of commits `d532cddb6c60` / `9280e6edf656` and `ffa1e7ada456`.
My next steps involve diving into commit `caea64675d8b` / `d3d429047cc6` within `net/mptcp/sockopt.c`. Concurrently, I will be performing `git-log` analysis on `net/core/sock.c` (specifically for `sock_lock_init`) and `drivers/block/nbd.c` to understand the evolution of these locking mechanisms and their interdependencies. This detailed examination is key to understanding the causal relationships and identifying the root of the behavior we're observing.
|
| 59/2 |
2026/11/28 10:04 |
tool |
git-show |
0m
Args:
Results: map[Output:commit caea64675d8b91deb59140a92f190124399ccd37
Author: Matthieu Baerts <matttbe@kernel.org>
Date: Fri Oct 21 17:45:05 2022 -0700
mptcp: sockopt: use new helper for TCP_DEFER_ACCEPT
mptcp_setsockopt_sol_tcp_defer() was doing the same thing as
mptcp_setsockopt_first_sf_only() except for the returned code in case of
error.
Ignoring the error is needed to mimic how TCP_DEFER_ACCEPT is handled
when used with "plain" TCP sockets.
The specific function for TCP_DEFER_ACCEPT can be replaced by the new
mptcp_setsockopt_first_sf_only() helper and errors can be ignored to
stay compatible with TCP. A bit of cleanup.
Suggested-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 1857281a0dd5..f85e9bbfe86f 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -758,18 +758,6 @@ static int mptcp_setsockopt_v4(struct mptcp_sock *msk, int optname,
return -EOPNOTSUPP;
}
-static int mptcp_setsockopt_sol_tcp_defer(struct mptcp_sock *msk, sockptr_t optval,
- unsigned int optlen)
-{
- struct socket *listener;
-
- listener = __mptcp_nmpc_socket(msk);
- if (!listener)
- return 0; /* TCP_DEFER_ACCEPT does not fail */
-
- return tcp_setsockopt(listener->sk, SOL_TCP, TCP_DEFER_ACCEPT, optval, optlen);
-}
-
static int mptcp_setsockopt_first_sf_only(struct mptcp_sock *msk, int level, int optname,
sockptr_t optval, unsigned int optlen)
{
@@ -810,7 +798,9 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
case TCP_NODELAY:
return mptcp_setsockopt_sol_tcp_nodelay(msk, optval, optlen);
case TCP_DEFER_ACCEPT:
- return mptcp_setsockopt_sol_tcp_defer(msk, optval, optlen);
+ /* See tcp.c: TCP_DEFER_ACCEPT does not fail */
+ mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname, optval, optlen);
+ return 0;
case TCP_FASTOPEN_CONNECT:
case TCP_FASTOPEN_NO_COOKIE:
return mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname,
]
|
| 60/2 |
2026/11/28 10:04 |
tool |
git-show |
0m
Args:
Results: map[Output:commit d3d429047cc66ff49780c93e4fccd9527723d385
Author: Matthieu Baerts <matttbe@kernel.org>
Date: Fri Oct 21 17:45:03 2022 -0700
mptcp: sockopt: make 'tcp_fastopen_connect' generic
There are other socket options that need to act only on the first
subflow, e.g. all TCP_FASTOPEN* socket options.
This is similar to the getsockopt version.
In the next commit, this new mptcp_setsockopt_first_sf_only() helper is
used by other another option.
Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index c7cb68c725b2..8d3b09d75c3a 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -769,17 +769,17 @@ static int mptcp_setsockopt_sol_tcp_defer(struct mptcp_sock *msk, sockptr_t optv
return tcp_setsockopt(listener->sk, SOL_TCP, TCP_DEFER_ACCEPT, optval, optlen);
}
-static int mptcp_setsockopt_sol_tcp_fastopen_connect(struct mptcp_sock *msk, sockptr_t optval,
- unsigned int optlen)
+static int mptcp_setsockopt_first_sf_only(struct mptcp_sock *msk, int level, int optname,
+ sockptr_t optval, unsigned int optlen)
{
struct socket *sock;
- /* Limit to first subflow */
+ /* Limit to first subflow, before the connection establishment */
sock = __mptcp_nmpc_socket(msk);
if (!sock)
return -EINVAL;
- return tcp_setsockopt(sock->sk, SOL_TCP, TCP_FASTOPEN_CONNECT, optval, optlen);
+ return tcp_setsockopt(sock->sk, level, optname, optval, optlen);
}
static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
@@ -811,7 +811,8 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
case TCP_DEFER_ACCEPT:
return mptcp_setsockopt_sol_tcp_defer(msk, optval, optlen);
case TCP_FASTOPEN_CONNECT:
- return mptcp_setsockopt_sol_tcp_fastopen_connect(msk, optval, optlen);
+ return mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname,
+ optval, optlen);
}
return -EOPNOTSUPP;
]
|
| 61/2 |
2026/11/28 10:04 |
tool |
git-log |
0m
Args: map[CodeRegexp:sk_kern_sock PathPrefix:net/core/sock.c]
Results: map[Output:de31e96cf423 net/core: move the lockdep-init of sk_callback_lock to sk_init_common()
cdfbabfb2f0c net: Work around lockdep limitation in sockets that use sockets
]
|
| 62/2 |
2026/11/28 10:04 |
tool |
git-log |
0m
Args: map[CodeRegexp:memalloc_noio_save PathPrefix:block/blk-mq.c]
Results: map[Output:4fcc499ea9bc blk-mq: set up a queue under tag_list_lock
1e1a9cecfab3 block: force noio scope in blk_mq_freeze_queue
]
|
| 63/2 |
2026/11/28 10:04 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 82083
output: 120
thoughts: 98
Thoughts: **My Investigative Thought Process**
Alright, I need to get a handle on what's been happening with these specific commits and a particular file. My first instinct is to use `git show` to get a quick snapshot of the changes introduced by `cdfbabfb2f0c`, `1e1a9cecfab3`, and `4fcc499ea9bc`. This will give me the commit message, author, date, and the actual diff for each. It's the fastest way to see *what* changed at a high level.
But just seeing the individual changes might not be enough. I also want to understand the *history* and context surrounding changes within `drivers/block/nbd.c`, especially around some key functions: `nbd_genl_connect`, `nbd_config_put`, `sock_shutdown`, and `nbd_start_device`. For this, `git log` is my go-to. I'll be looking for commits that touch this file and specifically those that involve these functions, which will help me trace the evolution of this part of the NBD driver and understand how these critical operations have been developed or modified over time.
|
| 64/2 |
2026/11/28 10:04 |
tool |
git-show |
0m
Args:
Results: map[Output:commit cdfbabfb2f0ce983fdaa42f20e5f7842178fc01e
Author: David Howells <dhowells@redhat.com>
Date: Thu Mar 9 08:09:05 2017 +0000
net: Work around lockdep limitation in sockets that use sockets
Lockdep issues a circular dependency warning when AFS issues an operation
through AF_RXRPC from a context in which the VFS/VM holds the mmap_sem.
The theory lockdep comes up with is as follows:
(1) If the pagefault handler decides it needs to read pages from AFS, it
calls AFS with mmap_sem held and AFS begins an AF_RXRPC call, but
creating a call requires the socket lock:
mmap_sem must be taken before sk_lock-AF_RXRPC
(2) afs_open_socket() opens an AF_RXRPC socket and binds it. rxrpc_bind()
binds the underlying UDP socket whilst holding its socket lock.
inet_bind() takes its own socket lock:
sk_lock-AF_RXRPC must be taken before sk_lock-AF_INET
(3) Reading from a TCP socket into a userspace buffer might cause a fault
and thus cause the kernel to take the mmap_sem, but the TCP socket is
locked whilst doing this:
sk_lock-AF_INET must be taken before mmap_sem
However, lockdep's theory is wrong in this instance because it deals only
with lock classes and not individual locks. The AF_INET lock in (2) isn't
really equivalent to the AF_INET lock in (3) as the former deals with a
socket entirely internal to the kernel that never sees userspace. This is
a limitation in the design of lockdep.
Fix the general case by:
(1) Double up all the locking keys used in sockets so that one set are
used if the socket is created by userspace and the other set is used
if the socket is created by the kernel.
(2) Store the kern parameter passed to sk_alloc() in a variable in the
sock struct (sk_kern_sock). This informs sock_lock_init(),
sock_init_data() and sk_clone_lock() as to the lock keys to be used.
Note that the child created by sk_clone_lock() inherits the parent's
kern setting.
(3) Add a 'kern' parameter to ->accept() that is analogous to the one
passed in to ->create() that distinguishes whether kernel_accept() or
sys_accept4() was the caller and can be passed to sk_alloc().
Note that a lot of accept functions merely dequeue an already
allocated socket. I haven't touched these as the new socket already
exists before we get the parameter.
Note also that there are a couple of places where I've made the accepted
socket unconditionally kernel-based:
irda_accept()
rds_rcp_accept_one()
tcp_accept_from_sock()
because they follow a sock_create_kern() and accept off of that.
Whilst creating this, I noticed that lustre and ocfs don't create sockets
through sock_create_kern() and thus they aren't marked as for-kernel,
though they appear to be internal. I wonder if these should do that so
that they use the new set of lock keys.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index f5e18c2a4852..690deca17c35 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -266,7 +266,7 @@ static int alg_setsockopt(struct socket *sock, int level, int optname,
return err;
}
-int af_alg_accept(struct sock *sk, struct socket *newsock)
+int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
{
struct alg_sock *ask = alg_sk(sk);
const struct af_alg_type *type;
@@ -281,7 +281,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock)
if (!type)
goto unlock;
- sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, 0);
+ sk2 = sk_alloc(sock_net(sk), PF_ALG, GFP_KERNEL, &alg_proto, kern);
err = -ENOMEM;
if (!sk2)
goto unlock;
@@ -323,9 +323,10 @@ int af_alg_accept(struct sock *sk, struct socket *newsock)
}
EXPORT_SYMBOL_GPL(af_alg_accept);
-static int alg_accept(struct socket *sock, struct socket *newsock, int flags)
+static int alg_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
- return af_alg_accept(sock->sk, newsock);
+ return af_alg_accept(sock->sk, newsock, kern);
}
static const struct proto_ops alg_proto_ops = {
diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
index 54fc90e8339c..5e92bd275ef3 100644
--- a/crypto/algif_hash.c
+++ b/crypto/algif_hash.c
@@ -239,7 +239,8 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
return err ?: len;
}
-static int hash_accept(struct socket *sock, struct socket *newsock, int flags)
+static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);
@@ -260,7 +261,7 @@ static int hash_accept(struct socket *sock, struct socket *newsock, int flags)
if (err)
return err;
- err = af_alg_accept(ask->parent, newsock);
+ err = af_alg_accept(ask->parent, newsock, kern);
if (err)
return err;
@@ -378,7 +379,7 @@ static int hash_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
}
static int hash_accept_nokey(struct socket *sock, struct socket *newsock,
- int flags)
+ int flags, bool kern)
{
int err;
@@ -386,7 +387,7 @@ static int hash_accept_nokey(struct socket *sock, struct socket *newsock,
if (err)
return err;
- return hash_accept(sock, newsock, flags);
+ return hash_accept(sock, newsock, flags, kern);
}
static struct proto_ops algif_hash_ops_nokey = {
diff --git a/drivers/staging/lustre/lnet/lnet/lib-socket.c b/drivers/staging/lustre/lnet/lnet/lib-socket.c
index b7b87ecefcdf..9fca8d225ee0 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-socket.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-socket.c
@@ -532,7 +532,7 @@ lnet_sock_accept(struct socket **newsockp, struct socket *sock)
newsock->ops = sock->ops;
- rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
+ rc = sock->ops->accept(sock, newsock, O_NONBLOCK, false);
if (rc == -EAGAIN) {
/* Nothing ready, so wait for activity */
init_waitqueue_entry(&wait, current);
@@ -540,7 +540,7 @@ lnet_sock_accept(struct socket **newsockp, struct socket *sock)
set_current_state(TASK_INTERRUPTIBLE);
schedule();
remove_wait_queue(sk_sleep(sock->sk), &wait);
- rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
+ rc = sock->ops->accept(sock, newsock, O_NONBLOCK, false);
}
if (rc)
diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 7d398d300e97..9382db998ec9 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -743,7 +743,7 @@ static int tcp_accept_from_sock(struct connection *con)
newsock->type = con->sock->type;
newsock->ops = con->sock->ops;
- result = con->sock->ops->accept(con->sock, newsock, O_NONBLOCK);
+ result = con->sock->ops->accept(con->sock, newsock, O_NONBLOCK, true);
if (result < 0)
goto accept_err;
diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c
index 4348027384f5..d0ab7e56d0b4 100644
--- a/fs/ocfs2/cluster/tcp.c
+++ b/fs/ocfs2/cluster/tcp.c
@@ -1863,7 +1863,7 @@ static int o2net_accept_one(struct socket *sock, int *more)
new_sock->type = sock->type;
new_sock->ops = sock->ops;
- ret = sock->ops->accept(sock, new_sock, O_NONBLOCK);
+ ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, false);
if (ret < 0)
goto out;
diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h
index a2bfd7843f18..e2b9c6fe2714 100644
--- a/include/crypto/if_alg.h
+++ b/include/crypto/if_alg.h
@@ -73,7 +73,7 @@ int af_alg_unregister_type(const struct af_alg_type *type);
int af_alg_release(struct socket *sock);
void af_alg_release_parent(struct sock *sk);
-int af_alg_accept(struct sock *sk, struct socket *newsock);
+int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern);
int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len);
void af_alg_free_sg(struct af_alg_sgl *sgl);
diff --git a/include/linux/net.h b/include/linux/net.h
index cd0c8bd0a1de..0620f5e18c96 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -146,7 +146,7 @@ struct proto_ops {
int (*socketpair)(struct socket *sock1,
struct socket *sock2);
int (*accept) (struct socket *sock,
- struct socket *newsock, int flags);
+ struct socket *newsock, int flags, bool kern);
int (*getname) (struct socket *sock,
struct sockaddr *addr,
int *sockaddr_len, int peer);
diff --git a/include/net/inet_common.h b/include/net/inet_common.h
index b7952d55b9c0..f39ae697347f 100644
--- a/include/net/inet_common.h
+++ b/include/net/inet_common.h
@@ -20,7 +20,8 @@ int __inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
int addr_len, int flags, int is_sendmsg);
int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
int addr_len, int flags);
-int inet_accept(struct socket *sock, struct socket *newsock, int flags);
+int inet_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern);
int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size);
ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
size_t size, int flags);
diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index 826f198374f8..c7a577976bec 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -258,7 +258,7 @@ inet_csk_rto_backoff(const struct inet_connection_sock *icsk,
return (unsigned long)min_t(u64, when, max_when);
}
-struct sock *inet_csk_accept(struct sock *sk, int flags, int *err);
+struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern);
int inet_csk_get_port(struct sock *sk, unsigned short snum);
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index a244db5e5ff7..07a0b128625a 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -476,7 +476,8 @@ struct sctp_pf {
int (*send_verify) (struct sctp_sock *, union sctp_addr *);
int (*supported_addrs)(const struct sctp_sock *, __be16 *);
struct sock *(*create_accept_sk) (struct sock *sk,
- struct sctp_association *asoc);
+ struct sctp_association *asoc,
+ bool kern);
int (*addr_to_user)(struct sctp_sock *sk, union sctp_addr *addr);
void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
diff --git a/include/net/sock.h b/include/net/sock.h
index 5e5997654db6..03252d53975d 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -236,6 +236,7 @@ struct sock_common {
* @sk_shutdown: mask of %SEND_SHUTDOWN and/or %RCV_SHUTDOWN
* @sk_userlocks: %SO_SNDBUF and %SO_RCVBUF settings
* @sk_lock: synchronizer
+ * @sk_kern_sock: True if sock is using kernel lock classes
* @sk_rcvbuf: size of receive buffer in bytes
* @sk_wq: sock wait queue and async head
* @sk_rx_dst: receive input route used by early demux
@@ -430,7 +431,8 @@ struct sock {
#endif
kmemcheck_bitfield_begin(flags);
- unsigned int sk_padding : 2,
+ unsigned int sk_padding : 1,
+ sk_kern_sock : 1,
sk_no_check_tx : 1,
sk_no_check_rx : 1,
sk_userlocks : 4,
@@ -1015,7 +1017,8 @@ struct proto {
int addr_len);
int (*disconnect)(struct sock *sk, int flags);
- struct sock * (*accept)(struct sock *sk, int flags, int *err);
+ struct sock * (*accept)(struct sock *sk, int flags, int *err,
+ bool kern);
int (*ioctl)(struct sock *sk, int cmd,
unsigned long arg);
@@ -1573,7 +1576,7 @@ int sock_cmsg_send(struct sock *sk, struct msghdr *msg,
int sock_no_bind(struct socket *, struct sockaddr *, int);
int sock_no_connect(struct socket *, struct sockaddr *, int, int);
int sock_no_socketpair(struct socket *, struct socket *);
-int sock_no_accept(struct socket *, struct socket *, int);
+int sock_no_accept(struct socket *, struct socket *, int, bool);
int sock_no_getname(struct socket *, struct sockaddr *, int *, int);
unsigned int sock_no_poll(struct file *, struct socket *,
struct poll_table_struct *);
diff --git a/net/atm/svc.c b/net/atm/svc.c
index db9794ec61d8..5589de7086af 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -318,7 +318,8 @@ static int svc_listen(struct socket *sock, int backlog)
return error;
}
-static int svc_accept(struct socket *sock, struct socket *newsock, int flags)
+static int svc_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sock *sk = sock->sk;
struct sk_buff *skb;
@@ -329,7 +330,7 @@ static int svc_accept(struct socket *sock, struct socket *newsock, int flags)
lock_sock(sk);
- error = svc_create(sock_net(sk), newsock, 0, 0);
+ error = svc_create(sock_net(sk), newsock, 0, kern);
if (error)
goto out;
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index a8e42cedf1db..b7c486752b3a 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -1320,7 +1320,8 @@ static int __must_check ax25_connect(struct socket *sock,
return err;
}
-static int ax25_accept(struct socket *sock, struct socket *newsock, int flags)
+static int ax25_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sk_buff *skb;
struct sock *newsk;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index f307b145ea54..507b80d59dec 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -301,7 +301,7 @@ static int l2cap_sock_listen(struct socket *sock, int backlog)
}
static int l2cap_sock_accept(struct socket *sock, struct socket *newsock,
- int flags)
+ int flags, bool kern)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
struct sock *sk = sock->sk, *nsk;
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index aa1a814ceddc..ac3c650cb234 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -471,7 +471,8 @@ static int rfcomm_sock_listen(struct socket *sock, int backlog)
return err;
}
-static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int flags)
+static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
struct sock *sk = sock->sk, *nsk;
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index e4e9a2da1e7e..728e0c8dc8e7 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -627,7 +627,7 @@ static int sco_sock_listen(struct socket *sock, int backlog)
}
static int sco_sock_accept(struct socket *sock, struct socket *newsock,
- int flags)
+ int flags, bool kern)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
struct sock *sk = sock->sk, *ch;
diff --git a/net/core/sock.c b/net/core/sock.c
index f6fd79f33097..a96d5f7a5734 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -197,66 +197,55 @@ EXPORT_SYMBOL(sk_net_capable);
/*
* Each address family might have different locking rules, so we have
- * one slock key per address family:
+ * one slock key per address family and separate keys for internal and
+ * userspace sockets.
*/
static struct lock_class_key af_family_keys[AF_MAX];
+static struct lock_class_key af_family_kern_keys[AF_MAX];
static struct lock_class_key af_family_slock_keys[AF_MAX];
+static struct lock_class_key af_family_kern_slock_keys[AF_MAX];
/*
* Make lock validator output more readable. (we pre-construct these
* strings build-time, so that runtime initialization of socket
* locks is fast):
*/
+
+#define _sock_locks(x) \
+ x "AF_UNSPEC", x "AF_UNIX" , x "AF_INET" , \
+ x "AF_AX25" , x "AF_IPX" , x "AF_APPLETALK", \
+ x "AF_NETROM", x "AF_BRIDGE" , x "AF_ATMPVC" , \
+ x "AF_X25" , x "AF_INET6" , x "AF_ROSE" , \
+ x "AF_DECnet", x "AF_NETBEUI" , x "AF_SECURITY" , \
+ x "AF_KEY" , x "AF_NETLINK" , x "AF_PACKET" , \
+ x "AF_ASH" , x "AF_ECONET" , x "AF_ATMSVC" , \
+ x "AF_RDS" , x "AF_SNA" , x "AF_IRDA" , \
+ x "AF_PPPOX" , x "AF_WANPIPE" , x "AF_LLC" , \
+ x "27" , x "28" , x "AF_CAN" , \
+ x "AF_TIPC" , x "AF_BLUETOOTH", x "IUCV" , \
+ x "AF_RXRPC" , x "AF_ISDN" , x "AF_PHONET" , \
+ x "AF_IEEE802154", x "AF_CAIF" , x "AF_ALG" , \
+ x "AF_NFC" , x "AF_VSOCK" , x "AF_KCM" , \
+ x "AF_QIPCRTR", x "AF_SMC" , x "AF_MAX"
+
static const char *const af_family_key_strings[AF_MAX+1] = {
- "sk_lock-AF_UNSPEC", "sk_lock-AF_UNIX" , "sk_lock-AF_INET" ,
- "sk_lock-AF_AX25" , "sk_lock-AF_IPX" , "sk_lock-AF_APPLETALK",
- "sk_lock-AF_NETROM", "sk_lock-AF_BRIDGE" , "sk_lock-AF_ATMPVC" ,
- "sk_lock-AF_X25" , "sk_lock-AF_INET6" , "sk_lock-AF_ROSE" ,
- "sk_lock-AF_DECnet", "sk_lock-AF_NETBEUI" , "sk_lock-AF_SECURITY" ,
- "sk_lock-AF_KEY" , "sk_lock-AF_NETLINK" , "sk_lock-AF_PACKET" ,
- "sk_lock-AF_ASH" , "sk_lock-AF_ECONET" , "sk_lock-AF_ATMSVC" ,
- "sk_lock-AF_RDS" , "sk_lock-AF_SNA" , "sk_lock-AF_IRDA" ,
- "sk_lock-AF_PPPOX" , "sk_lock-AF_WANPIPE" , "sk_lock-AF_LLC" ,
- "sk_lock-27" , "sk_lock-28" , "sk_lock-AF_CAN" ,
- "sk_lock-AF_TIPC" , "sk_lock-AF_BLUETOOTH", "sk_lock-IUCV" ,
- "sk_lock-AF_RXRPC" , "sk_lock-AF_ISDN" , "sk_lock-AF_PHONET" ,
- "sk_lock-AF_IEEE802154", "sk_lock-AF_CAIF" , "sk_lock-AF_ALG" ,
- "sk_lock-AF_NFC" , "sk_lock-AF_VSOCK" , "sk_lock-AF_KCM" ,
- "sk_lock-AF_QIPCRTR", "sk_lock-AF_SMC" , "sk_lock-AF_MAX"
+ _sock_locks("sk_lock-")
};
static const char *const af_family_slock_key_strings[AF_MAX+1] = {
- "slock-AF_UNSPEC", "slock-AF_UNIX" , "slock-AF_INET" ,
- "slock-AF_AX25" , "slock-AF_IPX" , "slock-AF_APPLETALK",
- "slock-AF_NETROM", "slock-AF_BRIDGE" , "slock-AF_ATMPVC" ,
- "slock-AF_X25" , "slock-AF_INET6" , "slock-AF_ROSE" ,
- "slock-AF_DECnet", "slock-AF_NETBEUI" , "slock-AF_SECURITY" ,
- "slock-AF_KEY" , "slock-AF_NETLINK" , "slock-AF_PACKET" ,
- "slock-AF_ASH" , "slock-AF_ECONET" , "slock-AF_ATMSVC" ,
- "slock-AF_RDS" , "slock-AF_SNA" , "slock-AF_IRDA" ,
- "slock-AF_PPPOX" , "slock-AF_WANPIPE" , "slock-AF_LLC" ,
- "slock-27" , "slock-28" , "slock-AF_CAN" ,
- "slock-AF_TIPC" , "slock-AF_BLUETOOTH", "slock-AF_IUCV" ,
- "slock-AF_RXRPC" , "slock-AF_ISDN" , "slock-AF_PHONET" ,
- "slock-AF_IEEE802154", "slock-AF_CAIF" , "slock-AF_ALG" ,
- "slock-AF_NFC" , "slock-AF_VSOCK" ,"slock-AF_KCM" ,
- "slock-AF_QIPCRTR", "slock-AF_SMC" , "slock-AF_MAX"
+ _sock_locks("slock-")
};
static const char *const af_family_clock_key_strings[AF_MAX+1] = {
- "clock-AF_UNSPEC", "clock-AF_UNIX" , "clock-AF_INET" ,
- "clock-AF_AX25" , "clock-AF_IPX" , "clock-AF_APPLETALK",
- "clock-AF_NETROM", "clock-AF_BRIDGE" , "clock-AF_ATMPVC" ,
- "clock-AF_X25" , "clock-AF_INET6" , "clock-AF_ROSE" ,
- "clock-AF_DECnet", "clock-AF_NETBEUI" , "clock-AF_SECURITY" ,
- "clock-AF_KEY" , "clock-AF_NETLINK" , "clock-AF_PACKET" ,
- "clock-AF_ASH" , "clock-AF_ECONET" , "clock-AF_ATMSVC" ,
- "clock-AF_RDS" , "clock-AF_SNA" , "clock-AF_IRDA" ,
- "clock-AF_PPPOX" , "clock-AF_WANPIPE" , "clock-AF_LLC" ,
- "clock-27" , "clock-28" , "clock-AF_CAN" ,
- "clock-AF_TIPC" , "clock-AF_BLUETOOTH", "clock-AF_IUCV" ,
- "clock-AF_RXRPC" , "clock-AF_ISDN" , "clock-AF_PHONET" ,
- "clock-AF_IEEE802154", "clock-AF_CAIF" , "clock-AF_ALG" ,
- "clock-AF_NFC" , "clock-AF_VSOCK" , "clock-AF_KCM" ,
- "clock-AF_QIPCRTR", "clock-AF_SMC" , "clock-AF_MAX"
+ _sock_locks("clock-")
+};
+
+static const char *const af_family_kern_key_strings[AF_MAX+1] = {
+ _sock_locks("k-sk_lock-")
+};
+static const char *const af_family_kern_slock_key_strings[AF_MAX+1] = {
+ _sock_locks("k-slock-")
+};
+static const char *const af_family_kern_clock_key_strings[AF_MAX+1] = {
+ _sock_locks("k-clock-")
};
/*
@@ -264,6 +253,7 @@ static const char *const af_family_clock_key_strings[AF_MAX+1] = {
* so split the lock classes by using a per-AF key:
*/
static struct lock_class_key af_callback_keys[AF_MAX];
+static struct lock_class_key af_kern_callback_keys[AF_MAX];
/* Take into consideration the size of the struct sk_buff overhead in the
* determination of these values, since that is non-constant across
@@ -1293,7 +1283,16 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
*/
static inline void sock_lock_init(struct sock *sk)
{
- sock_lock_init_class_and_name(sk,
+ if (sk->sk_kern_sock)
+ sock_lock_init_class_and_name(
+ sk,
+ af_family_kern_slock_key_strings[sk->sk_family],
+ af_family_kern_slock_keys + sk->sk_family,
+ af_family_kern_key_strings[sk->sk_family],
+ af_family_kern_keys + sk->sk_family);
+ else
+ sock_lock_init_class_and_name(
+ sk,
af_family_slock_key_strings[sk->sk_family],
af_family_slock_keys + sk->sk_family,
af_family_key_strings[sk->sk_family],
@@ -1399,6 +1398,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
* why we need sk_prot_creator -acme
*/
sk->sk_prot = sk->sk_prot_creator = prot;
+ sk->sk_kern_sock = kern;
sock_lock_init(sk);
sk->sk_net_refcnt = kern ? 0 : 1;
if (likely(sk->sk_net_refcnt))
@@ -2277,7 +2277,8 @@ int sock_no_socketpair(struct socket *sock1, struct socket *sock2)
}
EXPORT_SYMBOL(sock_no_socketpair);
-int sock_no_accept(struct socket *sock, struct socket *newsock, int flags)
+int sock_no_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
return -EOPNOTSUPP;
}
@@ -2481,7 +2482,14 @@ void sock_init_data(struct socket *sock, struct sock *sk)
}
rwlock_init(&sk->sk_callback_lock);
- lockdep_set_class_and_name(&sk->sk_callback_lock,
+ if (sk->sk_kern_sock)
+ lockdep_set_class_and_name(
+ &sk->sk_callback_lock,
+ af_kern_callback_keys + sk->sk_family,
+ af_family_kern_clock_key_strings[sk->sk_family]);
+ else
+ lockdep_set_class_and_name(
+ &sk->sk_callback_lock,
af_callback_keys + sk->sk_family,
af_family_clock_key_strings[sk->sk_family]);
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index e6e79eda9763..7de5b40a5d0d 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -1070,7 +1070,8 @@ static struct sk_buff *dn_wait_for_connect(struct sock *sk, long *timeo)
return skb == NULL ? ERR_PTR(err) : skb;
}
-static int dn_accept(struct socket *sock, struct socket *newsock, int flags)
+static int dn_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sock *sk = sock->sk, *newsk;
struct sk_buff *skb = NULL;
@@ -1099,7 +1100,7 @@ static int dn_accept(struct socket *sock, struct socket *newsock, int flags)
cb = DN_SKB_CB(skb);
sk->sk_ack_backlog--;
- newsk = dn_alloc_sock(sock_net(sk), newsock, sk->sk_allocation, 0);
+ newsk = dn_alloc_sock(sock_net(sk), newsock, sk->sk_allocation, kern);
if (newsk == NULL) {
release_sock(sk);
kfree_skb(skb);
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 5091f46826fa..6b1fc6e4278e 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -689,11 +689,12 @@ EXPORT_SYMBOL(inet_stream_connect);
* Accept a pending connection. The TCP layer now gives BSD semantics.
*/
-int inet_accept(struct socket *sock, struct socket *newsock, int flags)
+int inet_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sock *sk1 = sock->sk;
int err = -EINVAL;
- struct sock *sk2 = sk1->sk_prot->accept(sk1, flags, &err);
+ struct sock *sk2 = sk1->sk_prot->accept(sk1, flags, &err, kern);
if (!sk2)
goto do_err;
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index b4d5980ade3b..5e313c1ac94f 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -424,7 +424,7 @@ static int inet_csk_wait_for_connect(struct sock *sk, long timeo)
/*
* This will accept the next outstanding connection.
*/
-struct sock *inet_csk_accept(struct sock *sk, int flags, int *err)
+struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern)
{
struct inet_connection_sock *icsk = inet_csk(sk);
struct request_sock_queue *queue = &icsk->icsk_accept_queue;
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index 81adc29a448d..8d77ad5cadaf 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -828,7 +828,8 @@ static int irda_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
* Wait for incoming connection
*
*/
-static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
+static int irda_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sock *sk = sock->sk;
struct irda_sock *new, *self = irda_sk(sk);
@@ -836,7 +837,7 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
struct sk_buff *skb = NULL;
int err;
- err = irda_create(sock_net(sk), newsock, sk->sk_protocol, 0);
+ err = irda_create(sock_net(sk), newsock, sk->sk_protocol, kern);
if (err)
return err;
diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index 89bbde1081ce..84de7b6326dc 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -938,7 +938,7 @@ static int iucv_sock_listen(struct socket *sock, int backlog)
/* Accept a pending connection */
static int iucv_sock_accept(struct socket *sock, struct socket *newsock,
- int flags)
+ int flags, bool kern)
{
DECLARE_WAITQUEUE(wait, current);
struct sock *sk = sock->sk, *nsk;
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 06186d608a27..cb4fff785cbf 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -641,11 +641,13 @@ static void llc_cmsg_rcv(struct msghdr *msg, struct sk_buff *skb)
* @sock: Socket which connections arrive on.
* @newsock: Socket to move incoming connection to.
* @flags: User specified operational flags.
+ * @kern: If the socket is kernel internal
*
* Accept a new incoming connection.
* Returns 0 upon success, negative otherwise.
*/
-static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags)
+static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sock *sk = sock->sk, *newsk;
struct llc_sock *llc, *newllc;
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index 4bbf4526b885..ebf16f7f9089 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -765,7 +765,8 @@ static int nr_connect(struct socket *sock, struct sockaddr *uaddr,
return err;
}
-static int nr_accept(struct socket *sock, struct socket *newsock, int flags)
+static int nr_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sk_buff *skb;
struct sock *newsk;
diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
index 879885b31cce..2ffb18e73df6 100644
--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -441,7 +441,7 @@ struct sock *nfc_llcp_accept_dequeue(struct sock *parent,
}
static int llcp_sock_accept(struct socket *sock, struct socket *newsock,
- int flags)
+ int flags, bool kern)
{
DECLARE_WAITQUEUE(wait, current);
struct sock *sk = sock->sk, *new_sk;
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 222bedcd9575..e81537991ddf 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -772,7 +772,8 @@ static void pep_sock_close(struct sock *sk, long timeout)
sock_put(sk);
}
-static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp)
+static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp,
+ bool kern)
{
struct pep_sock *pn = pep_sk(sk), *newpn;
struct sock *newsk = NULL;
@@ -846,7 +847,8 @@ static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp)
}
/* Create a new to-be-accepted sock */
- newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_KERNEL, sk->sk_prot, 0);
+ newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_KERNEL, sk->sk_prot,
+ kern);
if (!newsk) {
pep_reject_conn(sk, skb, PN_PIPE_ERR_OVERLOAD, GFP_KERNEL);
err = -ENOBUFS;
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index a6c8da3ee893..64634e3ec2fc 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -305,7 +305,7 @@ static int pn_socket_connect(struct socket *sock, struct sockaddr *addr,
}
static int pn_socket_accept(struct socket *sock, struct socket *newsock,
- int flags)
+ int flags, bool kern)
{
struct sock *sk = sock->sk;
struct sock *newsk;
@@ -314,7 +314,7 @@ static int pn_socket_accept(struct socket *sock, struct socket *newsock,
if (unlikely(sk->sk_state != TCP_LISTEN))
return -EINVAL;
- newsk = sk->sk_prot->accept(sk, flags, &err);
+ newsk = sk->sk_prot->accept(sk, flags, &err, kern);
if (!newsk)
return err;
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index 2c69a508a693..507678853e6c 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -133,7 +133,7 @@ int rds_tcp_accept_one(struct socket *sock)
new_sock->type = sock->type;
new_sock->ops = sock->ops;
- ret = sock->ops->accept(sock, new_sock, O_NONBLOCK);
+ ret = sock->ops->accept(sock, new_sock, O_NONBLOCK, true);
if (ret < 0)
goto out;
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index b8a1df2c9785..4a9729257023 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -871,7 +871,8 @@ static int rose_connect(struct socket *sock, struct sockaddr *uaddr, int addr_le
return err;
}
-static int rose_accept(struct socket *sock, struct socket *newsock, int flags)
+static int rose_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sk_buff *skb;
struct sock *newsk;
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 063baac5b9fe..961ee59f696a 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -640,14 +640,15 @@ static sctp_scope_t sctp_v6_scope(union sctp_addr *addr)
/* Create and initialize a new sk for the socket to be returned by accept(). */
static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
- struct sctp_association *asoc)
+ struct sctp_association *asoc,
+ bool kern)
{
struct sock *newsk;
struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
struct sctp6_sock *newsctp6sk;
struct ipv6_txoptions *opt;
- newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot, 0);
+ newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot, kern);
if (!newsk)
goto out;
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 1b6d4574d2b0..989a900383b5 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -575,10 +575,11 @@ static int sctp_v4_is_ce(const struct sk_buff *skb)
/* Create and initialize a new sk for the socket returned by accept(). */
static struct sock *sctp_v4_create_accept_sk(struct sock *sk,
- struct sctp_association *asoc)
+ struct sctp_association *asoc,
+ bool kern)
{
struct sock *newsk = sk_alloc(sock_net(sk), PF_INET, GFP_KERNEL,
- sk->sk_prot, 0);
+ sk->sk_prot, kern);
struct inet_sock *newinet;
if (!newsk)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 6f0a9be50f50..0f378ea2ae38 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4116,7 +4116,7 @@ static int sctp_disconnect(struct sock *sk, int flags)
* descriptor will be returned from accept() to represent the newly
* formed association.
*/
-static struct sock *sctp_accept(struct sock *sk, int flags, int *err)
+static struct sock *sctp_accept(struct sock *sk, int flags, int *err, bool kern)
{
struct sctp_sock *sp;
struct sctp_endpoint *ep;
@@ -4151,7 +4151,7 @@ static struct sock *sctp_accept(struct sock *sk, int flags, int *err)
*/
asoc = list_entry(ep->asocs.next, struct sctp_association, asocs);
- newsk = sp->pf->create_accept_sk(sk, asoc);
+ newsk = sp->pf->create_accept_sk(sk, asoc, kern);
if (!newsk) {
error = -ENOMEM;
goto out;
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 85837ab90e89..093803786eac 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -944,7 +944,7 @@ static int smc_listen(struct socket *sock, int backlog)
}
static int smc_accept(struct socket *sock, struct socket *new_sock,
- int flags)
+ int flags, bool kern)
{
struct sock *sk = sock->sk, *nsk;
DECLARE_WAITQUEUE(wait, current);
diff --git a/net/socket.c b/net/socket.c
index e0757e648c0c..e034fe4164be 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1506,7 +1506,7 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
if (err)
goto out_fd;
- err = sock->ops->accept(sock, newsock, sock->file->f_flags);
+ err = sock->ops->accept(sock, newsock, sock->file->f_flags, false);
if (err < 0)
goto out_fd;
@@ -3239,7 +3239,7 @@ int kernel_accept(struct socket *sock, struct socket **newsock, int flags)
if (err < 0)
goto done;
- err = sock->ops->accept(sock, *newsock, flags);
+ err = sock->ops->accept(sock, *newsock, flags, true);
if (err < 0) {
sock_release(*newsock);
*newsock = NULL;
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 43e4045e72bc..7130e73bd42c 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -115,7 +115,8 @@ static void tipc_data_ready(struct sock *sk);
static void tipc_write_space(struct sock *sk);
static void tipc_sock_destruct(struct sock *sk);
static int tipc_release(struct socket *sock);
-static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags);
+static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags,
+ bool kern);
static void tipc_sk_timeout(unsigned long data);
static int tipc_sk_publish(struct tipc_sock *tsk, uint scope,
struct tipc_name_seq const *seq);
@@ -2029,7 +2030,8 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo)
*
* Returns 0 on success, errno otherwise
*/
-static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
+static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags,
+ bool kern)
{
struct sock *new_sk, *sk = sock->sk;
struct sk_buff *buf;
@@ -2051,7 +2053,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)
buf = skb_peek(&sk->sk_receive_queue);
- res = tipc_sk_create(sock_net(sock->sk), new_sock, 0, 0);
+ res = tipc_sk_create(sock_net(sock->sk), new_sock, 0, kern);
if (res)
goto exit;
security_sk_clone(sock->sk, new_sock->sk);
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index ee37b390260a..928691c43408 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -636,7 +636,7 @@ static int unix_bind(struct socket *, struct sockaddr *, int);
static int unix_stream_connect(struct socket *, struct sockaddr *,
int addr_len, int flags);
static int unix_socketpair(struct socket *, struct socket *);
-static int unix_accept(struct socket *, struct socket *, int);
+static int unix_accept(struct socket *, struct socket *, int, bool);
static int unix_getname(struct socket *, struct sockaddr *, int *, int);
static unsigned int unix_poll(struct file *, struct socket *, poll_table *);
static unsigned int unix_dgram_poll(struct file *, struct socket *,
@@ -1402,7 +1402,8 @@ static void unix_sock_inherit_flags(const struct socket *old,
set_bit(SOCK_PASSSEC, &new->flags);
}
-static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
+static int unix_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sock *sk = sock->sk;
struct sock *tsk;
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 9192ead66751..9f770f33c100 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1250,7 +1250,8 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
return err;
}
-static int vsock_accept(struct socket *sock, struct socket *newsock, int flags)
+static int vsock_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sock *listener;
int err;
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index fd28a49dbe8f..8b911c29860e 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -852,7 +852,8 @@ static int x25_wait_for_data(struct sock *sk, long timeout)
return rc;
}
-static int x25_accept(struct socket *sock, struct socket *newsock, int flags)
+static int x25_accept(struct socket *sock, struct socket *newsock, int flags,
+ bool kern)
{
struct sock *sk = sock->sk;
struct sock *newsk;
]
|
| 65/2 |
2026/11/28 10:04 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 1e1a9cecfab3f22ebef0a976f849c87be8d03c1c
Author: Christoph Hellwig <hch@lst.de>
Date: Fri Jan 31 13:03:47 2025 +0100
block: force noio scope in blk_mq_freeze_queue
When block drivers or the core block code perform allocations with a
frozen queue, this could try to recurse into the block device to
reclaim memory and deadlock. Thus all allocations done by a process
that froze a queue need to be done without __GFP_IO and __GFP_FS.
Instead of tying to track all of them down, force a noio scope as
part of freezing the queue.
Note that nvme is a bit of a mess here due to the non-owner freezes,
and they will be addressed separately.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250131120352.1315351-2-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 45a395862fbc..c795fa3a30e1 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1545,6 +1545,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
struct request_queue *q = disk->queue;
struct blkg_policy_data *pd_prealloc = NULL;
struct blkcg_gq *blkg, *pinned_blkg = NULL;
+ unsigned int memflags;
int ret;
if (blkcg_policy_enabled(q, pol))
@@ -1559,7 +1560,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
return -EINVAL;
if (queue_is_mq(q))
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
retry:
spin_lock_irq(&q->queue_lock);
@@ -1623,7 +1624,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
spin_unlock_irq(&q->queue_lock);
out:
if (queue_is_mq(q))
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
if (pinned_blkg)
blkg_put(pinned_blkg);
if (pd_prealloc)
@@ -1667,12 +1668,13 @@ void blkcg_deactivate_policy(struct gendisk *disk,
{
struct request_queue *q = disk->queue;
struct blkcg_gq *blkg;
+ unsigned int memflags;
if (!blkcg_policy_enabled(q, pol))
return;
if (queue_is_mq(q))
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
mutex_lock(&q->blkcg_mutex);
spin_lock_irq(&q->queue_lock);
@@ -1696,7 +1698,7 @@ void blkcg_deactivate_policy(struct gendisk *disk,
mutex_unlock(&q->blkcg_mutex);
if (queue_is_mq(q))
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
}
EXPORT_SYMBOL_GPL(blkcg_deactivate_policy);
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index a5894ec9696e..65a1d4427ccf 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -3224,6 +3224,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,
u32 qos[NR_QOS_PARAMS];
bool enable, user;
char *body, *p;
+ unsigned int memflags;
int ret;
blkg_conf_init(&ctx, input);
@@ -3247,7 +3248,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,
ioc = q_to_ioc(disk->queue);
}
- blk_mq_freeze_queue(disk->queue);
+ memflags = blk_mq_freeze_queue(disk->queue);
blk_mq_quiesce_queue(disk->queue);
spin_lock_irq(&ioc->lock);
@@ -3347,7 +3348,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,
wbt_enable_default(disk);
blk_mq_unquiesce_queue(disk->queue);
- blk_mq_unfreeze_queue(disk->queue);
+ blk_mq_unfreeze_queue(disk->queue, memflags);
blkg_conf_exit(&ctx);
return nbytes;
@@ -3355,7 +3356,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,
spin_unlock_irq(&ioc->lock);
blk_mq_unquiesce_queue(disk->queue);
- blk_mq_unfreeze_queue(disk->queue);
+ blk_mq_unfreeze_queue(disk->queue, memflags);
ret = -EINVAL;
err:
@@ -3414,6 +3415,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
{
struct blkg_conf_ctx ctx;
struct request_queue *q;
+ unsigned int memflags;
struct ioc *ioc;
u64 u[NR_I_LCOEFS];
bool user;
@@ -3441,7 +3443,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
ioc = q_to_ioc(q);
}
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
blk_mq_quiesce_queue(q);
spin_lock_irq(&ioc->lock);
@@ -3493,7 +3495,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
spin_unlock_irq(&ioc->lock);
blk_mq_unquiesce_queue(q);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
blkg_conf_exit(&ctx);
return nbytes;
@@ -3502,7 +3504,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
spin_unlock_irq(&ioc->lock);
blk_mq_unquiesce_queue(q);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
ret = -EINVAL;
err:
diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c
index ebb522788d97..42c1e0b9a68f 100644
--- a/block/blk-iolatency.c
+++ b/block/blk-iolatency.c
@@ -749,9 +749,11 @@ static void blkiolatency_enable_work_fn(struct work_struct *work)
*/
enabled = atomic_read(&blkiolat->enable_cnt);
if (enabled != blkiolat->enabled) {
- blk_mq_freeze_queue(blkiolat->rqos.disk->queue);
+ unsigned int memflags;
+
+ memflags = blk_mq_freeze_queue(blkiolat->rqos.disk->queue);
blkiolat->enabled = enabled;
- blk_mq_unfreeze_queue(blkiolat->rqos.disk->queue);
+ blk_mq_unfreeze_queue(blkiolat->rqos.disk->queue, memflags);
}
}
diff --git a/block/blk-mq.c b/block/blk-mq.c
index da39a1cac702..40490ac88045 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -210,12 +210,12 @@ int blk_mq_freeze_queue_wait_timeout(struct request_queue *q,
}
EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_wait_timeout);
-void blk_mq_freeze_queue(struct request_queue *q)
+void blk_mq_freeze_queue_nomemsave(struct request_queue *q)
{
blk_freeze_queue_start(q);
blk_mq_freeze_queue_wait(q);
}
-EXPORT_SYMBOL_GPL(blk_mq_freeze_queue);
+EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_nomemsave);
bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic)
{
@@ -236,12 +236,12 @@ bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic)
return unfreeze;
}
-void blk_mq_unfreeze_queue(struct request_queue *q)
+void blk_mq_unfreeze_queue_nomemrestore(struct request_queue *q)
{
if (__blk_mq_unfreeze_queue(q, false))
blk_unfreeze_release_lock(q);
}
-EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);
+EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue_nomemrestore);
/*
* non_owner variant of blk_freeze_queue_start
@@ -4223,13 +4223,14 @@ static void blk_mq_update_tag_set_shared(struct blk_mq_tag_set *set,
bool shared)
{
struct request_queue *q;
+ unsigned int memflags;
lockdep_assert_held(&set->tag_list_lock);
list_for_each_entry(q, &set->tag_list, tag_set_list) {
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
queue_set_hctx_shared(q, shared);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
}
}
@@ -4992,6 +4993,7 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
struct request_queue *q;
LIST_HEAD(head);
int prev_nr_hw_queues = set->nr_hw_queues;
+ unsigned int memflags;
int i;
lockdep_assert_held(&set->tag_list_lock);
@@ -5003,8 +5005,10 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
if (set->nr_maps == 1 && nr_hw_queues == set->nr_hw_queues)
return;
+ memflags = memalloc_noio_save();
list_for_each_entry(q, &set->tag_list, tag_set_list)
- blk_mq_freeze_queue(q);
+ blk_mq_freeze_queue_nomemsave(q);
+
/*
* Switch IO scheduler to 'none', cleaning up the data associated
* with the previous scheduler. We will switch back once we are done
@@ -5052,7 +5056,8 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
blk_mq_elv_switch_back(&head, q);
list_for_each_entry(q, &set->tag_list, tag_set_list)
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue_nomemrestore(q);
+ memalloc_noio_restore(memflags);
/* Free the excess tags when nr_hw_queues shrink. */
for (i = set->nr_hw_queues; i < prev_nr_hw_queues; i++)
diff --git a/block/blk-pm.c b/block/blk-pm.c
index 42e842074715..8d3e052f91da 100644
--- a/block/blk-pm.c
+++ b/block/blk-pm.c
@@ -89,7 +89,7 @@ int blk_pre_runtime_suspend(struct request_queue *q)
if (percpu_ref_is_zero(&q->q_usage_counter))
ret = 0;
/* Switch q_usage_counter back to per-cpu mode. */
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue_nomemrestore(q);
if (ret < 0) {
spin_lock_irq(&q->queue_lock);
diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c
index eb9618cd68ad..d4d4f4dc0e23 100644
--- a/block/blk-rq-qos.c
+++ b/block/blk-rq-qos.c
@@ -299,6 +299,7 @@ int rq_qos_add(struct rq_qos *rqos, struct gendisk *disk, enum rq_qos_id id,
const struct rq_qos_ops *ops)
{
struct request_queue *q = disk->queue;
+ unsigned int memflags;
lockdep_assert_held(&q->rq_qos_mutex);
@@ -310,14 +311,14 @@ int rq_qos_add(struct rq_qos *rqos, struct gendisk *disk, enum rq_qos_id id,
* No IO can be in-flight when adding rqos, so freeze queue, which
* is fine since we only support rq_qos for blk-mq queue.
*/
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
if (rq_qos_id(q, rqos->id))
goto ebusy;
rqos->next = q->rq_qos;
q->rq_qos = rqos;
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
if (rqos->ops->debugfs_attrs) {
mutex_lock(&q->debugfs_mutex);
@@ -327,7 +328,7 @@ int rq_qos_add(struct rq_qos *rqos, struct gendisk *disk, enum rq_qos_id id,
return 0;
ebusy:
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
return -EBUSY;
}
@@ -335,17 +336,18 @@ void rq_qos_del(struct rq_qos *rqos)
{
struct request_queue *q = rqos->disk->queue;
struct rq_qos **cur;
+ unsigned int memflags;
lockdep_assert_held(&q->rq_qos_mutex);
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
for (cur = &q->rq_qos; *cur; cur = &(*cur)->next) {
if (*cur == rqos) {
*cur = rqos->next;
break;
}
}
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
mutex_lock(&q->debugfs_mutex);
blk_mq_debugfs_unregister_rqos(rqos);
diff --git a/block/blk-settings.c b/block/blk-settings.c
index db12396ff5c7..c44dadc35e1e 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -461,11 +461,12 @@ EXPORT_SYMBOL_GPL(queue_limits_commit_update);
int queue_limits_commit_update_frozen(struct request_queue *q,
struct queue_limits *lim)
{
+ unsigned int memflags;
int ret;
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
ret = queue_limits_commit_update(q, lim);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
return ret;
}
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 7b970e6765e7..6f548a4376aa 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -681,7 +681,7 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
struct queue_sysfs_entry *entry = to_queue(attr);
struct gendisk *disk = container_of(kobj, struct gendisk, queue_kobj);
struct request_queue *q = disk->queue;
- unsigned int noio_flag;
+ unsigned int memflags;
ssize_t res;
if (!entry->store_limit && !entry->store)
@@ -711,11 +711,9 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
}
mutex_lock(&q->sysfs_lock);
- blk_mq_freeze_queue(q);
- noio_flag = memalloc_noio_save();
+ memflags = blk_mq_freeze_queue(q);
res = entry->store(disk, page, length);
- memalloc_noio_restore(noio_flag);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
mutex_unlock(&q->sysfs_lock);
return res;
}
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 82dbaefcfa3b..8d149aff9fd0 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1202,6 +1202,7 @@ static int blk_throtl_init(struct gendisk *disk)
{
struct request_queue *q = disk->queue;
struct throtl_data *td;
+ unsigned int memflags;
int ret;
td = kzalloc_node(sizeof(*td), GFP_KERNEL, q->node);
@@ -1215,7 +1216,7 @@ static int blk_throtl_init(struct gendisk *disk)
* Freeze queue before activating policy, to synchronize with IO path,
* which is protected by 'q_usage_counter'.
*/
- blk_mq_freeze_queue(disk->queue);
+ memflags = blk_mq_freeze_queue(disk->queue);
blk_mq_quiesce_queue(disk->queue);
q->td = td;
@@ -1239,7 +1240,7 @@ static int blk_throtl_init(struct gendisk *disk)
out:
blk_mq_unquiesce_queue(disk->queue);
- blk_mq_unfreeze_queue(disk->queue);
+ blk_mq_unfreeze_queue(disk->queue, memflags);
return ret;
}
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 9d08a54c201e..761ea662ddc3 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1717,9 +1717,10 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
else
pr_warn("%s: failed to revalidate zones\n", disk->disk_name);
if (ret) {
- blk_mq_freeze_queue(q);
+ unsigned int memflags = blk_mq_freeze_queue(q);
+
disk_free_zone_resources(disk);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
}
return ret;
diff --git a/block/elevator.c b/block/elevator.c
index b81216c48b6b..cd2ce4921601 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -570,6 +570,7 @@ static struct elevator_type *elevator_get_default(struct request_queue *q)
void elevator_init_mq(struct request_queue *q)
{
struct elevator_type *e;
+ unsigned int memflags;
int err;
WARN_ON_ONCE(blk_queue_registered(q));
@@ -590,13 +591,13 @@ void elevator_init_mq(struct request_queue *q)
*
* Disk isn't added yet, so verifying queue lock only manually.
*/
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
blk_mq_cancel_work_sync(q);
err = blk_mq_init_sched(q, e);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
if (err) {
pr_warn("\"%s\" elevator initialization failed, "
@@ -614,11 +615,12 @@ void elevator_init_mq(struct request_queue *q)
*/
int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
{
+ unsigned int memflags;
int ret;
lockdep_assert_held(&q->sysfs_lock);
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
blk_mq_quiesce_queue(q);
if (q->elevator) {
@@ -639,7 +641,7 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
out_unfreeze:
blk_mq_unquiesce_queue(q);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
if (ret) {
pr_warn("elv: switch to \"%s\" failed, falling back to \"none\"\n",
@@ -651,9 +653,11 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
void elevator_disable(struct request_queue *q)
{
+ unsigned int memflags;
+
lockdep_assert_held(&q->sysfs_lock);
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
blk_mq_quiesce_queue(q);
elv_unregister_queue(q);
@@ -664,7 +668,7 @@ void elevator_disable(struct request_queue *q)
blk_add_trace_msg(q, "elv switch: none");
blk_mq_unquiesce_queue(q);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
}
/*
diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
index 3523dd82d7a0..4db7f6ce8ade 100644
--- a/drivers/block/aoe/aoedev.c
+++ b/drivers/block/aoe/aoedev.c
@@ -226,10 +226,11 @@ aoedev_downdev(struct aoedev *d)
/* fast fail all pending I/O */
if (d->blkq) {
/* UP is cleared, freeze+quiesce to insure all are errored */
- blk_mq_freeze_queue(d->blkq);
+ unsigned int memflags = blk_mq_freeze_queue(d->blkq);
+
blk_mq_quiesce_queue(d->blkq);
blk_mq_unquiesce_queue(d->blkq);
- blk_mq_unfreeze_queue(d->blkq);
+ blk_mq_unfreeze_queue(d->blkq, memflags);
}
if (d->gd)
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 110f9aca2667..a81ade622a01 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -746,6 +746,7 @@ static int do_format(int drive, int type, struct atari_format_descr *desc)
unsigned char *p;
int sect, nsect;
unsigned long flags;
+ unsigned int memflags;
int ret;
if (type) {
@@ -758,7 +759,7 @@ static int do_format(int drive, int type, struct atari_format_descr *desc)
}
q = unit[drive].disk[type]->queue;
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
blk_mq_quiesce_queue(q);
local_irq_save(flags);
@@ -817,7 +818,7 @@ static int do_format(int drive, int type, struct atari_format_descr *desc)
ret = FormatError ? -EIO : 0;
out:
blk_mq_unquiesce_queue(q);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
return ret;
}
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index d1f1d6bef2e6..c05fe27a96b6 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -586,6 +586,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
{
struct file *file = fget(arg);
struct file *old_file;
+ unsigned int memflags;
int error;
bool partscan;
bool is_loop;
@@ -623,14 +624,14 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
/* and ... switch */
disk_force_media_change(lo->lo_disk);
- blk_mq_freeze_queue(lo->lo_queue);
+ memflags = blk_mq_freeze_queue(lo->lo_queue);
mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
lo->lo_backing_file = file;
lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
mapping_set_gfp_mask(file->f_mapping,
lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
loop_update_dio(lo);
- blk_mq_unfreeze_queue(lo->lo_queue);
+ blk_mq_unfreeze_queue(lo->lo_queue, memflags);
partscan = lo->lo_flags & LO_FLAGS_PARTSCAN;
loop_global_unlock(lo, is_loop);
@@ -1255,6 +1256,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
int err;
bool partscan = false;
bool size_changed = false;
+ unsigned int memflags;
err = mutex_lock_killable(&lo->lo_mutex);
if (err)
@@ -1272,7 +1274,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
}
/* I/O needs to be drained before changing lo_offset or lo_sizelimit */
- blk_mq_freeze_queue(lo->lo_queue);
+ memflags = blk_mq_freeze_queue(lo->lo_queue);
err = loop_set_status_from_info(lo, info);
if (err)
@@ -1294,7 +1296,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
loop_update_dio(lo);
out_unfreeze:
- blk_mq_unfreeze_queue(lo->lo_queue);
+ blk_mq_unfreeze_queue(lo->lo_queue, memflags);
if (partscan)
clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state);
out_unlock:
@@ -1446,6 +1448,7 @@ static int loop_set_capacity(struct loop_device *lo)
static int loop_set_dio(struct loop_device *lo, unsigned long arg)
{
bool use_dio = !!arg;
+ unsigned int memflags;
if (lo->lo_state != Lo_bound)
return -ENXIO;
@@ -1459,18 +1462,19 @@ static int loop_set_dio(struct loop_device *lo, unsigned long arg)
vfs_fsync(lo->lo_backing_file, 0);
}
- blk_mq_freeze_queue(lo->lo_queue);
+ memflags = blk_mq_freeze_queue(lo->lo_queue);
if (use_dio)
lo->lo_flags |= LO_FLAGS_DIRECT_IO;
else
lo->lo_flags &= ~LO_FLAGS_DIRECT_IO;
- blk_mq_unfreeze_queue(lo->lo_queue);
+ blk_mq_unfreeze_queue(lo->lo_queue, memflags);
return 0;
}
static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
{
struct queue_limits lim;
+ unsigned int memflags;
int err = 0;
if (lo->lo_state != Lo_bound)
@@ -1485,10 +1489,10 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
lim = queue_limits_start_update(lo->lo_queue);
loop_update_limits(lo, &lim, arg);
- blk_mq_freeze_queue(lo->lo_queue);
+ memflags = blk_mq_freeze_queue(lo->lo_queue);
err = queue_limits_commit_update(lo->lo_queue, &lim);
loop_update_dio(lo);
- blk_mq_unfreeze_queue(lo->lo_queue);
+ blk_mq_unfreeze_queue(lo->lo_queue, memflags);
return err;
}
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b63a0f29a54a..7bdc7eb808ea 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1234,6 +1234,7 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
struct socket *sock;
struct nbd_sock **socks;
struct nbd_sock *nsock;
+ unsigned int memflags;
int err;
/* Arg will be cast to int, check it to avoid overflow */
@@ -1247,7 +1248,7 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
* We need to make sure we don't get any errant requests while we're
* reallocating the ->socks array.
*/
- blk_mq_freeze_queue(nbd->disk->queue);
+ memflags = blk_mq_freeze_queue(nbd->disk->queue);
if (!netlink && !nbd->task_setup &&
!test_bit(NBD_RT_BOUND, &config->runtime_flags))
@@ -1288,12 +1289,12 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
INIT_WORK(&nsock->work, nbd_pending_cmd_work);
socks[config->num_connections++] = nsock;
atomic_inc(&config->live_connections);
- blk_mq_unfreeze_queue(nbd->disk->queue);
+ blk_mq_unfreeze_queue(nbd->disk->queue, memflags);
return 0;
put_socket:
- blk_mq_unfreeze_queue(nbd->disk->queue);
+ blk_mq_unfreeze_queue(nbd->disk->queue, memflags);
sockfd_put(sock);
return err;
}
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 5b393e4a1ddf..faafd7ff43d6 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -7281,9 +7281,10 @@ static ssize_t do_rbd_remove(const char *buf, size_t count)
* Prevent new IO from being queued and wait for existing
* IO to complete/fail.
*/
- blk_mq_freeze_queue(rbd_dev->disk->queue);
+ unsigned int memflags = blk_mq_freeze_queue(rbd_dev->disk->queue);
+
blk_mark_disk_dead(rbd_dev->disk);
- blk_mq_unfreeze_queue(rbd_dev->disk->queue);
+ blk_mq_unfreeze_queue(rbd_dev->disk->queue, memflags);
}
del_gendisk(rbd_dev->disk);
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
index 88dcae6ec575..05c4aee7f262 100644
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -1113,6 +1113,7 @@ static void vdc_requeue_inflight(struct vdc_port *port)
static void vdc_queue_drain(struct vdc_port *port)
{
struct request_queue *q = port->disk->queue;
+ unsigned int memflags;
/*
* Mark the queue as draining, then freeze/quiesce to ensure
@@ -1121,12 +1122,12 @@ static void vdc_queue_drain(struct vdc_port *port)
port->drain = 1;
spin_unlock_irq(&port->vio.lock);
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
blk_mq_quiesce_queue(q);
spin_lock_irq(&port->vio.lock);
port->drain = 0;
- blk_mq_unquiesce_queue(q);
+ blk_mq_unquiesce_queue(q, memflags);
blk_mq_unfreeze_queue(q);
}
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 9914153b365b..3aedcb5add61 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -840,6 +840,7 @@ static int grab_drive(struct floppy_state *fs, enum swim_state state,
static void release_drive(struct floppy_state *fs)
{
struct request_queue *q = disks[fs->index]->queue;
+ unsigned int memflags;
unsigned long flags;
swim3_dbg("%s", "-> release drive\n");
@@ -848,10 +849,10 @@ static void release_drive(struct floppy_state *fs)
fs->state = idle;
spin_unlock_irqrestore(&swim3_lock, flags);
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
blk_mq_quiesce_queue(q);
blk_mq_unquiesce_queue(q);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
}
static int fd_eject(struct floppy_state *fs)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index bbaa26b523b8..a4af39fc7ea2 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -1584,11 +1584,12 @@ static int virtblk_freeze(struct virtio_device *vdev)
{
struct virtio_blk *vblk = vdev->priv;
struct request_queue *q = vblk->disk->queue;
+ unsigned int memflags;
/* Ensure no requests in virtqueues before deleting vqs. */
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
blk_mq_quiesce_queue_nowait(q);
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
/* Ensure we don't receive any more interrupts */
virtio_reset_device(vdev);
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index ee7e1d908986..847c11542f02 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -404,6 +404,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
{
unsigned long flags;
+ unsigned int memflags;
lockdep_assert_held(&mtd_table_mutex);
@@ -420,10 +421,10 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
spin_unlock_irqrestore(&old->queue_lock, flags);
/* freeze+quiesce queue to ensure all requests are flushed */
- blk_mq_freeze_queue(old->rq);
+ memflags = blk_mq_freeze_queue(old->rq);
blk_mq_quiesce_queue(old->rq);
blk_mq_unquiesce_queue(old->rq);
- blk_mq_unfreeze_queue(old->rq);
+ blk_mq_unfreeze_queue(old->rq, memflags);
/* If the device is currently open, tell trans driver to close it,
then put mtd device, and don't touch it again */
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 76b615d4d5b9..40046770f1bf 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2132,15 +2132,16 @@ static int nvme_update_ns_info_generic(struct nvme_ns *ns,
struct nvme_ns_info *info)
{
struct queue_limits lim;
+ unsigned int memflags;
int ret;
lim = queue_limits_start_update(ns->disk->queue);
nvme_set_ctrl_limits(ns->ctrl, &lim);
- blk_mq_freeze_queue(ns->disk->queue);
+ memflags = blk_mq_freeze_queue(ns->disk->queue);
ret = queue_limits_commit_update(ns->disk->queue, &lim);
set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info));
- blk_mq_unfreeze_queue(ns->disk->queue);
+ blk_mq_unfreeze_queue(ns->disk->queue, memflags);
/* Hide the block-interface for these devices */
if (!ret)
@@ -2155,6 +2156,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
struct nvme_id_ns_nvm *nvm = NULL;
struct nvme_zone_info zi = {};
struct nvme_id_ns *id;
+ unsigned int memflags;
sector_t capacity;
unsigned lbaf;
int ret;
@@ -2186,7 +2188,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
lim = queue_limits_start_update(ns->disk->queue);
- blk_mq_freeze_queue(ns->disk->queue);
+ memflags = blk_mq_freeze_queue(ns->disk->queue);
ns->head->lba_shift = id->lbaf[lbaf].ds;
ns->head->nuse = le64_to_cpu(id->nuse);
capacity = nvme_lba_to_sect(ns->head, le64_to_cpu(id->nsze));
@@ -2219,7 +2221,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
ret = queue_limits_commit_update(ns->disk->queue, &lim);
if (ret) {
- blk_mq_unfreeze_queue(ns->disk->queue);
+ blk_mq_unfreeze_queue(ns->disk->queue, memflags);
goto out;
}
@@ -2235,7 +2237,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
ns->head->features |= NVME_NS_DEAC;
set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info));
set_bit(NVME_NS_READY, &ns->flags);
- blk_mq_unfreeze_queue(ns->disk->queue);
+ blk_mq_unfreeze_queue(ns->disk->queue, memflags);
if (blk_queue_is_zoned(ns->queue)) {
ret = blk_revalidate_disk_zones(ns->disk);
@@ -2291,9 +2293,10 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)
if (!ret && nvme_ns_head_multipath(ns->head)) {
struct queue_limits *ns_lim = &ns->disk->queue->limits;
struct queue_limits lim;
+ unsigned int memflags;
lim = queue_limits_start_update(ns->head->disk->queue);
- blk_mq_freeze_queue(ns->head->disk->queue);
+ memflags = blk_mq_freeze_queue(ns->head->disk->queue);
/*
* queue_limits mixes values that are the hardware limitations
* for bio splitting with what is the device configuration.
@@ -2325,7 +2328,7 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)
set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info));
nvme_mpath_revalidate_paths(ns);
- blk_mq_unfreeze_queue(ns->head->disk->queue);
+ blk_mq_unfreeze_queue(ns->head->disk->queue, memflags);
}
return ret;
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index a85d190942bd..2a7635565083 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -60,7 +60,7 @@ void nvme_mpath_unfreeze(struct nvme_subsystem *subsys)
lockdep_assert_held(&subsys->lock);
list_for_each_entry(h, &subsys->nsheads, entry)
if (h->disk)
- blk_mq_unfreeze_queue(h->disk->queue);
+ blk_mq_unfreeze_queue_nomemrestore(h->disk->queue);
}
void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 4411426a7894..b86e259516a7 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2723,6 +2723,7 @@ int
scsi_device_quiesce(struct scsi_device *sdev)
{
struct request_queue *q = sdev->request_queue;
+ unsigned int memflags;
int err;
/*
@@ -2737,7 +2738,7 @@ scsi_device_quiesce(struct scsi_device *sdev)
blk_set_pm_only(q);
- blk_mq_freeze_queue(q);
+ memflags = blk_mq_freeze_queue(q);
/*
* Ensure that the effect of blk_set_pm_only() will be visible
* for percpu_ref_tryget() callers that occur after the queue
@@ -2745,7 +2746,7 @@ scsi_device_quiesce(struct scsi_device *sdev)
* was called. See also https://lwn.net/Articles/573497/.
*/
synchronize_rcu();
- blk_mq_unfreeze_queue(q);
+ blk_mq_unfreeze_queue(q, memflags);
mutex_lock(&sdev->state_mutex);
err = scsi_device_set_state(sdev, SDEV_QUIESCE);
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 042329b74c6e..312d78213954 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -220,6 +220,7 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
int new_shift = sbitmap_calculate_shift(depth);
bool need_alloc = !sdev->budget_map.map;
bool need_free = false;
+ unsigned int memflags;
int ret;
struct sbitmap sb_backup;
@@ -240,7 +241,7 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
* and here disk isn't added yet, so freezing is pretty fast
*/
if (need_free) {
- blk_mq_freeze_queue(sdev->request_queue);
+ memflags = blk_mq_freeze_queue(sdev->request_queue);
sb_backup = sdev->budget_map;
}
ret = sbitmap_init_node(&sdev->budget_map,
@@ -256,7 +257,7 @@ static int scsi_realloc_sdev_budget_map(struct scsi_device *sdev,
else
sbitmap_free(&sb_backup);
ret = 0;
- blk_mq_unfreeze_queue(sdev->request_queue);
+ blk_mq_unfreeze_queue(sdev->request_queue, memflags);
}
return ret;
}
diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index 796e37a1d859..3438269a5440 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -1439,6 +1439,7 @@ static ssize_t max_number_of_rtt_store(struct device *dev,
struct ufs_hba *hba = dev_get_drvdata(dev);
struct ufs_dev_info *dev_info = &hba->dev_info;
struct scsi_device *sdev;
+ unsigned int memflags;
unsigned int rtt;
int ret;
@@ -1458,14 +1459,16 @@ static ssize_t max_number_of_rtt_store(struct device *dev,
ufshcd_rpm_get_sync(hba);
+ memflags = memalloc_noio_save();
shost_for_each_device(sdev, hba->host)
- blk_mq_freeze_queue(sdev->request_queue);
+ blk_mq_freeze_queue_nomemsave(sdev->request_queue);
ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR,
QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt);
shost_for_each_device(sdev, hba->host)
- blk_mq_unfreeze_queue(sdev->request_queue);
+ blk_mq_unfreeze_queue_nomemrestore(sdev->request_queue);
+ memalloc_noio_restore(memflags);
ufshcd_rpm_put_sync(hba);
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index a0a9007cc1e3..9ebb53f031cd 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -900,8 +900,22 @@ void blk_mq_delay_run_hw_queues(struct request_queue *q, unsigned long msecs);
void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
busy_tag_iter_fn *fn, void *priv);
void blk_mq_tagset_wait_completed_request(struct blk_mq_tag_set *tagset);
-void blk_mq_freeze_queue(struct request_queue *q);
-void blk_mq_unfreeze_queue(struct request_queue *q);
+void blk_mq_freeze_queue_nomemsave(struct request_queue *q);
+void blk_mq_unfreeze_queue_nomemrestore(struct request_queue *q);
+static inline unsigned int __must_check
+blk_mq_freeze_queue(struct request_queue *q)
+{
+ unsigned int memflags = memalloc_noio_save();
+
+ blk_mq_freeze_queue_nomemsave(q);
+ return memflags;
+}
+static inline void
+blk_mq_unfreeze_queue(struct request_queue *q, unsigned int memflags)
+{
+ blk_mq_unfreeze_queue_nomemrestore(q);
+ memalloc_noio_restore(memflags);
+}
void blk_freeze_queue_start(struct request_queue *q);
void blk_mq_freeze_queue_wait(struct request_queue *q);
int blk_mq_freeze_queue_wait_timeout(struct request_queue *q,
]
|
| 66/2 |
2026/11/28 10:04 |
tool |
git-log |
0m
Args: map[Count:15 MessageRegexps:[nbd] Since:1 year]
Results: map[Output:553d28925fde nbd: Reclassify sockets in the reconnect path
08ebf69c78a0 rnbd-srv: publish the sess_dev at the end of OPEN
4912dab88baa rnbd-srv: fix use-after-free on two CLOSE messages
81941915d53e block/rnbd-srv: drop the sess_dev kobject unlocked
d9667ade40f9 block/rnbd-srv: don't free the device on a sysfs error
0db9f8968a89 blk-mq: don't forget a timer the driver has restarted
0de4e69cd021 ppp: linearize and segment bridged packets when required
d4fabede1da0 loop: remove support for swapping loop fds
07b3eb8b9048 wifi: mac80211: use link address as TA for non-MLO 4-addr station on MLD AP
49701802948a wifi: mt76: keep beacons from queueing the scan work during an abort
ac5ec769afce wifi: mt76: mt7996: scan all bands with one request
3049a7f210ad wifi: mt76: scan all radios of a request at the same time
833de192a443 wifi: mt76: mt7996: take the offchannel link of a frame from its wcid
557a895d92f5 wifi: mt76: remove the unused signal field from struct mt76_rx_status
2d12f56631ef wifi: mt76: mt792x: compute the assoc RSSI from the chain signals
]
|
| 67/2 |
2026/11/28 10:04 |
tool |
git-log |
0m
Args: map[Count:15 MessageRegexps:[reclassify] Since:1 year]
Results: map[Output:553d28925fde nbd: Reclassify sockets in the reconnect path
447a7a3026ed nvme-tcp: delay nvme_tcp_reclassify_socket()
69226cd6fad7 HID: multitouch: reclassify HTIX5288 to WIN_8_FORCE_MULTI_INPUT_NSMU
8a276c0086cf mm/memory-failure: surface unhandlable kernel pages as -ENOTRECOVERABLE
9280e6edf656 nbd: don't warn when reclassifying a busy socket lock
d532cddb6c60 nbd: Reclassify sockets to avoid lockdep circular dependency
19bdb70c77d3 nvme-tcp: lockdep: use dynamic lockdep keys per socket instance
2caaa52c1a44 nvme-tcp: move nvme_tcp_reclassify_socket()
866f716b17da drm/amd/display: Align HWSS fast commit path with legacy path
de41cbc64d02 RDMA/rxe: let rxe_reclassify_recv_socket() call sk_owner_put()
0b00bee940cb Bluetooth: btusb: Reclassify Qualcomm WCN6855 debug packets
]
|
| 68/2 |
2026/11/28 10:04 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 112590
output: 86
thoughts: 98
Thoughts: **Upon Initial Review of the NVMe-TCP Reclassification Logic**
Wait a second! My attention has been immediately drawn to the commit `447a7a3026ed` which introduces a delay to `nvme_tcp_reclassify_socket()`. This immediately triggers a deeper dive into this specific commit, as well as `19bdb70c77d3` and `2caaa52c1a44`. My primary objective here is to thoroughly understand the mechanics of how `nvme-tcp` handles socket reclassification, and crucially, *why* this reclassification is being performed. I need to grasp the underlying motivations and the operational impact of this reclassification process to fully comprehend the implications of delaying it.
|
| 69/2 |
2026/11/28 10:04 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 447a7a3026eda85ac2738cbe6ee5ab066a39dad0
Author: Eric Dumazet <edumazet@kernel.org>
Date: Mon Sep 14 16:48:53 2026 +0900
nvme-tcp: delay nvme_tcp_reclassify_socket()
Commit 841aee4d75f1 ("nvme-tcp: lockdep: annotate in-kernel sockets")
introduced nvme_tcp_reclassify_socket() to resolve a lockdep WARN by
distinguishing userspace sockets from nvme-tcp sockets. After that, TLS
encryption support was introduced to nvme-tcp and it added another lock
dependency on userspace socket handling by tlshd, which resulted in a
new lockdep WARN. This WARN was hidden by the commit 19bdb70c77d3
("nvme-tcp: lockdep: use dynamic lockdep keys per socket instance").
However, it turned out the commit 19bdb70c77d3 has a bug of lockdep key
lifetime management, and it is to be reverted by another patch in this
series. After the revert, the WARN was unveiled and observed at the
blktests test case nvme/062:
WARNING: possible circular locking dependency detected
7.3.0-rc2+ #455 Tainted: G W
------------------------------------------------------
tlshd/75867 is trying to acquire lock:
ffffffff91ada5e0 (fs_reclaim){+.+.}-{0:0}, at: __kmalloc_cache_noprof+0x64/0x6d0
but task is already holding lock:
ffff888197808258 (sk_lock-AF_INET-NVME){+.+.}-{0:0}, at: do_tcp_setsockopt+0x499/0x26a0
which lock already depends on the new lock.
To fix the lockdep WARN caused by the TLS encryption support, delay the
reclassification of the nvme-tcp sockets. Currently the reclassification
happens before the TLS handshake starts, which pulls in the additional
lock dependencies related to tlshd. Reclassify the sockets after the TLS
handshake instead, to cut that dependency.
Link: https://lore.kernel.org/lkml/CANn89i+wnTLC==UnXCpjsS4YxvEfhe5oK0N7fttbqr1zKyqdug@mail.gmail.com/
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 0666bb469c0a..7eec983c0ead 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -1869,7 +1869,6 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
}
sk_net_refcnt_upgrade(queue->sock->sk);
- nvme_tcp_reclassify_socket(queue->sock);
/* Single syn retry */
tcp_sock_set_syncnt(queue->sock->sk, 1);
@@ -1958,6 +1957,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
goto err_init_connect;
}
+ nvme_tcp_reclassify_socket(queue->sock);
+
ret = nvme_tcp_init_connection(queue);
if (ret)
goto err_init_connect;
]
|
| 70/2 |
2026/11/28 10:04 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 2caaa52c1a440a3951fb098a148d716dada1ecc2
Author: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Date: Sat May 30 14:20:44 2026 +0900
nvme-tcp: move nvme_tcp_reclassify_socket()
Move nvme_tcp_reclassify_socket() in tcp.c after the struct
nvme_tcp_queue definition. This is preparation for adding a reference
to struct nvme_tcp_queue in the function, which would otherwise cause a
compile failure due to the struct being defined after the function.
Move the entire CONFIG_DEBUG_LOCK_ALLOC block along with the function
to maintain the code organization.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 6241e71130c4..353ac6ce9fbd 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -56,44 +56,6 @@ MODULE_PARM_DESC(tls_handshake_timeout,
static atomic_t nvme_tcp_cpu_queues[NR_CPUS];
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-/* lockdep can detect a circular dependency of the form
- * sk_lock -> mmap_lock (page fault) -> fs locks -> sk_lock
- * because dependencies are tracked for both nvme-tcp and user contexts. Using
- * a separate class prevents lockdep from conflating nvme-tcp socket use with
- * user-space socket API use.
- */
-static struct lock_class_key nvme_tcp_sk_key[2];
-static struct lock_class_key nvme_tcp_slock_key[2];
-
-static void nvme_tcp_reclassify_socket(struct socket *sock)
-{
- struct sock *sk = sock->sk;
-
- if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
- return;
-
- switch (sk->sk_family) {
- case AF_INET:
- sock_lock_init_class_and_name(sk, "slock-AF_INET-NVME",
- &nvme_tcp_slock_key[0],
- "sk_lock-AF_INET-NVME",
- &nvme_tcp_sk_key[0]);
- break;
- case AF_INET6:
- sock_lock_init_class_and_name(sk, "slock-AF_INET6-NVME",
- &nvme_tcp_slock_key[1],
- "sk_lock-AF_INET6-NVME",
- &nvme_tcp_sk_key[1]);
- break;
- default:
- WARN_ON_ONCE(1);
- }
-}
-#else
-static void nvme_tcp_reclassify_socket(struct socket *sock) { }
-#endif
-
enum nvme_tcp_send_state {
NVME_TCP_SEND_CMD_PDU = 0,
NVME_TCP_SEND_H2C_PDU,
@@ -207,6 +169,44 @@ static const struct blk_mq_ops nvme_tcp_mq_ops;
static const struct blk_mq_ops nvme_tcp_admin_mq_ops;
static int nvme_tcp_try_send(struct nvme_tcp_queue *queue);
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+/* lockdep can detect a circular dependency of the form
+ * sk_lock -> mmap_lock (page fault) -> fs locks -> sk_lock
+ * because dependencies are tracked for both nvme-tcp and user contexts. Using
+ * a separate class prevents lockdep from conflating nvme-tcp socket use with
+ * user-space socket API use.
+ */
+static struct lock_class_key nvme_tcp_sk_key[2];
+static struct lock_class_key nvme_tcp_slock_key[2];
+
+static void nvme_tcp_reclassify_socket(struct socket *sock)
+{
+ struct sock *sk = sock->sk;
+
+ if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
+ return;
+
+ switch (sk->sk_family) {
+ case AF_INET:
+ sock_lock_init_class_and_name(sk, "slock-AF_INET-NVME",
+ &nvme_tcp_slock_key[0],
+ "sk_lock-AF_INET-NVME",
+ &nvme_tcp_sk_key[0]);
+ break;
+ case AF_INET6:
+ sock_lock_init_class_and_name(sk, "slock-AF_INET6-NVME",
+ &nvme_tcp_slock_key[1],
+ "sk_lock-AF_INET6-NVME",
+ &nvme_tcp_sk_key[1]);
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ }
+}
+#else
+static void nvme_tcp_reclassify_socket(struct socket *sock) { }
+#endif
+
static inline struct nvme_tcp_ctrl *to_tcp_ctrl(struct nvme_ctrl *ctrl)
{
return container_of(ctrl, struct nvme_tcp_ctrl, ctrl);
]
|
| 71/2 |
2026/11/28 10:04 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 19bdb70c77d3b24239a453291299b64040bdba86
Author: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Date: Thu Jun 4 11:32:08 2026 +0900
nvme-tcp: lockdep: use dynamic lockdep keys per socket instance
When NVMe-TCP controller setup and teardown are repeated with lockdep
enabled, lockdep reports false positives WARN for the following locks:
1) &q->elevator_lock : IO scheduler change context
2) &q->q_usage_counter(io) : SCSI disk probe context
3) fs_reclaim : CPU hotplug bring-up context
4) cpu_hotplug_lock : socket establishment context
5) sk_lock-AF_INET-NVME : MQ sched dispatch context for the socket
6) set->srcu : NVMe controller delete context
The lockdep WARN was observed by running blktests test case nvme/005 for
tcp transport on v7.1-rc1 kernel with a patch. Refer to the Link tag for
the details of the WARN.
This is a false positive because lockdep confuses lock 4) (socket
establishment) with lock 5) (socket in use) for different socket
instances. The locks belong to different sockets, but lockdep treats
them as the same due to shared static lockdep keys.
Fix this by using dynamically allocated lockdep keys per socket instance
instead of static keys nvme_tcp_sk_key[] and nvme_tcp_slock_key[]. Add
nvme_tcp_sk_key and nvme_tcp_slock_key fields to struct nvme_tcp_queue
and pass them to sock_lock_init_class_and_name() for proper lockdep
tracking. Change the argument of nvme_tcp_reclassify_socket() from
'struct socket *' to 'struct nvme_tcp_queue *' to pass both the socket
and the keys. Add CONFIG_DEBUG_LOCK_ALLOC guards to nvme_tcp_alloc_queue()
and nvme_tcp_free_queue() to register and unregister the dynamic keys.
Additionally, move nvme_tcp_reclassify_socket() inside these guards since
it's only needed when lockdep is enabled.
Link: https://lore.kernel.org/linux-nvme/afB5syZbUrppgsDQ@shinmob/
Suggested-by: Nilay Shroff <nilay@linux.ibm.com>
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 353ac6ce9fbd..9d17c88a6200 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -142,6 +142,11 @@ struct nvme_tcp_queue {
void (*state_change)(struct sock *);
void (*data_ready)(struct sock *);
void (*write_space)(struct sock *);
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ struct lock_class_key nvme_tcp_sk_key;
+ struct lock_class_key nvme_tcp_slock_key;
+#endif
};
struct nvme_tcp_ctrl {
@@ -176,12 +181,9 @@ static int nvme_tcp_try_send(struct nvme_tcp_queue *queue);
* a separate class prevents lockdep from conflating nvme-tcp socket use with
* user-space socket API use.
*/
-static struct lock_class_key nvme_tcp_sk_key[2];
-static struct lock_class_key nvme_tcp_slock_key[2];
-
-static void nvme_tcp_reclassify_socket(struct socket *sock)
+static void nvme_tcp_reclassify_socket(struct nvme_tcp_queue *queue)
{
- struct sock *sk = sock->sk;
+ struct sock *sk = queue->sock->sk;
if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
return;
@@ -189,22 +191,20 @@ static void nvme_tcp_reclassify_socket(struct socket *sock)
switch (sk->sk_family) {
case AF_INET:
sock_lock_init_class_and_name(sk, "slock-AF_INET-NVME",
- &nvme_tcp_slock_key[0],
+ &queue->nvme_tcp_slock_key,
"sk_lock-AF_INET-NVME",
- &nvme_tcp_sk_key[0]);
+ &queue->nvme_tcp_sk_key);
break;
case AF_INET6:
sock_lock_init_class_and_name(sk, "slock-AF_INET6-NVME",
- &nvme_tcp_slock_key[1],
+ &queue->nvme_tcp_slock_key,
"sk_lock-AF_INET6-NVME",
- &nvme_tcp_sk_key[1]);
+ &queue->nvme_tcp_sk_key);
break;
default:
WARN_ON_ONCE(1);
}
}
-#else
-static void nvme_tcp_reclassify_socket(struct socket *sock) { }
#endif
static inline struct nvme_tcp_ctrl *to_tcp_ctrl(struct nvme_ctrl *ctrl)
@@ -1468,6 +1468,11 @@ static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid)
kfree(queue->pdu);
mutex_destroy(&queue->send_mutex);
mutex_destroy(&queue->queue_lock);
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ lockdep_unregister_key(&queue->nvme_tcp_sk_key);
+ lockdep_unregister_key(&queue->nvme_tcp_slock_key);
+#endif
}
static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue)
@@ -1813,7 +1818,12 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
}
sk_net_refcnt_upgrade(queue->sock->sk);
- nvme_tcp_reclassify_socket(queue->sock);
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ lockdep_register_key(&queue->nvme_tcp_sk_key);
+ lockdep_register_key(&queue->nvme_tcp_slock_key);
+ nvme_tcp_reclassify_socket(queue);
+#endif
/* Single syn retry */
tcp_sock_set_syncnt(queue->sock->sk, 1);
@@ -1918,6 +1928,10 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
/* Use sync variant - see nvme_tcp_free_queue() for explanation */
__fput_sync(queue->sock->file);
queue->sock = NULL;
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ lockdep_unregister_key(&queue->nvme_tcp_sk_key);
+ lockdep_unregister_key(&queue->nvme_tcp_slock_key);
+#endif
err_destroy_mutex:
mutex_destroy(&queue->send_mutex);
mutex_destroy(&queue->queue_lock);
]
|
| 72/2 |
2026/11/28 10:04 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 117328
output: 82
thoughts: 1832
Thoughts: **My Detailed Thoughts on the NBD Socket Reclassification Issue**
HOLD ON A MINUTE! I just noticed two critical pieces of information that seem to be directly related and potentially problematic.
First, I'm looking closely at the changes introduced in commit `9280e6edf656`, titled "nbd: don't warn when reclassifying a busy socket lock". Let me re-read its explanation very carefully. It states that NBD handles sockets differently because the user supplies a file descriptor (fd) which they retain. This means a concurrent system call on the same socket, or softirq processing acquiring `bh_lock_sock()` on a connected TCP socket, can legitimately hold the socket lock at the exact moment NBD tries to reclassify it. When `sock_allow_reclassification()` returns `false` in this scenario, the `WARN_ON_ONCE()` macro triggers. As we know, under `panic_on_warn`, this warning turns into a kernel crash. The commit's explanation says this is reachable by simply racing `NBD_CMD_CONNECT` against other socket activity on the same fd, as reported by syzbot.
The commit then goes on to say: "Hitting a held lock here is expected for an externally owned socket and is not a kernel bug, so skip reclassification silently instead of warning. Reclassification is a lockdep-only annotation, so skipping it in the rare racing case is harmless."
Now, here's where my brain really starts spinning. I'm looking at that last sentence: "Reclassification is a lockdep-only annotation, so skipping it in the rare racing case is harmless." This strikes me as potentially incomplete or even misleading.
Let's cast our minds back to commit `d532cddb6c60`. In that commit, `nbd_reclassify_socket()` originally contained this check:
if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
return;
Then, commit `9280e6edf656` changed it to:
if (!sock_allow_reclassification(sk))
return;
It simply removed the `WARN_ON_ONCE`, effectively making the reclassification conditional on `sock_allow_reclassification(sk)` returning true, and silently returning if it doesn't.
Here's the core of my concern: what if, by skipping the reclassification when `sock_allow_reclassification(sk)` is false, the socket (`sk`) *retains* its `sk_lock-AF_INET6` status *and* is simultaneously added to the NBD structure? This would then lead to a situation where NBD attempts to lock `sk` under `nsock->tx_lock` (as happens in functions like `nbd_mark_nsock_dead` or `sock_xmit`). This, in my view, creates the **exact circular lock dependency** (`fs_reclaim -> ... -> nsock->tx_lock -> sk_lock-AF_INET6`) that commit `d532cddb6c60` was supposed to fix in the first place!
This is a significant red flag. I need to investigate further. I need to cross-reference both `d532cddb6c60` and `9280e6edf656`, and critically, I must also check for any other potential bugs within `drivers/block/nbd.c`.
Let's focus on `drivers/block/nbd.c` first. I'm trying to understand why event `#6` occurred within `nbd_genl_connect`, leading to `nbd_config_put`, then `nbd_clear_sock`, `sock_shutdown`, and finally `nbd_mark_nsock_dead`.
Let's trace the execution of `nbd_genl_connect` within `drivers/block/nbd.c` (lines 2290-2324):
1. **Line 2291**: `ret = nbd_genl_foreach_sock(info, nbd_genl_connect_sock_cb, nbd);`
This iterates through each socket fd provided in the netlink message. For each fd, it calls `nbd_add_socket(nbd, fd, true)`.
Inside `nbd_add_socket`:
* `sock = nbd_get_socket(nbd, arg, &err);` retrieves the socket.
* Then, `nbd_reclassify_socket(sock);` is called. As we just discussed, if `!sock_allow_reclassification(sk)` (which can happen if another thread is concurrently performing a socket syscall on the same fd, or if a softirq holds `bh_lock_sock(sk)`), `nbd_reclassify_socket` *immediately returns* without reclassifying `sk`.
* Crucially, `nbd_add_socket` then proceeds to attach this `sock` to `config->socks[i]` *regardless* of whether the reclassification happened.
2. **Line 2311**: `ret = nbd_start_device(nbd);`
Inside `nbd_start_device`:
* **Line 1531**: `blk_mq_update_nr_hw_queues(&nbd->tag_set, num_connections);` This line is significant because it's where event `#2` was recorded, indicating a potential issue when the number of hardware queues is updated.
* After this, `nbd_start_device` can return an error. For example, if `device_create_file` fails (e.g., if `pid_attr` already exists), or if `num_connections > 1` and the `NBD_FLAG_CAN_MULTI_CONN` flag isn't set. If `nbd_start_device` *succeeds*, the code proceeds to line 2320: `nbd_config_put(nbd);`.
* Here's a critical branching point: If `ret == 0` (meaning `nbd_start_device` succeeded), `config_refs` is incremented at line 2315 (from 1 to 2). Consequently, when `nbd_config_put` at line 2320 is called, it decrements `config_refs` (2 -> 1), and the `if (config_refs == 0)` block is *not* entered. However, if `ret != 0` (e.g., `nbd_start_device` failed), `config_refs` remains 1. In this case, `nbd_config_put` at line 2320 decrements `config_refs` (1 -> 0), and the `if (config_refs == 0)` block *is* entered, leading to calls to `nbd_clear_sock` -> `sock_shutdown` -> `nbd_mark_nsock_dead`!
Now, let's connect this to event `#6`. `nbd_mark_nsock_dead` is also called during normal NBD I/O operations (e.g., in `sock_xmit`, `nbd_read_stat`, `nbd_disconnect_and_put`). In all these cases, the `tx_lock` is acquired, and then `sk_lock` is *also* acquired.
Even in the scenario where `nbd_start_device` succeeds and I/O is running, the path `nbd_queue_rq` -> `nbd_handle_cmd` -> `tx_lock` -> `sock_xmit` -> `sock_sendmsg` -> `tcp_sendmsg` -> `lock_sock(sk)` would *still* result in acquiring `sk_lock` under `tx_lock`!
The puzzling part about event `#6` is why `sk` still had the `sk_lock-AF_INET6` state when `nbd_mark_nsock_dead` was called within the `nbd_genl_connect` failure path. This suggests that the socket was never properly reclassified or its lock state was not correctly managed.
I need to meticulously re-examine lines 2200-2325 of `drivers/block/nbd.c` and lines 1330-1410 of `drivers/block/nbd.c` to see if there's any other code path within `nbd_genl_connect` that could result in a socket being added to `config->socks` without being properly reclassified. My hypothesis is that the change in `9280e6edf656` has inadvertently reintroduced a lock dependency that was meant to be fixed by `d532cddb6c60`, particularly when `sock_allow_reclassification()` returns false during the `nbd_add_socket` phase.
This is becoming a deep dive, and I'm concerned about the integrity of the lockdep annotations in this specific interaction. I also need to keep an eye on other potential areas of concern like `net/rds/tcp_recv.c` (`rds_tcp_recv_path` and `GFP_KERNEL` under `lock_sock`) and `net/mptcp/sockopt.c` (`mptcp_setsockopt_first_sf_only`), as these could be related or exhibit similar locking issues.
|
| 73/2 |
2026/11/28 10:04 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:1330 LineCount:90]
Results: map[Contents:1330: nsock->fallback_index = -1;
1331: nsock->dead = false;
1332: mutex_init(&nsock->tx_lock);
1333: nsock->sock = sock;
1334: nsock->pending = NULL;
1335: nsock->sent = 0;
1336: nsock->cookie = 0;
1337: INIT_WORK(&nsock->work, nbd_pending_cmd_work);
1338: socks[config->num_connections++] = nsock;
1339: atomic_inc(&config->live_connections);
1340:
1341: return 0;
1342:
1343: put_socket:
1344: sockfd_put(sock);
1345: return err;
1346: }
1347:
1348: static int nbd_genl_reconnect_sock_cb(struct nbd_device *nbd, unsigned long arg)
1349: {
1350: struct nbd_config *config = nbd->config;
1351: struct socket *sock, *old;
1352: struct recv_thread_args *args;
1353: int i;
1354: int err;
1355:
1356: sock = nbd_get_socket(nbd, arg, &err);
1357: if (!sock)
1358: return err;
1359: nbd_reclassify_socket(sock);
1360:
1361: args = kzalloc_obj(*args);
1362: if (!args) {
1363: sockfd_put(sock);
1364: return -ENOMEM;
1365: }
1366:
1367: for (i = 0; i < config->num_connections; i++) {
1368: struct nbd_sock *nsock = config->socks[i];
1369:
1370: if (!nsock->dead)
1371: continue;
1372:
1373: mutex_lock(&nsock->tx_lock);
1374: if (!nsock->dead) {
1375: mutex_unlock(&nsock->tx_lock);
1376: continue;
1377: }
1378: sk_set_memalloc(sock->sk);
1379: if (nbd->tag_set.timeout)
1380: sock->sk->sk_sndtimeo = nbd->tag_set.timeout;
1381: atomic_inc(&config->recv_threads);
1382: refcount_inc(&nbd->config_refs);
1383: old = nsock->sock;
1384: nsock->fallback_index = -1;
1385: nsock->sock = sock;
1386: nsock->dead = false;
1387: INIT_WORK(&args->work, recv_work);
1388: args->index = i;
1389: args->nbd = nbd;
1390: args->nsock = nsock;
1391: nsock->cookie++;
1392: mutex_unlock(&nsock->tx_lock);
1393: sockfd_put(old);
1394:
1395: clear_bit(NBD_RT_DISCONNECTED, &config->runtime_flags);
1396:
1397: /* We take the tx_mutex in an error path in the recv_work, so we
1398: * need to queue_work outside of the tx_mutex.
1399: */
1400: queue_work(nbd->recv_workq, &args->work);
1401:
1402: atomic_inc(&config->live_connections);
1403: wake_up(&config->conn_wait);
1404: dev_info(nbd_to_dev(nbd), "reconnected socket\n");
1405: return 0;
1406: }
1407: sockfd_put(sock);
1408: kfree(args);
1409: return 1;
1410: }
1411:
1412: static void nbd_bdev_reset(struct nbd_device *nbd)
1413: {
1414: if (disk_openers(nbd->disk) > 1)
1415: return;
1416: set_capacity(nbd->disk, 0);
1417: }
1418:
1419: static void nbd_parse_flags(struct nbd_device *nbd)
]
|
| 74/2 |
2026/11/28 10:04 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:2080 LineCount:90]
Results: map[Contents:2080: [NBD_ATTR_SOCKETS] = { .type = NLA_NESTED},
2081: [NBD_ATTR_DEAD_CONN_TIMEOUT] = { .type = NLA_U64 },
2082: [NBD_ATTR_DEVICE_LIST] = { .type = NLA_NESTED},
2083: [NBD_ATTR_BACKEND_IDENTIFIER] = { .type = NLA_STRING},
2084: };
2085:
2086: static const struct nla_policy nbd_sock_policy[NBD_SOCK_MAX + 1] = {
2087: [NBD_SOCK_FD] = { .type = NLA_U32 },
2088: };
2089:
2090: /* We don't use this right now since we don't parse the incoming list, but we
2091: * still want it here so userspace knows what to expect.
2092: */
2093: static const struct nla_policy __attribute__((unused))
2094: nbd_device_policy[NBD_DEVICE_ATTR_MAX + 1] = {
2095: [NBD_DEVICE_INDEX] = { .type = NLA_U32 },
2096: [NBD_DEVICE_CONNECTED] = { .type = NLA_U8 },
2097: };
2098:
2099: static int nbd_genl_size_set(struct genl_info *info, struct nbd_device *nbd)
2100: {
2101: struct nbd_config *config = nbd->config;
2102: u64 bsize = nbd_blksize(config);
2103: u64 bytes = config->bytesize;
2104:
2105: if (info->attrs[NBD_ATTR_SIZE_BYTES])
2106: bytes = nla_get_u64(info->attrs[NBD_ATTR_SIZE_BYTES]);
2107:
2108: if (info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES])
2109: bsize = nla_get_u64(info->attrs[NBD_ATTR_BLOCK_SIZE_BYTES]);
2110:
2111: if (bytes != config->bytesize || bsize != nbd_blksize(config))
2112: return nbd_set_size(nbd, bytes, bsize);
2113: return 0;
2114: }
2115:
2116: /*
2117: * Walk the NBD_ATTR_SOCKETS nested list can call @cb for each socket fd.
2118: *
2119: * Return the number of fds walked, or a negative errno.
2120: */
2121: static int nbd_genl_foreach_sock(struct genl_info *info,
2122: int (*cb)(struct nbd_device *nbd, unsigned long fd),
2123: struct nbd_device *nbd)
2124: {
2125: struct nlattr *attr;
2126: int rem, count = 0;
2127:
2128: if (!info->attrs[NBD_ATTR_SOCKETS])
2129: return 0;
2130:
2131: nla_for_each_nested(attr, info->attrs[NBD_ATTR_SOCKETS], rem) {
2132: struct nlattr *socks[NBD_SOCK_MAX + 1];
2133: int ret;
2134:
2135: if (nla_type(attr) != NBD_SOCK_ITEM) {
2136: pr_err("socks must be embedded in a SOCK_ITEM attr\n");
2137: return -EINVAL;
2138: }
2139:
2140: if (nla_parse_nested_deprecated(socks, NBD_SOCK_MAX,
2141: attr,
2142: nbd_sock_policy,
2143: info->extack)) {
2144: pr_err("error processing sock list\n");
2145: return -EINVAL;
2146: }
2147:
2148: if (!socks[NBD_SOCK_FD])
2149: continue;
2150:
2151: count++;
2152: if (cb) {
2153: ret = cb(nbd, (int)nla_get_u32(socks[NBD_SOCK_FD]));
2154: if (ret > 0)
2155: return count;
2156: if (ret < 0)
2157: return ret;
2158: }
2159: }
2160: return count;
2161: }
2162:
2163: static int nbd_genl_connect_sock_cb(struct nbd_device *nbd, unsigned long fd)
2164: {
2165: return nbd_add_socket(nbd, fd, true);
2166: }
2167:
2168: static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
2169: {
]
|
| 75/2 |
2026/11/28 10:04 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 122046
output: 42
thoughts: 1458
Thoughts: **My Deep Dive into the NBD Socket Reclassification Woes**
Okay, so I've been digging into some peculiar locking issues with NBD, specifically focusing on how sockets are handled and reclassified. It all started with a hunch, a feeling that something was off, and I zeroed in on a few key functions and commits: `nbd_reclassify_socket`, commit `d532cddb6c60`, commit `9280e6edf656`, `nbd_genl_connect`, and `rds_tcp_recv_path`. I figured I needed to look at this from every conceivable angle.
My first major avenue of investigation was to scrutinize `nbd_reclassify_socket(sock)` in conjunction with commit `9280e6edf656`. I traced back to commit `d532cddb6c60`, where Eric Dumazet introduced `nbd_reclassify_socket(sock)`. The stated purpose was to resolve a lockdep circular dependency involving `fs_reclaim` and the NBD socket locking mechanism (`nbd` -> `sk_lock-AF_INET6` vs. `sk_lock-AF_INET6` -> `fs_reclaim`). The original implementation in `d532cddb6c60` had a `WARN_ON_ONCE(!sock_allow_reclassification(sk))`.
Now, here's where commit `9280e6edf656`, titled "nbd: don't warn when reclassifying a busy socket lock," comes into play. It seems Syzkaller uncovered a race condition where an `NBD_CMD_CONNECT` operation was colliding with other socket activity on the same file descriptor. This race was triggering the `WARN_ON_ONCE(!sock_allow_reclassification(sk))`. The fix in `9280e6edf656` was to change the behavior from a warning to a silent return: `if (!sock_allow_reclassification(sk)) return;`.
This subtle change, I realized, had a critical implication. If `sock_allow_reclassification(sk)` evaluates to false, `nbd_reclassify_socket()` simply exits *without* reclassifying the socket. Crucially, `nbd_add_socket()` then *doesn't fail*. It proceeds to attach this *unreclassified* socket, which still retains its original `sk_lock-AF_INET6` class, to the `nbd->config->socks` list. The problem arises later when the NBD driver attempts to use this socket β for instance, in `nbd_mark_nsock_dead()`, which calls `kernel_sock_shutdown()`, leading to `inet_shutdown()` and then `lock_sock(sk)`. At this point, the lock acquisition is happening while holding `nsock->tx_lock`, and because the socket was never reclassified to the NBD-specific lock class, we end up with a lockdep violation: `nsock->tx_lock` -> `sk_lock-AF_INET6`.
My mind then went to a related observation: why did `nbd_genl_connect` also seem to trigger cascade of events, leading to `#2` (a `blk_mq_update_nr_hw_queues` issue) and then `#6` (a `nbd_config_put` leading to `nbd_clear_sock`, `sock_shutdown`, and `nbd_mark_nsock_dead`)? I pieced this together:
1. Imagine an NBD device already exists, perhaps with a pre-set `nr_hw_queues` of 1, or where the requested `num_connections` differs from the existing configuration. Alternatively, `nbd_genl_connect` might be reusing an existing device structure.
2. During `nbd_genl_connect`, the function `nbd_genl_foreach_sock` is called, which in turn invokes `nbd_add_socket`. Inside `nbd_add_socket`, `nbd_reclassify_socket(sock)` is called. If, due to the race condition discussed, `!sock_allow_reclassification(sk)` is true, the reclassification is skipped.
3. Subsequently, `nbd_start_device(nbd)` is called. This function attempts to update hardware queues with `blk_mq_update_nr_hw_queues` (this is `#2`). The key is that `nbd_start_device` might *fail* after this point. The exact failure point is a bit tricky, but it likely occurs somewhere between lines 1531 and 1580 in `drivers/block/nbd.c`, perhaps during `device_create_file`, thread creation, or another setup step. It's not directly due to the `num_connections` check that precedes the queue update.
4. Because `nbd_start_device` fails, `nbd_genl_connect` jumps to its error handling path (`out:`). This path then calls `nbd_config_put(nbd)` at line 2320. Since `nbd->config_refs` wasn't incremented appropriately in the successful path (due to the failure), this `nbd_config_put` call decrements the reference count to zero. This triggers the cleanup: `nbd_clear_sock` is called, which leads to `sock_shutdown`, and subsequently `nbd_mark_nsock_dead` (this is `#6`).
5. And here's the crux: within `nbd_mark_nsock_dead`, `kernel_sock_shutdown` invokes `inet_shutdown`, which calls `lock_sock(sk)`. Because the socket `sk` was *never* reclassified to `sk_lock-AF_INET6-NBD` (due to the earlier `!sock_allow_reclassification(sk)` condition), the lockdep system registers the problematic dependency: `nsock->tx_lock` -> `sk_lock-AF_INET6`.
I paused then, thinking: "Is this the whole story?" I had to be sure I wasn't missing anything.
My next step was to consider if `nbd_reclassify_socket` could fail for *any other reason* besides the race uncovered by Syzkaller and addressed (or perhaps mishandled) by `9280e6edf656`. I specifically wondered if there was a scenario where `sk` was an `AF_INET6` socket, `sk_is_tcp(sock->sk)` was true, `sk->sk_family` was `AF_INET6`, `sock_allow_reclassification(sk)` was true, and yet `nbd_reclassify_socket` *still* didn't perform the reclassification.
I dove into the `nbd_reclassify_socket` code again. If `sock_allow_reclassification(sk)` is true, and `sk->sk_family` is `AF_INET6`, the code unconditionally proceeds to call `sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD", &nbd_slock_key[1], "sk_lock-AF_INET6-NBD", &nbd_key[1])`. This strongly suggests that if `sock_allow_reclassification(sk)` is true and it's an `AF_INET6` socket, the reclassification *will* happen.
Then I thought, "What if `sock_lock_init_class_and_name` itself had an issue?" I checked its implementation in `include/net/sock.h` (lines 1680-1725), and while it's complex, it seems designed to correctly initialize the lock class. The core logic there doesn't immediately suggest a path where a socket, once intended for reclassification under `AF_INET6` and with `sock_allow_reclassification` true, would somehow remain stuck with the generic `sk_lock-AF_INET6` class after that call.
So, my current strong suspicion is that the interaction between commit `9280e6edf656` (which silences the warning) and the race condition, combined with the specific failure path in `nbd_genl_connect`, is the root cause of these lockdep violations. It's about an incomplete reclassification leaving a socket with the wrong lock class, which then gets invoked under the wrong circumstances.
|
| 76/2 |
2026/11/28 10:05 |
tool |
read-file |
0m
Args: map[File:include/net/sock.h FirstLine:1680 LineCount:50]
Results: map[Contents:1680: {
1681: }
1682:
1683: static inline void sk_owner_put(struct sock *sk)
1684: {
1685: }
1686: #endif
1687: /*
1688: * Macro so as to not evaluate some arguments when
1689: * lockdep is not enabled.
1690: *
1691: * Mark both the sk_lock and the sk_lock.slock as a
1692: * per-address-family lock class.
1693: */
1694: #define sock_lock_init_class_and_name(sk, sname, skey, name, key) \
1695: do { \
1696: sk_owner_set(sk, THIS_MODULE); \
1697: sk->sk_lock.owned = 0; \
1698: init_waitqueue_head(&sk->sk_lock.wq); \
1699: spin_lock_init(&(sk)->sk_lock.slock); \
1700: debug_check_no_locks_freed((void *)&(sk)->sk_lock, \
1701: sizeof((sk)->sk_lock)); \
1702: lockdep_set_class_and_name(&(sk)->sk_lock.slock, \
1703: (skey), (sname)); \
1704: lockdep_init_map(&(sk)->sk_lock.dep_map, (name), (key), 0); \
1705: } while (0)
1706:
1707: static inline bool lockdep_sock_is_held(const struct sock *sk)
1708: {
1709: return lockdep_is_held(&sk->sk_lock) ||
1710: lockdep_is_held(&sk->sk_lock.slock);
1711: }
1712:
1713: void lock_sock_nested(struct sock *sk, int subclass);
1714:
1715: static inline void lock_sock(struct sock *sk)
1716: {
1717: lock_sock_nested(sk, 0);
1718: }
1719:
1720: void __release_sock(struct sock *sk);
1721: void release_sock(struct sock *sk);
1722:
1723: /* BH context may only use the following locking interface. */
1724: #define bh_lock_sock(__sk) spin_lock(&((__sk)->sk_lock.slock))
1725: #define bh_lock_sock_nested(__sk) \
1726: spin_lock_nested(&((__sk)->sk_lock.slock), \
1727: SINGLE_DEPTH_NESTING)
1728: #define bh_unlock_sock(__sk) spin_unlock(&((__sk)->sk_lock.slock))
1729:
]
|
| 77/2 |
2026/11/28 10:05 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 124385
output: 81
thoughts: 1929
Thoughts: **My Thought Process on the `nbd` Socket Reclassification and Potential Deadlocks**
This is quite a rabbit hole, but I think I'm starting to piece together the core issues. Let's break it down.
First, I stumbled upon `sock_lock_init_class_and_name`. My immediate reaction was, "Whoa, this is doing a lot." It's not just initializing a spinlock; it's resetting the `owned` flag, the waitqueue head, and critically, it's calling `lockdep_init_map`. This `lockdep_init_map` is the key for lock dependency tracking.
This realization led me to understand *why* `sock_allow_reclassification(sk)` *must* be true before calling `sock_lock_init_class_and_name`. If the `sk_lock` (or its underlying `slock`) were already held by someone else when this function ran, and we then reset `owned` to 0 and re-initialized the spinlock, we'd be corrupting the lock state. That's a recipe for disaster.
Now, this is where `nbd` gets tricky. Unlike protocols like `nvme-tcp`, `cifs`, or `rds` which create their own internal sockets via `sock_create_kern`, `nbd` takes a user-supplied file descriptor. The crucial part here is that the userspace application *still owns and can lock this socket concurrently*. This means that if `nbd_reclassify_socket()` (which calls `sock_lock_init_class_and_name`) runs while another thread or softirq is holding `sk_lock`, we're back to that corruption scenario I just thought of.
So, what's the history here?
* In commit `d532cddb6c60` ("nbd: Reclassify sockets to avoid lockdep circular dependency"), they added `nbd_reclassify_socket()` and, importantly, included `if (WARN_ON_ONCE(!sock_allow_reclassification(sk))) return;`. This was a safety net, warning if the reclassification couldn't proceed.
* Then, commit `9280e6edf656` ("nbd: don't warn when reclassifying a busy socket lock") *removed* that `WARN_ON_ONCE`. The reasoning was that hitting a held lock on an externally owned socket is expected and not a kernel bug. They decided to skip reclassification silently instead of warning, claiming it's harmless for lockdep as it's just an annotation.
This is where my "WAIT A SECOND!" moment kicked in. I went back to `sock_allow_reclassification(sk)`. Even before `9280e6edf656`, `d532cddb6c60` already had that `WARN_ON_ONCE` in place. My internal alarm bells were ringing: if that `WARN_ON_ONCE` fired in `d532cddb6c60`, it would cause a panic on `syzkaller` due to `panic_on_warn`. But *after* `9280e6edf656`, it skips silently, and then, as I suspect, it *later* triggers the circular locking dependency that the original commit was trying to prevent! This feels like we've traded one problem for another, potentially worse one.
Then I started looking at the stack traces, specifically Check 2. I zeroed in on `#0` in the stack trace, which shows `rds_tcp_recv_path` calling `kmem_cache_alloc_noprof` (which can trigger `fs_reclaim`). This whole path is: `kmem_cache_alloc_noprof` -> `rds_tcp_data_recv` -> `__tcp_read_sock` -> `rds_tcp_read_sock` -> `rds_tcp_recv_path` -> `rds_tcp_conn_path_shutdown` -> `rds_conn_shutdown`. The key here is that `rds_tcp_recv_path` is operating under `lock_sock` (specifically `k-sk_lock-AF_INET6`).
This led me to question: is `rds_tcp_recv_path` doing `GFP_KERNEL` allocation under `lock_sock` (`k-sk_lock-AF_INET6`) a bug *within* `rds` itself, independent of `nbd`?
I decided to think through this scenario without `nbd` or assuming `nbd` had correctly reclassified its sockets (to `sk_lock-AF_INET6-NBD`). Could the `k-sk_lock-AF_INET6` -> `fs_reclaim` path ever be a *real* deadlock on its own?
My analysis went like this:
1. We know `mptcp_setsockopt_first_sf_only` can take `sk_lock-AF_INET6` (user MPTCP socket) and then move to `k-sk_lock-AF_INET6` (MPTCP kernel subflow socket). This is a valid transition.
2. `rds_tcp_recv_path` takes `k-sk_lock-AF_INET6` and then enters `fs_reclaim` (via `GFP_KERNEL`).
3. The crucial question: Does `fs_reclaim` ever take `sk_lock-AF_INET6`? My research indicates NO. `fs_reclaim` operates on block device/filesystem locks. For `nbd`, it would be `sk_lock-AF_INET6-NBD`. It *never* takes a generic user `sk_lock-AF_INET6`.
4. Does `fs_reclaim` ever take `k-sk_lock-AF_INET6`? This is the core of the question. I started listing subsystems that create kernel TCP/IPv6 sockets (`k-sk_lock-AF_INET6`) and use them within `fs_reclaim` contexts (swap, writeback, pageout, block I/O):
* `nvme-tcp`: Reclassifies to `sk_lock-AF_INET6-NVME`.
* `cifs`/`smb`: Reclassifies to `sk_lock-AF_INET6-CIFS`.
* `nfs` (`xprtsock.c`): Reclassifies to `sk_lock-AF_INET6-RPC`.
* `nfsd` (`svcsock.c`): Reclassifies to `sk_lock-AF_INET6-NFSD`.
* `nbd`: Reclassifies to `sk_lock-AF_INET6-NBD`.
* `iscsi_tcp`: I need to verify if this one reclassifies or uses `GFP_NOIO`, or if it also takes a user fd.
* `rds`: This is a networking protocol (`PF_RDS`), not a filesystem or block device. It *should not* be involved in `fs_reclaim` in a way that would contend with block I/O locks.
I also considered what happens *during* `tcp_sendmsg` or `do_tcp_setsockopt` on a `k-sk_lock-AF_INET6` socket. In `tcp_setsockopt`, `lock_sock(ssk)` (on `k-sk_lock-AF_INET6`) is held, and `GFP_KERNEL` allocations are made. Similarly, in `tcp_sendmsg` on a kernel socket, `lock_sock` is held, and `sk_stream_alloc_skb` (which uses `GFP_KERNEL`) happens. So, `k-sk_lock-AF_INET6` -> `fs_reclaim` is *normal and expected*, as is `sk_lock-AF_INET6` -> `k-sk_lock-AF_INET6` (like with MPTCP).
The critical forbidden path is `fs_reclaim` -> `sk_lock-AF_INET6` (or `k-sk_lock-AF_INET6` without proper reclassification). Because `fs_reclaim` absolutely must not depend on generic `sk_lock-AF_INET6` or `k-sk_lock-AF_INET6` that hasn't been specifically accounted for by a block device abstraction.
This brings me back to the original `nbd` situation. The silent skip in `9280e6edf656` seems to be allowing the `nbd` socket to remain in a state where its `sk_lock` is potentially held by userspace *while* `fs_reclaim` operations (which might be initiated by `rds` or other parts of the kernel) are trying to proceed. If `fs_reclaim` eventually needs to interact with the `nbd` socket's lock in a way that causes a circular dependency with the userspace-held lock, that's the deadlock.
My suspicion is that the issue is not inherently with `rds_tcp_recv_path` doing `GFP_KERNEL` under `k-sk_lock-AF_INET6` in isolation, but rather how `nbd`'s failure to properly reclassify (or the silent skip thereof) interacts with *other* parts of the kernel that might perform `fs_reclaim` operations and then potentially try to acquire locks that `nbd`'s underlying socket might be holding or waiting on due to userspace contention.
I need to meticulously re-examine all the recent commits in `drivers/block/nbd.c`, specifically around `nbd_genl_connect` and `nbd_start_device`, to see if there's a more fundamental flaw in how `nbd` manages its user-supplied sockets or if there's another commit or bug that's creating this race condition alongside the lockdep annotation changes.
|
| 78/2 |
2026/11/28 10:05 |
tool |
git-log |
0m
Args: map[Count:25 PathPrefix:drivers/block/nbd.c Since:1 year]
Results: map[Output:553d28925fde nbd: Reclassify sockets in the reconnect path
326d49039c10 nbd: add pre_defined_connections module parameter for pre-created devices
a9d414b4a15c nbd: remove queue freeze for newly created nbd from netlink path
f8d21c590e55 nbd: factor out a nbd_genl_foreach_sock
db285268df79 nbd: skip queue freeze when setting size at device startup
285908f554fe nbd: remove queue freeze in nbd_add_socket
0fdee7c5fa88 nbd: clear queue limits on disconnect
04d8fb23e520 nbd: disallow NBD_SET_SOCK on an active device
fe247030f1ce nbd: simplify find_fallback() by removing redundant logic
9280e6edf656 nbd: don't warn when reclassifying a busy socket lock
d532cddb6c60 nbd: Reclassify sockets to avoid lockdep circular dependency
b040a1a4523d block: switch numa_node to int in blk_mq_hw_ctx and init_request
bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
]
|
| 79/2 |
2026/11/28 10:05 |
tool |
read-file |
0m
Args: map[File:drivers/block/nbd.c FirstLine:1540 LineCount:65]
Results: map[Contents:1540: nbd->pid = task_pid_nr(current);
1541:
1542: nbd_parse_flags(nbd);
1543:
1544: error = device_create_file(disk_to_dev(nbd->disk), &pid_attr);
1545: if (error) {
1546: dev_err(disk_to_dev(nbd->disk), "device_create_file failed for pid!\n");
1547: return error;
1548: }
1549: set_bit(NBD_RT_HAS_PID_FILE, &config->runtime_flags);
1550:
1551: nbd_dev_dbg_init(nbd);
1552: for (i = 0; i < num_connections; i++) {
1553: struct recv_thread_args *args;
1554:
1555: args = kzalloc_obj(*args);
1556: if (!args) {
1557: sock_shutdown(nbd);
1558: /*
1559: * If num_connections is m (2 < m),
1560: * and NO.1 ~ NO.n(1 < n < m) kzallocs are successful.
1561: * But NO.(n + 1) failed. We still have n recv threads.
1562: * So, add flush_workqueue here to prevent recv threads
1563: * dropping the last config_refs and trying to destroy
1564: * the workqueue from inside the workqueue.
1565: */
1566: if (i)
1567: flush_workqueue(nbd->recv_workq);
1568: return -ENOMEM;
1569: }
1570: sk_set_memalloc(config->socks[i]->sock->sk);
1571: if (nbd->tag_set.timeout)
1572: config->socks[i]->sock->sk->sk_sndtimeo =
1573: nbd->tag_set.timeout;
1574: atomic_inc(&config->recv_threads);
1575: refcount_inc(&nbd->config_refs);
1576: INIT_WORK(&args->work, recv_work);
1577: args->nbd = nbd;
1578: args->nsock = config->socks[i];
1579: args->index = i;
1580: queue_work(nbd->recv_workq, &args->work);
1581: }
1582: return nbd_set_size(nbd, config->bytesize, nbd_blksize(config));
1583: }
1584:
1585: static int nbd_start_device_ioctl(struct nbd_device *nbd)
1586: {
1587: struct nbd_config *config = nbd->config;
1588: int ret;
1589:
1590: ret = nbd_start_device(nbd);
1591: if (ret)
1592: return ret;
1593:
1594: if (max_part)
1595: set_bit(GD_NEED_PART_SCAN, &nbd->disk->state);
1596: mutex_unlock(&nbd->config_lock);
1597: ret = wait_event_interruptible(config->recv_wq,
1598: atomic_read(&config->recv_threads) == 0);
1599: if (ret) {
1600: sock_shutdown(nbd);
1601: nbd_clear_que(nbd);
1602: }
1603:
1604: flush_workqueue(nbd->recv_workq);
]
|
| 80/2 |
2026/11/28 10:05 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 127829
output: 33
thoughts: 1964
Thoughts: **Deep Dive into the NBD Socket Reclassification Puzzle**
I've been really digging into this NBD socket issue, specifically looking at the changes introduced around commits `d532cddb6c60` and `9280e6edf656`. My immediate reaction was, "Wait a second, there's something fundamentally changing here with how sockets are handled, and it seems directly tied to this `nbd_reclassify_socket` function and its interaction with `nbd_add_socket`." I'm trying to trace every possible execution path to understand how we ended up in this state.
Hereβs how my thought process unfolded:
Initially, I focused on the call chain. I saw `nbd_genl_connect` calling `nbd_genl_foreach_sock`, which then leads to `nbd_add_socket`. Within `nbd_add_socket`, there's this crucial call to `nbd_reclassify_socket(sock)`. This function, as I examined it, has a critical check: `if (!sock_allow_reclassification(sk)) return;`. This immediately told me that the reclassification isn't always happening, and it depends on some condition related to the socket's state.
Then, I started comparing the behavior *before* and *after* those specific commits.
1. **Before `d532cddb6c60`:** My understanding is that NBD *never* reclassified sockets. This meant that any NBD socket would have retained its original `sk_lock-AF_INET6` classification. The question then became, "Why didn't this cause problems earlier?" This led me to realize that `d532cddb6c60` was actually introduced to *fix* a lockdep circular dependency issue that arose after commit `ffa1e7ada456` (which sounds like it made lockdep warnings more aggressive). So, the problem I'm seeing now is a consequence of trying to *resolve* a previous issue.
2. **With `d532cddb6c60`:** Eric Dumazet introduced `nbd_reclassify_socket(sock)`. The key part here is the `WARN_ON_ONCE(!sock_allow_reclassification(sk))`. My analysis suggests that when `!sock_allow_reclassification(sk)` was true β which happens when userspace still holds the file descriptor and another thread or softirq has acquired `sk->sk_lock` β this `WARN_ON_ONCE` would trigger. On systems like syzkaller where `panic_on_warn` is enabled, this would immediately cause a crash. So, this commit was an attempt to *detect* and *report* this problematic race condition.
3. **Then, with `9280e6edf656`:** Deepanshu Kartikey's commit directly addressed the `WARN_ON_ONCE`. The rationale was that hitting a held lock was expected for externally owned sockets and not a kernel bug, so the warning should be suppressed. The code was changed from `if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))` to `if (!sock_allow_reclassification(sk)) return;`. This effectively silenced the warning.
This is where I see the direct link to the syzkaller bug. My reasoning is:
* **Pre-`d532cddb6c60`:** We had the lockdep circular dependency.
* **`d532cddb6c60`:** Introduced a warning for the specific race condition. On crash-prone systems, this caused immediate failures.
* **`9280e6edf656`:** Silenced the warning based on the (in my view, flawed) assumption that skipping reclassification was harmless. The problem is, by silently skipping reclassification, `nbd_add_socket()` was attaching an *unreclassified* socket, specifically one still holding `sk_lock-AF_INET6`, to the NBD structure.
* **The Consequence:** Once this unreclassified socket is attached, operations like `nbd_mark_nsock_dead()` or `sock_xmit()` will lock `sk` under `nsock->tx_lock`. This reintroduces the problematic dependency: `fs_reclaim -> ... -> sk_lock-AF_INET6`, which then cycles back through `sk_lock-AF_INET6 -> k-sk_lock-AF_INET6 -> fs_reclaim`, creating the circular dependency lockdep flags.
Before I finalize my conclusion and decide whether `9280e6edf656` or `d532cddb6c60` (or something else entirely) is the "root cause," I'm meticulously checking every other avenue.
I'm asking myself: Is there *any other way* for `sk_lock-AF_INET6` to end up in `nbd_mark_nsock_dead` *without* `!sock_allow_reclassification(sk)` being true in `nbd_reclassify_socket`?
Let's consider:
1. **What if the `sock` in `nbd_add_socket` was *already* an `AF_INET6` socket, and `sock_allow_reclassification(sk)` was `true`?**
If `sock_allow_reclassification(sk)` were true, `nbd_reclassify_socket` would proceed to the `case AF_INET6:` block. This would execute `sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD", &nbd_slock_key[1], "sk_lock-AF_INET6-NBD", &nbd_key[1])`. This *changes* `sk->sk_lock.dep_map` to `"sk_lock-AF_INET6-NBD"`. The question then becomes: can `sk->sk_lock.dep_map` ever be reset back to `"sk_lock-AF_INET6"` *after* this reclassification? I'm planning to `grep` the entire kernel for `sock_lock_init` and `sk_lock.dep_map` to see if there's any other mechanism for this specific `dep_map` to be set or reset.
2. **What if `nbd_genl_connect` *didn't* call `nbd_reclassify_socket`?**
I've scoured the paths within `nbd_genl_connect`. Looking at lines around 2232, 2241, and crucially 2291, the `nbd_genl_foreach_sock` call seems to be the *only* place where sockets are iterated over and passed to `nbd_add_socket`. There's no other apparent way for a socket to be added to `config->socks` during `nbd_genl_connect` itself.
3. **Revisiting `sock_allow_reclassification(sk)` with `AF_INET6` sockets:**
I'm examining what types of `AF_INET6` sockets could pass the `sk_is_tcp(sock->sk)` check, which implies `sk_is_inet(sk) && sk->sk_type == SOCK_STREAM && sk->sk_protocol == IPPROTO_TCP`.
* Could it be a listening socket? Yes, that's possible (`tcp_listen_start` / `inet_listen` with `sk->sk_family == AF_INET6`).
* Could it be a newly created or connected TCP IPv6 socket? Yes, also possible.
* Could it have `sk_kern_sock`? No, because the socket comes from a user file descriptor via `sockfd_lookup`.
* Could `sk` have a different `sk_family`? No, the context of the relevant code (`#6` line in the original text) seems to point to `inet_shutdown` and `(sk_lock-AF_INET6)`, strongly indicating `sk->sk_family` *must* be `AF_INET6`.
Therefore, my current strong hypothesis is that the *only* way `sk` could have retained its original `(sk_lock-AF_INET6)` classification within `nbd_mark_nsock_dead` during `nbd_genl_connect` is if `sock_allow_reclassification(sk)` returned `false` in `nbd_reclassify_socket(sock)`, causing that function to exit early without performing the reclassification.
I'm still digging to ensure no other pathway exists, but this line of reasoning feels very solid.
|
| 81/2 |
2026/11/28 10:05 |
tool |
grepper |
0m
Args: map[Expression:sk_lock\.dep_map|sock_lock_init]
Results: map[Output:
Full output is too long, showing 200 out of 204 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (14 files in total):
drivers/block/nbd.c:3
drivers/infiniband/sw/rxe/rxe_net.c:3
drivers/infiniband/sw/rxe/rxe_qp.c:2
drivers/infiniband/sw/siw/siw_cm.c:2
drivers/nvme/host/tcp.c:2
fs/smb/client/connect.c:2
include/net/sock.h:7
net/bluetooth/af_bluetooth.c:1
net/core/sock.c:8
net/mptcp/pm_kernel.c:1
net/mptcp/subflow.c:2
net/smc/af_smc.c:1
net/sunrpc/svcsock.c:2
net/sunrpc/xprtsock.c:3
drivers/block/nbd.c=1245=static void nbd_reclassify_socket(struct socket *sock)
--
drivers/block/nbd.c-1253- case AF_INET:
drivers/block/nbd.c:1254: sock_lock_init_class_and_name(sk, "slock-AF_INET-NBD",
drivers/block/nbd.c-1255- &nbd_slock_key[0],
--
drivers/block/nbd.c-1259- case AF_INET6:
drivers/block/nbd.c:1260: sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD",
drivers/block/nbd.c-1261- &nbd_slock_key[1],
--
drivers/block/nbd.c-1265- case AF_UNIX:
drivers/block/nbd.c:1266: sock_lock_init_class_and_name(sk, "slock-AF_UNIX-NBD",
drivers/block/nbd.c-1267- &nbd_slock_key[2],
--
drivers/infiniband/sw/rxe/rxe_net.c=45=static inline void rxe_reclassify_recv_socket(struct socket *sock)
--
drivers/infiniband/sw/rxe/rxe_net.c-54- case AF_INET:
drivers/infiniband/sw/rxe/rxe_net.c:55: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/rxe/rxe_net.c-56- "slock-AF_INET-RDMA-RXE-RECV",
--
drivers/infiniband/sw/rxe/rxe_net.c-61- case AF_INET6:
drivers/infiniband/sw/rxe/rxe_net.c:62: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/rxe/rxe_net.c-63- "slock-AF_INET6-RDMA-RXE-RECV",
--
drivers/infiniband/sw/rxe/rxe_net.c-72- /*
drivers/infiniband/sw/rxe/rxe_net.c:73: * sock_lock_init_class_and_name() calls
drivers/infiniband/sw/rxe/rxe_net.c-74- * sk_owner_set(sk, THIS_MODULE); in order
--
drivers/infiniband/sw/rxe/rxe_qp.c=37=static inline void rxe_reclassify_send_socket(struct socket *sock)
--
drivers/infiniband/sw/rxe/rxe_qp.c-46- case AF_INET:
drivers/infiniband/sw/rxe/rxe_qp.c:47: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/rxe/rxe_qp.c-48- "slock-AF_INET-RDMA-RXE-SEND",
--
drivers/infiniband/sw/rxe/rxe_qp.c-53- case AF_INET6:
drivers/infiniband/sw/rxe/rxe_qp.c:54: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/rxe/rxe_qp.c-55- "slock-AF_INET6-RDMA-RXE-SEND",
--
drivers/infiniband/sw/siw/siw_cm.c=62=static inline void siw_reclassify_socket(struct socket *sock)
--
drivers/infiniband/sw/siw/siw_cm.c-71- case AF_INET:
drivers/infiniband/sw/siw/siw_cm.c:72: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/siw/siw_cm.c-73- "slock-AF_INET-RDMA-SIW",
--
drivers/infiniband/sw/siw/siw_cm.c-78- case AF_INET6:
drivers/infiniband/sw/siw/siw_cm.c:79: sock_lock_init_class_and_name(sk,
drivers/infiniband/sw/siw/siw_cm.c-80- "slock-AF_INET6-RDMA-SIW",
--
drivers/nvme/host/tcp.c=228=static void nvme_tcp_reclassify_socket(struct socket *sock)
--
drivers/nvme/host/tcp.c-236- case AF_INET:
drivers/nvme/host/tcp.c:237: sock_lock_init_class_and_name(sk, "slock-AF_INET-NVME",
drivers/nvme/host/tcp.c-238- &nvme_tcp_slock_key[0],
--
drivers/nvme/host/tcp.c-242- case AF_INET6:
drivers/nvme/host/tcp.c:243: sock_lock_init_class_and_name(sk, "slock-AF_INET6-NVME",
drivers/nvme/host/tcp.c-244- &nvme_tcp_slock_key[1],
--
fs/smb/client/connect.c=3144=cifs_reclassify_socket4(struct socket *sock)
--
fs/smb/client/connect.c-3148- BUG_ON(!sock_allow_reclassification(sk));
fs/smb/client/connect.c:3149: sock_lock_init_class_and_name(sk, "slock-AF_INET-CIFS",
fs/smb/client/connect.c-3150- &cifs_slock_key[0], "sk_lock-AF_INET-CIFS", &cifs_key[0]);
--
fs/smb/client/connect.c=3154=cifs_reclassify_socket6(struct socket *sock)
--
fs/smb/client/connect.c-3158- BUG_ON(!sock_allow_reclassification(sk));
fs/smb/client/connect.c:3159: sock_lock_init_class_and_name(sk, "slock-AF_INET6-CIFS",
fs/smb/client/connect.c-3160- &cifs_slock_key[1], "sk_lock-AF_INET6-CIFS", &cifs_key[1]);
--
include/net/sock.h=242=struct sk_filter;
--
include/net/sock.h-363- * @sk_owner: reference to the real owner of the socket that calls
include/net/sock.h:364: * sock_lock_init_class_and_name().
include/net/sock.h-365- */
--
include/net/sock.h=1683=static inline void sk_owner_put(struct sock *sk)
--
include/net/sock.h-1693- */
include/net/sock.h:1694:#define sock_lock_init_class_and_name(sk, sname, skey, name, key) \
include/net/sock.h-1695-do { \
--
include/net/sock.h-1703- (skey), (sname)); \
include/net/sock.h:1704: lockdep_init_map(&(sk)->sk_lock.dep_map, (name), (key), 0); \
include/net/sock.h-1705-} while (0)
--
include/net/sock.h=1745=static inline bool lock_sock_fast(struct sock *sk)
--
include/net/sock.h-1747- /* The sk_lock has mutex_lock() semantics here. */
include/net/sock.h:1748: mutex_acquire(&sk->sk_lock.dep_map, 0, 0, _RET_IP_);
include/net/sock.h-1749-
--
include/net/sock.h=1754=static inline bool lock_sock_fast_nested(struct sock *sk)
include/net/sock.h-1755-{
include/net/sock.h:1756: mutex_acquire(&sk->sk_lock.dep_map, SINGLE_DEPTH_NESTING, 0, _RET_IP_);
include/net/sock.h-1757-
--
include/net/sock.h=1769=static inline void unlock_sock_fast(struct sock *sk, bool slow)
--
include/net/sock.h-1775- } else {
include/net/sock.h:1776: mutex_release(&sk->sk_lock.dep_map, _RET_IP_);
include/net/sock.h-1777- spin_unlock_bh(&sk->sk_lock.slock);
--
include/net/sock.h=1825=static inline void sock_release_ownership(struct sock *sk)
--
include/net/sock.h-1830- /* The sk_lock has mutex_unlock() semantics: */
include/net/sock.h:1831: mutex_release(&sk->sk_lock.dep_map, _RET_IP_);
include/net/sock.h-1832-}
--
net/bluetooth/af_bluetooth.c=71=void bt_sock_reclassify_lock(struct sock *sk, int proto)
--
net/bluetooth/af_bluetooth.c-75-
net/bluetooth/af_bluetooth.c:76: sock_lock_init_class_and_name(sk,
net/bluetooth/af_bluetooth.c-77- bt_slock_key_strings[proto], &bt_slock_key[proto],
--
net/core/sock.c=546=int __sk_receive_skb(struct sock *sk, struct sk_buff *skb,
--
net/core/sock.c-571- */
net/core/sock.c:572: mutex_acquire(&sk->sk_lock.dep_map, 0, 1, _RET_IP_);
net/core/sock.c-573-
--
net/core/sock.c-575-
net/core/sock.c:576: mutex_release(&sk->sk_lock.dep_map, _RET_IP_);
net/core/sock.c-577- } else if ((err = sk_add_backlog(sk, skb, READ_ONCE(sk->sk_rcvbuf)))) {
--
net/core/sock.c=1786=int sk_getsockopt(struct sock *sk, int level, int optname,
--
net/core/sock.c-2215- */
net/core/sock.c:2216:static inline void sock_lock_init(struct sock *sk)
net/core/sock.c-2217-{
--
net/core/sock.c-2220- if (sk->sk_kern_sock)
net/core/sock.c:2221: sock_lock_init_class_and_name(
net/core/sock.c-2222- sk,
--
net/core/sock.c-2227- else
net/core/sock.c:2228: sock_lock_init_class_and_name(
net/core/sock.c-2229- sk,
--
net/core/sock.c=2334=struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
--
net/core/sock.c-2351- sk->sk_kern_sock = kern;
net/core/sock.c:2352: sock_lock_init(sk);
net/core/sock.c-2353-
--
net/core/sock.c=2511=struct sock *sk_clone(const struct sock *sk, const gfp_t priority,
--
net/core/sock.c-2548- sk_node_init(&newsk->sk_node);
net/core/sock.c:2549: sock_lock_init(newsk);
net/core/sock.c-2550- spin_lock_init(&newsk->sk_peer_lock);
--
net/core/sock.c=3906=void noinline lock_sock_nested(struct sock *sk, int subclass)
--
net/core/sock.c-3908- /* The sk_lock has mutex_lock() semantics here. */
net/core/sock.c:3909: mutex_acquire(&sk->sk_lock.dep_map, subclass, 0, _RET_IP_);
net/core/sock.c-3910-
--
net/mptcp/pm_kernel.c=852=static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
--
net/mptcp/pm_kernel.c-876- */
net/mptcp/pm_kernel.c:877: sock_lock_init_class_and_name(newsk,
net/mptcp/pm_kernel.c-878- is_ipv6 ? "mlock-AF_INET6" : "mlock-AF_INET",
--
net/mptcp/subflow.c=1957=void mptcp_subflow_queue_clean(struct sock *listener_sk, struct sock *listener_ssk)
--
net/mptcp/subflow.c-2009- */
net/mptcp/subflow.c:2010: mutex_release(&listener_sk->sk_lock.dep_map, _RET_IP_);
net/mptcp/subflow.c-2011- mptcp_cancel_work(sk);
net/mptcp/subflow.c:2012: mutex_acquire(&listener_sk->sk_lock.dep_map, 0, 0, _RET_IP_);
net/mptcp/subflow.c-2013-
--
net/smc/af_smc.c=395=void smc_sk_init(struct net *net, struct sock *sk, int protocol)
--
net/smc/af_smc.c-407- INIT_LIST_HEAD(&smc->accept_q);
net/smc/af_smc.c:408: sock_lock_init_class_and_name(sk, "slock-AF_SMC", &smc_slock_key,
net/smc/af_smc.c-409- "sk_lock-AF_SMC", &smc_key);
--
net/sunrpc/svcsock.c=95=static void svc_reclassify_socket(struct socket *sock)
--
net/sunrpc/svcsock.c-103- case AF_INET:
net/sunrpc/svcsock.c:104: sock_lock_init_class_and_name(sk, "slock-AF_INET-NFSD",
net/sunrpc/svcsock.c-105- &svc_slock_key[0],
--
net/sunrpc/svcsock.c-110- case AF_INET6:
net/sunrpc/svcsock.c:111: sock_lock_init_class_and_name(sk, "slock-AF_INET6-NFSD",
net/sunrpc/svcsock.c-112- &svc_slock_key[1],
--
net/sunrpc/xprtsock.c=1891=static inline void xs_reclassify_socketu(struct socket *sock)
--
net/sunrpc/xprtsock.c-1894-
net/sunrpc/xprtsock.c:1895: sock_lock_init_class_and_name(sk, "slock-AF_LOCAL-RPC",
net/sunrpc/xprtsock.c-1896- &xs_slock_key[0], "sk_lock-AF_LOCAL-RPC", &xs_key[0]);
--
net/sunrpc/xprtsock.c=1899=static inline void xs_reclassify_socket4(struct socket *sock)
--
net/sunrpc/xprtsock.c-1902-
net/sunrpc/xprtsock.c:1903: sock_lock_init_class_and_name(sk, "slock-AF_INET-RPC",
net/sunrpc/xprtsock.c-1904- &xs_slock_key[1], "sk_lock-AF_INET-RPC", &xs_key[1]);
--
net/sunrpc/xprtsock.c=1907=static inline void xs_reclassify_socket6(struct socket *sock)
]
|
| 82/2 |
2026/11/28 10:05 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 134424
output: 61
thoughts: 4777
Thoughts: **The Core of the Problem: A Lockdep Circular Dependency in NBD**
Alright, let's break down this lockdep splat. I've been digging into the NBD module and the interaction with socket locking, and I've finally pinpointed the issue. It's a classic lockdep circular dependency, specifically `fs_reclaim --> sk_lock-AF_INET6 --> k-sk_lock-AF_INET6`. My thought process has been a journey of elimination and careful analysis of specific commits.
Initially, the `sk_lock.dep_map` caught my eye. I noticed it's only initialized in `sock_lock_init()` (during socket allocation/cloning) and then, crucially, reclassified in `nbd_reclassify_socket()`. This immediately suggested that the problem might lie in how and when this reclassification happens.
My focus then shifted to two specific commits in `drivers/block/nbd.c`:
1. `d532cddb6c60` ("nbd: Reclassify sockets to avoid lockdep circular dependency")
2. `9280e6edf656` ("nbd: don't warn when reclassifying a busy socket lock")
Let's dissect them:
* **Before `d532cddb6c60`:** NBD didn't do any socket reclassification at all. This means *every* NBD socket inherently had the `sk_lock-AF_INET6` lock class. This setup, by itself, was the root cause of the circular dependency. So, the question becomes, why didn't `d532cddb6c60` *introduce* the bug, but rather attempt to fix it?
* **The role of `d532cddb6c60`:** This commit *introduced* `nbd_reclassify_socket()` precisely to fix the existing circular dependency. However, it included a check: `if (WARN_ON_ONCE(!sock_allow_reclassification(sk))) return;`. This means if the socket couldn't be reclassified (likely due to a concurrent lock acquisition), it would issue a warning and return. Crucially, even though it returned, it *didn't* fail the `nbd_add_socket()` call, meaning the socket would be added without reclassification, and a `WARN_ON_ONCE` would be triggered. If `panic_on_warn` were enabled, this would have caused a crash, but not the *specific* circular dependency splat we're seeing.
* **The critical change in `9280e6edf656`:** This commit *removed* the `WARN_ON_ONCE` from the `!sock_allow_reclassification(sk)` case within `nbd_reclassify_socket()`. Instead of warning, it was designed to "skip reclassification silently." The commit message justified this by stating that hitting a held lock was "expected for an externally owned socket and is not a kernel bug," and that "skipping it in the rare racing case is harmless."
This is where my "aha!" moment truly landed. That assumption of "harmlessness" was incorrect. Silently skipping the reclassification is *exactly* what leaves the socket with the default `sk_lock-AF_INET6` class. When this happens concurrently with operations that acquire locks in the `fs_reclaim` context (which is what's happening in the stack trace I'm seeing), it directly exposes the `fs_reclaim --> sk_lock-AF_INET6 --> k-sk_lock-AF_INET6` circular dependency that the lockdep validator is catching.
**Eliminating Other Possibilities:**
I then thoroughly investigated other potential culprits:
* **`ffa1e7ada456` ("block: Make request_queue lockdep splats show up earlier"):** This commit only served to make lockdep splats more visible by priming `q->io_lockdep_map` with `fs_reclaim`. It didn't introduce the fundamental locking issue itself. Rule 4 of lockdep analysis ("Do NOT blame commits that merely added debugging or sanitizer checks...") applies here; it exposed an older bug, it didn't create it.
* **`rds_tcp_recv_path` and other socket operations:** I spent significant time examining `rds_tcp_recv_path` and similar functions like `tcp_sendmsg`, `tcp_setsockopt`, and `udp_sendmsg`. The pattern of holding `lock_sock` while allocating with `GFP_KERNEL` (which can trigger `fs_reclaim`) is actually *normal* for sockets that are *not* on the swap/reclaim/block-IO path. Functions like `rds_tcp_recv_path` that use `GFP_KERNEL` under `k-sk_lock-AF_INET6` (for internally owned sockets) or `lock_sock` under `sk_lock-AF_INET6` (for user-owned sockets) are expected. The problematic part of the cycle isn't `k-sk_lock-AF_INET6 -> fs_reclaim` or even `sk_lock-AF_INET6 -> k-sk_lock-AF_INET6` in specific contexts, but the `fs_reclaim -> sk_lock-AF_INET6` transition *without* proper reclassification.
**Pinpointing the Culprit Commit:**
The critical insight came from tracing the actual splat back through the stack. The path starting from `fs_reclaim` and ending with `sk_lock-AF_INET6` involves several NBD-specific operations (`nbd_queue_rq`, `nbd_handle_cmd`, `nbd_mark_nsock_dead`) culminating in acquiring `sk_lock-AF_INET6` on an NBD socket. This socket, crucially, had *not* been reclassified to a more specific NBD class.
My analysis confirmed that `nbd_add_socket` (and by extension, `nbd_genl_connect`) is where this reclassification *should* happen. The function `nbd_reclassify_socket` has the early `return` if `!sock_allow_reclassification(sk)`.
Therefore, **commit `9280e6edf656` ("nbd: don't warn when reclassifying a busy socket lock") is the commit that directly introduced this specific lockdep circular dependency crash.** While `d532cddb6c60` *attempted* to fix the underlying issue, `9280e6edf656` effectively disabled the warning mechanism that would have alerted us to the race condition, leading to the silent skipping of reclassification and thus unmasking the circular dependency. If `9280e6edf656` hadn't happened, a race would either still have been caught by `d532cddb6c60`'s `WARN_ON_ONCE` (if `panic_on_warn=1`) or would have continued to be hidden by the earlier, pre-commit `d532cddb6c60` state where NBD didn't reclassify at all (leading to a consistent, non-racing splat). The race condition that exposes the splat in the syzkaller reproducer is enabled by the silent skip introduced in `9280e6edf656`.
|
| 83/2 |
2026/11/28 10:06 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 285908f554fe32d9ca7cb7c3a03a05144faeb461
Author: Yang Erkun <yangerkun@huawei.com>
Date: Wed Aug 5 20:29:26 2026 +0800
nbd: remove queue freeze in nbd_add_socket
nbd_add_socket() kreallocs config->socks, which a concurrent reader in
nbd_handle_cmd() could UAF; commit b98e762e3d71 ("nbd: freeze the queue
while we're adding connections")froze the queue to block that. But the
freeze costs an RCU grace period on every socket added, and setup adds
them one by one.
After the previous patch, nbd_add_socket() is rejected once nbd->pid is
set, so it only runs during setup. There the capacity is 0 and the
write cache is off (cleared on disconnect by the preceding patch, and
re-enabled only later in nbd_set_size), so submit_bio_noacct() rejects
every bio before it reaches the driver -- non-zero-sector ones via
bio_check_eod(), and flush-only ones via the !bdev_write_cache() branch.
No I/O is in flight, so the freeze is unnecessary.
Reviewed-by: Yu Kuai <yukuai@fygo.io>
Signed-off-by: Yang Erkun <yangerkun@huawei.com>
Link: https://patch.msgid.link/20260805122930.57647-5-yangerkun@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 78df6f459da6..cb7c1f8502f4 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1276,7 +1276,6 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
struct socket *sock;
struct nbd_sock **socks;
struct nbd_sock *nsock;
- unsigned int memflags;
int err;
/* Arg will be cast to int, check it to avoid overflow */
@@ -1294,12 +1293,6 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
return err;
nbd_reclassify_socket(sock);
- /*
- * We need to make sure we don't get any errant requests while we're
- * reallocating the ->socks array.
- */
- memflags = blk_mq_freeze_queue(nbd->disk->queue);
-
if (!netlink && !nbd->task_setup &&
!test_bit(NBD_RT_BOUND, &config->runtime_flags))
nbd->task_setup = current;
@@ -1339,12 +1332,10 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
INIT_WORK(&nsock->work, nbd_pending_cmd_work);
socks[config->num_connections++] = nsock;
atomic_inc(&config->live_connections);
- blk_mq_unfreeze_queue(nbd->disk->queue, memflags);
return 0;
put_socket:
- blk_mq_unfreeze_queue(nbd->disk->queue, memflags);
sockfd_put(sock);
return err;
}
]
|
| 84/2 |
2026/11/28 10:06 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 326d49039c10b65522ac7277b19b9b5c42ed1aeb
Author: Yang Erkun <yangerkun@huawei.com>
Date: Wed Aug 5 20:29:30 2026 +0800
nbd: add pre_defined_connections module parameter for pre-created devices
blk_mq_update_nr_hw_queues() in nbd_start_device() may cause a queue
freeze. The previous commit addressed this for newly created nbd
devices by setting the expected nr_hw_queues in nbd_dev_add(). However,
when reusing an old inactive nbd device, the queue freeze can still
occur if the old nbd->tag_set->nr_hw_queues does not match the new
socket connection count. Inactive nbd devices can originate from two
sources: loading the nbd module with nbds_max, which sets the default
nr_hw_queues to 1, and the netlink method, which sets nr_hw_queues
according to the expected number of socket connections. For the first
case, add a module parameter so the default nr_hw_queues can be
changed. Users who know their expected number of connections can then
prevent queue freezes on pre-created devices via nbds_max.
Before this patchset:
real 0m2.195s
user 0m0.005s
sys 0m0.022s
After this patchset:
real 0m0.090s
user 0m0.004s
sys 0m0.018s
Signed-off-by: Yang Erkun <yangerkun@huawei.com>
Reviewed-by: Yu Kuai <yukuai@fygo.io>
Link: https://patch.msgid.link/20260805122930.57647-9-yangerkun@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 6c4aa19ea11a..ffce519bf008 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -166,6 +166,7 @@ static struct dentry *nbd_dbg_dir;
static unsigned int nbds_max = 16;
static int max_part = 16;
+static int pre_defined_connections = 1;
static int part_shift;
static int nbd_dev_dbg_init(struct nbd_device *nbd);
@@ -2712,6 +2713,12 @@ static int __init nbd_init(void)
if (nbds_max > 1UL << (MINORBITS - part_shift))
return -EINVAL;
+ /* An excessively large value will be adjusted in blk_mq_alloc_tag_set */
+ if (pre_defined_connections < 1) {
+ pr_err("pre_defined_connections must be >= 1\n");
+ return -EINVAL;
+ }
+
if (register_blkdev(NBD_MAJOR, "nbd"))
return -EIO;
@@ -2728,8 +2735,12 @@ static int __init nbd_init(void)
}
nbd_dbg_init();
+ /*
+ * Set to the intended connection count so nbd_start_device() can skip
+ * the queue-freezing blk_mq_update_nr_hw_queues() call.
+ */
for (i = 0; i < nbds_max; i++)
- nbd_dev_add(i, 1, 1);
+ nbd_dev_add(i, 1, pre_defined_connections);
return 0;
}
@@ -2790,3 +2801,6 @@ module_param(nbds_max, int, 0444);
MODULE_PARM_DESC(nbds_max, "number of network block devices to initialize (default: 16)");
module_param(max_part, int, 0444);
MODULE_PARM_DESC(max_part, "number of partitions per device (default: 16)");
+module_param(pre_defined_connections, int, 0444);
+MODULE_PARM_DESC(pre_defined_connections,
+"number of connections for devices pre-created at module load (default: 1)");
]
|
| 85/2 |
2026/11/28 10:06 |
llm |
cause-finder-compressor |
0m
Model:
Reply: ### 1. Approaches Tried and Results
#### Analysis of the Lockdep Splat
* **Target deadlock:**
* Lock held by worker: `k-sk_lock-AF_INET6` (acquired in `rds_tcp_recv_path+0xfe/0x340 net/rds/tcp_recv.c:304` via `lock_sock`).
* Lock being acquired: `fs_reclaim` (at `kmem_cache_alloc_noprof` in `rds_tcp_data_recv+0x174/0xa00 net/rds/tcp_recv.c:174`).
* Dependency chain leading to deadlock:
* `#0`: `(fs_reclaim)` acquired while holding `(k-sk_lock-AF_INET6)` in `rds_tcp_recv_path` / `rds_tcp_data_recv`.
* `#1`: `&q->q_usage_counter(io)#51` under `(fs_reclaim)` (`blk_alloc_queue` priming via `fs_reclaim_acquire` / `rwsem_acquire_read`).
* `#2`: `&q->elevator_lock` under `&q->q_usage_counter(io)` (`elevator_change` called during `blk_mq_update_nr_hw_queues` in `nbd_start_device`).
* `#3`: `set->srcu` under `&q->elevator_lock` (`elevator_switch` -> `blk_mq_quiesce_queue` -> `__synchronize_srcu`).
* `#4`: `&cmd->lock` under `set->srcu` (`blk_mq_dispatch_rq_list` -> `nbd_queue_rq`).
* `#5`: `&nsock->tx_lock` under `&cmd->lock` (`nbd_handle_cmd`).
* `#6`: `(sk_lock-AF_INET6)` under `&nsock->tx_lock` (`sock_shutdown` -> `nbd_mark_nsock_dead` -> `kernel_sock_shutdown` -> `inet_shutdown` -> `lock_sock`).
* `#7`: `(k-sk_lock-AF_INET6)` under `(sk_lock-AF_INET6)` (`mptcp_setsockopt_first_sf_only` takes `lock_sock(sk)` on MPTCP user socket, then calls `tcp_setsockopt(ssk)` which takes `lock_sock` on kernel subflow TCP socket).
#### Investigation of Subsystems and Git History
* **RDS (`net/rds/tcp_recv.c`):**
* Examined `rds_tcp_recv_path()` and `rds_tcp_data_recv()`.
* `rds_tcp_recv_path()` locks `sock->sk` (a kernel socket with lock class `k-sk_lock-AF_INET6`) and calls `rds_tcp_read_sock(cp, GFP_KERNEL)`.
* `git blame` reveals this code in `rds_tcp_recv_path()` and `rds_tcp_data_recv()` (`kmem_cache_alloc(..., GFP_KERNEL)`) has existed unchanged since 2009/2016 (`70041088e3b9`, `2da43c4a1b51`). This is not newly introduced code.
* **MPTCP (`net/mptcp/sockopt.c`):**
* Examined `mptcp_setsockopt_first_sf_only()`.
* `git blame` and `git log` show `mptcp_setsockopt_first_sf_only()` was introduced in 2022 (`d3d429047cc6`, `caea64675d8b`). This is not recent.
* **Block layer (`block/blk-core.c`, `block/blk-mq.c`, `block/elevator.c`):**
* `ffa1e7ada456` ("block: Make request_queue lockdep splats show up earlier") in March 2025 primed `fs_reclaim -> q_usage_counter(io)` at `blk_alloc_queue()`.
* `1e1a9cecfab3` ("block: force noio scope in blk_mq_freeze_queue") in Jan 2025 wrapped freeze/unfreeze with `memalloc_noio_save()`.
* **NBD Driver (`drivers/block/nbd.c`):**
* Examined commits dealing with socket reclassification in NBD:
1. `d532cddb6c60` ("nbd: Reclassify sockets to avoid lockdep circular dependency") on June 13, 2026:
Introduced `nbd_reclassify_socket()` using `sock_lock_init_class_and_name()` into `sk_lock-AF_INET-NBD`, `sk_lock-AF_INET6-NBD`, `sk_lock-AF_UNIX-NBD`.
Guarded with `if (WARN_ON_ONCE(!sock_allow_reclassification(sk))) return;`.
Added call to `nbd_reclassify_socket(sock)` in `nbd_add_socket()`.
2. `9280e6edf656` ("nbd: don't warn when reclassifying a busy socket lock") on June 22, 2026:
Changed `if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))` to `if (!sock_allow_reclassification(sk)) return;`.
When `sock_allow_reclassification(sk)` returns false (because userspace or softirq holds `sk_lock` or `slock`), reclassification is silently skipped!
3. `553d28925fde` ("nbd: Reclassify sockets in the reconnect path") on Nov 12, 2026:
Added missing `nbd_reclassify_socket(sock)` to `nbd_genl_reconnect_sock_cb()`.
* Looked at why frame `#6` in the crash trace shows `sk_lock-AF_INET6` instead of `sk_lock-AF_INET6-NBD`.
---
### 2. Verified Facts
* **Fact 1:** Under normal operations, user sockets have lock class `sk_lock-AF_INET6` and kernel sockets have lock class `k-sk_lock-AF_INET6` (`net/core/sock.c:sock_lock_init`, since commit `cdfbabfb2f0c` in 2017).
* **Fact 2:** In frame `#6`, NBD is shutting down an NBD socket via `nbd_mark_nsock_dead()` -> `kernel_sock_shutdown()` -> `inet_shutdown()` -> `lock_sock()`. The lockdep class shown is `(sk_lock-AF_INET6)`, which is the **default user socket class**, NOT the `(sk_lock-AF_INET6-NBD)` class.
* **Fact 3:** In `drivers/block/nbd.c`, commit `d532cddb6c60` explicitly noted that NBD sockets cause false positive circular locking dependencies against `fs_reclaim` because NBD sockets take `sk_lock` under `tx_lock` (which is under block request submission / `fs_reclaim`). To fix this, `d532cddb6c60` reclassifies NBD sockets to `sk_lock-AF_INET6-NBD`.
* **Fact 4:** In commit `9280e6edf656` ("nbd: don't warn when reclassifying a busy socket lock"), `nbd_reclassify_socket()` was modified so that if `sock_allow_reclassification(sk)` is false, it returns silently without reclassifying. If userspace holds the socket lock or has concurrent socket activity during `nbd_add_socket()` / `nbd_genl_connect()`, reclassification is skipped and the socket remains `sk_lock-AF_INET6`.
* **Fact 5:** Alternatively, could NBD sockets be added or handled in a path that does NOT call `nbd_reclassify_socket()`?
Let's check all callers of `nbd_reclassify_socket`:
- `nbd_add_socket` (used by ioctl `NBD_SET_SOCK` and netlink `nbd_genl_connect`)
- `nbd_genl_reconnect_sock_cb` (added by `553d28925fde`)
* **Fact 6:** Check whether NBD or NVMe or another commit introduced or modified something in `drivers/block/nbd.c` or elsewhere recently.
---
### 3. Hypotheses and Open Lines of Investigation
* **Hypothesis 1:** Commit `9280e6edf656` ("nbd: don't warn when reclassifying a busy socket lock") introduced the bug.
*Rationale:* Author assumed: "Hitting a held lock here is expected for an externally owned socket and is not a kernel bug, so skip reclassification silently instead of warning. Reclassification is a lockdep-only annotation, so skipping it in the rare racing case is harmless." But skipping reclassification is NOT harmless! It leaves the socket in `sk_lock-AF_INET6`, which recreates the exact circular dependency that `d532cddb6c60` was added to fix!
* **Hypothesis 2:** Commit `553d28925fde` ("nbd: Reclassify sockets in the reconnect path") or another commit in NBD.
* Need to check if there is an NBD path that misses `nbd_reclassify_socket()`, or if the bug is specifically caused by `9280e6edf656` or `d532cddb6c60` or something else in NBD.
* **Hypothesis 3:** Check other recent commits in `drivers/block/nbd.c` around `nbd_genl_connect`, `nbd_config_put`, etc., such as `1649714b930f ("nbd: defer config unlock in nbd_genl_connect")` or `a9d414b4a15c ("nbd: remove queue freeze for newly created nbd from netlink path")`.
* **Hypothesis 4:** Could this be an issue introduced by a change in `fs_reclaim` / `blk_mq` / `sock` / `mptcp`?
* Check `git log` of `drivers/block/nbd.c` between June 2026 and November 2026.
---
### 4. Critical File Paths and Code Snippets
#### `drivers/block/nbd.c`:
```c
static void nbd_reclassify_socket(struct socket *sock)
{
struct sock *sk = sock->sk;
if (!sock_allow_reclassification(sk))
return;
switch (sk->sk_family) {
case AF_INET:
sock_lock_init_class_and_name(sk, "slock-AF_INET-NBD",
&nbd_slock_key[0],
"sk_lock-AF_INET-NBD",
&nbd_key[0]);
break;
case AF_INET6:
sock_lock_init_class_and_name(sk, "slock-AF_INET6-NBD",
&nbd_slock_key[1],
"sk_lock-AF_INET6-NBD",
&nbd_key[1]);
break;
case AF_UNIX:
sock_lock_init_class_and_name(sk, "slock-AF_UNIX-NBD",
&nbd_slock_key[2],
"sk_lock-AF_UNIX-NBD",
&nbd_key[2]);
break;
}
}
```
#### Commit `9280e6edf656` diff:
```c
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 3a585a0c882a..8f10762e90ef 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1246,7 +1246,7 @@ static void nbd_reclassify_socket(struct socket *sock)
{
struct sock *sk = sock->sk;
- if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
+ if (!sock_allow_reclassification(sk))
return;
```
#### Commit `d532cddb6c60` message:
"nbd: Reclassify sockets to avoid lockdep circular dependency
syzbot reported a possible circular locking dependency in udp_sendmsg() where fs_reclaim can be triggered while holding sk_lock, and fs_reclaim can eventually depend on another sk_lock (e.g., if NBD is used for swap or writeback and NBD uses TLS/TCP which acquires sk_lock).
Since the UDP socket and the NBD TCP/TLS socket are different, this is a false positive. Fix this by reclassifying NBD sockets to a separate lock class when they are added to the NBD device."
#### Commit `1649714b930f`:
Need to inspect `git show 1649714b930f` to see what changed in `nbd_genl_connect`.
---
### 5. Potential Loops / Redundant Operations to Avoid
* Do NOT spend more time inspecting `net/rds/` or `net/mptcp/` - their code in the traces is old (2009-2022).
* Do NOT re-read `block/elevator.c` - the lock ordering in block-mq is established and standard.
* Focus investigation on the exact commit that allowed the un-reclassified socket or the lockdep chain `fs_reclaim -> ... -> sk_lock-AF_INET6` to happen in NBD.
---
### 6. Concrete Next Steps
1. Inspect commit `1649714b930f` ("nbd: defer config unlock in nbd_genl_connect") to understand if it altered socket shutdown or lockdep context during `nbd_genl_connect`.
2. Check how other drivers (like `nvme-tcp`, `rxe`, `cifs`) handle `sock_allow_reclassification` or socket reclassification.
3. Check if `9280e6edf656` is indeed the commit that caused syzbot to trigger the circular locking dependency (because prior to `9280e6edf656`, racing tasks hit `WARN_ON_ONCE` instead of proceeding with an unclassified socket, or was `d532cddb6c60` itself flawed / incomplete?).
4. Examine syzkaller reports / git log of `drivers/block/nbd.c` around `9280e6edf656` and `d532cddb6c60`.
5. Determine whether `9280e6edf656` or `d532cddb6c60` (or another commit like `1649714b930f`) is the primary introducing commit, verify with `git-show`, and invoke `set-results`.
Tokens:
input: 121552
output: 3717
thoughts: 0
|
| 86/2 |
2026/11/28 10:06 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 43789
output: 35
thoughts: 1286
Thoughts: **My Analysis of the Lockdep Cycle and Its Root Cause**
I've meticulously reviewed the lockdep cycle that led to the crash, and it's all quite clear now. My primary focus is on understanding how we arrived at this specific `fs_reclaim --> sk_lock-AF_INET6 --> k-sk_lock-AF_INET6 --> fs_reclaim` dependency.
The core of the issue lies in how the NBD (Network Block Device) driver handles socket reclassification. Let's break it down:
1. **The Lockdep Cycle Itself:**
* The cycle begins with `fs_reclaim`. This is where the critical path seems to originate, involving operations that eventually lead to acquiring a socket lock.
* We then see `sk_lock-AF_INET6`. This represents a lock on a generic IPv6 TCP socket, commonly held during user-space socket operations.
* The dependency chain continues to `k-sk_lock-AF_INET6`. This signifies a lock on a kernel-managed socket, specifically a subflow socket in the context of MPTCP (MultiPath TCP) or similar kernel networking constructs.
* The cycle then loops back to `fs_reclaim`, completing the circular dependency.
Looking at the specific tracebacks:
* The `#0` entry shows `k-sk_lock-AF_INET6` calling `fs_reclaim`. This happens within `rds_tcp_recv_path()`, where `lock_sock(sock->sk)` is acquired on a kernel socket, leading to `kmem_cache_alloc`.
* The `#7` entry reveals `sk_lock-AF_INET6` calling `k-sk_lock-AF_INET6`. This is observed in `mptcp_setsockopt_first_sf_only()`, where `lock_sock(sk)` is held on a user-space MPTCP socket, and then a kernel subflow socket is manipulated via `do_tcp_setsockopt()`.
* The intermediate entries (`#1` to `#6`) trace a path from `fs_reclaim` through various NBD-specific structures (`q->q_usage_counter`, `q->elevator_lock`, etc.) and then eventually to `sk_lock-AF_INET6` within NBD's socket shutdown logic (`nbd_genl_connect()` -> `nbd_config_put()` -> `nbd_clear_sock()` -> `sock_shutdown()` -> `nbd_mark_nsock_dead()` -> `kernel_sock_shutdown()` -> `inet_shutdown()` -> `lock_sock()`). This demonstrates how `fs_reclaim` indirectly acquires the generic `sk_lock-AF_INET6`.
2. **The "Why" - The NBD Socket Reclassification Problem:**
* Commit `d532cddb6c60` introduced `nbd_reclassify_socket()` with the express purpose of *avoiding* this type of lockdep circular dependency. It aimed to move NBD's sockets out of the generic `sk_lock-AF_INET*` classes into dedicated `sk_lock-AF_INET*-NBD` classes.
* The problem arises because NBD receives sockets from user space via file descriptors. Concurrently, user space or softirq processing might be holding `sk->sk_lock` or `sk->sk_lock.slock` when `nbd_reclassify_socket()` attempts to run. This causes `sock_allow_reclassification(sk)` to return `false`.
* Initially, `d532cddb6c60` would `WARN_ON_ONCE` in this situation.
* However, commit `9280e6edf656` ("nbd: don't warn when reclassifying a busy socket lock") changed this behavior. It **removed the warning**, allowing `nbd_reclassify_socket()` to *silently skip* reclassification if `!sock_allow_reclassification(sk)`. The rationale was that hitting a held lock was expected for externally owned sockets and not a kernel bug, and that skipping this lockdep-only annotation was harmless.
3. **Why "Skipping is NOT Harmless":**
* This is where the critical flaw was introduced. When reclassification is skipped, the socket *retains its generic `sk_lock-AF_INET6` lockdep class*.
* Subsequently, `nbd_add_socket()` attaches this unreclassified socket to the NBD structure.
* Then, during operations like `nbd_mark_nsock_dead()` (called from `nbd_config_put()` during `nbd_genl_connect()`), the code proceeds to acquire `sk_lock-AF_INET6` via `lock_sock()`.
* Because this socket is still tagged with the generic `sk_lock-AF_INET6` class, and `fs_reclaim` is also involved in the path (as seen in the trace), we end up with the direct circular dependency: `fs_reclaim -> sk_lock-AF_INET6 -> k-sk_lock-AF_INET6`.
4. **Pinpointing the Primary Commit:**
* Before `9280e6edf656`, the `WARN_ON_ONCE` in `nbd_reclassify_socket()` would flag the racing condition.
* `9280e6edf656` is the commit that **silenced this warning** and allowed the code to proceed with an unreclassified socket, thereby directly enabling the silent creation of the lockdep circular dependency. While `d532cddb6c60` introduced the reclassification mechanism, it was `9280e6edf656` that made the silent failure path possible, leading to this specific splat. Other commits mentioned don't seem to be the direct enabler of this particular silent failure mode.
Therefore, my conclusion is that commit `9280e6edf656` is the primary culprit. I'll be using its full hash for the `set-results`.
|
| 87/2 |
2026/11/28 10:07 |
tool |
git-show |
0m
Args: map[Commit:9280e6edf656 Stat:true]
Results: map[Output:commit 9280e6edf65662b6aafc8b704ad065b54c08b519
Author: Deepanshu Kartikey <kartikey406@gmail.com>
Date: Mon Jun 22 05:22:55 2026 +0530
nbd: don't warn when reclassifying a busy socket lock
nbd_reclassify_socket() warns via WARN_ON_ONCE() if the socket lock is
held at the point of reclassification. That assertion was copied from
nvme-tcp, where the socket is created internally by the kernel
(sock_create_kern()) and is never visible to user space, so the lock
is guaranteed to be free.
NBD is different: the socket is looked up from a user-supplied fd in
nbd_get_socket(), and user space retains that fd. A concurrent syscall
on the same socket (or softirq processing taking bh_lock_sock() on a
connected TCP socket) can legitimately hold the lock at the instant
NBD reclassifies it. sock_allow_reclassification() then returns false
and the WARN_ON_ONCE() fires, which turns into a crash under
panic_on_warn. This is reachable by simply racing NBD_CMD_CONNECT
against socket activity on the same fd, as reported by syzbot.
Hitting a held lock here is expected for an externally owned socket and
is not a kernel bug, so skip reclassification silently instead of
warning. Reclassification is a lockdep-only annotation, so skipping it
in the rare racing case is harmless.
Reported-by: syzbot+6b85d1e39a5b8ed9a954@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6b85d1e39a5b8ed9a954
Fixes: d532cddb6c60 ("nbd: Reclassify sockets to avoid lockdep circular dependency")
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260621235255.66015-1-kartikey406@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/nbd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
]
|
| 88/2 |
2026/11/28 10:07 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 45757
output: 57
thoughts: 47
Thoughts: **My Internal Monologue on the Task at Hand**
Alright, the immediate directive is to execute a specific command: `set-results` with the single argument `"9280e6edf65662b6aafc8b704ad065b54c08b519"`. This is straightforward, a direct instruction to interface with a system component or API. My primary focus is on ensuring this command is dispatched correctly and without error. I'm not overthinking the *why* of this specific identifier; for now, it's simply the data payload required for the `set-results` operation. My internal processes are geared towards efficient and accurate execution of such commands, treating it as a discrete task with a clear input and expected output (or, in this case, a side effect of updating some state). I'm ready to proceed with this specific action.
|
| 89/2 |
2026/11/28 10:07 |
tool |
set-results |
0m
Args: map[CandidateCommits:[9280e6edf65662b6aafc8b704ad065b54c08b519]]
Results: map[CandidateCommits:[9280e6edf65662b6aafc8b704ad065b54c08b519]]
|
| 90/2 |
2026/11/28 10:07 |
llm |
cause-finder |
0m
Model:
Tokens:
input: 45914
output: 1260
thoughts: 65
Thoughts: **Deconstructing the Bug: A Deep Dive into the Root Cause and Commit `9280e6e`**
Ah, the satisfaction of a resolved issue! As I reflect on this recent problem, my thought process naturally segues into dissecting the journey to its solution. I need to articulate a clear, concise, and accurate explanation, focusing on the fundamental root cause, the path traced through our Git history, and specifically, how commit `9280e6edf65662b6aafc8b704ad065b54c08b519` acted as the unwitting architect of this bug.
My initial instinct is to pinpoint the *why* β the core, underlying flaw that allowed this issue to manifest. It wasn't a superficial error, but something deeper, a misinterpretation of a requirement, a subtle edge case overlooked, or perhaps a design decision that, while logical at the time, proved brittle. I need to recall the exact nature of this root cause, the fundamental assumption or logic that was incorrect.
Then, I'll mentally rewind the Git timeline. Tracing the history is crucial. I'm not just looking for *a* change, but *the* sequence of changes that led to the problematic state. This involves understanding how different commits built upon each other, how intended functionality might have been subtly altered, and how dependencies between code sections played out. My goal here is to demonstrate a logical progression, showing how the system evolved to a point where the bug could exist.
Finally, the spotlight must fall on `9280e6edf65662b6aafc8b704ad065b54c08b519`. This commit is the pivot point. I need to explain precisely what this commit *did* and, more importantly, *why* that action, in conjunction with the established root cause and the preceding Git history, introduced the bug. Was it a refactoring that inadvertently broke backward compatibility for a specific scenario? Did it introduce a new dependency that wasn't properly accounted for? Was it an attempt to fix one thing that broke another? My explanation needs to be surgically precise, connecting the specific code changes within `9280e6e` to the observable bug. I'm confident I can present this with the clarity and accuracy our field demands.
|
| 91/1 |
2026/11/28 10:07 |
action |
format-bisect |
0m
Results: map[Commits:[map[AuthorEmail:kartikey406@gmail.com AuthorName:Deepanshu Kartikey Date:2026-06-22T05:22:55+05:30 Hash:9280e6edf65662b6aafc8b704ad065b54c08b519 Recipients:[map[Email:axboe@kernel.dk Name: To:true] map[Email:edumazet@google.com Name: To:true] map[Email:kartikey406@gmail.com Name: To:true]] Title:nbd: don't warn when reclassifying a busy socket lock]] IsRelease:false]
|