From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=fail (p=quarantine dis=none) header.from=janestreet.com Received: from mxout5.mail.janestreet.com (mxout5.mail.janestreet.com [64.215.233.18]) by passt.top (Postfix) with ESMTPS id 541395A0269 for ; Mon, 23 Nov 2026 22:16:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1795468571; bh=prMY8aDqhCHd7sfSuhE5AxsbsLeRrsgywl+qrm6wW0Q=; h=From:To:Cc:Subject:Date; b=nGWY/yindzVoeIKmnVo8kjD2f4kFqISSIrOjq3iX/BtGnPgfWGbPem7cWHDJjGBlR DUqxgghuTDsKTSey4yjAj58ZW4Sl66s+Jzjl5VYsb6tDgRFZdfUxChWtIN3iHbL6sw BwJXk9LwkInKQAPIjlc94/Ge1YRom7OpKuhzU+EyitubkIdIVv/z0xjSB8Rl7wNHuT XlzQIjJG8qWGivEocfcefAw4e+ilYFE72qrY0AVk+l0Zhp5vydmLBKprP0xBuHdwtL FonG9NMSFF9/I3UNego1MSR2Je+Qj2q1AzgjJOWA2r0w9ixDh17tnhJJtQR83meZno Rm1Igqmw8ZqZg== From: Jason Chu To: passt-dev@passt.top Subject: [PATCH] tcp: Keep window from tap below MAX_WINDOW Date: Mon, 23 Nov 2026 16:16:00 -0500 Message-ID: <20261123211602.3188010-1-jaschu@janestreet.com> X-Mailer: git-send-email 2.54.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MailFrom: jaschu@janestreet.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: NGI42QYYECEDGKEUAZ5TCBZZAWWVWFQW X-Message-ID-Hash: NGI42QYYECEDGKEUAZ5TCBZZAWWVWFQW X-Mailman-Approved-At: Mon, 23 Nov 2026 22:28:03 +0100 CC: Jason Chu , Stefano Brivio , David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In tcp_internal.h, SEQ_GE(a, b) checks (uint32_t)(a) - (uint32_t)(b) < MAX_WINDOW, so a sequence number exactly MAX_WINDOW (16 MiB) ahead is treated as out of range. tcp_tap_window_update() clamps the advertised window from tap to MAX_WINDOW inclusive, and pasta sends up to that full window. If the peer negotiates a window scale above MAX_WS (9 to 14) and advertises at least 16 MiB, pasta can put exactly MAX_WINDOW bytes in flight. When the peer acknowledges all of them in one ACK, tcp_data_from_tap() fails SEQ_GE(ack_seq, conn->seq_ack_from_tap) and ignores the ACK. pasta then rewinds on each ACK timeout and retransmits the same 16 MiB, which the peer drops as duplicate data while repeating the same ACK, so the connection stalls. We hit this on Linux with a raised net.ipv4.tcp_rmem maximum (and it also reproduces via SO_RCVBUF) when the receiver pauses while more than 16 MiB arrives. In that case the kernel only sends a delayed ACK, and pasta delivers all 16 MiB before the delayed ACK timer fires. With a 6 MiB tcp_rmem maximum, the default on older kernels, the peer uses a window scale of 7 and the window never reaches 16 MiB. Current kernels default to up to 32 MiB, which we haven't tested. Clamp the window in tcp_tap_window_update() to MAX_WINDOW - 1 instead. For window scales 9 to 14, the right shift rounds the stored window down by one scale unit, keeping every valid ACK within SEQ_GE() range. Window scales up to MAX_WS cannot represent MAX_WINDOW anyway. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Jason Chu --- Tested on master (094211f), Linux 6.12.112, with host net.ipv4.tcp_rmem max >= 32 MiB so pasta's host socket can queue 16 MiB. With a script that starts pasta, raises net.ipv4.tcp_rmem inside the namespace, and reads 64 MiB responses after a 0.3 s pause, unmodified master stalled in 5/5 runs at 64 MiB (as well as 32 MiB and 512 MiB) and completed at 4 MiB and 16 MiB. With this patch all 10 requests completed in 5/5 runs at 64 MiB, and at 4, 16, 32, and 512 MiB. Reproducer (no root needed, requires pasta and python3). Run on a host with tcp_rmem max >= 32 MiB, or wrap in unshare -Urn sh -c "ip link set lo up && \ echo '4096 131072 33554432' > /proc/sys/net/ipv4/tcp_rmem && \ exec python3 repro.py" import os, select, socket, subprocess, sys, time PORT, SIZE, HOST = 45432, 64 << 20, "192.0.2.1" if sys.argv[1:2] == ["client"]: buf = int(sys.argv[2]) open("/proc/sys/net/ipv4/tcp_rmem", "w").write(f"4096 {buf} {buf}") s = socket.socket() s.connect((HOST, PORT)) for i in range(1, 11): s.sendall(b"g") time.sleep(0.3) got = 0 while got < SIZE and select.select([s], [], [], 5)[0]: d = s.recv(1 << 20) if not d: sys.exit(f"req {i}: closed at {got}") got += len(d) print(f"req {i}: {got}/{SIZE}" + (" STALLED" if got < SIZE else "")) if got < SIZE: sys.exit(1) else: ln = socket.socket() ln.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) ln.bind(("127.0.0.1", PORT)) ln.listen(1) pid = os.fork() if pid == 0: c, _ = ln.accept() while c.recv(1): c.sendall(b"x" * SIZE) os._exit(0) try: sys.exit(subprocess.call([ os.environ.get("PASTA", "pasta"), "--config-net", "--map-host-loopback", HOST, "--", sys.executable, os.path.abspath(__file__), "client", str(64 << 20), ])) finally: os.kill(pid, 9) tcp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tcp.c b/tcp.c index ea545b0..9390e5b 100644 --- a/tcp.c +++ b/tcp.c @@ -1494,7 +1494,10 @@ static bool tcp_tap_window_update(const struct ctx *c, struct tcp_tap_conn *conn, unsigned wnd, const struct timespec *now) { - wnd = MIN(MAX_WINDOW, wnd << conn->ws_from_tap); + /* SEQ_*() only handles sequence differences strictly less than + * MAX_WINDOW, so clamp to MAX_WINDOW - 1. + */ + wnd = MIN(MAX_WINDOW - 1, wnd << conn->ws_from_tap); /* Work-around for bug introduced in peer kernel code, commit * e2142825c120 ("net: tcp: send zero-window ACK when no memory"): don't -- 2.43.7