From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v11 1/4] mptcp: track app-limited state in mptcp_sendmsg
Date: Thu, 03 Dec 2026 14:59:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-248044@kernel.org> (raw)
In-Reply-To: <4fc318fc6b3764ff8ff0547f7a9d69ff707fa3b1.1796308130.git.geliang@kernel.org>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] mptcp: __mptcp_push_pending() re-marks subflows as
app-limited across bursts
- [Medium] mptcp: msk->app_limited held across sk_stream_wait_connect()
lock release
- [Medium] mptcp: unconditional mptcp_data_lock() in
mptcp_rate_check_app_limited()
- [Medium] mptcp: wait_for_memory clears app_limited without checking
subflows
- [Low] mptcp: mptcp_sendmsg() races with mptcp_sk_clone_init() on
TCP_LISTEN
- [Low] mptcp: placing app_limited before notsent_lowat grows struct
mptcp_sock
--
commit c4ee47e05973bf0226120dac06abfeee7a11ebbb
Author: Geliang Tang <geliang@kernel.org>
mptcp: track app-limited state in mptcp_sendmsg
This commit adds mptcp_rate_check_app_limited() to evaluate MPTCP-level
application-limited state in mptcp_sendmsg() and store it in
msk->app_limited, calling tcp_rate_check_app_limited() on scheduled
subflows in __subflow_push_pending().
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index b9c6e5a615c8b..4be1990e2a243 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -1815,6 +1815,9 @@ static int __subflow_push_pending(struct sock *sk, struct sock *ssk,
> struct mptcp_data_frag *dfrag;
> int len, copied = 0, err = 0;
>
> + if (msk->app_limited)
> + tcp_rate_check_app_limited(ssk);
> +
> while ((dfrag = mptcp_send_head(sk))) {
> info->sent = dfrag->already_sent;
> info->limit = dfrag->data_len;
[Severity: Medium]
Can __mptcp_push_pending() call tcp_rate_check_app_limited() repeatedly on
the same subflow across multiple bursts within a single mptcp_sendmsg()?
Because msk->app_limited stays set until __mptcp_push_pending() returns, a
multi-subflow connection sending more than two bursts (~128 KB) in one
sendmsg() visits ssk1 in round 1, switches to ssk2 in round 2 (which calls
mptcp_push_release(ssk1, &info) -> tcp_push(ssk1, ...), advancing
tp->snd_nxt to tp->write_seq), and then returns to ssk1 in round 3 while
unsent dfrags are still queued.
Once round 1's packets leave the host TX queue (such as on fast NICs, veth,
or loopback), the second tcp_rate_check_app_limited(ssk1) call overwrites
tp->app_limited to tp->delivered + tcp_packets_in_flight(tp). This marks
non-app-limited bulk bursts as application-limited, impairing BBR Startup
exit and bandwidth sampling.
> @@ -2112,6 +2115,23 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
> }
> }
>
> +static void mptcp_rate_check_app_limited(struct sock *sk)
> +{
> + struct mptcp_sock *msk = mptcp_sk(sk);
> + unsigned long flags;
> + bool retransmit;
> +
> + flags = READ_ONCE(msk->flags);
> + mptcp_data_lock(sk);
> + retransmit = test_bit(MPTCP_RETRANSMIT, &msk->cb_flags);
> + mptcp_data_unlock(sk);
> +
> + msk->app_limited = msk->write_seq == msk->snd_nxt &&
> + !mptcp_send_head(sk) &&
> + !test_bit(MPTCP_WORK_RTX, &flags) &&
> + !retransmit;
> +}
> +
> static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> {
> struct mptcp_sock *msk = mptcp_sk(sk);
[Severity: Medium]
Why does mptcp_rate_check_app_limited() take mptcp_data_lock(sk)
unconditionally before checking the cheap socket-lock-protected fields?
mptcp_data_lock(sk) acquires spin_lock_bh(&sk->sk_lock.slock), which adds a
third slock acquisition and BH disable/enable pair to every mptcp_sendmsg()
call and contends with softirq RX/ACK processing such as
mptcp_update_data_ack(). Short-circuiting on write_seq == snd_nxt,
!mptcp_send_head(sk), and !test_bit(MPTCP_WORK_RTX, &flags) first avoids
taking the spinlock whenever the socket is already non-app-limited.
> @@ -2142,6 +2162,9 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
>
> timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
>
> + /* is sending application-limited? */
> + mptcp_rate_check_app_limited(sk);
> +
> if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
> ret = sk_stream_wait_connect(sk, &timeo);
> if (ret)
[Severity: Medium]
Is it safe to leave msk->app_limited set across sk_stream_wait_connect()?
When sk is still connecting, sk_stream_wait_connect() sleeps in
sk_wait_event() and releases lock_sock(sk) while msk->app_limited is 1:
CPU0 CPU1
mptcp_sendmsg()
lock_sock(sk)
mptcp_rate_check_app_limited()
msk->app_limited = 1
sk_stream_wait_connect()
sk_wait_event()
release_sock(sk) <-- msk->app_limited leaked as 1
mptcp_sendmsg(MSG_DONTWAIT)
lock_sock(sk)
sk_stream_wait_connect() -> -EAGAIN
out: msk->app_limited = 0
release_sock(sk)
lock_sock(sk) <-- resumes with clobbered/stale flag
While CPU0 sleeps, mptcp_release_cb() or an asynchronous push/retransmit
path can observe the leaked msk->app_limited = 1, and any concurrent
mptcp_sendmsg() clears it at out:. When CPU0 wakes up, it enters the copy
loop without re-evaluating mptcp_rate_check_app_limited(). Moving the call
after sk_stream_wait_connect() and the sk_err/SEND_SHUTDOWN check avoids
holding this transient state across lock release.
> @@ -2224,6 +2247,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> wait_for_memory:
> sk_set_nospace(sk);
> __mptcp_push_pending(sk, msg->msg_flags);
> + msk->app_limited = 0;
> ret = sk_stream_wait_memory(sk, &timeo);
> if (ret)
> goto do_error;
[Severity: Medium]
Does clearing msk->app_limited here discard the app-limited check on
SO_SNDBUF-limited connections?
When sk->sk_wmem_queued >= sk->sk_sndbuf on the first iteration of the
sendmsg loop, mptcp_send_limit() returns 0 and jumps to wait_for_memory
with mptcp_send_head(sk) == NULL. __mptcp_push_pending() then returns
immediately without calling __subflow_push_pending() or
tcp_rate_check_app_limited(ssk), and clearing msk->app_limited = 0 before
sleeping ensures no subflow is ever marked after wakeup either.
Unlike plain TCP, which calls tcp_rate_check_app_limited() before entering
the wait_for_space loop, BBR will treat SO_SNDBUF-limited delivery rate
samples as non-app-limited network-bottleneck samples.
> @@ -2241,6 +2265,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> }
>
> out:
> + msk->app_limited = 0;
> release_sock(sk);
> return copied;
>
[Severity: Low]
Can mptcp_sendmsg() on a TCP_LISTEN socket race with mptcp_sk_clone_init()
when writing msk->app_limited?
CPU0 <softirq>
mptcp_sendmsg() on TCP_LISTEN
lock_sock(sk)
mptcp_rate_check_app_limited()
msk->app_limited = 1
sk_stream_wait_connect()
-> -EPIPE subflow_syn_recv_sock()
out: mptcp_sk_clone_init()
msk->app_limited = 0 sk_clone_lock()
sock_copy(newsk, sk) <-- data race
subflow_syn_recv_sock() calls mptcp_sk_clone_init() -> sk_clone_lock() ->
sock_copy() without lock_sock(sk), so writing msk->app_limited on a
listening socket creates a KCSAN data race, and neither __mptcp_init_sock()
nor mptcp_sk_clone_init() resets app_limited on the cloned child. Note
that even moving mptcp_rate_check_app_limited() after
sk_stream_wait_connect() still leaves the unconditional write at out:
mutating a TCP_LISTEN socket unless guarded or kept local to sendmsg.
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index 7cdd0a7e8296b..9dde6502a429d 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -350,6 +350,7 @@ struct mptcp_sock {
> free_first:1,
> rcvspace_init:1,
> fastclosing:1;
> + u8 app_limited:1;
> u32 notsent_lowat;
> int keepalive_cnt;
> int keepalive_idle;
[Severity: Low]
Placing app_limited here adds 3 bytes of padding before notsent_lowat and 4
bytes after maxseg before struct work_struct work, growing struct
mptcp_sock (and struct mptcp6_sock) by 8 bytes on 64-bit builds. There is
an existing 2-byte alignment hole after scaling_ratio and allow_subflows
before subflow_id that could hold it without growing the struct.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796308130.git.geliang@kernel.org?part=1
next prev parent reply other threads:[~2026-12-03 14:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 14:32 [PATCH mptcp-next v11 0/4] prepare interfaces for kTLS and sockmap support Geliang Tang
2026-12-03 14:32 ` [PATCH mptcp-next v11 1/4] mptcp: track app-limited state in mptcp_sendmsg Geliang Tang
2026-12-03 14:59 ` sashiko-bot [this message]
2026-12-05 3:36 ` netdev-bot+sashiko
2026-12-03 14:32 ` [PATCH mptcp-next v11 2/4] selftests: mptcp: sockopt: check app_limited Geliang Tang
2026-12-03 14:32 ` [PATCH mptcp-next v11 3/4] mptcp: add sendmsg_locked to proto_ops Geliang Tang
2026-12-05 3:36 ` netdev-bot+sashiko
2026-12-03 14:32 ` [PATCH mptcp-next v11 4/4] mptcp: update mptcp_check_readable Geliang Tang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-248044@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=geliang@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox