From nobody Mon Jun 15 07:40:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5792F364924; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; cv=none; b=svI6UuUTVyMh4tWzEF/0DaFnLyuCM6KeMA4crGSJ1Dv9ZxBIocrFE/TiKZyTjKv2HOGaB1aneKvRT5qWzMRAjNIzQ5pc7pFDtMZeRXTYw7iaf7UcMjGsj7LKB+1h2x125ZuW3w8AnXm+ECjdS+sQT5iSF+2XzxQYJML4iMzZHa0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; c=relaxed/simple; bh=wF7RtoJqCsp7VoLarCmy8QgMT99pPiY3eMv5KoPNKFI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pWWHRrda1bumhKDkGrivLormhl1Fzc8bYwUt2VncGRDlOvXDwbZvqaqjDYqvEZocAIIRR3Gj9AtQPG0D7DwDq8qB7wSiaT/HMuj5Bb7XiyePASuks6XhEPjGekiHTiTHCRYBMJi3PKcFCa/nx4jvDT/yvOyx5w5cjDHeoXUB8wM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XHEQVnLy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XHEQVnLy" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1EE30C2BC9E; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775685042; bh=wF7RtoJqCsp7VoLarCmy8QgMT99pPiY3eMv5KoPNKFI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=XHEQVnLyquFWsrFhVohD0Ne/8+CeYqCYyNUMIUlscn1StsmYOGS7cKIifC1vD/f14 PB7vpVZ7u/A+ZvyxBl3auBwUFitmIKc8OJyPqPmw9CZJ+YOniltblWeym5YcuZLE/r nS0I8ttabXI9X3tuDImSYz455vXLRsP92oxZeQXvkcHcDmuOPAT5lfnqmKushF/He0 rhGxPVxfodOz8DxJjQSGA1bLgvZOB8y1aot4raRHt9JNj9cEy8f60gZdCFMZhusxw6 r2O5/eUW9AE1RYyNcE7i9kdCTcddQNowhQ0Hwb709rL4bLaSXFQiY9cF5dHl8J9Drh upVTV6JFNOqHA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0771110FC44D; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Wed, 08 Apr 2026 23:50:02 +0200 Subject: [PATCH net-next 1/7] tcp: keep rcv_wnd/rcv_ssthresh clamped by window_clamp if no scaling in use Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-1-76a6f212e153@gmail.com> References: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> In-Reply-To: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775685040; l=3731; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=D5Yj7InMLE8s8H7wijn4PBjZo6pD1UsEIMIUKtUVqsI=; b=T0np/fm0cCfmsmopm+yAL64WwCWbKQ5xalMNOXDtqcWDarCXh4XgNcPAWLwjOAD74EK84mCTt 4BzDrMH7MxVBdK2sxWjq/soVkXrNEeyj2l6EenIRU9XJHC6IzbNNpi5 X-Developer-Key: i=gmbnomis@gmail.com; a=ed25519; pk=T/JIz/6F5bf1uQJr69lmyi7czVG+F9TVZ/8x5z9Wtqw= X-Endpoint-Received: by B4 Relay for gmbnomis@gmail.com/20260220 with auth_id=641 X-Original-From: Simon Baatz Reply-To: gmbnomis@gmail.com From: Simon Baatz When window scaling is not used, we already clamp window_clamp to 65535, but rcv_wnd/rcv_ssthresh can still remain larger than this. Fix this by capping rcv_wnd to 65535 in the non-scaling paths of both active and passive opens. Since the advertised window in SYN and SYN/ACK segments is unscaled, this cannot shrink the window advertised to the peer. Also ensure that tcp_select_initial_window() always keeps rcv_wnd less than or equal to the (scale-limited) window_clamp. Signed-off-by: Simon Baatz --- net/ipv4/tcp_input.c | 7 ++++++- net/ipv4/tcp_minisocks.c | 8 ++++++-- net/ipv4/tcp_output.c | 5 +++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 7171442c3ed7a..505884dcb7a2b 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6898,7 +6898,6 @@ static int tcp_rcv_synsent_state_process(struct sock = *sk, struct sk_buff *skb, */ WRITE_ONCE(tp->rcv_nxt, TCP_SKB_CB(skb)->seq + 1); tp->rcv_wup =3D TCP_SKB_CB(skb)->seq + 1; - tp->rcv_mwnd_seq =3D tp->rcv_wup + tp->rcv_wnd; =20 /* RFC1323: The window in SYN & SYN/ACK segments is * never scaled. @@ -6909,7 +6908,13 @@ static int tcp_rcv_synsent_state_process(struct sock= *sk, struct sk_buff *skb, tp->rx_opt.snd_wscale =3D tp->rx_opt.rcv_wscale =3D 0; WRITE_ONCE(tp->window_clamp, min(tp->window_clamp, 65535U)); + tp->rcv_ssthresh =3D min(tp->rcv_ssthresh, 65535U); + /* As the window in the SYN was not scaled, + * we did not advertise more than 65535. + */ + tp->rcv_wnd =3D min(tp->rcv_wnd, 65535U); } + tp->rcv_mwnd_seq =3D tp->rcv_wup + tp->rcv_wnd; =20 if (tp->rx_opt.saw_tstamp) { tp->rx_opt.tstamp_ok =3D 1; diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 199f0b579e89c..6496fe3b9e139 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -600,9 +600,7 @@ struct sock *tcp_create_openreq_child(const struct sock= *sk, newtp->rx_opt.tstamp_ok =3D ireq->tstamp_ok; newtp->rx_opt.sack_ok =3D ireq->sack_ok; newtp->window_clamp =3D req->rsk_window_clamp; - newtp->rcv_ssthresh =3D req->rsk_rcv_wnd; newtp->rcv_wnd =3D req->rsk_rcv_wnd; - newtp->rcv_mwnd_seq =3D newtp->rcv_wup + req->rsk_rcv_wnd; newtp->rx_opt.wscale_ok =3D ireq->wscale_ok; if (newtp->rx_opt.wscale_ok) { newtp->rx_opt.snd_wscale =3D ireq->snd_wscale; @@ -610,7 +608,13 @@ struct sock *tcp_create_openreq_child(const struct soc= k *sk, } else { newtp->rx_opt.snd_wscale =3D newtp->rx_opt.rcv_wscale =3D 0; newtp->window_clamp =3D min(newtp->window_clamp, 65535U); + /* As the window in the SYN/ACK was not scaled, + * we did not advertise more than 65535. + */ + newtp->rcv_wnd =3D min(newtp->rcv_wnd, 65535U); } + newtp->rcv_ssthresh =3D newtp->rcv_wnd; + newtp->rcv_mwnd_seq =3D newtp->rcv_wup + newtp->rcv_wnd; newtp->snd_wnd =3D ntohs(tcp_hdr(skb)->window) << newtp->rx_opt.snd_wscal= e; newtp->max_window =3D newtp->snd_wnd; =20 diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 8e99687526a64..bf7a12872acb3 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -269,8 +269,9 @@ void tcp_select_initial_window(const struct sock *sk, i= nt __space, __u32 mss, 0, TCP_MAX_WSCALE); } /* Set the clamp no higher than max representable value */ - WRITE_ONCE(*__window_clamp, - min_t(__u32, U16_MAX << (*rcv_wscale), window_clamp)); + window_clamp =3D min_t(u32, U16_MAX << (*rcv_wscale), window_clamp); + WRITE_ONCE(*__window_clamp, window_clamp); + *rcv_wnd =3D min(*rcv_wnd, window_clamp); } =20 /* Chose a new window to advertise, update state in tcp_sock for the --=20 2.53.0 From nobody Mon Jun 15 07:40:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 587C837268B; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; cv=none; b=L4mk1ve7XNczPFRtT2WZbJnknVdAW6ehPkJT/jx9CQBiL23DQnr8eCYxQXZszzUVE0oVanaqtsFuM2wc5geX4z3pPJeVngT1pTMTe74W81i5zRf0HlTm83vKTkIHmgfmcqJHn2GXeQC3c7zv9hwRA7wYcn0FKWXUQ6aMcejPZis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; c=relaxed/simple; bh=NXAlZswugSUiB4D4cG30HsE10gfwpu+78Cn2B0tMAH4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KsyKhtNhHsK4Yl2mI3nQCpejdFEuihJlC+cDfrcZI3kgBN74ue0K4AVGpCPvMXRdcAY7SHqEzFtlTQYqG3JpFEkrShXFsU2UIl8a0RdXLH+qw/J9M3a7aTtdFyRxlCI7TGf7p4r20wb4CBTETzKef6ZSK8hkxHQ4i4vxrA4cwV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s/gRb2FU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s/gRb2FU" Received: by smtp.kernel.org (Postfix) with ESMTPS id 29239C4AF0B; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775685042; bh=NXAlZswugSUiB4D4cG30HsE10gfwpu+78Cn2B0tMAH4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=s/gRb2FUGk20EQh7sh+RkHzbTA4UYr3j46WGjIJFuMB62JKLJ/CMW1EqDov0Oxlx7 Jl+aGi7VBzp2iv8H0LvCXMqy0Rm6XrTBzMulafdhFGpN7vtWNCkkmqrmU6zD8d+8sX OAMwkJpb+vI7agIZyS8Ho27Ab8OLuQMycYPUK9JFeQb678PIhw+A9suEtmqt15AuRw T2zR2UDKRXnKenfTcT+auLdaH0ssFONqmb+9VovUCJ19rhq0Kw+D5Jw5q2+IB/fvgN aj/1me16SSoMsmxvW0gn2jU1dVHPePcZZTDFj+AM9Df8UdXsa/gghZZlGYpwkspMP/ oVjm/zd6aROzA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A90010FC44F; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Wed, 08 Apr 2026 23:50:03 +0200 Subject: [PATCH net-next 2/7] selftests/net: packetdrill: verify non-scaled rcv_wnd initialization Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-2-76a6f212e153@gmail.com> References: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> In-Reply-To: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775685040; l=5710; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=vE5ahbPUORfc7BXPMMFoPZPw044dM5vYwM0HDuTK/k4=; b=g2mREI0J5JAwtc0Uy++tUoZhnp4evlRNHBw95JOmA8wSCOH1ed8mNvJ+QdUpTZTumvqA0jX9R R4myNc3ACMSDjFW35m0xNAIQ6Ffwdr2qybRQ1//UU+fRysdEBlAzil+ X-Developer-Key: i=gmbnomis@gmail.com; a=ed25519; pk=T/JIz/6F5bf1uQJr69lmyi7czVG+F9TVZ/8x5z9Wtqw= X-Endpoint-Received: by B4 Relay for gmbnomis@gmail.com/20260220 with auth_id=641 X-Original-From: Simon Baatz Reply-To: gmbnomis@gmail.com From: Simon Baatz If we or our peer do not support window scaling in an active or passive open, we must restrict rcv_wnd to 65535. Signed-off-by: Simon Baatz --- .../packetdrill/tcp_rcv_wnd_active_no_scaling.pkt | 27 +++++++++++++++++++ .../tcp_rcv_wnd_active_peer_no_scaling.pkt | 26 +++++++++++++++++++ .../packetdrill/tcp_rcv_wnd_passive_no_scaling.pkt | 30 ++++++++++++++++++= ++++ .../tcp_rcv_wnd_passive_peer_no_scaling.pkt | 29 ++++++++++++++++++= +++ 4 files changed, 112 insertions(+) diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_active_no_= scaling.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_active_no= _scaling.pkt new file mode 100644 index 0000000000000..d39f834299fec --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_active_no_scaling= .pkt @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// If we do not support window scaling in an active open, we must +// restrict rcv_wnd to 65535. + +`./defaults.sh +sysctl -q net.ipv4.tcp_window_scaling=3D0` + + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) =3D 4 + +0 setsockopt(4, SOL_SOCKET, SO_RCVBUF, [256000], 4) =3D 0 + + +0...0 connect(4, ..., ...) =3D 0 + +0 > S 0:0(0) win 65535 + +0 < S. 0:0(0) ack 1 win 65535 + +0 > . 1:1(0) ack 1 + + +0 send(4, ..., 1000, 0) =3D 1000 + +0 > P. 1:1001(1000) ack 1 +// Beyond window ACK is dropped, causing an immediate ACK + +0 < . 65537:65537(0) ack 1001 win 65535 + +0 > . 1001:1001(0) ack 1 + + +.1 %{ assert tcpi_bytes_acked =3D=3D 1, tcpi_bytes_acked; }% + +// In window ACK is accepted + +0 < . 65536:65536(0) ack 1001 win 65535 + +.1 %{ assert tcpi_bytes_acked =3D=3D 1001, tcpi_bytes_acked; }% diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_active_pee= r_no_scaling.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_acti= ve_peer_no_scaling.pkt new file mode 100644 index 0000000000000..a212945996e85 --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_active_peer_no_sc= aling.pkt @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// If the peer does not support window scaling in an active open, we must +// restrict rcv_wnd to 65535. + +`./defaults.sh` + + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) =3D 4 + +0 setsockopt(4, SOL_SOCKET, SO_RCVBUF, [256000], 4) =3D 0 + + +0...0 connect(4, ..., ...) =3D 0 + +0 > S 0:0(0) win 65535 + +0 < S. 0:0(0) ack 1 win 65535 + +0 > . 1:1(0) ack 1 + + +0 send(4, ..., 1000, 0) =3D 1000 + +0 > P. 1:1001(1000) ack 1 +// Beyond window ACK is dropped, causing an immediate ACK + +0 < . 65537:65537(0) ack 1001 win 65535 + +0 > . 1001:1001(0) ack 1 + + +.1 %{ assert tcpi_bytes_acked =3D=3D 1, tcpi_bytes_acked; }% + +// In window ACK is accepted + +0 < . 65536:65536(0) ack 1001 win 65535 + +.1 %{ assert tcpi_bytes_acked =3D=3D 1001, tcpi_bytes_acked; }% diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_passive_no= _scaling.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_passive_= no_scaling.pkt new file mode 100644 index 0000000000000..907d452afc311 --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_passive_no_scalin= g.pkt @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// If we do not support window scaling in a passive open, we must +// restrict rcv_wnd to 65535. + +`./defaults.sh +sysctl -q net.ipv4.tcp_window_scaling=3D0` + + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) =3D 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) =3D 0 + +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [256000], 4) =3D 0 + +0 bind(3, ..., ...) =3D 0 + +0 listen(3, 1) =3D 0 + + +0 < S 0:0(0) win 32792 + +0 > S. 0:0(0) ack 1 win 65535 + +0 < . 1:1(0) ack 1 win 32792 + + +0 accept(3, ..., ...) =3D 4 + +0 send(4, ..., 1000, 0) =3D 1000 + +0 > P. 1:1001(1000) ack 1 +// Beyond window ACK is dropped, causing an immediate ACK + +0 < . 65537:65537(0) ack 1001 win 32792 + +0 > . 1001:1001(0) ack 1 + + +.1 %{ assert tcpi_bytes_acked =3D=3D 0, tcpi_bytes_acked; }% + +// In window ACK is accepted + +0 < . 65536:65536(0) ack 1001 win 32792 + +.1 %{ assert tcpi_bytes_acked =3D=3D 1000, tcpi_bytes_acked; }% diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_passive_pe= er_no_scaling.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_pas= sive_peer_no_scaling.pkt new file mode 100644 index 0000000000000..df88dd9b6f83e --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_passive_peer_no_s= caling.pkt @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// If the peer does not support window scaling in a passive open, we must +// restrict rcv_wnd to 65535. + +`./defaults.sh` + + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) =3D 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) =3D 0 + +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [256000], 4) =3D 0 + +0 bind(3, ..., ...) =3D 0 + +0 listen(3, 1) =3D 0 + + +0 < S 0:0(0) win 32792 + +0 > S. 0:0(0) ack 1 win 65535 + +0 < . 1:1(0) ack 1 win 32792 + + +0 accept(3, ..., ...) =3D 4 + +0 send(4, ..., 1000, 0) =3D 1000 + +0 > P. 1:1001(1000) ack 1 +// Beyond window ACK is dropped, causing an immediate ACK + +0 < . 65537:65537(0) ack 1001 win 32792 + +0 > . 1001:1001(0) ack 1 + + +.1 %{ assert tcpi_bytes_acked =3D=3D 0, tcpi_bytes_acked; }% + +// In window ACK is accepted + +0 < . 65536:65536(0) ack 1001 win 32792 + +.1 %{ assert tcpi_bytes_acked =3D=3D 1000, tcpi_bytes_acked; }% --=20 2.53.0 From nobody Mon Jun 15 07:40:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70ABA37D116; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; cv=none; b=TxSwLPXQn21dLy8LEBZB+h0jJXOkrAF8bYR87gaJIWtUOCzdK9Vgs61NfxWviQRWDDsBZj4BKa7Izw2mGbFKsKXT3nT7S0JPIbUQzfzloq1XHJjNz78xpzzmHSX5CKCZ6TNyS1Veecyh5cFbvoqLTOhhxWiID0TJUFCntPw4yWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; c=relaxed/simple; bh=4pWzV1h3heWEGQcfHFsxq1YGy4rq8ktVBtFrlR54Y1E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AtRVf6jd9E+dbS5+RYt6qpJAtjZVN38oURGDPcaVSFjyq4x63bVzZsrDEUHnnvbw6ZtFpu7nwkmRxNQNDw08r3GapRvkD4RIXJP13hvFxcf6U6v3MT+oPAmO8Da3WvnkA5mbVRUjaLr1PzGeZuPg/absR9xvpuASJKxqGC47zRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NFJf1IlG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NFJf1IlG" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3DB7AC2BCB0; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775685042; bh=4pWzV1h3heWEGQcfHFsxq1YGy4rq8ktVBtFrlR54Y1E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=NFJf1IlGdUoDKrvasjXaOY7dMRnm2t1Z8Q3CHvqcPY0fnRD03ZNUNR3Bi3vsf4Ed+ Edt8IwMeF7vw1r2UgkjCfv9FnslKB8sZTTg/JkVgsL3/8zOUHBTFQSdXFTYcTkAznj tlrdZjOvMboMawcce+thoVWq7TjmXIlT3K9thq1mswQ6zpKfeKlEdUxcRqcUlKgX9W +YBahdqmxDaIueygIrzoD5By5JcQDLwoijYv8aX22T176M3f0BfeNcxEvgkXVKQFdB cnCwsaZlkXr/nsDCGXRI8CDhQbq7YDYyS5iw3pqjDEy4ixIrJBYBWgnCYkeqzwA4d+ Y9MLqrD0dgUUQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AA7C10FC451; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Wed, 08 Apr 2026 23:50:04 +0200 Subject: [PATCH net-next 3/7] tcp: Ensure window_clamp is limited to representable window Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-3-76a6f212e153@gmail.com> References: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> In-Reply-To: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775685040; l=3305; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=8RoSAA/YzN+3F5cJqgh/h47kr9+FGErmiW1Qt/v8bjw=; b=pkGclS7fY07/CNGhI7e+WKGswdZ1Rp+LPibce79xhOMdvLomiPLlqKMcMYZQrIsNdkUCCQA/r DnQh49vpQNxCkyMg1ZdjrqsFZh9In7cJ/db9yEOQWxmhTCJKYP8tEeN X-Developer-Key: i=gmbnomis@gmail.com; a=ed25519; pk=T/JIz/6F5bf1uQJr69lmyi7czVG+F9TVZ/8x5z9Wtqw= X-Endpoint-Received: by B4 Relay for gmbnomis@gmail.com/20260220 with auth_id=641 X-Original-From: Simon Baatz Reply-To: gmbnomis@gmail.com From: Simon Baatz On connection initiation, window_clamp is limited to the maximum value representable for the connection's window scale factor. However, window_clamp may be changed later when: - it needs to be adjusted due to scaling_ratio changes - the receive buffer grows due to autotuning - the TCP_WINDOW_CLAMP socket option is set In all cases, window_clamp must not end up higher than the maximum representable advertised window. Thus, if the TCP connection state indicates that we can rely on rx_opt.rcv_wscale, clamp the new window_clamp to the maximum window for that scaling factor (including the "no window scaling" case where rcv_wscale is zero). This has visible consequences for calculations based on rcv_wnd. For example, the logic in __tcp_ack_snd_check() uses the advance of the right edge of the receive window to determine when to send an immediate ACK. If rcv_wnd does not properly reflect the "on the wire" advertised window (i.e. it is much higher than the maximum value representable), this calculation will be wrong and ACKs may be delayed when they should be sent immediately. One concrete example is when the TCP receive buffer is much larger than 64KB, but no window scaling is used. If window_clamp (and thus rcv_wnd) are not limited to 65535, the "internal" window based on rcv_wnd can extend far beyond the 16=E2=80=91bit window actually advertised= on the wire. After receiving a data segment, the right edge of the "on the wire" window can be moved (as there is plenty of space in rcv_wnd) and an immediate ACK should be sent. But, it won't do so if the calculation based on rcv_wnd does not happen to change "internal" window right edge. Signed-off-by: Simon Baatz --- net/ipv4/tcp.c | 4 ++++ net/ipv4/tcp_input.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e57eaffc007a0..bd03c99f793ae 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3802,6 +3802,10 @@ int tcp_set_window_clamp(struct sock *sk, int val) old_window_clamp =3D tp->window_clamp; new_window_clamp =3D max_t(int, SOCK_MIN_RCVBUF / 2, val); =20 + if ((1 << sk->sk_state) & (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT | + TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2)) + new_window_clamp =3D min_t(u32, U16_MAX << tp->rx_opt.rcv_wscale, new_wi= ndow_clamp); + if (new_window_clamp =3D=3D old_window_clamp) return 0; =20 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 505884dcb7a2b..6e9123c98152f 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -914,6 +914,7 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval) struct tcp_sock *tp =3D tcp_sk(sk); u32 rcvwin, rcvbuf, cap, oldval; u32 rtt_threshold, rtt_us; + u32 window_clamp; u64 grow; =20 oldval =3D tp->rcvq_space.space; @@ -949,8 +950,9 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval) if (rcvbuf > sk->sk_rcvbuf) { WRITE_ONCE(sk->sk_rcvbuf, rcvbuf); /* Make the window clamp follow along. */ - WRITE_ONCE(tp->window_clamp, - tcp_win_from_space(sk, rcvbuf)); + window_clamp =3D tcp_win_from_space(sk, rcvbuf); + window_clamp =3D min_t(u32, U16_MAX << tp->rx_opt.rcv_wscale, window_cla= mp); + WRITE_ONCE(tp->window_clamp, window_clamp); } } /* --=20 2.53.0 From nobody Mon Jun 15 07:40:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E55638839C; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; cv=none; b=THms7K8V+o+Zd4v8ptNzly+2KbJ7afj9ICqT/bZxFRwpJddABOXC+tPW++6VRz5JY1gtH+/TKcKdXJgQChNL036L8eYudHxArLFtp1PDRbOyayOV90XgtklGQfcIUvu6SdWzK79PDsOqC34ROFgo1KokY2LGeoivBjhZOa/k7BQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; c=relaxed/simple; bh=hRk7AedOBquVMuQbZKSP0j2rlUDei3LqUvzOUZS0iys=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qtucKP/ZF7ZsRwCOhz6CNPT2wQ89rJviBvtT3daGrd6ghmoUuPQMlz2VqX76j96Dn5XcTxXlgFyxzWtTLLSJNDv42dpFkL/ZhQHeKfETc6MkLT70PDJIOaQwftkttnGJUo2ZI5FAncvTdQtqatpRvcp85+cEpDGR4+hyxel3AMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rFVDdCXu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rFVDdCXu" Received: by smtp.kernel.org (Postfix) with ESMTPS id 44C00C4AF0F; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775685042; bh=hRk7AedOBquVMuQbZKSP0j2rlUDei3LqUvzOUZS0iys=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rFVDdCXuI9c3J7oE9ptfIdRKZSbLmhurunKU/j45chFd74NU3ebN0+kebY1TOOT2o c4tvdeU7gEoEKBk27etB6YRZ230J38wQKV8h76Y2oykJYw1pyNPpsl7M2yk3veKrj6 Ka73ZovCq+YjBTcXbpozno21jUasEuZSofzywoiN+ItPO0aNaFwtpS9Ue0+s5VHzru EDwQsZ/ayZwibzkoE12GAMTYliFK5+H+x1BOgn47lbsTvgvxxbM4AawzJUUjQPAHDY LfsYD6bzDqKDQSY8ftMrpQN0CWjjezL1O22lf9NvZRw43UsXrPEJGQFNzfbN6fwXAw DbrUKOxSZEQtQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 398AF10FC44E; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Wed, 08 Apr 2026 23:50:05 +0200 Subject: [PATCH net-next 4/7] selftests/net: packetdrill: add tcp_rcv_wnd_snd_ack_no_scaling.pkt Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-4-76a6f212e153@gmail.com> References: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> In-Reply-To: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775685040; l=2164; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=3UD78GSmL8ZM19AY/0d9FZwB1822EnTOwXfy0idIPhY=; b=63aS0f7Hf24M3Z/9aXF1uyxaeIDIWMqQkDKXmH8Hxy4rrkgc1FEZ7MtW3FgIkJvPfqK0z/qfd u97GMpuJIHPDF0MiaLdaaSjz5tHe8Pgvs16YbUeZWernVMwjfqY+hly X-Developer-Key: i=gmbnomis@gmail.com; a=ed25519; pk=T/JIz/6F5bf1uQJr69lmyi7czVG+F9TVZ/8x5z9Wtqw= X-Endpoint-Received: by B4 Relay for gmbnomis@gmail.com/20260220 with auth_id=641 X-Original-From: Simon Baatz Reply-To: gmbnomis@gmail.com From: Simon Baatz Verify that, when no TCP window scaling is used, each packet that substantially advances the right edge of the receive window is ACKed immediately. Multiple packets are used so that the scaling_ratio receive window adaptation can settle and does not by itself cause immediate ACKs, avoiding false positives. Signed-off-by: Simon Baatz --- .../packetdrill/tcp_rcv_wnd_snd_ack_no_scaling.pkt | 37 ++++++++++++++++++= ++++ 1 file changed, 37 insertions(+) diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_snd_ack_no= _scaling.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_snd_ack_= no_scaling.pkt new file mode 100644 index 0000000000000..41561b026da85 --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_snd_ack_no_scalin= g.pkt @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Every packet must be ACKed immediately if the right edge of receive win= dow +// advances substantially. This test verifies that behavior when the conne= ction +// does not use window scaling. +--mss=3D1000 + +`./defaults.sh` + +// Initialize connection + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) =3D 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) =3D 0 + +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [256000], 4) =3D 0 + +0 bind(3, ..., ...) =3D 0 + +0 listen(3, 1) =3D 0 + + +0 < S 0:0(0) win 32792 + +0 > S. 0:0(0) ack 1 win 65535 + +0 < . 1:1(0) ack 1 win 32792 + + +0 accept(3, ..., ...) =3D 4 + + +0 < P. 1:65001(65000) ack 1 win 32792 + +0 > . 1:1(0) ack 65001 win 65535 + +0 < P. 65001:130001(65000) ack 1 win 32792 + +0 > . 1:1(0) ack 130001 win 65535 + +0 < P. 130001:195001(65000) ack 1 win 32792 + +0 > . 1:1(0) ack 195001 win 65535 + +0 < P. 195001:260001(65000) ack 1 win 32792 + +0 > . 1:1(0) ack 260001 win 65535 + +0 < P. 260001:325001(65000) ack 1 win 32792 + +0 > . 1:1(0) ack 325001 win 65535 + +// reading all data does not open the window further -> no ACK + +0 read(4, ..., 325000) =3D 325000 + +0.2 < P. 325001:390001(65000) ack 1 win 32792 + +0 > . 1:1(0) ack 390001 win 65535 --=20 2.53.0 From nobody Mon Jun 15 07:40:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 843E438D6BA; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; cv=none; b=OnfSrmqIPV2CY5VyOeI2F9AWagJPWZZQialOILXZI6ZhOpFFi/IeqsWgt9KW0QaFKax6c4dpe2hJNVUcSmf2yMr1IeJkPjCx1tD2sXp4USPjoxzppQ6hQsgJm6l0GP44ABt2srWr42Kkc77mbW+d6izdJScfQPM/gdEMXiRlpGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; c=relaxed/simple; bh=e5aX09f01vYkyZoCut8vLCRQbxg7RF31Px93HMOteQc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jh8AjApSb25OnxpzWx0QwrwowoXe6PrTXcE9w3fYK85/NZ408v/sg9rQ9uGPAxXdgeWTgyGMkU0Z+pJF9li9LhrBe+dC3KBI+l9dCWaxgUInj3/+9VBz+ShDMQqCQzh3xomYf4R3Pkc6F7IONo3QPdxAkBIG9Bw7rFE9YjJsu5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OZnJ+z0B; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OZnJ+z0B" Received: by smtp.kernel.org (Postfix) with ESMTPS id 539B1C2BCB2; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775685042; bh=e5aX09f01vYkyZoCut8vLCRQbxg7RF31Px93HMOteQc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=OZnJ+z0BPcUIcLX4c4LXFxxyPMnocjn9Wc67wMrzpZ/9NehTd0fKR3N+MNWwZVxdN EpU+wh3HciMViFJGDKx704nPQdEyWGi5cpC8yCDrgnEDuQpe1OnTYZz/x48jHfQz6r zFPEHvoGXcIXCvej1umO24IK05aBD2QsbPQr4M7ZlDztrVJXiCCe86JcWfj/LW9lC3 p/4eXEPX1PeuaHjhvAKbo8kZB5RbwpXTcpeUVU9yv4j8Bp8wD6a3EvBcBqSZw7FK1M EpfV7Xk9ZnFcBRgVMAF0hXcf7QQ/5uj0SmnwtFKF1EUvHmBQ6TJf7b87gQXumd3GYv xHAh88sSCekfA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4971A10FC453; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Wed, 08 Apr 2026 23:50:06 +0200 Subject: [PATCH net-next 5/7] selftests/net: packetdrill: add TCP_WINDOW_CLAMP test Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-5-76a6f212e153@gmail.com> References: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> In-Reply-To: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775685040; l=1779; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=hTLTER1y0lqFNVxFYgmLQOhJrfwaiyL20oWEx5ESl0s=; b=3LrMJhspiTFgK4hTMJxNxNE0+Cy3LA+4CJRvHndFJSg8VcDt4Mo8qZUb+b2ZSwOQiH3LYup9X xj6E/4b/5RwDf4i4f4vfoGWlfSpcJ6oOPHWRKkPHTLLaFCWWRcoigDY X-Developer-Key: i=gmbnomis@gmail.com; a=ed25519; pk=T/JIz/6F5bf1uQJr69lmyi7czVG+F9TVZ/8x5z9Wtqw= X-Endpoint-Received: by B4 Relay for gmbnomis@gmail.com/20260220 with auth_id=641 X-Original-From: Simon Baatz Reply-To: gmbnomis@gmail.com From: Simon Baatz Add a packetdrill test to verify that the socket option TCP_WINDOW_CLAMP can be set to a large value on a listening socket, but is clamped on an established socket to the maximum representable advertised window. Signed-off-by: Simon Baatz --- .../net/packetdrill/tcp_rcv_sockopt_wnd_clamp.pkt | 28 ++++++++++++++++++= ++++ 1 file changed, 28 insertions(+) diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_sockopt_wnd_cl= amp.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_sockopt_wnd_clamp= .pkt new file mode 100644 index 0000000000000..d7203f2893c3f --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_sockopt_wnd_clamp.pkt @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Verify that TCP_WINDOW_CLAMP can be set to a high value on a LISTEN soc= ket, but, +// in an established connection, the value is clamped to the maximum repre= sentable +// advertised window. +--mss=3D1000 + +`./defaults.sh` + +// Initialize connection + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) =3D 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) =3D 0 + +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [256000], 4) =3D 0 + +0 setsockopt(3, IPPROTO_TCP, 10, [255999], 4) =3D 0 // TCP_WINDOW_CLA= MP =3D=3D 10 + +0 getsockopt(3, IPPROTO_TCP, 10, [255999], [4]) =3D 0 + +0 bind(3, ..., ...) =3D 0 + +0 listen(3, 1) =3D 0 + + +0 < S 0:0(0) win 32792 + +0 > S. 0:0(0) ack 1 win 65535 + +0 < . 1:1(0) ack 1 win 32792 + + +0 accept(3, ..., ...) =3D 4 + + +0 getsockopt(4, IPPROTO_TCP, 10, [65535], [4]) =3D 0 + +0 setsockopt(4, IPPROTO_TCP, 10, [255999], 4) =3D 0 + +0 getsockopt(4, IPPROTO_TCP, 10, [65535], [4]) =3D 0 + +0 getsockopt(3, IPPROTO_TCP, 10, [255999], [4]) =3D 0 --=20 2.53.0 From nobody Mon Jun 15 07:40:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BADB38E5CE; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; cv=none; b=riE8ypYeBg9lvjy2DJp516MFWBFHzTY2EBXT1RXlRPb2L/scnfKn1kxAukX1ZUC1TFwDNfN+K/5c0WntUjKIi/roLdCxU+nataw/dsKoBPsSsxO7MuqrMW7PvpE699uoGPLmqol3arWgbbiiH8PX3+p9ScU+RfBmktC8X6POeVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; c=relaxed/simple; bh=VneR4pbgcqIN6sbPwlCfN6IcWDCyTCfy1kooH0Z8SEg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ADM2rwysBt+/esqSdIpvNEQbfzdYIyTCzlHZtIzqf3Ta3Y31VA+JOkQOEJQp3UMQQdwOQaY2AQuUHpcF1kkLG2inc6y39ms+cZNkV4ABaujjaiQUMXJdoyUJjZEDVzwQZ7WaeuI1AEutRnLQ3+ZOBX58d6NSvt7qfpiCoOgqLV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=egtbCO5z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="egtbCO5z" Received: by smtp.kernel.org (Postfix) with ESMTPS id 64D1FC2BCB3; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775685042; bh=VneR4pbgcqIN6sbPwlCfN6IcWDCyTCfy1kooH0Z8SEg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=egtbCO5zPF1jrXVR1eWvexRck8sPeR936+OBVm1qiX3LBga8A6HpkoRedbg0V6swH 2pk2gdRCaY/v7ubKv2/AnmUYnfj72XQw1gjtwYVEBJvO8L9oCSWR5iLwoB0QSOoSKj rHTc1uy2Ea4wXcVWTXkw6ooK8LGx4XDQJInaew0KNwI0v96hotOBbD1WhNxL9LjJAv 81oUzheP5M24tYExFRNmpOoLRLvTViNHk9zf2pHX/kR58TFwYJNbfbKDPHJySkmztY q7Bra6l8Vvy5fdmpTdgPcaOZgNXiYHWOZjWOqhDheAHg0ECRpUijGYDARk1LOOan4e vUnApUy1w5YAQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C3F010FC450; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Wed, 08 Apr 2026 23:50:07 +0200 Subject: [PATCH net-next 6/7] tcp: use tcp_set_window_clamp() for SO_RCVLOWAT Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-6-76a6f212e153@gmail.com> References: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> In-Reply-To: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775685040; l=840; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=YX2cO/5mpSzXQomZxTf4zIIjeQiySv9/NccTLoZ6hE8=; b=uSmFS+H0UrO5bmZ2d6kTWUrR2F8Q2onjHcSAGM7MOr6umiI6WvCeOqE2IJI50FZMizn6xiGkZ E2/EnAMitWpCzHEVQcKmizcdmqtu+KYw6DBcEy5uYFSSNGs3IsH4T6T X-Developer-Key: i=gmbnomis@gmail.com; a=ed25519; pk=T/JIz/6F5bf1uQJr69lmyi7czVG+F9TVZ/8x5z9Wtqw= X-Endpoint-Received: by B4 Relay for gmbnomis@gmail.com/20260220 with auth_id=641 X-Original-From: Simon Baatz Reply-To: gmbnomis@gmail.com From: Simon Baatz Setting the SO_RCVLOWAT socket option may raise the receive window clamp. Currently this is done by assigning to window_clamp directly. Use the tcp_set_window_clamp() helper instead, so that raising the clamp is subject to the same constraints and rcv_ssthresh adjustments as TCP_WINDOW_CLAMP. Signed-off-by: Simon Baatz --- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index bd03c99f793ae..567027bc86b3f 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1853,7 +1853,7 @@ int tcp_set_rcvlowat(struct sock *sk, int val) WRITE_ONCE(sk->sk_rcvbuf, space); =20 if (tp->window_clamp && tp->window_clamp < val) - WRITE_ONCE(tp->window_clamp, val); + tcp_set_window_clamp(sk, val); } return 0; } --=20 2.53.0 From nobody Mon Jun 15 07:40:18 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9484D391E76; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; cv=none; b=OIiPBSqfgVL2CqHpVDVtvHIeKdxPAKTwM+gDTOWfH+qX0r8UvxPUXyHGUghv31ItLbXCouZAoDIMywbhEd07T4kSc5PKKvaGHJY0pcNTPaD/CeD2VilwgurLiYtUgjrzRO0yajL0jgOb+YklR+wr7Sn0r+4ApTAVCAsEg/G1/Lc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775685042; c=relaxed/simple; bh=tZoQmXkp15Vh9OQaWsiwo6JmIaYjxK5EBrx7AlOMVuM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VujFVWwjmqqqumoaKJt7SMNFl7Y4bWiAQZ8+wOsmtzDJFj1yrUdIyEjbJ8nsOs9bOwkR4D+Yf/M+kWazPr9UjCE+k9y2H3UhnODeDwbz3mkXDSpayuFBsqJ3iS8dpL/3XRHzGHHcEmgsiCyVJ+EMPyJlhpx51Fy0bx3W456TqEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BGWLIxIv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BGWLIxIv" Received: by smtp.kernel.org (Postfix) with ESMTPS id 75BA4C2BCB5; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775685042; bh=tZoQmXkp15Vh9OQaWsiwo6JmIaYjxK5EBrx7AlOMVuM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=BGWLIxIvHyXwJ5Ps8qxkFd8RCJSoBP74BQU52uIALiIirtFnqu39jhCmDyttJYLGd N9FxFXfMAmNAlz3OWXX9sYmSAiflwn9aK7P6mnZtouYjmxhEZERPMpZx02OUtu4S8b KLN649KThsesXJDZiii5mefHSoC2dReswOAC/9neJCFmyRuw8lS42KqnxK/jQt9lt1 9YNwRbs8Ir6W1oWjX3HQ9fmthFIohRoD36J5HfOYfBKzTLrGh4h/w4HyesbVs0Xyg1 Zj6kdM45+1pvnGwFdAwjHifbqGrxo4cehuB1ym88Dom1yNSOOBBWbWiWKojycQfVOc +MCcYn2BdBMHg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D49010FC454; Wed, 8 Apr 2026 21:50:42 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Wed, 08 Apr 2026 23:50:08 +0200 Subject: [PATCH net-next 7/7] selftests/net: packetdrill: add test for SO_RCVLOWAT window clamp Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-7-76a6f212e153@gmail.com> References: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> In-Reply-To: <20260408-tcp_rcv_exact_clamp_and_wnd-v1-0-76a6f212e153@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , David Ahern , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775685040; l=1463; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=gC0dAmHTD0G0+YB4UA/xKTisIbrfSqAJXrxt8JMOFa4=; b=rBkIil9wGCCLnI/BoDylQdp1r0FU0d9tXIMG+PSJZZcpFkTSI3sRW/N6FUfXLIQxZmJgTWRYY VXHpem9VBQ6D+Vl3yQ5oxiCrDbsMl26yVdVZdBQgnZpQZAFKiqOjmhR X-Developer-Key: i=gmbnomis@gmail.com; a=ed25519; pk=T/JIz/6F5bf1uQJr69lmyi7czVG+F9TVZ/8x5z9Wtqw= X-Endpoint-Received: by B4 Relay for gmbnomis@gmail.com/20260220 with auth_id=641 X-Original-From: Simon Baatz Reply-To: gmbnomis@gmail.com From: Simon Baatz Add a packetdrill test to verify that setting SO_RCVLOWAT does not raise window_clamp beyond the maximum value allowed by window scaling. Signed-off-by: Simon Baatz --- .../net/packetdrill/tcp_rcv_sockopt_lowat.pkt | 24 ++++++++++++++++++= ++++ 1 file changed, 24 insertions(+) diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_sockopt_lowat.= pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_sockopt_lowat.pkt new file mode 100644 index 0000000000000..c024f3953f5a4 --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_sockopt_lowat.pkt @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Verify that setting SO_RCVLOWAT does not set window_clamp higher than t= he +// maximum value allowed by window scaling. +--mss=3D1000 + +`./defaults.sh` + +// Initialize connection + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) =3D 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) =3D 0 + +0 bind(3, ..., ...) =3D 0 + +0 listen(3, 1) =3D 0 + + +0 < S 0:0(0) win 32792 + +0 > S. 0:0(0) ack 1 win 65535 + +0 < . 1:1(0) ack 1 win 32792 + + +0 accept(3, ..., ...) =3D 4 + + +0 getsockopt(4, IPPROTO_TCP, 10, [65535], [4]) =3D 0 // TCP_WINDOW_CLA= MP =3D=3D 10 + +0 setsockopt(4, SOL_SOCKET, SO_RCVLOWAT, [1024000], 4) =3D 0 + +0 getsockopt(4, SOL_SOCKET, SO_RCVLOWAT, [1024000], [4]) =3D 0 + +0 getsockopt(4, IPPROTO_TCP, 10, [65535], [4]) =3D 0 --=20 2.53.0