From nobody Tue Apr 7 14:41:59 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 651D21F12E9; Thu, 26 Feb 2026 00:49:26 +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=1772066966; cv=none; b=ASevISZrBQs0EA6NFsQ6NOQzvVbNzsLHuDZoxRRSFDHlkRg35oPi7KFLQUHpr9xH67h5Bs6YuW6ocgTMdVJAqocK/5EREuyDNM5xJEHJTfOW0B7VyGNOfcRcPAsV/QG/354hXwgNvhM2KkkeQyhp4H/nbvmn1UC4PVieZAEirp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772066966; c=relaxed/simple; bh=8m7uRlrXEDmuadjPLt3NSBGHH5dQ+esdpAE2KuvNT5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ABharKfuC6wHbIMXugBen819hb3Kf36NQkEe/zQ+3+IYLbA6TnJIbnXr+xZANCHQaTIpItjtXTw9Um61Nntu81FeoC/NbxNNyWmICy90Wi8Dfe1/6DGf6YPt5AeTec+mItz2olzb8oGZyte6YYX45YVP21EfbuxevHNQMsa2CIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XpAQGlLn; 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="XpAQGlLn" Received: by smtp.kernel.org (Postfix) with ESMTPS id 36B3CC19425; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772066966; bh=8m7uRlrXEDmuadjPLt3NSBGHH5dQ+esdpAE2KuvNT5g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=XpAQGlLnhnPBzfxqBh2mvB0S7oo/2zS6rfrOgt6BRhdDwmHKNSp+CsLekV8evhLeY u2qNcO5eQaAuptCG00Spz/bvGDPuFaoSqZfa5FivQw9u644YPzOFq3UXB9PNz2jpfs X7Knr+R40GxNEMjb2D7GJjVGluhd2x/ovsrntPyevEoD8kaeEwfW2rRGAxGGRtOCus KtTKq5JsqrnWcuLHA1oHbCAx6/qcQd1dOZUeNb/MI8exR27tKodekmp7fg3xqjQxsd kc8whopNypOTQyBBJXKz8G1fK+HQbX3CVaxLvtXXoWEdfiaTFyf6qWZFNQNNOi0iYg 0EwgbPE80Yf/A== 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 24ECAFD45FE; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Thu, 26 Feb 2026 01:49:07 +0100 Subject: [PATCH RFC net-next v2 1/5] tcp: implement RFC 7323 window retraction receiver requirements 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: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-1-aa3f8f9cc639@gmail.com> References: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> In-Reply-To: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , David Ahern , Stefano Brivio , Jon Maloy , Jason Xing , mfreemon@cloudflare.com, Shuah Khan , Stefano Brivio Cc: Christian Ebner , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1772066964; l=11321; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=4XZ8Pr+xaKfMht4eFNKhU8kxZLbyq5G7MUR6m7XvNg4=; b=NyPbIZ75EReTVliP2OPZxVV0KJFBCAjJzy5bGfb/5l+mx+EkLTxJft/KkDRV4GpO4ubhQp6VC Ns8L/q1QeeFDhk1GiTImHF9l6m1MgpO0HUyR/KyPsquV78n90Uf6I0U 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 By default, the Linux TCP implementation does not shrink the advertised window (RFC 7323 calls this "window retraction") with the following exceptions: - When an incoming segment cannot be added due to the receive buffer running out of memory. Since commit 8c670bdfa58e ("tcp: correct handling of extreme memory squeeze") a zero window will be advertised in this case. It turns out that reaching the required "memory pressure" is very easy when window scaling is in use. In the simplest case, sending a sufficient number of segments smaller than the scale factor to a receiver that does not read data is enough. Since commit 1d2fbaad7cd8 ("tcp: stronger sk_rcvbuf checks") this happens much earlier than before, leading to regressions (the test suite of the Valkey project does not pass because of a TCP connection that is no longer bi-directional). - Commit b650d953cd39 ("tcp: enforce receive buffer memory limits by allowing the tcp window to shrink") addressed the "eating memory" problem by introducing a sysctl knob that allows shrinking the window before running out of memory. However, RFC 7323 does not only state that shrinking the window is necessary in some cases, it also formulates requirements for TCP implementations when doing so (Section 2.4). This commit addresses the receiver-side requirements: After retracting the window, the peer may have a snd_nxt that lies within a previously advertised window but is now beyond the retracted window. This means that all incoming segments (including pure ACKs) will be rejected until the application happens to read enough data to let the peer's snd_nxt be in window again (which may be never). To comply with RFC 7323, the receiver MUST honor any segment that would have been in window for any ACK sent by the receiver and, when window scaling is in effect, SHOULD track the maximum window sequence number it has advertised. This patch tracks that maximum window sequence number throughout the connection and uses it in tcp_sequence() when deciding whether a segment is acceptable. The logic for handling received data in tcp_data_queue() is already sufficient and does not need to be updated. Fixes: 8c670bdfa58e ("tcp: correct handling of extreme memory squeeze") Fixes: b650d953cd39 ("tcp: enforce receive buffer memory limits by allowing= the tcp window to shrink") Signed-off-by: Simon Baatz --- Documentation/networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 3 +++ include/net/tcp.h | 13 +++++++++= ++++ net/ipv4/tcp.c | 1 + net/ipv4/tcp_fastopen.c | 1 + net/ipv4/tcp_input.c | 6 ++++-- net/ipv4/tcp_minisocks.c | 1 + net/ipv4/tcp_output.c | 12 +++++++++= +++ .../selftests/net/packetdrill/tcp_rcv_big_endseq.pkt | 2 +- 9 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documen= tation/networking/net_cachelines/tcp_sock.rst index 563daea10d6c5c074f004cb1b8574f5392157abb..fecf61166a54ee2f64bcef5312c= 81dcc4aa9a124 100644 --- a/Documentation/networking/net_cachelines/tcp_sock.rst +++ b/Documentation/networking/net_cachelines/tcp_sock.rst @@ -121,6 +121,7 @@ u64 delivered_mstamp r= ead_write u32 rate_delivered = read_mostly tcp_rate_gen u32 rate_interval_us = read_mostly rate_delivered,rate_app_limited u32 rcv_wnd read_write = read_mostly tcp_select_window,tcp_receive_window,tcp_fast_path_check +u32 rcv_mwnd_seq read_write = tcp_select_window u32 write_seq read_write = tcp_rate_check_app_limited,tcp_write_queue_empty,tcp_sk= b_entail,forced_push,tcp_mark_push u32 notsent_lowat read_mostly = tcp_stream_memory_free u32 pushed_seq read_write = tcp_mark_push,forced_push diff --git a/include/linux/tcp.h b/include/linux/tcp.h index f72eef31fa23cc584f2f0cefacdc35cae43aa52d..73aa2e0ccd1d7a6314a00c27950= b019b62a3851c 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -316,6 +316,9 @@ struct tcp_sock { */ u32 app_limited; /* limited until "delivered" reaches this val */ u32 rcv_wnd; /* Current receiver window */ + u32 rcv_mwnd_seq; /* Maximum window sequence number (RFC 7323, + * section 2.4, receiver requirements) + */ u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */ /* * Options received (usually on last packet, some only on SYN packets= ). diff --git a/include/net/tcp.h b/include/net/tcp.h index eb8bf63fdafc3243469f293fd06aef0ce086c5a4..658552133d12edd9cef2aa97460= a3e5bf129d74e 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -914,6 +914,19 @@ static inline u32 tcp_receive_window(const struct tcp_= sock *tp) return (u32) win; } =20 +/* Compute the maximum receive window we ever advertised. + * Rcv_nxt can be after the window if our peer push more data + * than the offered window. + */ +static inline u32 tcp_max_receive_window(const struct tcp_sock *tp) +{ + s32 win =3D tp->rcv_mwnd_seq - tp->rcv_nxt; + + if (win < 0) + win =3D 0; + return (u32) win; +} + /* Choose a new window, without checks for shrinking, and without * scaling applied to the result. The caller does these things * if necessary. This is a "raw" window selection. diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 6ce03a9adb4a97f554bd6b6cf887f4ad9dbfe5c3..6fcde6494a4f400731556be119a= e21cbfd86bb27 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3578,6 +3578,7 @@ static int tcp_repair_set_window(struct tcp_sock *tp,= sockptr_t optbuf, int len) =20 tp->rcv_wnd =3D opt.rcv_wnd; tp->rcv_wup =3D opt.rcv_wup; + tp->rcv_mwnd_seq =3D opt.rcv_wup + opt.rcv_wnd; =20 return 0; } diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index df803f088f454cf157e0efbba8e2ff3f6d205530..4566e2289ad3d85171a9994032b= a7f7366545286 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -377,6 +377,7 @@ static struct sock *tcp_fastopen_create_child(struct so= ck *sk, =20 tcp_rsk(req)->rcv_nxt =3D tp->rcv_nxt; tp->rcv_wup =3D tp->rcv_nxt; + tp->rcv_mwnd_seq =3D tp->rcv_wup + tp->rcv_wnd; /* tcp_conn_request() is sending the SYNACK, * and queues the child into listener accept queue. */ diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index e7b41abb82aad33d8cab4fcfa989cc4771149b41..af9dd51256b01fd31d9e390d69d= cb1d1700daf1b 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4865,8 +4865,8 @@ static enum skb_drop_reason tcp_sequence(const struct= sock *sk, if (before(end_seq, tp->rcv_wup)) return SKB_DROP_REASON_TCP_OLD_SEQUENCE; =20 - if (after(end_seq, tp->rcv_nxt + tcp_receive_window(tp))) { - if (after(seq, tp->rcv_nxt + tcp_receive_window(tp))) + if (after(end_seq, tp->rcv_nxt + tcp_max_receive_window(tp))) { + if (after(seq, tp->rcv_nxt + tcp_max_receive_window(tp))) return SKB_DROP_REASON_TCP_INVALID_SEQUENCE; =20 /* Only accept this packet if receive queue is empty. */ @@ -6959,6 +6959,7 @@ 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. @@ -7071,6 +7072,7 @@ 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); WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); 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. diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index d9c5a43bd2818c17d79d8433ac5dd2bdd199b812..35e115b7a9db3da906c0fc3ef7d= 318d9d946f52a 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -604,6 +604,7 @@ struct sock *tcp_create_openreq_child(const struct sock= *sk, 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; diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 326b58ff1118d02fc396753d56f210f9d3007c7f..50774443f6ae0ca83f360c7fc32= 39184a1523e1b 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -274,6 +274,15 @@ void tcp_select_initial_window(const struct sock *sk, = int __space, __u32 mss, } EXPORT_IPV6_MOD(tcp_select_initial_window); =20 +/* Check if we need to update the maximum window sequence number */ +static inline void tcp_update_max_wnd_seq(struct tcp_sock *tp) +{ + u32 wre =3D tp->rcv_wup + tp->rcv_wnd; + + if (after(wre, tp->rcv_mwnd_seq)) + tp->rcv_mwnd_seq =3D wre; +} + /* Chose a new window to advertise, update state in tcp_sock for the * socket, and return result with RFC1323 scaling applied. The return * value can be stuffed directly into th->window for an outgoing @@ -293,6 +302,7 @@ static u16 tcp_select_window(struct sock *sk) tp->pred_flags =3D 0; tp->rcv_wnd =3D 0; tp->rcv_wup =3D tp->rcv_nxt; + tcp_update_max_wnd_seq(tp); return 0; } =20 @@ -316,6 +326,7 @@ static u16 tcp_select_window(struct sock *sk) =20 tp->rcv_wnd =3D new_win; tp->rcv_wup =3D tp->rcv_nxt; + tcp_update_max_wnd_seq(tp); =20 /* Make sure we do not exceed the maximum possible * scaled window. @@ -4169,6 +4180,7 @@ static void tcp_connect_init(struct sock *sk) else tp->rcv_tstamp =3D tcp_jiffies32; tp->rcv_wup =3D tp->rcv_nxt; + tp->rcv_mwnd_seq =3D tp->rcv_nxt + tp->rcv_wnd; WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); =20 inet_csk(sk)->icsk_rto =3D tcp_timeout_init(sk); diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_big_endseq.pkt= b/tools/testing/selftests/net/packetdrill/tcp_rcv_big_endseq.pkt index 3848b419e68c3fc895ad736d06373fc32f3691c1..1a86ee5093696deb316c532ca8f= 7de2bbf5cd8ea 100644 --- a/tools/testing/selftests/net/packetdrill/tcp_rcv_big_endseq.pkt +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_big_endseq.pkt @@ -36,7 +36,7 @@ =20 +0 read(4, ..., 100000) =3D 4000 =20 -// If queue is empty, accept a packet even if its end_seq is above wup + r= cv_wnd +// If queue is empty, accept a packet even if its end_seq is above rcv_mwn= d_seq +0 < P. 4001:54001(50000) ack 1 win 257 +0 > . 1:1(0) ack 54001 win 0 =20 --=20 2.53.0 From nobody Tue Apr 7 14:41:59 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 8043B2FB084; Thu, 26 Feb 2026 00:49:26 +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=1772066966; cv=none; b=uYySsrGLXm1DyVZWHqxlZ5l61/JL9rJpzlgMYilef+86U0Ucow031kVvHHtxoZ8G9kdQ0V7G0KtnCMa2vKykP+CbDeUSXPuqDZzuA3nlqzjey7T1hicVnBnTw39JfBK/gJxQNBcceuoT1HZVNbVdc6f7SB1/Lb+4bpgfB1MRtHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772066966; c=relaxed/simple; bh=QbmP0kfVx4ni8gBhdAx7ruGqnPyNKx3OkmGsJ2k4JQw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Sjc5oDEYK0uwa3Z4nzAIVoXldmsX1rSmjo9qI/HdWnA4gVntQD3pUEOmerMy9yaUzsqx87ZZ7vZSHzmGLEwGc71POaNQ/xY1r85Q/rzOlD8T8WnL16TCZf9v0ZOIcUOvy5wC+inSv5fPlYnobvKKvff2qM63VB88GxpsHuWvu1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZyONrMwu; 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="ZyONrMwu" Received: by smtp.kernel.org (Postfix) with ESMTPS id 461E1C19423; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772066966; bh=QbmP0kfVx4ni8gBhdAx7ruGqnPyNKx3OkmGsJ2k4JQw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ZyONrMwuSb0C4O74lwzp5Imory2gvu5LHtn72h2U4W/oWpoeyK3FVrw4eAKDA4oBz /B1Dc7HogLGw9RXnVb7nbGHFbX9ylYpM1yUyDSeIYkdSpOPouKoO8OvH/KdA0stVrD S2Me8UgwS00Ox4e0S5eePHabjzyzGtFDSXCaGo1G11Vq9kJGbM1EGZiK6imKYDn4Xe 9a8FzzS/PL1fryioAVFwLo9ZCeCLvwmLFkE3LTrsdvNc9xJD2r6tK0+Mw+QDKqu5mi kL6+1GzPy3SwnNc6ksvPA81ngr/B0rDqPSZaUPWix9pbFEgYEdSCMQ53671hC4T5/H J7Jd6tTFow/iA== 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 386F2FD4600; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Thu, 26 Feb 2026 01:49:08 +0100 Subject: [PATCH RFC net-next v2 2/5] tcp: increase LINUX_MIB_BEYOND_WINDOW for SKB_DROP_REASON_TCP_OVERWINDOW 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: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-2-aa3f8f9cc639@gmail.com> References: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> In-Reply-To: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , David Ahern , Stefano Brivio , Jon Maloy , Jason Xing , mfreemon@cloudflare.com, Shuah Khan , Stefano Brivio Cc: Christian Ebner , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1772066964; l=994; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=93fRnxWZqbnzx4Mxdc8zEz40T5BbuQ5V9PbYF4g/mgk=; b=YUzvuvtU4ngaLSbzzTBtAqZv0HBJyEl8GgWKQ11NZIm8QNVuWZhqCk617T2fb1XOrx1VC/+tL Vgr6L7j1NoQBNOy+dLtIFoqU1H3+5jOB24pVhMRxaW1Owgpg2WGTlQs 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 Since commit 9ca48d616ed7 ("tcp: do not accept packets beyond window"), the path leading to SKB_DROP_REASON_TCP_OVERWINDOW in tcp_data_queue() is probably dead. However, it can be reached now when tcp_max_receive_window() is larger than tcp_receive_window(). In that case, increment LINUX_MIB_BEYOND_WINDOW as done in tcp_sequence(). Signed-off-by: Simon Baatz --- net/ipv4/tcp_input.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index af9dd51256b01fd31d9e390d69dcb1d1700daf1b..f0ee3a599755aff00a00236728b= 430c7883087ff 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5739,6 +5739,7 @@ static void tcp_data_queue(struct sock *sk, struct sk= _buff *skb) if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt + tcp_receive_window(tp))) { reason =3D SKB_DROP_REASON_TCP_OVERWINDOW; + NET_INC_STATS(sock_net(sk), LINUX_MIB_BEYOND_WINDOW); goto out_of_window; } =20 --=20 2.53.0 From nobody Tue Apr 7 14:41:59 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 804DC33BBBA; Thu, 26 Feb 2026 00:49:26 +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=1772066966; cv=none; b=Vws4e+rsdaGq5i9lEv0x2Q07j2ZZgaSTyqyA1mtOHEumjBVD4Tv6Yulyairx3io1Bd55L8SYOW/OGr04kt9ZvF6/8RNHqLe1djJ+C8bwbb57s38rjQ9lhArd94t6G2mHhlYKzTdsUOabdI3r4ERdzFRnqHDumO5flDc1ua8AIMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772066966; c=relaxed/simple; bh=BZpRKv0qUQNJgTX2csX8ZDu3ooSLf/2IMAaH7yg5RCQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PvYpZcVv73Fup78KP+ZvJkIdT8cfccNCZGROiTd2bz6O08dfmfLIPXzxhDRbk9A0Q6t9S3UOip7SBn8qR9MWQLSLRL8mFPDqUHISOyME755qhdGC58a8pxy6zA/zlWmMZCP/XVmA/gPWWYnAiYXGP/sFehik1oEGKcP5CyPE3JE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F6n5l7e5; 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="F6n5l7e5" Received: by smtp.kernel.org (Postfix) with ESMTPS id 58DC6C2BCB0; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772066966; bh=BZpRKv0qUQNJgTX2csX8ZDu3ooSLf/2IMAaH7yg5RCQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=F6n5l7e5CjHR6Z6eexwneirEfufNqy7XfQISPC6bFoySvAX8OSlPe7NVpDI2/186b Vjhi8qerqVVvRI/qfNzeX6RMiK1dPkrxkREVS2PguK5jf4+hEcdqf6RppJtMYlRYrK HjQla0dBYjRYtxvBhAcHGzGyPdDLMQVfdkmdkhv6nL861IRsFGNvLQWBxPMBeK300M iYgIUcAY50xFTyTm+8uXiD1as+/a0XZebPgh4XheL6EXtfTs3fc0ZskRgDApvxmMDk 3eE91CNg1xK3C2S8aRjnD0lhuHRctoZB4h5+1Yxu+PRRnYcG0gAdqc5j2kRmD4mysJ A1193escnDS4A== 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 4B90EFD4603; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Thu, 26 Feb 2026 01:49:09 +0100 Subject: [PATCH RFC net-next v2 3/5] selftests/net: packetdrill: add tcp_rcv_wnd_shrink_nomem.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: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-3-aa3f8f9cc639@gmail.com> References: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> In-Reply-To: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , David Ahern , Stefano Brivio , Jon Maloy , Jason Xing , mfreemon@cloudflare.com, Shuah Khan , Stefano Brivio Cc: Christian Ebner , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1772066964; l=7103; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=srbpCOkGkyiCgA3m8CsvVIdQ91JloySYJEtphyneQ6k=; b=oawNhURjKMYSDqzEVviXqSd5vevOvSPvsdubEDUYf6H1MqPAZK39DOvUg+cCNurHoLDxVqmkc 0YSwWChN6AiCNlWLp2xM00KJTCwwDnZsjFL6fJTmeaaQPeyZkSKHbFA 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 This test verifies - the sequence number checks using the maximum advertised window sequence number and - the logic for handling received data in tcp_data_queue() for the cases: 1. The window is reduced to zero because of memory 2. The window grows again but still does not reach the originally advertised window Signed-off-by: Simon Baatz --- .../net/packetdrill/tcp_rcv_wnd_shrink_nomem.pkt | 141 +++++++++++++++++= ++++ 1 file changed, 141 insertions(+) diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_nom= em.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_nomem.p= kt new file mode 100644 index 0000000000000000000000000000000000000000..8c30e231d7c82705f522f0e7bcd= affb9fb825974 --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_nomem.pkt @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0 +// When tcp_receive_window() < tcp_max_receive_window(), tcp_sequence() ac= cepts +// packets that would be dropped under normal conditions (i.e. tcp_receive= _window() +// equal to tcp_max_receive_window()). +// Test that such packets are handled as expected for RWIN =3D=3D 0 and fo= r RWIN > 0. + +--mss=3D1000 + +`./defaults.sh` + + 0 `nstat -n` + +// Establish a 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, [1000000], 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 257 + + +0 accept(3, ..., ...) =3D 4 + +// Put 1040000 bytes into the receive buffer + +0 < P. 1:65001(65000) ack 1 win 257 + * > . 1:1(0) ack 65001 + +0 < P. 65001:130001(65000) ack 1 win 257 + * > . 1:1(0) ack 130001 + +0 < P. 130001:195001(65000) ack 1 win 257 + * > . 1:1(0) ack 195001 + +0 < P. 195001:260001(65000) ack 1 win 257 + * > . 1:1(0) ack 260001 + +0 < P. 260001:325001(65000) ack 1 win 257 + * > . 1:1(0) ack 325001 + +0 < P. 325001:390001(65000) ack 1 win 257 + * > . 1:1(0) ack 390001 + +0 < P. 390001:455001(65000) ack 1 win 257 + * > . 1:1(0) ack 455001 + +0 < P. 455001:520001(65000) ack 1 win 257 + * > . 1:1(0) ack 520001 + +0 < P. 520001:585001(65000) ack 1 win 257 + * > . 1:1(0) ack 585001 + +0 < P. 585001:650001(65000) ack 1 win 257 + * > . 1:1(0) ack 650001 + +0 < P. 650001:715001(65000) ack 1 win 257 + * > . 1:1(0) ack 715001 + +0 < P. 715001:780001(65000) ack 1 win 257 + * > . 1:1(0) ack 780001 + +0 < P. 780001:845001(65000) ack 1 win 257 + * > . 1:1(0) ack 845001 + +0 < P. 845001:910001(65000) ack 1 win 257 + * > . 1:1(0) ack 910001 + +0 < P. 910001:975001(65000) ack 1 win 257 + * > . 1:1(0) ack 975001 + +0 < P. 975001:1040001(65000) ack 1 win 257 + * > . 1:1(0) ack 1040001 + +// Trigger an extreme memory squeeze by shrinking SO_RCVBUF + +0 setsockopt(4, SOL_SOCKET, SO_RCVBUF, [16000], 4) =3D 0 + + +0 < P. 1040001:1105001(65000) ack 1 win 257 + * > . 1:1(0) ack 1040001 win 0 +// Check LINUX_MIB_TCPRCVQDROP has been incremented + +0 `nstat -s | grep TcpExtTCPRcvQDrop| grep -q " 1 "` + +// RWIN =3D=3D 0: rcv_wup =3D 1040001, rcv_wnd =3D 0, rcv_mwnd_seq > 11050= 01 (significantly larger, typically ~1970000) + +// Accept pure ack with seq in max adv. window + +0 write(4, ..., 1000) =3D 1000 + +0 > P. 1:1001(1000) ack 1040001 win 0 + +0 < . 1105001:1105001(0) ack 1001 win 257 + +// In order segment, in max adv. window -> drop (SKB_DROP_REASON_TCP_ZEROW= INDOW) + +0 < P. 1040001:1041001(1000) ack 1001 win 257 + +0 > . 1001:1001(0) ack 1040001 win 0 +// Ooo partial segment, in max adv. window -> drop (SKB_DROP_REASON_TCP_ZE= ROWINDOW) + +0 < P. 1039001:1041001(2000) ack 1001 win 257 + +0 > . 1001:1001(0) ack 1040001 win 0 +// Check LINUX_MIB_TCPZEROWINDOWDROP has been incremented twice + +0 `nstat -s | grep TcpExtTCPZeroWindowDrop| grep -q " 2 "` + +// Ooo segment, in max adv. window -> drop (SKB_DROP_REASON_TCP_OVERWINDOW) + +0 < P. 1105001:1106001(1000) ack 1001 win 257 + +0 > . 1001:1001(0) ack 1040001 win 0 +// Ooo segment, beyond max adv. window -> drop (SKB_DROP_REASON_TCP_INVALI= D_SEQUENCE) + +0 < P. 2000001:2001001(1000) ack 1001 win 257 + +0 > . 1001:1001(0) ack 1040001 win 0 +// Check LINUX_MIB_BEYOND_WINDOW has been incremented twice + +0 `nstat -s | grep TcpExtBeyondWindow | grep -q " 2 "` + +// Read all data + +0 read(4, ..., 2000000) =3D 1040000 + * > . 1001:1001(0) ack 1040001 + +// RWIN > 0: rcv_wup =3D 1040001, 0 < rcv_wnd < 32000, rcv_mwnd_seq > 1105= 001 (significantly larger, typically ~1970000) + +// Accept pure ack with seq in max adv. window, beyond adv. window + +0 write(4, ..., 1000) =3D 1000 + +0 > P. 1001:2001(1000) ack 1040001 + +0 < . 1105001:1105001(0) ack 2001 win 257 + +// In order segment, in max adv. window, in adv. window -> accept +// Note: This also ensures that we cannot hit the empty queue exception in= tcp_sequence() in the following tests + +0 < P. 1040001:1041001(1000) ack 2001 win 257 + * > . 2001:2001(0) ack 1041001 + +// Ooo partial segment, in adv. window -> accept + +0 < P. 1040001:1042001(2000) ack 2001 win 257 + +0 > . 2001:2001(0) ack 1042001 + +// Ooo segment, in max adv. window, beyond adv. window -> drop (SKB_DROP_R= EASON_TCP_OVERWINDOW) + +0 < P. 1105001:1106001(1000) ack 2001 win 257 + +0 > . 2001:2001(0) ack 1042001 +// Ooo segment, beyond max adv. window, beyond adv. window -> drop (SKB_DR= OP_REASON_TCP_INVALID_SEQUENCE) + +0 < P. 2000001:2001001(1000) ack 2001 win 257 + +0 > . 2001:2001(0) ack 1042001 +// Check LINUX_MIB_BEYOND_WINDOW has been incremented twice + +0 `nstat -s | grep TcpExtBeyondWindow | grep -q " 4 "` + +// Let's probe how much more data we can squeeze in, 2 * 10k should be ok + +0 < P. 1042001:1052001(10000) ack 2001 win 257 + * > . 2001:2001(0) ack 1052001 + +0 < P. 1052001:1062001(10000) ack 2001 win 257 + * > . 2001:2001(0) ack 1062001 + +// Ooo segment, in max adv. window, seq 152002 in adv. window, not enough = buffer space -> drop, _no_ ack + +0 < P. 1062002:1072002(10000) ack 2001 win 257 +// Check LINUX_MIB_TCPOFODROP has been incremented + +.1 `nstat -s | grep TcpExtTCPOFODrop | grep -q " 1 "` + +// In order segment, in max adv. window, not enough buffer space -> drop + +0 < P. 1062001:1072001(10000) ack 2001 win 257 + +0 > . 2001:2001(0) ack 1062001 win 0 +// Check LINUX_MIB_TCPRCVQDROP has been incremented again + +0 `nstat -s | grep TcpExtTCPRcvQDrop | grep -q " 2 "` + +// Verify that our other counters did not change + +0 `nstat -s | grep TcpExtTCPZeroWindowDrop | grep -q " 2 "` + +0 `nstat -s | grep TcpExtBeyondWindow | grep -q " 4 "` --=20 2.53.0 From nobody Tue Apr 7 14:41:59 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 8BB6F36EAB1; Thu, 26 Feb 2026 00:49:26 +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=1772066966; cv=none; b=tpUgAxrVn4Yex8vmWOFcejEFlIzMCcPjYCIT406L7+8m9CFQlw7AsHdKamguEAojFT4UQhUyzmqr9949X2KUVoZ651JcqQCQSl4Xqa4OhBKSinV4yRkOF/71KDFNPqvMVB7/36Q1sfW/OqBwxamj/N09QOmxmDVFEuOAC9wqMDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772066966; c=relaxed/simple; bh=jZffL8U2QVP5FJBgcvEGQCxmQSHTSiBnbGAz5Y5JC7E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qoA+bNsacF/4X6STcIVm7iGFIaAvFaTyQehAFMFy+bX3K3QksL7iloXThmQ9oBgkHinqkB7XpiC0Cb1T9e4RUxwZ/wpL8eF6HNqaiBdyKCET8vXmnpOT/J0o/dgr+70izjEPfOAWzW+4V3HqRktaYVGBBRbPdbjFxkrgTuehTSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gozgT/0I; 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="gozgT/0I" Received: by smtp.kernel.org (Postfix) with ESMTPS id 671A3C2BCB6; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772066966; bh=jZffL8U2QVP5FJBgcvEGQCxmQSHTSiBnbGAz5Y5JC7E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gozgT/0IOKSK7CWDxTBzw9L2GcXvVklh79bTFhLmrCyPzcgIAJrUyEyMy5sn34PNS Z3Jtf9Yniq3m78xzszopxeAgnh6hMXWLD9rmDlwvboEvk555KqrMUIXXlvrS606AG0 HYbYX1wYMWmUeVqSjZIdx0VDjjomwd7PZWqCugFJ5iInQE87nEAqRWSYiogVyKLUJv jUKnQBxqy/YwlP0qRQrtRlSL/VSzWz3EFk3zl0DcLuOpZpyUwO6ZCtkBvfiOy0dVYa PYakRf9KmduWWOcswqEZsff/j/fl9QTgr9UCJzz5eqt1PUDbplvnuC00dkkiL7CW/b HgYgrR6TmzFRw== 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 5F883FD45FF; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Thu, 26 Feb 2026 01:49:10 +0100 Subject: [PATCH RFC net-next v2 4/5] selftests/net: packetdrill: add tcp_rcv_wnd_shrink_allowed.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: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-4-aa3f8f9cc639@gmail.com> References: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> In-Reply-To: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , David Ahern , Stefano Brivio , Jon Maloy , Jason Xing , mfreemon@cloudflare.com, Shuah Khan , Stefano Brivio Cc: Christian Ebner , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1772066964; l=1916; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=MjsZPkGn8QBvDWJIOlx0ttylpFWaDY4F2mI8uGeZDj4=; b=YW4cf33OXLAcJwKNDwLdtBUt+Rhl4+Bnu31WmAA5B+E401wN8L3lhdkgqCGNc4YZWFdsBZA01 9Cz/FplpjcRDdA8KeTgsmKYeCBbPkypbJbSEuuXFaB+go0b6rk930P6 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 This test verifies the sequence number checks using the maximum advertised window sequence number when net.ipv4.tcp_shrink_window is enabled. Signed-off-by: Simon Baatz --- .../net/packetdrill/tcp_rcv_wnd_shrink_allowed.pkt | 40 ++++++++++++++++++= ++++ 1 file changed, 40 insertions(+) diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_all= owed.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_allow= ed.pkt new file mode 100644 index 0000000000000000000000000000000000000000..e2c73e464954331f45c11b3152f= 2eddecc55f88b --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_allowed.pkt @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 + +--mss=3D1000 + +`./defaults.sh +sysctl -q net.ipv4.tcp_shrink_window=3D1 +sysctl -q net.ipv4.tcp_rmem=3D"4096 32768 $((32*1024*1024))"` + + 0 `nstat -n` + +// Establish a 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 + +0 < . 1:1(0) ack 1 win 257 + + +0 accept(3, ..., ...) =3D 4 + + +0 < P. 1:10001(10000) ack 1 win 257 + * > . 1:1(0) ack 10001 win 15 + + +0 < P. 10001:11024(1023) ack 1 win 257 + * > . 1:1(0) ack 11024 win 13 + +// Max window seq advertised 10001 + 15*1024 =3D 25361, last advertised: 1= 1024 + 13*1024 =3D 24336 + +// Segment beyond the max window is dropped + +0 < P. 11024:25362(14338) ack 1 win 257 + * > . 1:1(0) ack 11024 win 13 + +// Segment using the max window is accepted + +0 < P. 11024:25361(14337) ack 1 win 257 + * > . 1:1(0) ack 25361 win 0 + +// Check LINUX_MIB_BEYOND_WINDOW has been incremented once + +0 `nstat | grep TcpExtBeyondWindow | grep -q " 1 "` --=20 2.53.0 From nobody Tue Apr 7 14:41:59 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 9A5FD36EAB7; Thu, 26 Feb 2026 00:49:26 +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=1772066966; cv=none; b=K7vva8/pA1H6aWMMVyZraU+KLbarcEM7A+weSM2/YI251Qwvm8tgWnBPv/zfhT1b86OehdBfSHl99GUjNx5hcsX0tBrC43KJTrEDiC1ASXEkWYRMFfqFp2NYP2FwW0vx9QNtKfsIrlWkGuQD6SWPLKYA4luuxDUn6a1KMVtYdXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772066966; c=relaxed/simple; bh=emTIU1TaBbIx/tDTZhzmiIjXQ7JpqWXdQa8oeCKbuEQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QUOdviRMvR8M0MRf/VfwpquKrAVFQ29RLTkMpzrB8JHh/0hfHL1DFlKKfkOKbrGNZm36J/wCzqB9Jo98w2a00n8Gen8SgFd3qdn/p96Ppe75Mp31ICD/+5c5c8X0y6fW6Xh/pY73grWdr7p+cB63M96f0a4vSaIL35M/hktCyvc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vGfuIYgx; 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="vGfuIYgx" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7AEDEC2BCB3; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772066966; bh=emTIU1TaBbIx/tDTZhzmiIjXQ7JpqWXdQa8oeCKbuEQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=vGfuIYgx4DoBb5f4vSs6mOxQudTIUHweAho9Fjkungb1qds1LyZ/TtP0w+DRtkOPO qWVZVKWJGFPopemycgKK0bm0HSKZynQoDvXNSA+gtXN5Ban/cfPfB/nk3T2oB1wivU Mh+82R1x0kjroVe6fUU7ZZDYQpgEirUNd1ZTacwzNCfv/pxbxQQPgy+PI8G2/1b3N9 fXfk4Ulji99zlWN+gRDpNOJO11p1oOsC0ZT3drX97zFBplLzDyt3snZL5/R6y7IhZ8 S5Iq9UF7tHmTtKd0aVxGfyA3ZdQcs5qBNXHtqjJRnV1lYjRzbLAWGqzyvaCJOaaPhc vqPiPJv8uVv1A== 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 70737FD45FE; Thu, 26 Feb 2026 00:49:26 +0000 (UTC) From: Simon Baatz via B4 Relay Date: Thu, 26 Feb 2026 01:49:11 +0100 Subject: [PATCH RFC net-next v2 5/5] selftests/net: packetdrill: add tcp_rcv_neg_window.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: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-5-aa3f8f9cc639@gmail.com> References: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> In-Reply-To: <20260226-tcp_rfc7323_retract_wnd_rfc-v2-0-aa3f8f9cc639@gmail.com> To: Eric Dumazet , Neal Cardwell , Kuniyuki Iwashima , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , David Ahern , Stefano Brivio , Jon Maloy , Jason Xing , mfreemon@cloudflare.com, Shuah Khan , Stefano Brivio Cc: Christian Ebner , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Simon Baatz X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1772066964; l=1560; i=gmbnomis@gmail.com; s=20260220; h=from:subject:message-id; bh=/JWWw4Fx6ONTjfm9hTqMNguk1B74iLUSkQSY5L1syFw=; b=qtBvPU3M3B3V/VgUAmVlVHh3U9olqOaO8RlGMGMq/jDkZ3NJb8DN2fmTUTuAv9N6vkBm7o8Zl i1rmFiNfQTYBQ+Kkkk6LDQbUeM7RXN9h3C3Mwq9qcT33KON9ik/bgHf 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 The test ensures we correctly apply the maximum advertised window limit when rcv_nxt advances past rcv_mwnd_seq, so that the "usable window" is properly clamped to zero rather than becoming negative. Signed-off-by: Simon Baatz --- .../net/packetdrill/tcp_rcv_neg_window.pkt | 26 ++++++++++++++++++= ++++ 1 file changed, 26 insertions(+) diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_neg_window.pkt= b/tools/testing/selftests/net/packetdrill/tcp_rcv_neg_window.pkt new file mode 100644 index 0000000000000000000000000000000000000000..15a9b4938f16d175ac54f3fd192= ed2b59b0a4399 --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_neg_window.pkt @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 + +--mss=3D1000 + +`./defaults.sh` + +// Establish a 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, [20000], 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 18980 + +.1 < . 1:1(0) ack 1 win 257 + + +0 accept(3, ..., ...) =3D 4 + +// A too big packet is accepted if the receive queue is empty + +0 < P. 1:20001(20000) ack 1 win 257 +// Send a RST immediately so that there is no rcv_wup/rcv_mwnd_seq update = yet + +0 < R. 20001:20001(0) ack 1 win 257 + + +.1 %{ assert tcpi_state =3D=3D TCP_CLOSE, tcpi_state }% + --=20 2.53.0