MPTCP Linux Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v10 1/4] mptcp: track app-limited state in mptcp_sendmsg
Date: Thu, 03 Dec 2026 07:22:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-247284@kernel.org> (raw)
In-Reply-To: <3311ba5fb214546589dbeddb9051eee19201c63d.1796281059.git.tanggeliang@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] mptcp: stale msk->app_limited persists past mptcp_sendmsg()
  into later pushes
- [Medium] mptcp: clearing msk->app_limited on first subflow skips other
  subflows
- [Low] mptcp: unlocked read of msk->cb_flags in
  mptcp_rate_check_app_limited()
- [Low] mptcp: overflowing u8 bitfield with app_limited grows struct
  mptcp_sock
--

commit e31ed458b18e6de3bbc4393082fedf86b119c7a2
Author: Geliang Tang <geliang@kernel.org>

mptcp: track app-limited state in mptcp_sendmsg

This commit adds mptcp_rate_check_app_limited() to latch MPTCP-level
application-limited state in msk->app_limited at the start of
mptcp_sendmsg(), and consumes it in __subflow_push_pending() by calling
tcp_rate_check_app_limited() on the scheduled subflow.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index b9c6e5a615c8b..7e0bafef6735c 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -1815,6 +1815,11 @@ 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);
> +		msk->app_limited = 0;
> +	}
> +
>  	while ((dfrag = mptcp_send_head(sk))) {
>  		info->sent = dfrag->already_sent;
>  		info->limit = dfrag->data_len;

[Severity: Medium]
Does clearing msk->app_limited here skip tcp_rate_check_app_limited() on
other idle subflows?

When a burst after an idle gap exceeds MPTCP_SEND_BURST_SIZE (or a
scheduler marks multiple subflows in one mptcp_sched_get_send() call),
__mptcp_push_pending() pushes across multiple subflows, but every subflow
after the first sees msk->app_limited == 0.  Because
mptcp_subflow_get_send() compares linger_time with strict less-than, the
first idle subflow on conn_list is always picked first and clears the
flag, leaving secondary subflows running BBR to treat app-limited samples
as non-app-limited.

Clearing msk->app_limited before mptcp_sendmsg_frag() also loses the flag
when the first scheduled subflow fails to enqueue any data, so the next
subflow that actually transmits misses the check.

> @@ -2112,6 +2117,20 @@ 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, cb_flags;
> +
> +	flags = READ_ONCE(msk->flags);
> +	cb_flags = READ_ONCE(msk->cb_flags);
> +
> +	msk->app_limited = msk->write_seq == msk->snd_nxt &&
> +			   !mptcp_send_head(sk) &&
> +			   !test_bit(MPTCP_WORK_RTX, &flags) &&
> +			   !test_bit(MPTCP_RETRANSMIT, &cb_flags);
> +}
> +
>  static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
>  {
>  	struct mptcp_sock *msk = mptcp_sk(sk);

[Severity: Low]
Is reading msk->cb_flags without mptcp_data_lock(sk) a data race?

mptcp_sendmsg() holds lock_sock(sk) without mptcp_data_lock(sk), while
softirq and timer handlers modify msk->cb_flags with non-atomic
__set_bit() under bh_lock_sock(sk) specifically when sock_owned_by_user()
is true:

CPU0                              CPU1 (<softirq>)
mptcp_sendmsg()
  lock_sock(sk)
  mptcp_rate_check_app_limited()
    READ_ONCE(msk->cb_flags)      mptcp_retransmit_timer()
                                    bh_lock_sock(sk)
                                    __set_bit(MPTCP_RETRANSMIT,
                                              &msk->cb_flags) <-- data race

Pairing an unmarked non-atomic __set_bit() with an unlocked READ_ONCE()
violates msk->cb_flags locking and triggers KCSAN under
CONFIG_KCSAN_STRICT=y.

> @@ -2142,6 +2161,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]
Can msk->app_limited remain stale past this mptcp_sendmsg() call and
falsely mark a later push as application-limited?

msk->app_limited is only cleared inside __subflow_push_pending().  Because
__mptcp_sync_sndbuf() sets sk->sk_sndbuf larger than each subflow's
sk_sndbuf, a prior push routinely drains msk->rtx_queue (leaving write_seq
== snd_nxt and !mptcp_send_head(sk)) while filling ssk so
!sk_stream_memory_free(ssk).  On the next back-to-back mptcp_sendmsg(),
mptcp_rate_check_app_limited() sets msk->app_limited = 1, the copy loop
enqueues new dfrags, and __mptcp_push_pending() breaks out when
mptcp_sched_get_send() finds no subflow with free memory.

msk->app_limited then stays 1 while unsent dfrags sit queued.  When an ACK
later drains ssk and triggers ack_update_msk() -> __mptcp_check_push() ->
__subflow_push_pending(), it consumes the stale flag and calls
tcp_rate_check_app_limited(ssk), letting BBR misclassify non-app-limited
samples and degrading bandwidth estimation.

The same stale flag survives across sk_stream_wait_memory() when msk's
send buffer is full, as well as early exits with copied == 0.  Clearing
msk->app_limited before sleeping in wait_for_memory and on exit from
mptcp_sendmsg() would keep it scoped to the current send.

> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index 7cdd0a7e8296b..97c6e3281acc4 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -349,7 +349,8 @@ struct mptcp_sock {
>  			in_accept_queue:1,
>  			free_first:1,
>  			rcvspace_init:1,
> -			fastclosing:1;
> +			fastclosing:1,
> +			app_limited:1;
>  	u32		notsent_lowat;
>  	int		keepalive_cnt;
>  	int		keepalive_idle;

[Severity: Low]
Does adding app_limited:1 as a 9th bit to this u8 bitfield grow struct
mptcp_sock by 8 bytes?

Overflowing the 8-bit group adds 3 bytes of padding before notsent_lowat
and 4 bytes of padding after maxseg before struct work_struct work,
enlarging both struct mptcp_sock and struct mptcp6_sock.  Placing a bool
app_limited in the existing 2-byte hole between allow_subflows and
subflow_id avoids any size increase.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796281059.git.tanggeliang@kylinos.cn?part=1

  reply	other threads:[~2026-12-03  7:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  7:00 [PATCH mptcp-next v10 0/4] prepare interfaces for kTLS and sockmap support Geliang Tang
2026-12-03  7:00 ` [PATCH mptcp-next v10 1/4] mptcp: track app-limited state in mptcp_sendmsg Geliang Tang
2026-12-03  7:22   ` sashiko-bot [this message]
2026-12-03  7:00 ` [PATCH mptcp-next v10 2/4] selftests: mptcp: sockopt: check app_limited Geliang Tang
2026-12-03  7:20   ` sashiko-bot
2026-12-03  7:00 ` [PATCH mptcp-next v10 3/4] mptcp: add sendmsg_locked to proto_ops Geliang Tang
2026-12-03  7:00 ` [PATCH mptcp-next v10 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-247284@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