Netdev List
 help / color / mirror / Atom feed
* [PATCH net] tcp: clamp the u64 delta in tcp_rcv_rtt_measure()
@ 2026-12-03 20:45 Chris Mason
  2026-12-04  6:16 ` Jiayuan Chen
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Mason @ 2026-12-03 20:45 UTC (permalink / raw)
  To: edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms, willemb,
	josef, netdev, mason

TCP autotuning can leave the receive buffer too small if the sender
takes more than 71 minutes to fill a receive window.

tcp_rcv_rtt_measure() uses that time as an RTT sample, but truncates it
to u32 before tcp_rcv_rtt_update() clamps it:

    tcp_mstamp - rcv_rtt_est.time = 4295000000 us
    (u32)4295000000               = 32704 us
    min(32704, TCP_RTT_MAX_US)    = 32704 us

Without TCP timestamps, autotuning keeps the smallest sample as its RTT
estimate for the rest of the connection.

The fix used here is to clamp the sample while it is still a u64.

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: 645f4c6f2ebd ("tcp: switch rcv_rtt_est and rcvq_space to high resolution timestamps")
Signed-off-by: Chris Mason <mason@kernel.org>
---
 net/ipv4/tcp_input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 50c0da17923e4..0bbb0ed71469b 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -895,7 +895,7 @@ static inline void tcp_rcv_rtt_measure(struct tcp_sock *tp)
 		goto new_measure;
 	if (before(tp->rcv_nxt, tp->rcv_rtt_est.seq))
 		return;
-	delta_us = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcv_rtt_est.time);
+	delta_us = min(tp->tcp_mstamp - tp->rcv_rtt_est.time, TCP_RTT_MAX_US);
 	if (!delta_us)
 		delta_us = 1;
 	tcp_rcv_rtt_update(tp, delta_us, 1);
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] tcp: clamp the u64 delta in tcp_rcv_rtt_measure()
  2026-12-03 20:45 [PATCH net] tcp: clamp the u64 delta in tcp_rcv_rtt_measure() Chris Mason
@ 2026-12-04  6:16 ` Jiayuan Chen
  0 siblings, 0 replies; 2+ messages in thread
From: Jiayuan Chen @ 2026-12-04  6:16 UTC (permalink / raw)
  To: Chris Mason, edumazet, ncardwell, kuniyu, davem, kuba, pabeni,
	horms, willemb, josef, netdev



On 12/4/26 4:45 AM, Chris Mason wrote:
> TCP autotuning can leave the receive buffer too small if the sender
> takes more than 71 minutes to fill a receive window.
>
> tcp_rcv_rtt_measure() uses that time as an RTT sample, but truncates it
> to u32 before tcp_rcv_rtt_update() clamps it:
>
>     tcp_mstamp - rcv_rtt_est.time = 4295000000 us
>     (u32)4295000000               = 32704 us
>     min(32704, TCP_RTT_MAX_US)    = 32704 us

The math is right, but in practice it needs a lot of conditions to actually hit this.

> Without TCP timestamps, autotuning keeps the smallest sample as its RTT
> estimate for the rest of the connection.
>
> The fix used here is to clamp the sample while it is still a u64.
>
> 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: 645f4c6f2ebd ("tcp: switch rcv_rtt_est and rcvq_space to high resolution timestamps")
> Signed-off-by: Chris Mason <mason@kernel.org>

Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>

> ---
>  net/ipv4/tcp_input.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 50c0da17923e4..0bbb0ed71469b 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -895,7 +895,7 @@ static inline void tcp_rcv_rtt_measure(struct tcp_sock *tp)
>  		goto new_measure;
>  	if (before(tp->rcv_nxt, tp->rcv_rtt_est.seq))
>  		return;
> -	delta_us = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcv_rtt_est.time);
> +	delta_us = min(tp->tcp_mstamp - tp->rcv_rtt_est.time, TCP_RTT_MAX_US);
>  	if (!delta_us)
>  		delta_us = 1;
>  	tcp_rcv_rtt_update(tp, delta_us, 1);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04  6:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 20:45 [PATCH net] tcp: clamp the u64 delta in tcp_rcv_rtt_measure() Chris Mason
2026-12-04  6:16 ` Jiayuan Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox