๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Chris Mason Wed, 18 Nov 2026 15:51
[PATCH net v2 0/5] tcp: avoid integer wraps in the RTT estimator and the RTO
#18621
Author: Chris Mason
Date: Wed, 18 Nov 2026 15:51
55 lines
9231 bytes
Hi everyone,

This is v2 of the RTT clamps, with Eric's review folded in.

Patch 1: __tcp_set_rto() never returns 0, so that the backoff recovers
from any state of the RTT estimator.

Patch 2: tcp_rtt_estimator() clamps each sample to 120 s, so that
srtt_us, mdev_us, rttvar_us and the sum in __tcp_set_rto() can't wrap.

Patch 3: tcp_rtt_tsopt_us() rejects a TSecr sample above 120 s.

Patch 4: new, from Eric's review. tcp_rcv_rtt_update() clamps its
samples too, which covers tcp_rcv_rtt_measure().

Patch 5: new. tcp_rto_min() bounds the locked rto_min of a route.

Eric, I have a question on patch 5. You pointed at a locked rto_min of 0 for
patch 1. We can also get an RTO of 0 out of tcp_init_metrics(), which doesn't
go through __tcp_set_rto(), so I bounded the metric in tcp_rto_min(). For a
locked cwnd of 0 you wanted ip_metrics_convert() to reject it instead.

I didn't do that here because claude points out that "rto_min lock 0" is
accepted today and mostly works, but just let me know how you want
this to look.

Changes since v1:

- Patch 1: no code change. New changelog and Fixes: tag (Eric). David
  suggested "return rto ?: 1;". I kept max(), since tcp_rtt_estimator()
  ends with max(1U, srtt).
- Patch 2: clamp mrtt_us itself, so that tcp_bpf_rtt() gets the clamped
  sample (Eric).
- Patch 3: no code change. The part on sample << 3 moved to patch 4.
- Patch 4: new (Eric), with min() instead of min_t() (David).
- Patch 5: new.

v1: https://lore.kernel.org/all/20261118005048.53393-1-mason@kernel.org/

This is on top of v7.4-rc3.

Chris Mason (5):
  tcp: don't let __tcp_set_rto() return 0
  tcp: clamp RTT samples in tcp_rtt_estimator()
  tcp: reject RTT samples from TSecr above 120 s
  tcp: clamp the samples in tcp_rcv_rtt_update()
  tcp: bound the rto_min of a route in tcp_rto_min()

 include/net/tcp.h    | 14 ++++++++++++--
 net/ipv4/tcp_input.c | 21 +++++++++++++++------
 2 files changed, 27 insertions(+), 8 deletions(-)

-- 
2.55.0
[PATCH net v2 5/5] tcp: bound the rto_min of a route in tcp_rto_min()
#18622
Author: Chris Mason
Date: Wed, 18 Nov 2026 15:51
60 lines
9448 bytes
For a route with a locked RTAX_RTO_MIN, tcp_rto_min() returns the metric
as it is, and that can be any 32-bit number of milliseconds. All other
ways to set the minimum RTO have a nonzero floor: the tcp_rto_min_us
sysctl, TCP_RTO_MIN_US and TCP_BPF_RTO_MIN.

Both ends of that range give us trouble.

With an rto_min of 0, tcp_init_metrics() can start a connection with an
RTO of 0, if the cached RTT is below one jiffy:

    icsk_rto = crtt + max(2 * crtt, tcp_rto_min(sk)) = 0

It sets icsk_rto itself, so the lower bound in __tcp_set_rto() does not
help here.

At the other end, tcp_rto_min_us() and the sum in __tcp_set_rto() are
u32 values in usec, so an rto_min of more than about 71 minutes does not
fit.

Clamp a locked rto_min to the range from one jiffy to TCP_RTO_MAX in
tcp_rto_min().

ip_metrics_convert() could reject these values instead, as it does for a
locked cwnd of 0. But a route with "rto_min lock 0" is accepted today
and mostly works, so that would break existing setups.

A route still shows the rto_min that it was given, while TCP uses one
jiffy or 120 s.

Found by LLM code inspection, and confirmed with LLM generated
reproducers on an unmodified kernel. Fixed by LLM, and tested with
the reproducers and existing kernel selftests.

Fixes: 05bb1fad1cde ("[TCP]: Allow minimum RTO to be configurable via routing metrics.")
Signed-off-by: Chris Mason <mason@kernel.org>
---

Notes:
    v1->v2: new patch

 include/net/tcp.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index a617a72ee2c6..27de546dc802 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -939,7 +939,8 @@ static inline u32 tcp_rto_min(const struct sock *sk)
 	u32 rto_min = READ_ONCE(inet_csk(sk)->icsk_rto_min);
 
 	if (dst && dst_metric_locked(dst, RTAX_RTO_MIN))
-		rto_min = dst_metric_rtt(dst, RTAX_RTO_MIN);
+		rto_min = clamp(dst_metric_rtt(dst, RTAX_RTO_MIN),
+				1, TCP_RTO_MAX);
 	return rto_min;
 }
 
-- 
2.55.0
Re: [PATCH net v2 5/5] tcp: bound the rto_min of a route in tcp_rto_min()
#18640
Author: Eric Dumazet
Date: Wed, 18 Nov 2026 16:33
73 lines
11337 bytes
Le mer. 18 nov. 2026 ร  16:51, Chris Mason <mason@kernel.org> a รฉcrit :
>
> For a route with a locked RTAX_RTO_MIN, tcp_rto_min() returns the metric
> as it is, and that can be any 32-bit number of milliseconds. All other
> ways to set the minimum RTO have a nonzero floor: the tcp_rto_min_us
> sysctl, TCP_RTO_MIN_US and TCP_BPF_RTO_MIN.
>
> Both ends of that range give us trouble.
>
> With an rto_min of 0, tcp_init_metrics() can start a connection with an
> RTO of 0, if the cached RTT is below one jiffy:
>
>     icsk_rto = crtt + max(2 * crtt, tcp_rto_min(sk)) = 0
>
> It sets icsk_rto itself, so the lower bound in __tcp_set_rto() does not
> help here.
>
> At the other end, tcp_rto_min_us() and the sum in __tcp_set_rto() are
> u32 values in usec, so an rto_min of more than about 71 minutes does not
> fit.
>
> Clamp a locked rto_min to the range from one jiffy to TCP_RTO_MAX in
> tcp_rto_min().
>
> ip_metrics_convert() could reject these values instead, as it does for a
> locked cwnd of 0. But a route with "rto_min lock 0" is accepted today
> and mostly works, so that would break existing setups.
>

I agree, please keep the clamp in tcp_rto_min().

A locked cwnd of 0 makes no sense, but "rto_min lock 0" can be read
as "as low as possible", and we can not start rejecting it now.

Reviewed-by: Eric Dumazet <edumazet@kernel.org>

> A route still shows the rto_min that it was given, while TCP uses one
> jiffy or 120 s.
>
> Found by LLM code inspection, and confirmed with LLM generated
> reproducers on an unmodified kernel. Fixed by LLM, and tested with
> the reproducers and existing kernel selftests.
>
> Fixes: 05bb1fad1cde ("[TCP]: Allow minimum RTO to be configurable via routing metrics.")
> Signed-off-by: Chris Mason <mason@kernel.org>
> ---
>
> Notes:
>     v1->v2: new patch
>
>  include/net/tcp.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index a617a72ee2c6..27de546dc802 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -939,7 +939,8 @@ static inline u32 tcp_rto_min(const struct sock *sk)
>         u32 rto_min = READ_ONCE(inet_csk(sk)->icsk_rto_min);
>
>         if (dst && dst_metric_locked(dst, RTAX_RTO_MIN))
> -               rto_min = dst_metric_rtt(dst, RTAX_RTO_MIN);
> +               rto_min = clamp(dst_metric_rtt(dst, RTAX_RTO_MIN),
> +                               1, TCP_RTO_MAX);
>         return rto_min;
>  }
>
> --
> 2.55.0
>
Re: [PATCH net v2 0/5] tcp: avoid integer wraps in the RTT estimator and the RTO
#19183
Author: patchwork-bot+netdevbpf
Date: Thu, 19 Nov 2026 14:00
32 lines
8976 bytes
Hello:

This series was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Wed, 18 Nov 2026 10:51:44 -0500 you wrote:
> Hi everyone,
> 
> This is v2 of the RTT clamps, with Eric's review folded in.
> 
> Patch 1: __tcp_set_rto() never returns 0, so that the backoff recovers
> from any state of the RTT estimator.
> 
> [...]

Here is the summary with links:
  - [net,v2,1/5] tcp: don't let __tcp_set_rto() return 0
    https://git.kernel.org/netdev/net/c/5d2a5ad03677
  - [net,v2,2/5] tcp: clamp RTT samples in tcp_rtt_estimator()
    https://git.kernel.org/netdev/net/c/fa472d53d9b7
  - [net,v2,3/5] tcp: reject RTT samples from TSecr above 120 s
    https://git.kernel.org/netdev/net/c/1b91d9c09aa7
  - [net,v2,4/5] tcp: clamp the samples in tcp_rcv_rtt_update()
    https://git.kernel.org/netdev/net/c/f22d5042faa6
  - [net,v2,5/5] tcp: bound the rto_min of a route in tcp_rto_min()
    https://git.kernel.org/netdev/net/c/314b35c8173c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads