All of lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: geliang@kernel.org
Cc: mptcp@lists.linux.dev, kuba@kernel.org
Subject: Re: [PATCH mptcp-next v11 1/4] mptcp: track app-limited state in mptcp_sendmsg
Date: Sat, 05 Dec 2026 03:36:26 +0000	[thread overview]
Message-ID: <179644178695.3143.11606891340428189075@kernel.org> (raw)
In-Reply-To: <4fc318fc6b3764ff8ff0547f7a9d69ff707fa3b1.1796308130.git.geliang@kernel.org>

Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 4

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] In __subflow_push_pending(), subflows can be marked app-
  limited again during a single bulk send, even though unsent dfrags are…
- [Medium] mptcp: unconditional mptcp_data_lock() in
  mptcp_rate_check_app_limited()
- [Low] In mptcp_sendmsg(), the app-limited result computed at entry can
  be cleared before any subflow uses it.
- [Low] The commit message explains how the code works but not why the
  change is needed.
- [Low] The commit author and the Signed-off-by do not match.
- [Low] mptcp: placing app_limited before notsent_lowat grows struct
  mptcp_sock

--

mptcp: track app-limited state in mptcp_sendmsg

This commit adds mptcp_rate_check_app_limited(). It is called once at
mptcp_sendmsg() entry, checks MPTCP-level conditions and stores the result
in msk->app_limited. When that flag is set, __subflow_push_pending() calls
tcp_rate_check_app_limited() on the scheduled subflow. The flag is cleared
on the wait_for_memory path and on sendmsg exit.

> mptcp: track app-limited state in mptcp_sendmsg
>
> Add mptcp_rate_check_app_limited() that evaluates MPTCP-level conditions
> (write_seq == snd_nxt, no pending dfrags, no pending retransmission)
> and stores the result in msk->app_limited. Called from mptcp_sendmsg()
> before the data copy loop. In __subflow_push_pending(), if
> msk->app_limited is set, call tcp_rate_check_app_limited() on the
> scheduled subflow. The flag is cleared in the wait_for_memory path and
> on sendmsg exit, so it is evaluated once per sendmsg and later pushes
> do not re-mark subflows while unsent dfrags are still queued, which
> would let BBR treat non-app-limited samples as application-limited.

[Severity: Low]
This isn't a bug, but the message explains how the code works and not why
the change is needed. Could it include a problem statement?

Before this patch, nothing in net/mptcp/ called
tcp_rate_check_app_limited(). The only callers were tcp_sendmsg_locked()
and espintcp.

The real premise seems to be that MPTCP subflows never go through
tcp_sendmsg_locked(), so tp->app_limited on a subflow is never re-armed
after tcp_init_sock(). This commit doesn't say so. Only the follow-up
selftest commit hints at it.

The new writes to tcp_sk(ssk)->app_limited feed the generic rate sampling
code (tcp_rate_skb_sent() and tcp_rate_gen()). That affects every
congestion control module that uses rate samples, not only BBR. It also
changes the delivery rate fields seen through TCP_INFO and MPTCP_TCPINFO.

Would it be possible to add the observed symptom and some before/after
results, for example with BBR and the default CUBIC?

>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>

[Severity: Low]
This isn't a bug, but the author is Geliang Tang <geliang@kernel.org>,
while the only Signed-off-by uses <tanggeliang@kylinos.cn>. checkpatch
reports this as FROM_SIGN_OFF_MISMATCH.

Could the From: line or the trailer be changed to match? The later commits
"selftests: mptcp: sockopt: check app_limited" and "mptcp: add
sendmsg_locked to proto_ops" have the same mismatch.

> 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);
> +

[Severity: Medium]
Can this mark a subflow app-limited again in the middle of a bulk send,
while unsent dfrags are still queued?

msk->app_limited stays set until the out: label in mptcp_sendmsg(). That
label runs only after the final __mptcp_push_pending() has returned.
Inside that push, the loop keeps going while data is pending, and every
round calls __subflow_push_pending() again:

net/mptcp/protocol.c:__mptcp_push_pending() {
	while (mptcp_send_head(sk) && (push_count > 0)) {
		...
		if (mptcp_sched_get_send(msk))
			break;
		...
				ret = __subflow_push_pending(sk, ssk, &info);
	...
}

Each __subflow_push_pending() call stops after msk->snd_burst bytes. So a
large sendmsg on a connection with several subflows takes several rounds,
and the scheduler can switch subflows between rounds.

On a switch, mptcp_push_release() calls tcp_push() and release_sock() on
the previous ssk. That subflow can then send all its data and process
ACKs. sk_wmem_alloc can also drop quickly, for example with skb_orphan on
loopback or veth.

If the scheduler picks that subflow again in a later round, all the
per-subflow checks in tcp_rate_check_app_limited() can pass, and
tp->app_limited gets set again. At that point mptcp_send_head(sk) is
non-NULL, so the msk-level check in mptcp_rate_check_app_limited() would
reject this state.

This seems to contradict the commit message:

  "later pushes do not re-mark subflows while unsent dfrags are still
  queued"

Plain TCP marks only once, at tcp_sendmsg_locked() entry, and never inside
its push loop.

When this happens, samples from data that was not app-limited get tagged
is_app_limited. BBR then ignores them unless bw >= max_bw, skips
full-bandwidth detection on them, and resets long-term sampling.
tcpi_delivery_rate_app_limited reported to userspace is also wrong.

The later commits in this series don't change this logic. They only
rename mptcp_sendmsg to mptcp_sendmsg_locked.

[ ... ]

> @@ -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: Low]
Is the app-limited result from mptcp_sendmsg() entry lost here, if the
first loop iteration jumps to wait_for_memory before any dfrag is queued?

mptcp_rate_check_app_limited() sets msk->app_limited only when
mptcp_send_head(sk) is NULL. The first iteration can then reach
wait_for_memory through this check in mptcp_sendmsg():

		copy_limit = mptcp_send_limit(sk);
		if (!copy_limit)
			goto wait_for_memory;

That happens when sk_wmem_queued >= sk_sndbuf because unacked data is
still charged to the msk. It also happens when mptcp_page_frag_refill() or
sk_wmem_schedule() fails.

In that case __mptcp_push_pending() does nothing, because its loop needs a
send head. No subflow gets marked, and then the flag is cleared here.
Nothing evaluates it again after sk_stream_wait_memory(), so data copied
after the wait is pushed with the flag clear.

Plain TCP doesn't have this gap, because tcp_rate_check_app_limited()
writes tp->app_limited directly at sendmsg entry, before any wait. Later
commits in the series don't change this.

[ ... ]

> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> --- 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]
Does this grow struct mptcp_sock by 8 bytes on 64-bit kernels?

After unsigned long cb_flags come 9 bools, pending_state,
mpc_endpoint_id and the existing u8 bitfield. Together they fill
exactly 12 bytes. Today notsent_lowat therefore sits 4-byte aligned
with no padding, and the four ints after it end on an 8-byte boundary
right before struct work_struct work.

That bitfield already uses all 8 bits, so app_limited:1 starts a new
byte at offset 12. This adds 3 bytes of padding before notsent_lowat.
It then adds 4 more bytes after maxseg, before work.

The growth also carries into struct mptcp6_sock, which embeds struct
mptcp_sock by value. On 32-bit the struct still grows by 4 bytes. The
rest of the series doesn't touch net/mptcp/protocol.h, so this stays.

There is already a 2-byte hole after scaling_ratio and allow_subflows,
right before subflow_id. Could app_limited go there instead? Running
pahole on struct mptcp_sock before and after should confirm that the
size doesn't change.

[ ... ]

> @@ -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]
Does every mptcp_sendmsg() call now need to take the msk data lock?

mptcp_data_lock() is spin_lock_bh() on sk->sk_lock.slock. Before this
patch, the sendmsg path only touched that spinlock inside lock_sock()
and release_sock(). Now every call adds a third acquisition, only to
read MPTCP_RETRANSMIT from msk->cb_flags.

The subflow RX and ACK softirq paths take the same spinlock, for
example mptcp_update_data_ack(), mptcp_data_ready() and
mptcp_retransmit_timer(). A busy sender now contends more often with
incoming ACK processing. The local_bh_enable() in the unlock can also
run pending softirqs before any data has been copied.

The lock is taken even when the cheaper checks already decide the
result. On a bulk sender, msk->write_seq != msk->snd_nxt or a non-NULL
mptcp_send_head(sk) is the common case. Both are protected by the msk
socket lock that sendmsg already holds.

The lock also doesn't give a stable answer. mptcp_retransmit_timer()
can set MPTCP_RETRANSMIT right after mptcp_data_unlock(), and the bit
is only acted on in mptcp_release_cb() at release_sock() time anyway.

Could the write_seq, send head and MPTCP_WORK_RTX checks run first, so
the cb_flags test is reached only when all of them pass? And given the
race above, is the data lock needed for that read at all, or would an
annotated lockless read be enough?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1796308130.git.geliang%40kernel.org

  parent reply	other threads:[~2026-12-05  3:36 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
2026-12-05  3:36   ` netdev-bot+sashiko [this message]
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=179644178695.3143.11606891340428189075@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=geliang@kernel.org \
    --cc=kuba@kernel.org \
    --cc=mptcp@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.