Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796309999; b=s/MpNsSUCjKNnq3Dsyf+J3z5ZPaujKNzSoWBoaDYyLITxl8K0QR6PjERZ+dmq3UMENYE 4UTSI8bDo+M7r2t9Axa+EldOYIJD7rhuTvQ7KNoxtKc9/r81UT2uO1mu7075ulKUVUjsD 65v/SGPv9AxHrnaVx5N/tM9akuqr5QgSXZf+CRfHw61xS2fH83nC4DYkxcXuutJlg7c3R 2C4wezfRzqgB1inMIgQb3h4b2JlB/ep1mZLJdf22kPEtoCzgRhxmHe7ArNF+xKK0GRu2O 4H2yiwHNSm5B3OzUbDYaIerJCD1VBa4RdGYflcAbSwV0QXgVf7Pj2zxrIlzg0hKTSMQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309999; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=uEG/hBPH06A1BuTwcCtoq0d5IIyIBc+iVLGkJlYsGc4=; b=YkAk5y7IhjQOFEH1EdUoedbVkw5/pm3SwYp7NQUTcaIKSaRtQA6Rd9lclDKtFIpnr4yB 4JV7TGKdlli0XjIrnYy57z7scyWN4oFmZyvb6maWQd1Ct4BXNvte82FE3qpQKSEbFFiEz OeeyKG7sBSOMLrqocHh676Ub2OLCi0CSFubfTzOD6N47zkRUVAo8TY4F1rXOJ57LhquK2 LwLp4GyHgV0XHvUbXrFCmEiFMhdx4kqHUIl/wcg3yi3pJWR+4TlmkAW2tMn+a+OAqslSS ByOoV+KJITIf+CVNhaXENx5tGwL1IDj+hm9nF76fE5f9POgMGDFBlHwn0H97SLtSI3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NRzrrlMK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63F8E60A383D for ; Thu, 3 Dec 2026 14:59:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NRzrrlMK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1989C1F0089F; Thu, 3 Dec 2026 14:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796309999; bh=uEG/hBPH06A1BuTwcCtoq0d5IIyIBc+iVLGkJlYsGc4=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=NRzrrlMKx+rHLcy67sl1qSUI9m/qIAfnEj8lCjN79Z9vNxfi7Het/VOi/tJBdmKyB pqoQ9T7OIPERav5ZofjuaOMwANk/RFq0m6eBYo7lJ1EvRI7Qr+5WypNTQT+ooT1Y87 Qf5ERRReQ9JiD8zwOIJf1nH6ti+c5CDlMYDy0TzOJxOT08ZGxyZTDa7ZyYLkCxu8Fy 8Zl64jxNq6X3qdV+uctXgsRinNHj9fyFzKpp4OoNnBLUS0dOmZQ+Wk+1695u7XRThY Wz1NOsefyRaSUwqgiAkU9efAW17v/ZUPrbsJq0ks82K+b+AMNYq7abrOQuxu2SQkZE q2WcDkqKe1Gvg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH mptcp-next v11 1/4] mptcp: track app-limited state in mptcp_sendmsg Reply-To: sashiko-reviews@lists.linux.dev To: "Geliang Tang" , mptcp@lists.linux.dev In-Reply-To: <4fc318fc6b3764ff8ff0547f7a9d69ff707fa3b1.1796308130.git.geliang@kernel.org> References: <4fc318fc6b3764ff8ff0547f7a9d69ff707fa3b1.1796308130.git.geliang@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 14:59:58 +0000 X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D 0, err =3D 0; > =20 > + if (msk->app_limited) > + tcp_rate_check_app_limited(ssk); > + > while ((dfrag =3D mptcp_send_head(sk))) { > info->sent =3D dfrag->already_sent; > info->limit =3D 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) > } > } > =20 > +static void mptcp_rate_check_app_limited(struct sock *sk) > +{ > + struct mptcp_sock *msk =3D mptcp_sk(sk); > + unsigned long flags; > + bool retransmit; > + > + flags =3D READ_ONCE(msk->flags); > + mptcp_data_lock(sk); > + retransmit =3D test_bit(MPTCP_RETRANSMIT, &msk->cb_flags); > + mptcp_data_unlock(sk); > + > + msk->app_limited =3D msk->write_seq =3D=3D 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 =3D 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 =3D=3D 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 ms= ghdr *msg, size_t len) > =20 > timeo =3D sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); > =20 > + /* is sending application-limited? */ > + mptcp_rate_check_app_limited(sk); > + > if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) { > ret =3D 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 =3D 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 =3D 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 =3D 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 ms= ghdr *msg, size_t len) > wait_for_memory: > sk_set_nospace(sk); > __mptcp_push_pending(sk, msg->msg_flags); > + msk->app_limited =3D 0; > ret =3D 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 >=3D 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) =3D=3D NULL. __mptcp_push_pending() then returns immediately without calling __subflow_push_pending() or tcp_rate_check_app_limited(ssk), and clearing msk->app_limited =3D 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 ms= ghdr *msg, size_t len) > } > =20 > out: > + msk->app_limited =3D 0; > release_sock(sk); > return copied; > =20 [Severity: Low] Can mptcp_sendmsg() on a TCP_LISTEN socket race with mptcp_sk_clone_init() when writing msk->app_limited? CPU0 mptcp_sendmsg() on TCP_LISTEN lock_sock(sk) mptcp_rate_check_app_limited() msk->app_limited =3D 1 sk_stream_wait_connect() -> -EPIPE subflow_syn_recv_sock() out: mptcp_sk_clone_init() msk->app_limited =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796308130.gi= t.geliang@kernel.org?part=3D1