All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ruilin Mao" <zibuyu423@gmail.com>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next 1/2] mptcp: support a connection-wide SO_MAX_PACING_RATE
Date: Thu, 03 Dec 2026 15:29:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-248110@kernel.org> (raw)
In-Reply-To: <179630953225.20.6842896706912408920.mptcp-578-0001@gmail.com>

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 <zibuyu423@gmail.com>

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 = tcp_sk(sk);
> +	u64 deadline = tcp_needs_internal_pacing(sk) ? tp->tcp_wstamp_ns : 0;
>  
> -	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 = max(deadline, mptcp_pacing_deadline(sk));
>  
> -	if (tp->tcp_wstamp_ns <= tp->tcp_clock_cache)
> +	if (deadline <= tp->tcp_clock_cache)
>  		return false;
>  
>  	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_context *subflow)
>  #define SSK_MODE_BACKUP	1
>  #define SSK_MODE_MAX	2
>  
> +u64 mptcp_pacing_deadline(const struct sock *ssk)
> +{
> +	const struct sock *sk = 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 = mptcp_subflow_ctx(ssk)->conn;
> +	s64 now, next, interval, credit;
> +	struct mptcp_sock *msk;
> +	unsigned long rate;
> +
> +	if (!sk || !len)
> +		return;
> +
> +	msk = mptcp_sk(sk);
> +	spin_lock_bh(&msk->pacing_lock);
> +	rate = READ_ONCE(sk->sk_max_pacing_rate);
> +	if (rate && rate != ~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 = tcp_sk(ssk)->tcp_clock_cache;
> +		interval = div64_ul((u64)len * NSEC_PER_SEC, rate);
> +		credit = min_t(s64, hrtimer_resolution,
> +			       div64_ul((u64)MPTCP_SEND_BURST_SIZE * NSEC_PER_SEC, rate));
> +		credit = max(credit, interval / 2);
> +		next = 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 flags)
>  	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 = 0;
>  	msk->bytes_acked = 0;
>  	msk->bytes_received = 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 = 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 = 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;
>  }
>  
> +static int mptcp_setsockopt_pacing_rate(struct mptcp_sock *msk, sockptr_t optval,
> +					unsigned int optlen)
> +{
> +	struct mptcp_subflow_context *subflow;
> +	struct sock *sk = (struct sock *)msk;
> +	unsigned long old, rate;
> +	bool relaxed;
> +	int ret;
> +
> +	lock_sock(sk);
> +	old = READ_ONCE(sk->sk_max_pacing_rate);
> +	ret = sk_setsockopt(sk, SOL_SOCKET, SO_MAX_PACING_RATE, optval, optlen);
> +	if (ret)
> +		goto out;
> +
> +	rate = READ_ONCE(sk->sk_max_pacing_rate);
> +	if (rate == old)
> +		goto out;
> +
> +	relaxed = old && old != ~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 = mptcp_subflow_tcp_sock(subflow);
> +		struct hrtimer *timer = &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 = 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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179630953225.20.4977913523988952504.mptcp-578-0000@gmail.com?part=1

  reply	other threads:[~2026-12-03 15:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 14:53 [PATCH mptcp-next 0/2] mptcp: pace subflows against a connection-wide rate limit Ruilin Mao
2026-12-03 14:53 ` [PATCH mptcp-next 1/2] mptcp: support a connection-wide SO_MAX_PACING_RATE Ruilin Mao
2026-12-03 15:29   ` sashiko-bot [this message]
2026-12-05  5:06   ` netdev-bot+sashiko
2026-12-03 14:53 ` [PATCH mptcp-next 2/2] selftests: mptcp: check the aggregate pacing rate across two paths Ruilin Mao
2026-12-03 15:09   ` sashiko-bot
2026-12-05  5:06   ` netdev-bot+sashiko

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-248110@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zibuyu423@gmail.com \
    /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.