mptcp: defer read_sock cleanup to mptcp_worker
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The commit message describes a BH call path that does not exist in this tree.
- [Medium] The deferral in __mptcp_read_sock() is unconditional, so it changes every real caller, all of which run in process context with…
--
mptcp: defer read_sock cleanup to mptcp_worker
This commit moves the mptcp_rcv_space_adjust() and mptcp_cleanup_rbuf() calls out of __mptcp_read_sock() and into mptcp_worker(). It adds a msk->read_copied accumulator and a MPTCP_WORK_READ_COMPLETE flag. It also drops the backlog flush from mptcp_recv_skb() and the msk_owned_by_me() assertion in __mptcp_read_sock().
Quoted 4 lines
When MPTCP carries TLS,
__mptcp_read_sock()is reached from BH context (viatls_strp_read_copyin()->sk->sk_read_sock()), where callingmptcp_rcv_space_adjust()andmptcp_cleanup_rbuf()is not safe as both expect process context.
[Severity: Medium]
Does this call path exist in the current tree? tls_strp_read_copyin() calls tcp_read_sock() directly, not through an indirection:
net/tls/tls_strp.c:tls_strp_read_copyin() {
...
/* sk should be locked here, so okay to do read_sock */
tcp_read_sock(strp->sk, &desc, tls_strp_copyin);
...
}There also doesn't seem to be an sk_read_sock hook anywhere in include/net, net/tls, net/mptcp or net/ipv4.
kTLS also can't be attached to an MPTCP socket right now, because mptcp_setsockopt_sol_tcp() rejects TCP_ULP:
net/mptcp/sockopt.c:mptcp_setsockopt_sol_tcp() {
...
case TCP_ULP:
return -EOPNOTSUPP;
...
}The other read_sock users don't seem to reach MPTCP from BH either:
- strparser is only reachable through KCM and sockmap. KCM only accepts IPPROTO_TCP. Sockmap rejects mptcp_prot because it has no psock_update_sk_prot.
- The NVMe-TCP host creates IPPROTO_TCP sockets and calls read_sock under lock_sock().
The new "Can be invoked in BH scope" note in __mptcp_read_sock() and the removed msk_owned_by_me() also point to a BH caller that doesn't exist yet.
Is this patch groundwork for a later TLS-over-MPTCP series? If so, could the commit message say that and name the series it depends on? As written, it reads like a fix for a context bug that can be hit today, so it could get backported on its own.
Quoted 4 lines
net/mptcp/protocol.c +0
-0
[ ... ]
Quoted 7 lines
net/mptcp/protocol.c +1
-2@@ -4659,11 +4675,14 @@ static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,if (noack) goto out; -mptcp_rcv_space_adjust (msk, copied); - +/* The backlog flushing is only needed when some data is actually
net/mptcp/protocol.c static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc, · line 4686
Quoted 10 lines
net/mptcp/protocol.c +6
-2+* moved and will take place in mptcp_release_cb() via +* release_sock() in the worker. +*/ if (copied >0 ) { -mptcp_recv_skb (sk, &offset); -mptcp_cleanup_rbuf (msk, copied); + msk->read_copied += copied; +set_bit (MPTCP_WORK_READ_COMPLETE , &msk->flags); +mptcp_schedule_work (sk); }
[Severity: Medium]
This deferral applies to every caller of __mptcp_read_sock(). All of the current callers run in process context and own the msk. Is the change in behaviour for them intended?
Before this patch, every read with copied > 0 ran mptcp_rcv_space_adjust() and mptcp_cleanup_rbuf() inline. mptcp_cleanup_rbuf() reaches tcp_cleanup_rbuf() on each subflow via mptcp_subflow_cleanup_rbuf(). That sends the window update once the reader has freed space.
Now each chunk costs a sock_hold() and a schedule_work(). The real work only runs after mptcp_worker() takes lock_sock(sk).
mptcp_splice_read() holds the msk lock for the whole call. Between chunks it only does this:
net/mptcp/protocol.c:mptcp_splice_read() {
...
release_sock(sk);
lock_sock(sk);
...
}The splicer can retake the lock before the woken kworker gets it. For splice() users, would window-update ACKs and rcvbuf autotuning then wait until the splice call finishes or blocks, plus workqueue latency?
Autotuning samples are also now taken when the worker runs, not when the data is read. The rcvq_space.time and mptcp_inq_hint() values that mptcp_rcv_space_adjust() sees could skew the rate estimate.
mptcp_recvmsg() still does both steps inline, so the two read paths now behave differently. The commit message only covers the BH caller and doesn't mention splice() or read_sock.
Would it work to defer only when the caller doesn't own the msk, and keep the inline calls otherwise?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1793255126.git.tanggeliang%40kylinos.cn