[PATCH net-next v5 4/4] tcp: add MSS ceiling callback for congestion control
From: chia-yu . chang
Date: Mon Nov 30 2026 - 07:57:25 EST
From: Chia-Yu Chang <chia-yu.chang@xxxxxxxxxxxxxxxxxxx>
Allow congestion control modules to provide an optional MSS ceiling
through the new mss_ceiling() callback. The callback returns an upper
bound for tp->mss_cache and therefore uses the same units and semantics
as mss_cache.
The TCP stack derives MSS from PMTU discovery and other existing
constraints, while congestion control may further reduce the effective
MSS when needed. The ceiling is applied during MSS calculation and
remains subject to existing PMTU updates and other TCP MSS constraints.
Add tcp_update_mss_ceiling() to allow congestion control modules to
request immediate recomputation of mss_cache after changing their MSS
ceiling. This will be used by upcoming congestion controls, e.g., TCP
Prague, that perform fine-grained rate control at very low rates
(e.g., sub-Mbps) to improve latency characteristics.
The motivation for this facility and its performance impact on low-rate
Prague traffic are in: https://dl.acm.org/doi/10.1145/3822163.3827934
Signed-off-by: Chia-Yu Chang <chia-yu.chang@xxxxxxxxxxxxxxxxxxx>
---
v5:
- Apply mss_ceiling() in tcp_sync_mss() instead of __tcp_mtu_to_mss()
- Only invoke mss_ceiling() after congestion control initialization
- Document mss_ceiling() callback semantics and update commit message
- Add tcp_update_mss_ceiling() helper to recompute mss_cache after
congestion-control MSS ceiling updates
- Clamp excessively small MSS ceilings to the effective minimum send MSS
- Add BPF struct_ops support for mss_ceiling()
v3:
- Replace mss_cache_set_by_cca with mss_ceiling() callback
- Add tcp_update_mss() helper for immediate MSS recomputation
---
include/net/tcp.h | 7 +++++++
net/ipv4/bpf_tcp_ca.c | 7 +++++++
net/ipv4/tcp_output.c | 27 +++++++++++++++++++++++++++
3 files changed, 41 insertions(+)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 1cc3f60da8d6..01402ccad477 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -865,6 +865,7 @@ static inline void tcp_clear_xmit_timers(struct sock *sk)
unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu);
unsigned int tcp_current_mss(struct sock *sk);
+unsigned int tcp_update_mss_ceiling(struct sock *sk);
u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when);
u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now,
@@ -1439,6 +1440,12 @@ struct tcp_congestion_ops {
/* returns the multiplier used in tcp_sndbuf_expand (optional) */
u32 (*sndbuf_expand)(struct sock *sk);
+ /*
+ * Return the maximum value allowed for tp->mss_cache (optional)
+ * The returned value uses the same units and semantics as mss_cache.
+ */
+ u32 (*mss_ceiling)(struct sock *sk);
+
/* control/slow paths put last */
/* get info for inet_diag (optional) */
size_t (*get_info)(struct sock *sk, u32 ext, int *attr,
diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c
index 2a71dc81562f..b03cc9e9c064 100644
--- a/net/ipv4/bpf_tcp_ca.c
+++ b/net/ipv4/bpf_tcp_ca.c
@@ -195,6 +195,7 @@ BTF_ID_FLAGS(func, tcp_reno_undo_cwnd)
BTF_ID_FLAGS(func, tcp_slow_start)
BTF_ID_FLAGS(func, tcp_cong_avoid_ai)
BTF_ID_FLAGS(func, tcp_tso_autosize)
+BTF_ID_FLAGS(func, tcp_update_mss_ceiling)
BTF_KFUNCS_END(bpf_tcp_ca_check_kfunc_ids)
static const struct btf_kfunc_id_set bpf_tcp_ca_kfunc_set = {
@@ -290,6 +291,11 @@ static u32 bpf_tcp_ca_tso_segs(struct sock *sk, u32 mss_now)
return 0;
}
+static u32 bpf_tcp_ca_mss_ceiling(struct sock *sk)
+{
+ return 0;
+}
+
static void bpf_tcp_ca_cong_control(struct sock *sk, u32 ack, int flag,
const struct rate_sample *rs)
{
@@ -322,6 +328,7 @@ static struct tcp_congestion_ops __bpf_ops_tcp_congestion_ops = {
.in_ack_event = bpf_tcp_ca_in_ack_event,
.pkts_acked = bpf_tcp_ca_pkts_acked,
.tso_segs = bpf_tcp_ca_tso_segs,
+ .mss_ceiling = bpf_tcp_ca_mss_ceiling,
.cong_control = bpf_tcp_ca_cong_control,
.undo_cwnd = bpf_tcp_ca_undo_cwnd,
.sndbuf_expand = bpf_tcp_ca_sndbuf_expand,
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 7b694479095e..96ed9ba7abe6 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2147,6 +2147,21 @@ unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu)
mss_now = tcp_mtu_to_mss(sk, pmtu);
mss_now = tcp_bound_to_half_wnd(tp, mss_now);
+ /*
+ * Apply an optional MSS ceiling requested by the congestion control
+ * module. Values below the effective minimum send MSS are clamped.
+ */
+ if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->mss_ceiling) {
+ u32 mss_ceiling = icsk->icsk_ca_ops->mss_ceiling(sk);
+
+ if (mss_ceiling && mss_ceiling < mss_now) {
+ u32 min_snd_mss = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_min_snd_mss) -
+ (tcp_sk(sk)->tcp_header_len - sizeof(struct tcphdr));
+
+ mss_now = max(mss_ceiling, min_snd_mss);
+ }
+ }
+
/* And store cached results */
icsk->icsk_pmtu_cookie = pmtu;
if (icsk->icsk_mtup.enabled)
@@ -2190,6 +2205,18 @@ unsigned int tcp_current_mss(struct sock *sk)
return mss_now;
}
+__bpf_kfunc unsigned int tcp_update_mss_ceiling(struct sock *sk)
+{
+ struct inet_connection_sock *icsk = inet_csk(sk);
+
+ if (icsk->icsk_ca_initialized &&
+ icsk->icsk_ca_ops->mss_ceiling &&
+ icsk->icsk_pmtu_cookie)
+ return tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
+ return tcp_sk(sk)->mss_cache;
+}
+EXPORT_SYMBOL_GPL(tcp_update_mss_ceiling);
+
/* RFC2861, slow part. Adjust cwnd, after it was not full during one rto.
* As additional protections, we do not touch cwnd in retransmission phases,
* and if application hit its sndbuf limit recently.
--
2.34.1