mptcp: defer read_sock cleanup to mptcp_worker
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 2
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 presents the patch as a fix for a BH- context call path that does not exist in this tree.
- [Medium] __mptcp_read_sock() now always defers mptcp_rcv_space_adjust() and mptcp_cleanup_rbuf() to mptcp_worker(), including for callers that…
- [Low] The commit author is 'Geliang Tang <[email protected]>' but the only Signed-off-by is 'Geliang Tang <[email protected]>'.
- [Low] The patch removes msk_owned_by_me(msk) from __mptcp_read_sock(), saying the "BH caller does not own the msk lock".
--
mptcp: defer read_sock cleanup to mptcp_worker
This patch moves the mptcp_rcv_space_adjust() and mptcp_cleanup_rbuf() calls out of __mptcp_read_sock() and into mptcp_worker(). The consumed byte count is accumulated in a new msk->read_copied field and signalled through a new MPTCP_WORK_READ_COMPLETE bit. It also drops the backlog flush from mptcp_recv_skb(), the msk_owned_by_me() assertion, and the post-loop mptcp_recv_skb() call 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]
Can this call chain be reached in this tree?
tls_strp_read_copyin() calls tcp_read_sock() directly. It does not go through sk->sk_read_sock():
net/tls/tls_strp.c:tls_strp_read_copyin() {
...
tcp_read_sock(strp->sk, &desc, tls_strp_copyin);
...
}Nothing under net/ seems to reference sk->sk_read_sock. The TLS strparser also uses tcp_inq() and tcp_recv_skb(), so it looks TCP-specific.
The TLS ULP can't be attached to an MPTCP socket either, because mptcp_setsockopt_sol_tcp() rejects it:
net/mptcp/sockopt.c:mptcp_setsockopt_sol_tcp() {
...
case TCP_ULP:
return -EOPNOTSUPP;
...
}The only caller of __mptcp_read_sock() is mptcp_read_sock(). That is reached through proto_ops.read_sock and mptcp_splice_read(), and both run in process context with lock_sock() held.
If this is groundwork for a pending MPTCP-over-TLS series, could the commit message say so?
Could it also describe what changes for the existing callers? Those changes are the deferred window update and autotuning, the dropped backlog drain in the read path, and the removed lockdep assertion.
Quoted 2 lines
Suggested-by Paolo Abeni <[email protected]>Signed-off-by Geliang Tang <[email protected]>
[Severity: Low]
This isn't a bug, but the author address is [email protected] and the only Signed-off-by uses [email protected]. checkpatch reports this as a From:/Signed-off-by: email mismatch.
The neighbouring commits in this series ("mptcp: sync mptcp skb cb layout with tcp one" and "mptcp: remove CB offset field") use [email protected] in the Signed-off-by. Was this an oversight?
Quoted 4 lines
net/mptcp/protocol.c +0
-0
[ ... ]
Quoted 9 lines
net/mptcp/protocol.c +1
-0@@ -4646,6 +4663,7 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)/* * Note: * - It is assumed that the socket was locked by the caller. +* - Can be invoked in BH scope. */ static int __mptcp_read_sock (struct sock *sk,read_descriptor_t *desc,sk_read_actor_t recv_actor,bool noack)
net/mptcp/protocol.c static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc, · line 4659
Quoted 5 lines
net/mptcp/protocol.c +0
-2@@ -4655,8 +4673,6 @@ static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,int copied =0 ;u32 offset; -msk_owned_by_me (msk); -
[Severity: Low]
The commit message says the assertion is dropped because the "BH caller does not own the msk lock". Would the assertion actually fire for that caller?
msk_owned_by_me() ends up in sock_owned_by_me(), which checks lockdep_sock_is_held():
include/net/sock.h:lockdep_sock_is_held() {
return lockdep_is_held(&sk->sk_lock) ||
lockdep_is_held(&sk->sk_lock.slock);
}A BH caller reached through sk->sk_data_ready() would hold the msk slock. mptcp_data_ready() takes mptcp_data_lock(), which is spin_lock_bh() on sk->sk_lock.slock, before it calls sk_data_ready(). tls_strp_data_ready() also notes that it runs under bh_lock_sock.
With the assertion removed, nothing checks the locking in a function that modifies sk_receive_queue, copied_seq, bytes_consumed, the rmem accounting and read_copied. The comment above still only says the socket "was locked by the caller", without saying which lock.
Could the assertion stay, or be replaced with something like DEBUG_NET_WARN_ON_ONCE(!lockdep_sock_is_held(sk)), so both kinds of caller are still checked?
Quoted 12 lines
net/mptcp/protocol.c +3
-2if (sk->sk_state ==TCP_LISTEN )return -ENOTCONN ;while ((skb =mptcp_recv_skb (sk, &offset)) !=NULL ) {@@ -4687,11 +4703,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 +* moved and will take place in mptcp_release_cb() via +* release_sock() in the worker.
net/mptcp/protocol.c static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc, · line 4716
Quoted 10 lines
net/mptcp/protocol.c +4
-2+*/ 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); } out:return copied;
[Severity: Medium]
Does this delay the window update for the existing process-context callers?
In this tree those callers already own the msk lock, for example:
mptcp_splice_read()
lock_sock(sk)
__mptcp_splice_read()
mptcp_read_sock()
__mptcp_read_sock()Before this patch, mptcp_cleanup_rbuf(msk, copied) ran inline. Its path through mptcp_subflow_cleanup_rbuf() -> tcp_cleanup_rbuf() is what sends the window-opening ACK.
Now every read that consumes data does sock_hold() plus schedule_work(). It then needs a full mptcp_worker() pass (lock_sock(), the PM worker, the data-fin checks, release_sock()) just to run these two calls.
mptcp_splice_read() holds the msk lock across its loop and takes it again right after each release_sock(sk)/lock_sock(sk). The worker usually can't get the lock until the splice call returns or blocks in sk_wait_data(). The autotuning in mptcp_rcv_space_adjust() is delayed in the same way.
mptcp_release_cb() doesn't seem to cover this, because it passes copied == 0:
net/mptcp/protocol.c:mptcp_release_cb() {
...
/* notify ack seq update */
mptcp_cleanup_rbuf(msk, 0);
...
}With copied == 0, both the cleanup and rx_empty conditions in mptcp_cleanup_rbuf() are false.
The order of operations changes too. mptcp_read_complete() runs inside mptcp_worker(), before release_sock() spools msk->backlog_list. The old code moved the backlog first, through the post-loop mptcp_recv_skb() -> mptcp_move_skbs() call.
Would it work to defer only when the caller doesn't own the msk, and keep the inline calls for process-context callers?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1793361629.git.tanggeliang%40kylinos.cn