* [PATCH mptcp-next 0/2] mptcp: pace subflows against a connection-wide rate limit @ 2026-12-03 14:53 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 14:53 ` [PATCH mptcp-next 2/2] selftests: mptcp: check the aggregate pacing rate across two paths Ruilin Mao 0 siblings, 2 replies; 7+ messages in thread From: Ruilin Mao @ 2026-12-03 14:53 UTC (permalink / raw) To: mptcp An application that sets SO_MAX_PACING_RATE on an MPTCP socket needs the limit to apply to all its paths together. This series accounts transmitted payload against a common clock while keeping each TCP subflow's congestion-control pacing in effect. It also adds a two-path regression test to simult_flows.sh. On one two-path connection, caps of 500,000 and 250,000 bytes/s gave 496,841 and 249,269 bytes/s respectively. Removing the cap increased throughput to 903,945 bytes/s. Both paths carried payload. All 11 simult_flows.sh cases passed in x86-64 QEMU with both coarse and high-resolution timers. The affected i386 objects were compile-tested. Codex drafted the patches and ran the tests. https://github.com/multipath-tcp/mptcp_net-next/issues/578 Ruilin Mao (2): mptcp: support a connection-wide SO_MAX_PACING_RATE selftests: mptcp: check the aggregate pacing rate across two paths include/linux/tcp.h | 1 + include/net/mptcp.h | 14 ++++++ net/ipv4/tcp_output.c | 12 +++-- net/mptcp/protocol.c | 40 +++++++++++++++ net/mptcp/protocol.h | 9 ++++ net/mptcp/sockopt.c | 47 ++++++++++++++++- net/mptcp/subflow.c | 9 ++++ .../selftests/net/mptcp/mptcp_connect.c | 18 +++++-- .../selftests/net/mptcp/simult_flows.sh | 50 ++++++++++++++++++- 9 files changed, 190 insertions(+), 10 deletions(-) ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH mptcp-next 1/2] mptcp: support a connection-wide SO_MAX_PACING_RATE 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 ` Ruilin Mao 2026-12-03 15:29 ` sashiko-bot 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 1 sibling, 2 replies; 7+ messages in thread From: Ruilin Mao @ 2026-12-03 14:53 UTC (permalink / raw) To: mptcp Allow an application to cap the aggregate transmit rate of a Multipath TCP connection. Applying the same rate independently to every subflow would let throughput grow with the number of paths and a fixed division would waste bandwidth when a path is idle. Charge successful TCP payload transmissions, including retransmissions, to a common departure clock. A subflow waits until both its congestion control and the shared clock allow it to send. This also works with fq, which otherwise sees each TCP subflow as an independent flow. Allow a bounded amount of credit to account for coarse timer resolution. Keep the normal SOL_SOCKET handling of 32-bit and native-width values. New subflows share their connection's clock, and a child handed off to plain TCP inherits the native TCP limit. Recheck outstanding timers when the application raises or removes a limit. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/578 Signed-off-by: Ruilin Mao <zibuyu423@gmail.com> --- include/linux/tcp.h | 1 + include/net/mptcp.h | 14 +++++++++++++ net/ipv4/tcp_output.c | 12 +++++++---- net/mptcp/protocol.c | 40 ++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 9 +++++++++ net/mptcp/sockopt.c | 47 ++++++++++++++++++++++++++++++++++++++++++- net/mptcp/subflow.c | 9 +++++++++ 7 files changed, 127 insertions(+), 5 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index d4b07fbae2d5..b35cdbe0e1dd 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -515,6 +515,7 @@ struct tcp_sock { u32 plb_rehash; /* PLB-triggered rehash attempts */ #if IS_ENABLED(CONFIG_MPTCP) bool is_mptcp; + bool mptcp_pacing; #endif #if IS_ENABLED(CONFIG_AF_KCM) bool kcm_attached; diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 8943d9f2b48b8ff0af2ec19a322bc29949af3abf..e8cced86b6152101b151f58d80474ade8ffc25d5 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -140,6 +140,11 @@ static inline bool sk_is_mptcp(const struct sock *sk) return tcp_sk(sk)->is_mptcp; } +static inline bool mptcp_needs_pacing(const struct sock *sk) +{ + return tcp_sk(sk)->mptcp_pacing; +} + static inline bool rsk_is_mptcp(const struct request_sock *req) { return tcp_rsk(req)->is_mptcp; @@ -157,6 +162,8 @@ static inline bool msk_is_mptcp(const struct sock *sk) sk->sk_protocol == IPPROTO_MPTCP; } +u64 mptcp_pacing_deadline(const struct sock *ssk); +void mptcp_pacing_account(const struct sock *ssk, unsigned int len); void mptcp_space(const struct sock *ssk, int *space, int *full_space); bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb, unsigned int *size, struct mptcp_out_options *opts); @@ -258,6 +265,11 @@ static inline bool sk_is_mptcp(const struct sock *sk) return false; } +static inline bool mptcp_needs_pacing(const struct sock *sk) +{ + return false; +} + static inline bool rsk_is_mptcp(const struct request_sock *req) { return false; @@ -309,6 +321,8 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to, return true; } +static inline u64 mptcp_pacing_deadline(const struct sock *ssk) { return 0; } +static inline void mptcp_pacing_account(const struct sock *ssk, unsigned int len) { } static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { } static inline void mptcp_seq_show(struct seq_file *seq) { } diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index cf3ddc055d48..99f72fceb16a 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1520,6 +1520,8 @@ static void tcp_update_skb_after_send(struct sock *sk, struct sk_buff *skb, tp->tcp_wstamp_ns += len_ns; } } + if (mptcp_needs_pacing(sk)) + mptcp_pacing_account(sk, skb->len); list_move_tail(&skb->tcp_tsorted_anchor, &tp->tsorted_sent_queue); } @@ -2879,16 +2881,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); } diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index bba84018cb67..62faf4258877 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1576,6 +1576,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; +} + +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); +} + /* implement the mptcp packet scheduler; * returns the subflow that will transmit the next DSS * additionally updates the rtx timeout @@ -3179,6 +3215,8 @@ static void __mptcp_init_sock(struct sock *sk) INIT_WORK(&msk->work, mptcp_worker); msk->out_of_order_queue = RB_ROOT; msk->first_pending = NULL; + spin_lock_init(&msk->pacing_lock); + atomic64_set(&msk->pacing_next_ns, 0); /* msk does not go through tcp_init_sock(); seed RTO bounds. */ icsk->icsk_rto_min = @@ -3637,6 +3675,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; @@ -3761,6 +3800,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, WRITE_ONCE(msk->snd_una, msk->write_seq); WRITE_ONCE(msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd); msk->setsockopt_seq = mptcp_sk(sk)->setsockopt_seq; + tcp_sk(ssk)->mptcp_pacing = mptcp_pacing_enabled(nsk); mptcp_init_sched(msk, mptcp_sk(sk)->sched); /* passive msk is created after the first/MPC subflow */ diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 7d226ee38315..ff78c6a52323 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -307,6 +307,8 @@ struct mptcp_sock { u64 bytes_received; u64 ack_seq; atomic64_t rcv_wnd_sent; + atomic64_t pacing_next_ns; + spinlock_t pacing_lock; /* serializes charging and rate changes */ u64 rcv_data_fin_seq; u64 bytes_retrans; u64 bytes_consumed; @@ -1291,6 +1293,13 @@ static inline bool mptcp_pm_add_addr_c_flag_case(struct mptcp_sock *msk) msk->pm.extra_subflows < mptcp_pm_get_limit_extra_subflows(msk); } +static inline bool mptcp_pacing_enabled(const struct sock *sk) +{ + unsigned long rate = READ_ONCE(sk->sk_max_pacing_rate); + + return rate && rate != ~0UL; +} + void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk); static inline struct mptcp_ext *mptcp_get_ext(const struct sk_buff *skb) diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index fcf6feb2a9eb..96adce1b79eb 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -297,6 +297,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; +} + static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname, sockptr_t optval, unsigned int optlen) { @@ -348,6 +391,8 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname, case SO_TIMESTAMPING_NEW: return mptcp_setsockopt_sol_socket_timestamping(msk, optname, optval, optlen); + case SO_MAX_PACING_RATE: + return mptcp_setsockopt_pacing_rate(msk, optval, optlen); case SO_LINGER: return mptcp_setsockopt_sol_socket_linger(msk, optval, optlen); case SO_RCVLOWAT: @@ -383,7 +428,6 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname, * explicitly the sk_protocol field * * SO_PEEK_OFF is unsupported, as it is for plain TCP - * SO_MAX_PACING_RATE is unsupported, we must be careful with subflows * SO_CNX_ADVICE is currently unsupported, could possibly be relevant, * but likely needs careful design * @@ -1610,6 +1654,7 @@ void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk) msk_owned_by_me(msk); ssk->sk_rcvlowat = 0; + tcp_sk(ssk)->mptcp_pacing = mptcp_pacing_enabled((struct sock *)msk); /* subflows must ignore any latency-related settings: will not affect * the user-space - only the msk is relevant - but will foul the diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 6f07544bfe40..7faba3f22012 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -814,6 +814,7 @@ static void subflow_ulp_fallback(struct sock *sk, icsk->icsk_ulp_ops = NULL; rcu_assign_pointer(icsk->icsk_ulp_data, NULL); tcp_sk(sk)->is_mptcp = 0; + tcp_sk(sk)->mptcp_pacing = false; mptcp_subflow_ops_undo_override(sk); } @@ -1024,6 +1025,14 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, fallback: if (fallback) SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK); + /* This child is handed to plain TCP and will have no parent clock. */ + if (listener->conn) { + unsigned long rate = READ_ONCE(listener->conn->sk_max_pacing_rate); + + if (rate != ~0UL) + sk_setsockopt(child, SOL_SOCKET, SO_MAX_PACING_RATE, + KERNEL_SOCKPTR(&rate), sizeof(rate)); + } mptcp_subflow_drop_ctx(child); return child; } ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH mptcp-next 1/2] mptcp: support a connection-wide SO_MAX_PACING_RATE 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 2026-12-05 5:06 ` netdev-bot+sashiko 1 sibling, 0 replies; 7+ messages in thread From: sashiko-bot @ 2026-12-03 15:29 UTC (permalink / raw) To: Ruilin Mao, mptcp 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH mptcp-next 1/2] mptcp: support a connection-wide SO_MAX_PACING_RATE 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 @ 2026-12-05 5:06 ` netdev-bot+sashiko 1 sibling, 0 replies; 7+ messages in thread From: netdev-bot+sashiko @ 2026-12-05 5:06 UTC (permalink / raw) To: zibuyu423; +Cc: mptcp, kuba Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 3 · 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] The connection-wide cap only gates when the next skb may start (tcp_pacing_check()). - [Medium] Some subflows keep using the shared msk clock after the patch's synchronization stops covering them. - [Medium] mptcp: tcp_pacing_delay() ignores mptcp_pacing_deadline() causing early probe0 - [Low] The patch handles SO_MAX_PACING_RATE == 0 differently depending on whether the connection stays MPTCP or falls back to plain TCP. - [Low] The patch adds `bool mptcp_pacing` to struct tcp_sock (include/linux/tcp.h, next to is_mptcp) but does not update… - [Low] The comment on msk->pacing_lock (net/mptcp/protocol.h:314), 'serializes charging and rate changes', does not match how the lock is… - [Low] The shared departure clock msk->pacing_next_ns has no upper bound. -- mptcp: support a connection-wide SO_MAX_PACING_RATE This patch lets an application cap the aggregate transmit rate of an MPTCP connection. It charges every subflow transmission to a departure clock stored in the msk, and tcp_pacing_check() waits on that shared deadline. A passive child that falls back to plain TCP gets the listener's limit as a native TCP limit. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/578 > diff --git a/include/linux/tcp.h b/include/linux/tcp.h > index 3d6eb6c8681dc..296cca1313c91 100644 > --- a/include/linux/tcp.h > +++ b/include/linux/tcp.h > @@ -516,6 +516,7 @@ struct tcp_sock { > u32 plb_rehash; /* PLB-triggered rehash attempts */ > #if IS_ENABLED(CONFIG_MPTCP) > bool is_mptcp; > + bool mptcp_pacing; > #endif [Severity: Low] The comment at the top of struct tcp_sock asks for Documentation/networking/net_cachelines/tcp_sock.rst to be updated when fields are added. That document lists is_mptcp but has no entry for mptcp_pacing. Should an entry be added? The field is now read on the TX path of every TCP socket, in tcp_update_skb_after_send() and in tcp_pacing_check(). [ ... ] > 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 > @@ -1520,6 +1520,8 @@ static void tcp_update_skb_after_send(struct sock *sk, struct sk_buff *skb, > tp->tcp_wstamp_ns += len_ns; > } > } > + if (mptcp_needs_pacing(sk)) > + mptcp_pacing_account(sk, skb->len); > list_move_tail(&skb->tcp_tsorted_anchor, &tp->tsorted_sent_queue); > } [Severity: Medium] tcp_pacing_check() now holds back the write queue until the shared MPTCP deadline. The timers armed with pace_delay = true still only add tcp_pacing_delay(), which looks at the subflow's own clock (tcp_wstamp_ns - tcp_clock_cache) and never at pacing_next_ns. The subflows keep sk_max_pacing_rate at ~0UL, so tcp_wstamp_ns does not reflect the MPTCP cap, and tcp_pacing_delay() returns 0 even when the shared deadline is far in the future. Consider a subflow whose in-flight data is all ACKed before the shared deadline. The next tcp_write_xmit() call, for instance from tcp_data_snd_check() -> __tcp_push_pending_frames(), stops in tcp_pacing_check(). It returns true with packets_out == 0 and a non-empty write queue. tcp_check_probe_timer() then arms ICSK_TIME_PROBE0 for tcp_probe0_base(), about 200ms, with no pacing delay added. If the MPTCP gap is longer than that, the probe fires first. tcp_send_probe0() -> tcp_write_wakeup() sends up to one MSS straight through tcp_transmit_skb() without consulting tcp_pacing_check(). That segment is still charged by tcp_update_skb_after_send() -> mptcp_pacing_account(), which pushes pacing_next_ns further out. Once it is ACKed, packets_out drops back to 0 and the probe timer is re-armed, so the cycle repeats. Take a cap below roughly one MSS per 200ms per subflow, or a burst that leaves pacing_next_ns more than 200ms ahead. Doesn't each subflow then send an unpaced MSS every probe interval? With several subflows the aggregate can exceed SO_MAX_PACING_RATE, while the shared clock drifts ever further into the future. The other tcp_reset_xmit_timer(..., true) callers, such as tcp_schedule_loss_probe(), tcp_rearm_rto() and tcp_ack_probe(), have the same underestimate. TLP and RTO timers on a paced subflow can therefore also fire before the shared deadline. Should tcp_pacing_delay() also consider mptcp_pacing_deadline() when mptcp_needs_pacing() is set? Or is there a better way to keep these timers behind the shared clock? [Severity: Medium] The shared clock is charged only after the whole skb has gone out. tcp_pacing_check() only decides when the next skb may start. The subflows keep sk_max_pacing_rate at ~0UL. mptcp_setsockopt_pacing_rate() only writes the msk value, and sync_socket_options() does not copy it. So the subflow sk_pacing_rate is never capped, and tcp_tso_autosize() still sizes skbs from it: net/ipv4/tcp_output.c:tcp_tso_autosize() { ... bytes = READ_ONCE(sk->sk_pacing_rate) >> READ_ONCE(sk->sk_pacing_shift); ... } On paths with min_rtt above about 512us, plain TCP with the same cap would build skbs of roughly cap >> sk_pacing_shift bytes. Can an MPTCP subflow instead build skbs up to sk_gso_max_size and send each one at line rate before the shared clock makes it wait? For example, a 100 KB/s cap on a fast WAN path would give 64KB line-rate bursts followed by about 0.6s of silence. Plain TCP would send ~3KB skbs at an even pace. fq does not smooth this out, because the skb EDT comes from the subflow's own tcp_wstamp_ns. The long-run average stays capped, but the bursts differ from SO_MAX_PACING_RATE on plain TCP. Should the commit message mention this, or should the cap also apply to the subflow sk_pacing_rate? [ ... ] > 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) [ ... ] > +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); [Severity: Low] pacing_next_ns has no upper bound. interval is len * NSEC_PER_SEC / rate, where the rate only has to be non-zero and not ~0UL. next + interval is stored without any clamp. Some transmissions charge this clock without going through tcp_pacing_check(): - RTO retransmits from tcp_retransmit_timer() via __tcp_retransmit_skb() - TLP retransmits - MTU probes, because tcp_mtu_probe() runs in tcp_write_xmit() before the pacing check At a rate of 1 B/s, a single 64KB charge adds about 6.5e13 ns. If the debt ever passes 2^63 ns, can next + interval wrap negative? If it does, mptcp_pacing_deadline() returns a huge u64. tcp_pacing_check() then arms the pacing hrtimer with an absolute time that has already expired. The path tcp_pace_kick() -> tcp_tsq_handler() -> tcp_write_xmit() -> tcp_pacing_check() can re-arm that timer from its own callback. Could the soft hrtimer loop spin? Getting there takes a very large number of unchecked charges at a degenerate rate, and plain TCP's tcp_wstamp_ns grows in a similar unbounded way, so this is mostly a hardening question. sch_fq clamps the per-packet delay to NSEC_PER_SEC. Would a similar bound on interval or on the total debt make sense here? > + } > + spin_unlock_bh(&msk->pacing_lock); > +} [ ... ] > @@ -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); [Severity: Medium] What happens to subflows that have left conn_list but are still sending? __mptcp_close_ssk() unlinks a disposable subflow and closes it while icsk_ulp_ops is still set: net/mptcp/protocol.c:__mptcp_close_ssk() { ... if (dispose_it) list_del(&subflow->node); ... __tcp_close(ssk, 0); ... } Nothing clears tcp_sk(ssk)->mptcp_pacing, and ctx->conn points at the msk until subflow_ulp_release(). An orphaned subflow in FIN_WAIT1 with unacked data keeps retransmitting from softirq timers. Each retransmission goes through tcp_update_skb_after_send() -> mptcp_pacing_account() and charges msk->pacing_next_ns. This reset is a plain atomic64_set() without pacing_lock. By contrast, mptcp_pacing_account() does a read-modify-write under that lock: next = max_t(s64, atomic64_read(&msk->pacing_next_ns), now - credit); atomic64_set(&msk->pacing_next_ns, next + interval); Can a concurrent charge from a lingering subflow read the old value and overwrite this reset? Even without that race, would charges from the old connection's subflows keep throttling the new connection after connect(AF_UNSPEC) and a reconnect? There is a related gap in mptcp_setsockopt_pacing_rate(). It walks only conn_list through mptcp_for_each_subflow(), so detached subflows never get mptcp_pacing updated or their queued pacing timer re-armed when the limit changes. > msk->bytes_consumed = 0; > msk->bytes_acked = 0; > msk->bytes_received = 0; [ ... ] > diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h > index 7cdd0a7e8296b..1a98e5bd47bcb 100644 > --- a/net/mptcp/protocol.h > +++ b/net/mptcp/protocol.h > @@ -310,6 +310,8 @@ struct mptcp_sock { > u64 bytes_received; > u64 ack_seq; > atomic64_t rcv_wnd_sent; > + atomic64_t pacing_next_ns; > + spinlock_t pacing_lock; /* serializes charging and rate changes */ [Severity: Low] Is this comment accurate? It does not seem to match how the lock is used: - In mptcp_setsockopt_pacing_rate(), sk_setsockopt() writes sk->sk_max_pacing_rate under lock_sock(msk) only, before pacing_lock is taken. - pacing_lock is taken only in the relaxed branch, around the debt reset. Tightening the rate never takes it. - mptcp_disconnect() resets pacing_next_ns without it. For the same reason, the comment "Account sends using the previous rate before clearing its debt" in mptcp_setsockopt_pacing_rate() is not guaranteed. mptcp_pacing_account() can take pacing_lock between the WRITE_ONCE() in sk_setsockopt() and the spin_lock_bh() in the relaxed branch, and charge at the new rate. In practice the lock only serializes charging against the setsockopt debt reset. Could the comment say that? [ ... ] > diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c > index 85695fe00cc38..5ae6be0cdb459 100644 > --- a/net/mptcp/subflow.c > +++ b/net/mptcp/subflow.c [ ... ] > @@ -1056,6 +1057,14 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, > fallback: > if (fallback) > SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK); > + /* This child is handed to plain TCP and will have no parent clock. */ > + if (listener->conn) { > + unsigned long rate = READ_ONCE(listener->conn->sk_max_pacing_rate); > + > + if (rate != ~0UL) > + sk_setsockopt(child, SOL_SOCKET, SO_MAX_PACING_RATE, > + KERNEL_SOCKPTR(&rate), sizeof(rate)); [Severity: Low] Should a rate of 0 be skipped here as well? On the MPTCP side, 0 means no limit: - mptcp_pacing_enabled() and mptcp_pacing_account() both check rate && rate != ~0UL. - mptcp_setsockopt_pacing_rate() treats a change to 0 as relaxing the limit. This check filters only ~0UL. If the listener has SO_MAX_PACING_RATE set to 0, the fallback child ends up with sk_pacing_status set to SK_PACING_NEEDED, and with sk_max_pacing_rate and sk_pacing_rate both 0. tcp_small_queue_check() then limits the child to 2 * skb->truesize, and tcp_tso_autosize() loses its pacing-rate term. MPTCP children from the same listener get mptcp_pacing = false in mptcp_sk_clone_init() and keep the normal TSQ/TSO sizing. So one listener setting gives different transmit behaviour depending on whether the connection fell back. Would checking mptcp_pacing_enabled(listener->conn) here keep the two cases consistent? > + } > mptcp_subflow_drop_ctx(child); > return child; > } -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179630953225.20.4977913523988952504.mptcp-578-0000%40gmail.com ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH mptcp-next 2/2] selftests: mptcp: check the aggregate pacing rate across two paths 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 14:53 ` Ruilin Mao 2026-12-03 15:09 ` sashiko-bot 2026-12-05 5:06 ` netdev-bot+sashiko 1 sibling, 2 replies; 7+ messages in thread From: Ruilin Mao @ 2026-12-03 14:53 UTC (permalink / raw) To: mptcp Run the simultaneous-flows transfer over two 10-Mbit/s links with the connector limited to 14 Mbit/s. Verify the transfer duration and check that both egress interfaces carried data. Applying a separate cap of 14 Mbit/s to each path would allow a transfer near 20 Mbit/s. Keep the existing transfer and payload checks, and skip the new case when running against a kernel without connection-wide pacing support. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/578 Signed-off-by: Ruilin Mao <zibuyu423@gmail.com> --- .../selftests/net/mptcp/mptcp_connect.c | 18 +++++-- .../selftests/net/mptcp/simult_flows.sh | 50 ++++++++++++++++++- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c index 178d98d91fea..9a32dcc31160 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -68,6 +68,7 @@ static const char *cfg_port = "12000"; static int cfg_sock_proto = IPPROTO_MPTCP; static int pf = AF_INET; static int cfg_sndbuf; +static int cfg_pacing_rate; static int cfg_rcvbuf; static bool cfg_join; static bool cfg_remove; @@ -110,10 +111,12 @@ static struct cfg_sockopt_types cfg_sockopt_types; static void die_usage(void) { - fprintf(stderr, "Usage: mptcp_connect [-6] [-c cmsg] [-f offset] [-i file] [-I num] [-j] [-l] " - "[-m mode] [-M mark] [-o option] [-p port] [-P mode] [-r num] [-R num] " - "[-s MPTCP|TCP] [-S num] [-t num] [-T num] [-w sec] connect_address\n"); + fprintf(stderr, "Usage: mptcp_connect [-6] [-a rate] [-c cmsg] [-f offset] [-i file]\n" + " [-I num] [-j] [-l] [-m mode] [-M mark] [-o option] [-p port] [-P mode]\n" + " [-r num] [-R num] [-s MPTCP|TCP] [-S num] [-t num] [-T num] [-w sec]\n" + " connect_address\n"); fprintf(stderr, "\t-6 use ipv6\n"); + fprintf(stderr, "\t-a rate -- set connector SO_MAX_PACING_RATE in bytes/second\n"); fprintf(stderr, "\t-c cmsg -- test cmsg type <cmsg>\n"); fprintf(stderr, "\t-f offset -- stop the I/O after receiving and sending the specified amount " "of bytes. If there are unread bytes in the receive queue, that will cause a MPTCP " @@ -394,6 +397,10 @@ static int sock_connect_mptcp(const char * const remoteaddr, SOCK_TEST_TCPULP(sock, proto); + if (cfg_pacing_rate && setsockopt(sock, SOL_SOCKET, SO_MAX_PACING_RATE, + &cfg_pacing_rate, sizeof(cfg_pacing_rate))) + xerror("SO_MAX_PACING_RATE: %m\n"); + if (cfg_mark) set_mark(sock, cfg_mark); @@ -1516,7 +1523,7 @@ static void parse_opts(int argc, char **argv) { int c; - while ((c = getopt(argc, argv, "6c:f:hi:I:jlm:M:o:p:P:r:R:s:S:t:T:w:")) != -1) { + while ((c = getopt(argc, argv, "6a:c:f:hi:I:jlm:M:o:p:P:r:R:s:S:t:T:w:")) != -1) { switch (c) { case 'f': cfg_truncate = atoi(optarg); @@ -1573,6 +1580,9 @@ static void parse_opts(int argc, char **argv) case 'm': cfg_mode = parse_mode(optarg); break; + case 'a': + cfg_pacing_rate = parse_int(optarg); + break; case 'S': cfg_sndbuf = parse_int(optarg); break; diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/testing/selftests/net/mptcp/simult_flows.sh index 3ea3d1efe32e..d4a6bda0e3a2 100755 --- a/tools/testing/selftests/net/mptcp/simult_flows.sh +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh @@ -128,11 +128,19 @@ setup() grep -q ' kmemleak_init$\| lockdep_init$\| kasan_init$\| prove_locking$' /proc/kallsyms && slack=$((slack+550)) } +get_tx_bytes() +{ + ip netns exec "$ns1" cat "/sys/class/net/$1/statistics/tx_bytes" +} + do_transfer() { local cin=$1 local sin=$2 local max_time=$3 + local rate=${4:-0} + local pacing_opts=() + local start end elapsed min_time tx1 tx2 local port port=$((10000+MPTCP_LIB_TEST_COUNTER)) @@ -170,8 +178,14 @@ do_transfer() mptcp_lib_wait_local_port_listen "${ns3}" "${port}" + if ((rate)); then + pacing_opts=(-a "$rate") + tx1=$(get_tx_bytes ns1eth1) + tx2=$(get_tx_bytes ns1eth2) + start=$(date +%s%N) + fi ip netns exec ${ns1} \ - ./mptcp_connect -jt ${timeout_poll} -p $port -T $max_time \ + ./mptcp_connect -jt ${timeout_poll} -p $port -T $max_time "${pacing_opts[@]}" \ 10.0.3.3 < "$cin" > "$cout" & local cpid=$! @@ -184,6 +198,23 @@ do_transfer() wait $spid local rets=$? + if ((rate)); then + end=$(date +%s%N) + elapsed=$(((end - start) / 1000000)) + # Allow one GSO burst and timer jitter at the endpoints. + min_time=$((size * 1000 / rate * 90 / 100)) + if ((elapsed < min_time)); then + mptcp_lib_print_err "pacing: ${elapsed}ms, minimum ${min_time}ms" + retc=1 + fi + tx1=$(($(get_tx_bytes ns1eth1) - tx1)) + tx2=$(($(get_tx_bytes ns1eth2) - tx2)) + if ((tx1 < 65536 || tx2 < 65536)); then + mptcp_lib_print_err "path byte counts too low: $tx1 and $tx2" + retc=1 + fi + fi + if kill -0 $timeout_pid; then # Finished before the timeout: kill the background job mptcp_lib_kill_group_wait $timeout_pid @@ -309,6 +340,23 @@ done setup mptcp_lib_subtests_last_ts_reset run_test 10 10 0 0 20 20 "balanced bwidth" + +# Keep the two 10-Mbit/s paths from the previous test. A 14-Mbit/s +# connection cap leaves room to use both while exposing independent caps. +msg="aggregate pacing rate" +mptcp_lib_print_title "$msg" +if mptcp_lib_kallsyms_has 'mptcp_pacing_account$'; then + do_transfer "$large" "$small" "$((timeout_poll * 1000))" 1750000 + rc=$? + mptcp_lib_result_code "$rc" "$msg" + if ((rc)); then + ret=$rc + ((bail)) && exit "$ret" + fi +else + mptcp_lib_pr_skip + mptcp_lib_result_skip "$msg" +fi run_test 10 10 1 25 20 50 "balanced bwidth with unbalanced delay" # we still need some additional infrastructure to pass the following test-cases ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH mptcp-next 2/2] selftests: mptcp: check the aggregate pacing rate across two paths 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 1 sibling, 0 replies; 7+ messages in thread From: sashiko-bot @ 2026-12-03 15:09 UTC (permalink / raw) To: Ruilin Mao, mptcp Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] selftests: mptcp: mid-script mptcp_lib_kallsyms_has() aborts simult_flows.sh - [Low] selftests: mptcp: silent skip in simult_flows.sh lacks reason string - [Low] selftests: mptcp: loose max_time in simult_flows.sh misses over-throttling - [Low] selftests: mptcp: unconditional pacing checks overwrite retc in do_transfer() -- commit d7318c01326d99e2d3acfdbd5eb6d1d7164dba08 Author: Ruilin Mao <zibuyu423@gmail.com> selftests: mptcp: check the aggregate pacing rate across two paths This commit adds a -a option to mptcp_connect to set SO_MAX_PACING_RATE and adds an aggregate pacing rate subtest to simult_flows.sh over two 10-Mbit/s paths. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/578 > diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/testing/selftests/net/mptcp/simult_flows.sh > index 3ea3d1efe32e1..d4a6bda0e3a24 100755 > --- a/tools/testing/selftests/net/mptcp/simult_flows.sh > +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh [ ... ] > @@ -184,6 +198,23 @@ do_transfer() > wait $spid > local rets=$? > > + if ((rate)); then > + end=$(date +%s%N) > + elapsed=$(((end - start) / 1000000)) > + # Allow one GSO burst and timer jitter at the endpoints. > + min_time=$((size * 1000 / rate * 90 / 100)) > + if ((elapsed < min_time)); then > + mptcp_lib_print_err "pacing: ${elapsed}ms, minimum ${min_time}ms" > + retc=1 > + fi > + tx1=$(($(get_tx_bytes ns1eth1) - tx1)) > + tx2=$(($(get_tx_bytes ns1eth2) - tx2)) > + if ((tx1 < 65536 || tx2 < 65536)); then > + mptcp_lib_print_err "path byte counts too low: $tx1 and $tx2" > + retc=1 > + fi > + fi [Severity: Low] Should these pacing checks require retc and rets to be zero and track failures in a separate variable? When mptcp_connect fails early, elapsed and tx1/tx2 miss their thresholds, printing spurious pacing errors and overwriting retc with 1 before mptcp_lib_pr_fail() reports it. Even when both peers exit 0, mutating retc makes mptcp_lib_pr_fail() misreport a client exit code of 1. [ ... ] > @@ -309,6 +340,23 @@ done > setup > mptcp_lib_subtests_last_ts_reset > run_test 10 10 0 0 20 20 "balanced bwidth" > + > +# Keep the two 10-Mbit/s paths from the previous test. A 14-Mbit/s > +# connection cap leaves room to use both while exposing independent caps. > +msg="aggregate pacing rate" > +mptcp_lib_print_title "$msg" > +if mptcp_lib_kallsyms_has 'mptcp_pacing_account$'; then [Severity: Medium] Can calling mptcp_lib_kallsyms_has() mid-script abort simult_flows.sh when CONFIG_KALLSYMS is disabled? mptcp_lib_kallsyms_has() calls mptcp_lib_check_kallsyms(), which runs exit ${KSFT_SKIP} when /proc/kallsyms is absent. Terminating after the first run_test() skips the remaining subtests, drops the TAP summary, and masks any failure already recorded in ret. Calling mptcp_lib_check_kallsyms() at startup like the sibling MPTCP selftests, or checking for /proc/kallsyms before this test, would avoid exiting mid-run. > + do_transfer "$large" "$small" "$((timeout_poll * 1000))" 1750000 [Severity: Low] Is passing $((timeout_poll * 1000)) (30000 ms) as max_time too loose to catch over-throttling? For a 16 MiB transfer capped at 14 Mbit/s (~9.6 s expected), a 30 s upper bound lets a 7-Mbit/s over-throttled transfer or a mostly single-path 10-Mbit/s transfer (after 64 KiB on the second path) pass. Deriving max_time from the 14-Mbit/s rate and slack, like run_test() does, would catch that. [ ... ] > +else > + mptcp_lib_pr_skip > + mptcp_lib_result_skip "$msg" > +fi [Severity: Low] Should mptcp_lib_pr_skip take a reason string here? Calling it with no arguments prints a bare "[SKIP]" without saying which kernel feature is missing (for example, "SO_MAX_PACING_RATE not supported by the kernel"). -- Sashiko AI review · https://sashiko.dev/#/patchset/179630953225.20.4977913523988952504.mptcp-578-0000@gmail.com?part=2 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH mptcp-next 2/2] selftests: mptcp: check the aggregate pacing rate across two paths 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 1 sibling, 0 replies; 7+ messages in thread From: netdev-bot+sashiko @ 2026-12-05 5:06 UTC (permalink / raw) To: zibuyu423; +Cc: mptcp, kuba Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · 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] selftests: mptcp: mid-script mptcp_lib_kallsyms_has() aborts simult_flows.sh - [Low] The new 'aggregate pacing rate' subtest in simult_flows.sh only checks that the rate is not exceeded. - [Low] The 10% tolerance in the new pacing lower bound does not match its comment, and it leaves only a narrow margin over the script's own… - [Low] The new -a option in mptcp_connect.c parses its argument with parse_int(). - [Low] selftests: mptcp: unconditional pacing checks overwrite retc in do_transfer() -- selftests: mptcp: check the aggregate pacing rate across two paths This commit adds a -a option to mptcp_connect, which sets SO_MAX_PACING_RATE on the connecting socket. It also adds an "aggregate pacing rate" subtest to simult_flows.sh. The subtest runs a transfer over two 10 Mbit/s links with a 14 Mbit/s cap, then checks a minimum transfer duration and that both egress interfaces sent at least 64 KiB. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/578 > diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c > index 8c788977e5947..9a601fe4493a4 100644 > --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c > +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c [ ... ] > @@ -1588,6 +1595,9 @@ static void parse_opts(int argc, char **argv) > case 'm': > cfg_mode = parse_mode(optarg); > break; > + case 'a': > + cfg_pacing_rate = parse_int(optarg); > + break; [Severity: Low] This isn't a bug, but parse_int() reports every failure as a sndbuf problem: tools/testing/selftests/net/mptcp/mptcp_connect.c:parse_int() { ... if (s > INT_MAX) { fprintf(stderr, "Invalid sndbuf size %s (%s)\n", size, strerror(ERANGE)); die_usage(); } ... } The errno path prints the same text. As a result, something like "-a 3000000000" is reported as an invalid sndbuf size, while die_usage() describes -a as setting SO_MAX_PACING_RATE. The -R option already has this mismatch, and the new option adds another caller with it. Could the message be made generic, or name the option being parsed? > case 'S': > cfg_sndbuf = parse_int(optarg); > break; > diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/testing/selftests/net/mptcp/simult_flows.sh > index 3ea3d1efe32e1..d4a6bda0e3a24 100755 > --- a/tools/testing/selftests/net/mptcp/simult_flows.sh > +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh [ ... ] > @@ -184,6 +198,23 @@ do_transfer() > wait $spid > local rets=$? > > + if ((rate)); then > + end=$(date +%s%N) > + elapsed=$(((end - start) / 1000000)) > + # Allow one GSO burst and timer jitter at the endpoints. > + min_time=$((size * 1000 / rate * 90 / 100)) [Severity: Low] Should these checks only run when both mptcp_connect instances succeeded? The block runs right after the two wait calls, whatever the values of retc and rets. The client can fail early, for example when connect() fails, the poll timeout fires, or the timeout job kills it. In that case elapsed is below min_time and tx1/tx2 are under 64 KiB. The test then prints "pacing: ..." and "path byte counts too low: ..." on top of the real failure, and overwrites retc with 1. The existing failure report in do_transfer() then shows the wrong value: mptcp_lib_pr_fail "client exit code $retc, server $rets" It prints 1 instead of the exit code mptcp_connect returned. That exit code is the first thing someone debugging the failure needs. If both processes exited 0 and only the pacing or byte-count check failed, the same message reports "client exit code 1, server 0". That points at mptcp_connect instead of the pacing check. The subtest still fails in both cases, so no regression is hidden. The output is just harder to interpret. Could the checks be guarded on retc and rets both being 0? Could the pacing failure also be tracked in a separate variable rather than by reusing retc? [Severity: Low] Does this comment match the tolerance being applied? With the 16 MiB payload and a rate of 1750000, min_time is 8627 ms. The 10% slack is about 960 ms, which is roughly 1.68 MB at 1.75 MB/s. On the kernel side, mptcp_pacing_account() allows idle credit of only about one tick or one MPTCP_SEND_BURST_SIZE burst: net/mptcp/protocol.c:mptcp_pacing_account() { ... credit = min_t(s64, hrtimer_resolution, div64_ul((u64)MPTCP_SEND_BURST_SIZE * NSEC_PER_SEC, rate)); credit = max(credit, interval / 2); ... } At this rate that is around 37 ms, so the slack covers about 25 bursts, not one. The elapsed window is also wider than the transfer itself. It starts before ip netns exec launches the client and ends after wait $spid. It also includes the 200 ms -j sleep on each side. Together this accepts a sustained rate of roughly 16 Mbit/s rather than 14. Is the margin over the per-path cap case wide enough? run_test() budgets an unpaced 2x10 Mbit/s transfer as: local time=$((1000 * size * 8 * 10 / ((rate1 + rate2) * 1000 * 1000 * 9) )) time=$((time + 400 + slack)) That comes to 7906 ms, or 8456 ms with the debug kernel slack, which is only about 170 ms below the 8627 ms threshold. On a slow or debug CI kernel, could a per-subflow cap implementation take more than 8627 ms of shell wall time and still pass? Could the comment be fixed? Could the threshold also be tightened, or be based on a measured unpaced baseline? > + if ((elapsed < min_time)); then > + mptcp_lib_print_err "pacing: ${elapsed}ms, minimum ${min_time}ms" > + retc=1 > + fi [ ... ] > @@ -309,6 +340,23 @@ done > setup > mptcp_lib_subtests_last_ts_reset > run_test 10 10 0 0 20 20 "balanced bwidth" > + > +# Keep the two 10-Mbit/s paths from the previous test. A 14-Mbit/s > +# connection cap leaves room to use both while exposing independent caps. > +msg="aggregate pacing rate" > +mptcp_lib_print_title "$msg" > +if mptcp_lib_kallsyms_has 'mptcp_pacing_account$'; then > + do_transfer "$large" "$small" "$((timeout_poll * 1000))" 1750000 [Severity: Medium] Can this abort the rest of simult_flows.sh on a kernel built without CONFIG_KALLSYMS? mptcp_lib_kallsyms_has() goes through __mptcp_lib_kallsyms_has(), which calls mptcp_lib_check_kallsyms() in mptcp_lib.sh: mptcp_lib_check_kallsyms() { if ! mptcp_lib_has_file "/proc/kallsyms"; then mptcp_lib_pr_skip "CONFIG_KALLSYMS is missing" exit ${KSFT_SKIP} fi } mptcp_connect.sh, mptcp_join.sh, mptcp_sockopt.sh and userspace_pm.sh all call mptcp_lib_check_kallsyms() at startup. simult_flows.sh only calls mptcp_lib_check_mptcp() and mptcp_lib_check_tools(). Until now it ran to completion without /proc/kallsyms, because the grep in setup() is not fatal. With this patch, the script exits with KSFT_SKIP in the middle of the run, right after the "balanced bwidth" subtests. This has three effects: - The four remaining run_test() calls never run. - mptcp_lib_result_print_all_tap() is never reached. - A failure already recorded in ret by the first subtests is reported as a skip. The config fragment in this directory sets CONFIG_KALLSYMS=y, so default selftest builds are fine. Other CI configurations may not enable it, though. Should the script call mptcp_lib_check_kallsyms() at startup like its siblings do? That would skip the whole script on such kernels. Alternatively, the test could check for /proc/kallsyms before calling mptcp_lib_kallsyms_has(), so only the new subtest is skipped. Which behaviour do you prefer here? [Severity: Low] Can this subtest catch a pacer that throttles too much? do_transfer() checks only a lower bound on elapsed time and a 64 KiB floor per egress interface: if ((tx1 < 65536 || tx2 < 65536)); then That floor is under 0.4% of the 16 MiB payload. The only upper bound is the max_time passed here, timeout_poll * 1000 = 30000 ms, which mptcp_connect enforces through -T. That works out to about 4.5 Mbit/s of goodput, which is below a single 10 Mbit/s link. These pacer regressions would still pass: - Charging the shared msk deadline twice per send halves the rate to about 7 Mbit/s, so the transfer takes about 19 s. - Starving one subflow, so nearly all data goes over one 10 Mbit/s path, takes about 14-15 s. A little traffic on the second subflow still clears the 64 KiB floor. The kernel change "mptcp: support a connection-wide SO_MAX_PACING_RATE" says a fixed split "would waste bandwidth when a path is idle". The comment above also says the 14 Mbit/s cap "leaves room to use both" paths. The test does catch independent per-path caps near 20 Mbit/s, which is the case the commit message names. However, the subject says it checks "the aggregate pacing rate across two paths". Could an upper bound be added? One option is size / rate plus the 400 ms of join sleeps plus slack, as run_test() does. Another is to require elapsed to stay below the single-link transfer time. If neither fits, should the commit message say that only a minimum duration is enforced? > + rc=$? > + mptcp_lib_result_code "$rc" "$msg" [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179630953225.20.4977913523988952504.mptcp-578-0000%40gmail.com ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-05 5:06 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
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.