Thread View: linux.kernel.netdev
4 messages
4 total messages
Started by Chris Mason
Wed, 18 Nov 2026 15:51
[PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update()
Author: Chris Mason
Date: Wed, 18 Nov 2026 15:51
Date: Wed, 18 Nov 2026 15:51
48 lines
9213 bytes
9213 bytes
tcp_rcv_rtt_update() starts with sample << 3 in u32 arithmetic, so a
sample of 536.9 s or more wraps.
tcp_rcv_rtt_measure() can hand it one. Its sample is the time the sender
took to fill one receive window, and a low rate flow can take longer
than that. This caller only looks for a minimum, so the wrapped value is
kept whenever it is below the current estimate. A 540 s sample ends up
as an estimate of about 3.1 s.
Clamp the sample to TCP_RTT_MAX_US in tcp_rcv_rtt_update(), like
tcp_rtt_estimator() does on the send side. That covers both callers, and
the smoothed estimate now tops out at 8 * 120 s, which fits in a u32.
Found by code inspection (Eric Dumazet), who also suggested the fix.
Confirmed with an LLM generated reproducer on an unmodified kernel, and
tested with the reproducer and existing kernel selftests.
Fixes: 645f4c6f2ebd ("tcp: switch rcv_rtt_est and rcvq_space to high resolution timestamps")
Suggested-by: Eric Dumazet <edumazet@kernel.org>
Signed-off-by: Chris Mason <mason@kernel.org>
---
Notes:
v1->v2: new patch (Eric), with min() instead of min_t() (David)
net/ipv4/tcp_input.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 69e038b9389a..d9a66a1342ef 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -857,7 +857,11 @@ void tcp_initialize_rcv_mss(struct sock *sk)
static void tcp_rcv_rtt_update(struct tcp_sock *tp, u32 sample, int win_dep)
{
u32 new_sample, old_sample = tp->rcv_rtt_est.rtt_us;
- long m = sample << 3;
+ long m;
+
+ /* Keep sample << 3 and the smoothed estimate within u32. */
+ sample = min(sample, TCP_RTT_MAX_US);
+ m = sample << 3;
if (old_sample == 0 || m < old_sample) {
new_sample = m;
--
2.55.0
Re: [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update()
Author: Eric Dumazet
Date: Wed, 18 Nov 2026 16:34
Date: Wed, 18 Nov 2026 16:34
31 lines
10082 bytes
10082 bytes
Le mer. 18 nov. 2026 à 16:51, Chris Mason <mason@kernel.org> a écrit :
>
> tcp_rcv_rtt_update() starts with sample << 3 in u32 arithmetic, so a
> sample of 536.9 s or more wraps.
>
> tcp_rcv_rtt_measure() can hand it one. Its sample is the time the sender
> took to fill one receive window, and a low rate flow can take longer
> than that. This caller only looks for a minimum, so the wrapped value is
> kept whenever it is below the current estimate. A 540 s sample ends up
> as an estimate of about 3.1 s.
>
> Clamp the sample to TCP_RTT_MAX_US in tcp_rcv_rtt_update(), like
> tcp_rtt_estimator() does on the send side. That covers both callers, and
> the smoothed estimate now tops out at 8 * 120 s, which fits in a u32.
>
> Found by code inspection (Eric Dumazet), who also suggested the fix.
> Confirmed with an LLM generated reproducer on an unmodified kernel, and
> tested with the reproducer and existing kernel selftests.
>
> Fixes: 645f4c6f2ebd ("tcp: switch rcv_rtt_est and rcvq_space to high resolution timestamps")
> Suggested-by: Eric Dumazet <edumazet@kernel.org>
> Signed-off-by: Chris Mason <mason@kernel.org>
> ---
>
> Notes:
> v1->v2: new patch (Eric), with min() instead of min_t() (David)
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Re: [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update()
Author: netdev-bot+sashiko
Date: Wed, 18 Nov 2026 18:23
Date: Wed, 18 Nov 2026 18:23
106 lines
11789 bytes
11789 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
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).
- [High] The fix is incomplete.
- [Low] The comment on TCP_RTT_MAX_US in include/net/tcp.h (lines
167-172) still says it is the 'Max RTT sample for tcp_rtt_estimator()'…
--
tcp: clamp the samples in tcp_rcv_rtt_update()
This patch clamps the sample passed to tcp_rcv_rtt_update() to
TCP_RTT_MAX_US before the shift left by 3. The goal is that a
receive-window fill time of 536.9 s or more no longer wraps in u32
arithmetic. The commit message says this covers both callers of
tcp_rcv_rtt_update().
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 69e038b9389ae..d9a66a1342efd 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -857,7 +857,11 @@ void tcp_initialize_rcv_mss(struct sock *sk)
> static void tcp_rcv_rtt_update(struct tcp_sock *tp, u32 sample, int win_dep)
> {
> u32 new_sample, old_sample = tp->rcv_rtt_est.rtt_us;
> - long m = sample << 3;
> + long m;
> +
> + /* Keep sample << 3 and the smoothed estimate within u32. */
> + sample = min(sample, TCP_RTT_MAX_US);
> + m = sample << 3;
[Severity: High]
Can a long window-fill time still wrap before it gets to this clamp?
In tcp_rcv_rtt_measure(), the sample comes from tcp_stamp_us_delta():
net/ipv4/tcp_input.c:tcp_rcv_rtt_measure() {
...
delta_us = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcv_rtt_est.time);
if (!delta_us)
delta_us = 1;
tcp_rcv_rtt_update(tp, delta_us, 1);
...
}
That helper narrows the s64 difference to u32:
include/net/tcp.h:
static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0)
{
return max_t(s64, t1 - t0, 0);
}
So by the time min() sees an interval of 2^32 us (about 4295 s) or more,
it has already been reduced modulo 2^32.
For example, a 4300 s window-fill time arrives here as 5,032,704 us
(about 5.03 s). That passes the 120 s clamp unchanged. With win_dep=1 it
is stored when old_sample == 0 or when m < old_sample.
The only writer of rcv_rtt_est.time is the new_measure label in
tcp_rcv_rtt_measure(), and nothing resets a pending measurement when the
connection goes idle. The window-completing segment could arrive after
more than about 72 minutes of idle time or a slow sender. Would that
still hit the case the commit message describes, where "the wrapped
value is kept whenever it is below the current estimate", only with a
higher threshold?
Without timestamps the win_dep path only lowers the estimate. A bogus
small value would stay for the life of the connection.
Would it be better to clamp the 64-bit delta in tcp_rcv_rtt_measure()
before it is narrowed to u32?
[Severity: Low]
This isn't a bug, but the comment on TCP_RTT_MAX_US in include/net/tcp.h
still describes the constant only in terms of tcp_rtt_estimator() and the
RTO:
/* Max RTT sample for tcp_rtt_estimator(). srtt_us holds 8 times the RTT, and
* mdev_us and rttvar_us up to 4 times its deviation, all in u32, like the sum
* in __tcp_set_rto(). A larger sample could not raise the RTO, which
* TCP_RTO_MAX bounds.
*/
#define TCP_RTT_MAX_US (TCP_RTO_MAX_SEC * USEC_PER_SEC)
After this patch, tcp_rcv_rtt_update() also relies on 8 * TCP_RTT_MAX_US
fitting in u32 for rcv_rtt_est.rtt_us, which is not an input to
__tcp_set_rto(). tcp_rtt_tsopt_us() also uses the constant.
Could the header comment be extended to cover the receive-side users?
Alternatively, a static_assert could check that TCP_RTT_MAX_US << 3 fits
in a u32.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118155144.18393-1-mason%40kernel.org
Re: [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update()
Author: "Chris Mason"
Date: Wed, 18 Nov 2026 18:48
Date: Wed, 18 Nov 2026 18:48
24 lines
10723 bytes
10723 bytes
On Wed, 18 Nov 2026 18:23:03 +0000, netdev-bot+sashiko@kernel.org wrote: > [Severity: High] > Can a long window-fill time still wrap before it gets to this clamp? tcp_stamp_us_delta() narrows the delta to u32 first, so from 4295 s on the clamp sees what is left of it. Your 4300 s example is right. It takes a flow that needs more than 71 minutes to fill one receive window, so I don't think it's as bad as High, but the changelog says the patch covers both callers and for this one that isn't true yet. > Would it be better to clamp the 64-bit delta in tcp_rcv_rtt_measure() > before it is narrowed to u32? Yes, so I can spin a v3 with this change, or make a follow up, I'll defer to netdev maintainers: - delta_us = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcv_rtt_est.time); + /* Clamp the delta before it is narrowed to u32. */ + delta_us = min_t(u64, tp->tcp_mstamp - tp->rcv_rtt_est.time, + TCP_RTT_MAX_US); -chris
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