From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796311757; b=BI3gUkwpA0aWh8vHMDWkAvD00HXa1m7jWercj5pNW0Pck/N8rnf6cPqPwHu7Vynlu7Pn x9YIprGJySPKmAOter953zorIi0STz5vWZnQzPmCWhlyr4JWlerNt/lBlnONxyBXOMU0g W6hQrcKrwAkIrFiOSFWPCxPefraxFfpPFZzhaocB+C+hnDJQ36ALEj1GKqoIbnrWhtUs+ iucY/jRrmzt40o5IcwDpn4Y85W9F7kc8iwEj87xMidzdi9tkYQYUP/JsB6oEyvrnh0xAH Oow1n+hm2S3PHJ8dMaGAeLRGCmjPrVqstT3A0N7AHzO2g52oMlXq+fQmZQFDFgfU+LQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796311757; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=NKr94JK9ayHAty5cEiZE5b+70F00+hTeJ0re2Jbb7Gc=; b=KrjTJ09sfjameZ9GybWZphj7maOWKL8qocOYgv1ecWdYLQdDdXOXc74AMPl7n6jhFjO/ iTyFeTrwUlFAjXSE9AfJgX6q0Al+QE80ndTNVNBK/uvOf9IhgpKIb7Z4l6dZUdTF3vrvr zoEu+Z+ep/cBVEsD9txF+umteR+wKU+vEV3jpHGNjznelXC6N0KyUVdSvbwUFUELxiDeo GiYU1KqpMauiN2gSEApmZwKUP91z6bw9D6d32wRchkGVUViI035NmIqf4ksHQ3Tw7J2uJ Blrqcm57Lygvb4wrdQqmbnHQ0fuvwkPv5LlQMYtY1lF/r37gOZvmW8HhZ4/IT4vCxlw== 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=b+l0pgjs; 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 95337606A322 for ; Thu, 3 Dec 2026 15:29:17 +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=b+l0pgjs Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C6491F000C1; Thu, 3 Dec 2026 15:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796311757; bh=NKr94JK9ayHAty5cEiZE5b+70F00+hTeJ0re2Jbb7Gc=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=b+l0pgjs9AhpCIHgB75zB6MT7W6DqQoEmrpjNoFiv9K/+NcEqy+EozCXUA1szisqw SpNjMucMg9f0+qNwzMJUBo2xlIPEhLs26jlH8Q7rBz3OGvPsIfv+2DyjSJWQACMYlv 2gEvH810vDBhxlpRWXPFAm8mcm/yYAncmG3oDQXF/atj2zSOiEqnRuGFnoZHhJe/Hz AQ3Hbtl95tZR8B5zk9vo3/bp5bO0yil8zjrEmSnxNRO5ILFNqjrRQfCF8NTKQtBiV9 UfdEBWXm3k93Ab1g9XhRSX1IRf1omX6wMDGCl2v0nJ01RoR50N1b5xCoB4VFLH3Qs6 NbhB2tunbquNg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH mptcp-next 1/2] mptcp: support a connection-wide SO_MAX_PACING_RATE Reply-To: sashiko-reviews@lists.linux.dev To: "Ruilin Mao" , mptcp@lists.linux.dev In-Reply-To: <179630953225.20.6842896706912408920.mptcp-578-0001@gmail.com> References: <179630953225.20.4977913523988952504.mptcp-578-0000@gmail.com> <179630953225.20.6842896706912408920.mptcp-578-0001@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 15:29:16 +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: tcp_pacing_delay() ignores mptcp_pacing_deadline() causing early probe0 - [Medium] mptcp: shared pacing_next_ns deadline causes O(K) subflow hrtimer thundering herd - [Medium] mptcp: uncapped subflow pacing rate breaks TSO autosize and probe0 pacing - [Medium] mptcp: hot-path pacing_lock with redundant division and false sharing - [Medium] mptcp: mptcp_disconnect() does not synchronously cancel first pacing_timer - [Low] mptcp: stale tcp_clock_cache used in pacing on PMTU retransmit -- commit bc7e0a2fc4a3882e9bcb10532b68035acd7262f9 Author: Ruilin Mao mptcp: support a connection-wide SO_MAX_PACING_RATE This commit adds connection-wide SO_MAX_PACING_RATE support for MPTCP by charging transmitted subflow payload bytes to a shared departure clock and gating subflow transmission on it in tcp_pacing_check(). Link: https://github.com/multipath-tcp/mptcp_net-next/issues/578 [ ... ] > diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c > index e9313f39c7b81..57c7aeaec3af5 100644 > --- a/net/ipv4/tcp_output.c > +++ b/net/ipv4/tcp_output.c [ ... ] > @@ -2885,16 +2887,18 @@ static int tcp_mtu_probe(struct sock *sk) > static bool tcp_pacing_check(struct sock *sk) > { > struct tcp_sock *tp =3D tcp_sk(sk); > + u64 deadline =3D tcp_needs_internal_pacing(sk) ? tp->tcp_wstamp_ns : 0; > =20 > - if (!tcp_needs_internal_pacing(sk)) > - return false; > + /* fq can pace a TCP flow but cannot see the other subflows. */ > + if (mptcp_needs_pacing(sk)) > + deadline =3D max(deadline, mptcp_pacing_deadline(sk)); > =20 > - if (tp->tcp_wstamp_ns <=3D tp->tcp_clock_cache) > + if (deadline <=3D tp->tcp_clock_cache) > return false; > =20 > if (!hrtimer_is_queued(&tp->pacing_timer)) { > hrtimer_start(&tp->pacing_timer, > - ns_to_ktime(tp->tcp_wstamp_ns), > + ns_to_ktime(deadline), > HRTIMER_MODE_ABS_PINNED_SOFT); > sock_hold(sk); > } [Severity: Medium] Should tcp_pacing_delay() also take mptcp_pacing_deadline() into account? When packets_out drops to zero while sk_write_queue is non-empty, __tcp_push_pending_frames() sees tcp_write_xmit() stop on tcp_pacing_check() and calls tcp_check_probe_timer() -> tcp_reset_xmit_timer(..., true). Because tcp_pacing_delay() only inspects tp->tcp_wstamp_ns, it returns 0 and arms ICSK_TIME_PROBE0 for about 200 ms. If the MPTCP pacing gap is longer than that, tcp_send_probe0() -> tcp_write_wakeup() sends a full MSS directly via tcp_transmit_skb() without checking tcp_pacing_check(), bypassing SO_MAX_PACING_RATE and pushing msk->pacing_next_ns even further ahead. Other tcp_reset_xmit_timer(..., true) callers such as tcp_schedule_loss_probe() and tcp_rearm_rto() also underestimate the pacing delay. > diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c > index b9c6e5a615c8b..1ffab3ece0002 100644 > --- a/net/mptcp/protocol.c > +++ b/net/mptcp/protocol.c > @@ -1684,6 +1684,42 @@ bool mptcp_subflow_active(struct mptcp_subflow_con= text *subflow) > #define SSK_MODE_BACKUP 1 > #define SSK_MODE_MAX 2 > =20 > +u64 mptcp_pacing_deadline(const struct sock *ssk) > +{ > + const struct sock *sk =3D mptcp_subflow_ctx(ssk)->conn; > + > + return sk ? atomic64_read(&mptcp_sk(sk)->pacing_next_ns) : 0; > +} [Severity: Medium] Does returning the same un-staggered msk->pacing_next_ns to every subflow create an hrtimer thundering herd? During bulk transfer, mptcp_subflow_get_send() spreads unsent data across all active subflows, so all K subflows arm their pacing_timer for the exact same deadline. On one CPU, K - 1 subflows wake via tcp_pace_kick() -> tcp_write_xmit(), send nothing, and re-arm on every pacing interval; across CPUs, multiple subflows can pass tcp_pacing_check() together, burst simultaneously, and contend on msk->pacing_lock. > +void mptcp_pacing_account(const struct sock *ssk, unsigned int len) > +{ > + struct sock *sk =3D mptcp_subflow_ctx(ssk)->conn; > + s64 now, next, interval, credit; > + struct mptcp_sock *msk; > + unsigned long rate; > + > + if (!sk || !len) > + return; > + > + msk =3D mptcp_sk(sk); > + spin_lock_bh(&msk->pacing_lock); > + rate =3D READ_ONCE(sk->sk_max_pacing_rate); > + if (rate && rate !=3D ~0UL) { > + /* Keep enough credit for one timer tick. Without GSO a tick can > + * cover several packets, all of which should be sent on wakeup. > + * Limit idle credit to one MPTCP burst on fast connections. > + */ > + now =3D tcp_sk(ssk)->tcp_clock_cache; > + interval =3D div64_ul((u64)len * NSEC_PER_SEC, rate); > + credit =3D min_t(s64, hrtimer_resolution, > + div64_ul((u64)MPTCP_SEND_BURST_SIZE * NSEC_PER_SEC, rate)); > + credit =3D max(credit, interval / 2); > + next =3D max_t(s64, atomic64_read(&msk->pacing_next_ns), now - credit); > + atomic64_set(&msk->pacing_next_ns, next + interval); > + } > + spin_unlock_bh(&msk->pacing_lock); > +} [Severity: Medium] Can mptcp_pacing_account() avoid the per-packet spin_lock_bh and the redundant 64-bit division inside it? tcp_update_skb_after_send() calls this on every transmitted skb, so holding a connection-wide pacing_lock across two div64_ul() calls adds contention and hold time on the TX hot path. The second division for MPTCP_SEND_BURST_SIZE depends only on rate, and on CONFIG_HIGH_RES_TIMERS kernels hrtimer_resolution is 1 ns, so min_t() clamps it to 1 ns before max(credit, interval / 2) discards it anyway. In struct mptcp_sock, placing pacing_next_ns and pacing_lock directly between hot RX/ACK fields (bytes_received, ack_seq, rcv_wnd_sent) and bytes_retrans/bytes_consumed also introduces cacheline false sharing on every transmitted packet. [Severity: Low] Can tcp_clock_cache be stale here on the PMTU reduction retransmit path? tcp_v4_mtu_reduced() and tcp_v6_mtu_reduced() reach tcp_xmit_retransmit_queue() via tcp_simple_retransmit() without calling tcp_mstamp_refresh(). Because this patch compares the cross-subflow pacing_next_ns against tp->tcp_clock_cache in tcp_pacing_check() and charges relative to it here, a quiet subflow with an old clock cache can either arm pacing_timer for an already-expired deadline or charge the retransmit against a past timestamp so it goes uncharged at current time. Refreshing tp->tcp_clock_cache in tcp_simple_retransmit() would avoid this. [ ... ] > @@ -3920,6 +3958,7 @@ static int mptcp_disconnect(struct sock *sk, int fl= ags) > WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk))); > mptcp_pm_data_reset(msk); > mptcp_ca_reset(sk); > + atomic64_set(&msk->pacing_next_ns, 0); > msk->bytes_consumed =3D 0; > msk->bytes_acked =3D 0; > msk->bytes_received =3D 0; [Severity: Medium] Can mptcp_disconnect() leave a stale future pacing_timer queued on msk->first? tcp_clear_xmit_timers(), called from tcp_disconnect(), only calls hrtimer_try_to_cancel(&tp->pacing_timer) once and ignores a -1 return when tcp_pace_kick() is still exiting after re-arming the timer: CPU0 CPU1 mptcp_disconnect() mptcp_do_fastclose() release_sock(ssk) __run_hrtimer() base->running =3D timer tcp_pace_kick() -> tcp_tsq_handler() bh_lock_sock(ssk) tcp_write_xmit() -> tcp_pacing_check() hrtimer_start(timer, T1) bh_unlock_sock(ssk) mptcp_destroy_common() ... -> tcp_disconnect(ssk, 0) tcp_clear_xmit_timers(ssk) hrtimer_try_to_cancel() <-- returns -1; timer stays queued for T1 atomic64_set(pacing_next_ns, 0) base->running =3D NULL After reconnecting the socket (reusing msk->first), new sends compute an earlier deadline T2 < T1, but tcp_pacing_check() sees hrtimer_is_queued() is true and skips re-arming, stalling transmission on msk->first until T1 expires. Calling hrtimer_cancel() (and __sock_put(ssk) if it returns 1) after tcp_disconnect() would close this race. [ ... ] > diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c > index 922f6ae5c80cb..4b14fe539ec9b 100644 > --- a/net/mptcp/sockopt.c > +++ b/net/mptcp/sockopt.c > @@ -306,6 +306,49 @@ static int mptcp_setsockopt_sol_socket_linger(struct= mptcp_sock *msk, sockptr_t > return 0; > } > =20 > +static int mptcp_setsockopt_pacing_rate(struct mptcp_sock *msk, sockptr_= t optval, > + unsigned int optlen) > +{ > + struct mptcp_subflow_context *subflow; > + struct sock *sk =3D (struct sock *)msk; > + unsigned long old, rate; > + bool relaxed; > + int ret; > + > + lock_sock(sk); > + old =3D READ_ONCE(sk->sk_max_pacing_rate); > + ret =3D sk_setsockopt(sk, SOL_SOCKET, SO_MAX_PACING_RATE, optval, optle= n); > + if (ret) > + goto out; > + > + rate =3D READ_ONCE(sk->sk_max_pacing_rate); > + if (rate =3D=3D old) > + goto out; > + > + relaxed =3D old && old !=3D ~0UL && (!rate || rate > old); > + if (relaxed) { > + /* Account sends using the previous rate before clearing its debt. */ > + spin_lock_bh(&msk->pacing_lock); > + atomic64_set(&msk->pacing_next_ns, 0); > + spin_unlock_bh(&msk->pacing_lock); > + } > + mptcp_for_each_subflow(msk, subflow) { > + struct sock *ssk =3D mptcp_subflow_tcp_sock(subflow); > + struct hrtimer *timer =3D &tcp_sk(ssk)->pacing_timer; > + > + /* The timer callback takes the subflow's BH lock. */ > + lock_sock_nested(ssk, SINGLE_DEPTH_NESTING); > + tcp_sk(ssk)->mptcp_pacing =3D mptcp_pacing_enabled(sk); > + /* Re-evaluate the deadline, retaining the queued timer's ref. */ > + if (relaxed && hrtimer_cancel(timer)) > + hrtimer_start(timer, 0, HRTIMER_MODE_ABS_PINNED_SOFT); > + release_sock(ssk); > + } > +out: > + release_sock(sk); > + return ret; > +} [Severity: Medium] Does leaving ssk->sk_max_pacing_rate at ~0UL and ssk->sk_pacing_status at SK_PACING_NONE break subflow TSO autosizing and pacing-dependent checks? Because tcp_update_pacing_rate() caps sk_pacing_rate against sk_max_pacing_rate, each subflow computes an uncapped sk_pacing_rate and tcp_tso_autosize() can emit up to ~64 KB GSO bursts even at a low SO_MAX_PACING_RATE cap. Charging such a burst in mptcp_pacing_account() then stalls all subflows for hundreds of milliseconds or seconds. When a burst-induced stall exceeds msk->timer_ival (200 ms), mptcp_retransmit_timer() reinjects duplicate dfrags onto idle subflows, and ICSK_TIME_PROBE0 fires early via tcp_write_wakeup() without checking tcp_pacing_check(). Uncapped subflow pacing state also leaves tcp_small_queue_check() uncapped, causes CUBIC hystart_update() to treat paced subflows as unpaced, and leaves TCP_INFO reporting tcpi_max_pacing_rate as ~0ULL on the first subflow and after active fallback. Since no single subflow can legitimately exceed the connection-wide cap, propagating the upper bound to subflow sk_max_pacing_rate and sk_pacing_status would keep TSO sizing, TSQ, congestion control, and TCP_INFO consistent with plain TCP. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179630953225.20.497= 7913523988952504.mptcp-578-0000@gmail.com?part=3D1