Skip to contentSkip to conversation

tcp: take care of zero tp->window_clamp in tcp_set_rcvlowat()

PATCH Applied Eric Dumazet 4 participants 4 messages Oct 3, 2025 – Oct 6, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: take care of zero tp->window_clamp in tcp_set_rcvlowat()

Some applications (like selftests/net/tcp_mmap.c) call SO_RCVLOWAT on their listener, before accept().

This has an unfortunate effect on wscale selection in tcp_select_initial_window() during 3WHS.

For instance, tcp_mmap was negotiating wscale 4, regardless of tcp_rmem[2] and sysctl_rmem_max.

Do not change tp->window_clamp if it is zero
or bigger than our computed value.

Zero value is special, it allows tcp_select_initial_window() to enable autotuning.

Note that SO_RCVLOWAT use on listener is probably not wise, because tp->scaling_ratio has a default value, possibly wrong.

Fixes d1361840f8c5 ("tcp: fix SO_RCVLOWAT and RCVBUF autotuning")
---
 net/ipv4/tcp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp.c +4 -1
index 7949d16506a46eb561479b77bebce4fe88971c12..8a18aeca7ab07480844946120f51a0555699b4c3 100644
@@ -1791,6 +1791,7 @@ EXPORT_IPV6_MOD(tcp_peek_len);
 /* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */
 int tcp_set_rcvlowat(struct sock *sk, int val)
 {
+	struct tcp_sock *tp = tcp_sk(sk);
 	int space, cap;
 
 	if (sk->sk_userlocks & SOCK_RCVBUF_LOCK)
@@ -1809,7 +1810,9 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
 	space = tcp_space_from_win(sk, val);
 	if (space > sk->sk_rcvbuf) {
 		WRITE_ONCE(sk->sk_rcvbuf, space);
-		WRITE_ONCE(tcp_sk(sk)->window_clamp, val);
+
+		if (tp->window_clamp && tp->window_clamp < val)
+			WRITE_ONCE(tp->window_clamp, val);
 	}
 	return 0;
 }
Signature · 1 line
2.51.0.618.g983fd99d29-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Eric Dumazet

Some applications (like selftests/net/tcp_mmap.c) call SO_RCVLOWAT on their listener, before accept().

This has an unfortunate effect on wscale selection in tcp_select_initial_window() during 3WHS.

For instance, tcp_mmap was negotiating wscale 4, regardless of tcp_rmem[2] and sysctl_rmem_max.

Do not change tp->window_clamp if it is zero
or bigger than our computed value.

Quoted 8 lines

Zero value is special, it allows tcp_select_initial_window() to enable autotuning.

Note that SO_RCVLOWAT use on listener is probably not wise, because tp->scaling_ratio has a default value, possibly wrong.

Fixes d1361840f8c5 ("tcp: fix SO_RCVLOWAT and RCVBUF autotuning")

Thanks!

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Eric Dumazet
Quoted 13 lines · Eric Dumazet

Some applications (like selftests/net/tcp_mmap.c) call SO_RCVLOWAT on their listener, before accept().

This has an unfortunate effect on wscale selection in tcp_select_initial_window() during 3WHS.

For instance, tcp_mmap was negotiating wscale 4, regardless of tcp_rmem[2] and sysctl_rmem_max.

Do not change tp->window_clamp if it is zero
or bigger than our computed value.

Quoted 8 lines

Zero value is special, it allows tcp_select_initial_window() to enable autotuning.

Note that SO_RCVLOWAT use on listener is probably not wise, because tp->scaling_ratio has a default value, possibly wrong.

Fixes d1361840f8c5 ("tcp: fix SO_RCVLOWAT and RCVBUF autotuning")

Thanks, Eric!

neal

#3 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Fri, 3 Oct 2025 18:41:19 +0000 you wrote:

Some applications (like selftests/net/tcp_mmap.c) call SO_RCVLOWAT on their listener, before accept().

This has an unfortunate effect on wscale selection in tcp_select_initial_window() during 3WHS.

For instance, tcp_mmap was negotiating wscale 4, regardless of tcp_rmem[2] and sysctl_rmem_max.

[...]

Here is the summary with links:
- [net] tcp: take care of zero tp->window_clamp in tcp_set_rcvlowat()

    https://git.kernel.org/netdev/net/c/21b29e74ffe5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html