πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16528

Re: [PATCH v1 net-next 1/8] tcp: Clean up the first loop in tcp_collapse().

#16528
From: netdev-bot+sashiko
Date: Sun, 15 Nov 2026 04:10
117 lines
11969 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch is titled a clean-up, and its message presents the
  change as equivalent to the old code ("If we goto skip_this in both…

--

tcp: Clean up the first loop in tcp_collapse().

This commit restructures the first loop of tcp_collapse(). The SYN/FIN
and skb_frags_readable() checks are folded into one goto skip_this test,
and the end_of_skbs flag is replaced with the inverted loop condition.
It also moves the readability check after the fully overlapping check.

> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index a2074a1af4222..32e63d089db89 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -5839,23 +5839,17 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,

[ ... ]

>  restart:
> -	for (end_of_skbs = true; skb != NULL && skb != tail; skb = n) {
> +	for (; skb && skb != tail; skb = n) {
>  		n = tcp_skb_next(skb, list);
>  
> -		if (!skb_frags_readable(skb))
> -			goto skip_this;
> -
>  		/* No new bits? It is possible on ofo queue. */
>  		if (!before(start, TCP_SKB_CB(skb)->end_seq)) {
>  			skb = tcp_collapse_one(sk, skb, list, root);
> -			if (!skb)
> -				break;
>  			goto restart;
>  		}
>  
> @@ -5864,27 +5858,25 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
>  		 * - bloated or contains data before "start" or
>  		 *   overlaps to the next one and mptcp allow collapsing.
>  		 */
> -		if (!(TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)) &&
> -		    (tcp_win_from_space(sk, skb->truesize) > skb->len ||
> -		     before(TCP_SKB_CB(skb)->seq, start))) {
> -			end_of_skbs = false;
> +		if (!skb_frags_readable(skb) ||
> +		    TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN))
> +			goto skip_this;

[Severity: Low]
The commit message describes this as an equivalent clean-up:

  If we goto skip_this in both cases, we can remove the second
  tests and simply replace end_of_skbs with the inverted loop
  condition.

Is that true for SYN/FIN skbs? Before this patch, take a SYN or FIN skb
whose readable successor n overlaps it and is allowed by
tcp_skb_can_collapse_rx(). That skb reached the second break with
end_of_skbs = false:

	if (n && n != tail && skb_frags_readable(n) &&
	    tcp_skb_can_collapse_rx(skb, n) &&
	    TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(n)->seq) {
		end_of_skbs = false;
		break;
	}

The post-loop test then returned early:

	if (end_of_skbs ||
	    (TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)) ||
	    !skb_frags_readable(skb))
		return;

So nothing in the head..tail range was collapsed in that call. The
post-loop SYN/FIN test was not redundant.

With this patch every SYN/FIN skb goes to skip_this. start advances and
scanning continues, so later skbs in the same range can now be collapsed.
A peer can reach this path, for example with a FIN segment followed by an
overlapping segment in the ofo queue.

The readability reordering also changes behaviour. Unreadable (devmem)
skbs that lie entirely below start used to be skipped. Now they are
unlinked and freed by tcp_collapse_one(), which also increments
LINUX_MIB_TCPRCVCOLLAPSED. The message only says:

  Also, skb_frags_readable() should be tested after the fully
  overlapping check.

It gives no reason for the change.

The new behaviour looks safe as far as I can tell. The copy loop still
stops at SYN/FIN skbs, and offset stays non-negative.

Could the changelog state both the SYN/FIN change and the devmem change
explicitly, rather than presenting the patch as a pure clean-up? The first
loop at the end of the series still behaves this way, so this patch looks
like the right place to describe it.

> +
> +		if (tcp_win_from_space(sk, skb->truesize) > skb->len ||
> +		    before(TCP_SKB_CB(skb)->seq, start))
>  			break;
> -		}

[ ... ]

-- 
Sashiko AI review Β· https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114040101.1043546-1-kuniyu%40google.com
Technical Details
Message-ID: <179471585026.2199510.8755335400317906663@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363556-linux-kernel-netdev=dewy.ru
References: <20261114040101.1043546-2-kuniyu@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363556-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v1 net-next 1/8] tcp: Clean up the first loop in tcp_collapse().
Date: Sun, 15 Nov 2026 04:10:50 +0000
Organization: Usenet Network
Message-ID: <179471585026.2199510.8755335400317906663@kernel.org>
References: <20261114040101.1043546-2-kuniyu@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1726427"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:JMYgR8mmlkMSDYIbWXEHGkA4EMM= sha256:wKrJc+koms2Jgj3fDnR1YdDlf5RUhaRNhgDLSVsX7bs=
	sha1:yLkKuAuXrq/S/ftaXuFfduXfAZc= sha256:vi16kBWcFae7SPS+wBKItLMuQSZf3VAOCmcUxnL6nZ8=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id CCD9F125D40; Sun, 15 Nov 2026 07:11:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Xgywuc1lUJpE;
	Sun, 15 Nov 2026 07:11:04 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-363556-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 5D825125D3C; Sun, 15 Nov 2026 07:10:55 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 962D935722; Sun, 15 Nov 2026 04:10:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794715852;
	b=Klo+7CXunbIF3ZodvNOfx6RT65FOGTI5IDsH6wfg1uWWp0g0i8ZnCfEztEUKtjrp59kS
	 7Xj+L80iIKa6y+3+3pcJ/Ux/f6O5OJFCSluqD4sB/H7st5f5GvLcm/qhWmrWcIsYHzmgK
	 iY0mLjlPXZFl1xDBezez6u/g0FEw+OpSGBTBNS29ckE+hzT+v0MFU24Ep4IDxzo4uw9K7
	 8UHS+Ourllo2+KOuICp73E3s9mxwHV7VqkdKl8pJAlXJy+HyiLND53Ehh2Ilh4WeQUZ3S
	 PZviDLLWvYHOg/hR3QehJkDBIBo6pQcstMMIvjddgEZ0C2Sz3SZEaMzPSbUhJISLyog==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794715852;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=tsLCwFlP8oV0uxIOwY1n3e/7rDkFW/5EHcAnj0k6cBU=;
	b=Xy9PYS39+mIwRHlpntnCRTEWzKoj/YODwcQNtTPZsLCUlgZKq5r55fdrXcYfX9wND3+S
	 8Vm0/f5zdkWk9h1psy0POLdpC2WxYFArcVY05cNC/AFCBB/57aChh8OL10NH0Zn0MNwDV
	 eWU8g+YC5I38wLu6RtiIOezYNWSDIGkMpvP1wSEl1ByB4CzceVD+8xG/o1TltO2QIcg6M
	 4dtdqRZKTujqwYM9mLWjST42y5N3kPhippLdET+Z911gNWoXZVPCqWXwHVgpFCi2l1dqd
	 HkYeY2A3ddQmfrXzmU9vWP3bMnq6iMI4IXtI9HOBP5uzDq3TnrsCCNZRQuLyLZXR4rA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NUVHtCPo;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 6436F606A333;
	Sun, 15 Nov 2026 04:10:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NUVHtCPo
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794715851;
	b=dNo1GcOmpR//ZDIBu3/vf172lR+nvEYBC+E+sbU3KuIXdcd4cOWv3X4CrULyaYNnD3Jw
	 +eO9kn2h2VmOOpdY9pq8MAi+l47sGzfs6AuQCuaQZWCqcwVGpQOQ67iBfxfrW1FCkxC/A
	 7HUvvy8wDX7EcoJXZLhW/y+rC+AmdnBtXnMw+8Mlx9bk6wahFfBKdVFO89EXQ/2eOLUxZ
	 P9WHb+FkH7/ZUGt8/8bSCV0aUXAQj8m/yCDkImjdn9aqgs29vN/0r4hCIVHZ2fbiBvSNO
	 cK58Ufb5H/g/RuHNMChrssalcyGFz1aEUco6hg4ikr2ace6+R2LeQ5pHhsIo07UaYRw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794715851;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=tsLCwFlP8oV0uxIOwY1n3e/7rDkFW/5EHcAnj0k6cBU=;
	b=VZttnuGINwTYmEsKGzBUMXCjYf3HulXfWsuDWjxkYz8cXhFps5xRIIkvZ4OSmCWfo6vb
	 rZJttEL9SbGKH/MEoZKxDMcs245rSyrIdD1xnadyp+5Lqn2LwFrbgb5D/KOY3QbsOTBrG
	 zjqllp2QNNP2IzAxyUCSD7SVrfZsFUjmUrT1caFQ6ZldHye3BMcMx3YdjPEYO6yDbYapp
	 6y/t6tdHwSVpKcv47Z2txZHTBedOFe/yM8B5rovHlnnh7U38c8nyBfD9xLGfKqojdS8Pt
	 jdRVQWdBtuRN3aBLnImxgFZe3hB+XxG6DALpMjTo45mOdB/cW3kKDYDf71Du51qkGzg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NUVHtCPo;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8224B606A327
	for <netdev@vger.kernel.org>; Sun, 15 Nov 2026 04:10:51 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7CBC1F000C4;
	Sun, 15 Nov 2026 04:10:50 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794715851;
	bh=tsLCwFlP8oV0uxIOwY1n3e/7rDkFW/5EHcAnj0k6cBU=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=NUVHtCPoba7GDwYb73IYD07zpC1Is4uHZlfPm7KwsgwwteCyR6oddB194N/ouAau+
	 jLVA54EsyIbhKtq+mtocMh2mSzM4HRub7eqxYOmY15yuN/gKKo6n3cg51Z33zUpsaE
	 Aiw/nDjvyAINz663LYMuQm+RTS1zzbCKDlvJfIepyEyxGVZRbVubAhmHEAJLMsW3Gi
	 2lYUuEb1/bCdDIY1E9XW4MGGB89QpSxnq3Raeoz+jkiatuRJEBWRwQb4646vZpWijM
	 ARnSGjEQbUQNIZK7+2tnQqanlw7yF6A1As2LQOtQnU55mKHhK0KrJpUia8VgDDquee
	 5ZhD9VI69n1Jg==
X-Cc: edumazet@kernel.org, ncardwell@google.com, davem@davemloft.net,
 kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, kuni1840@gmail.com,
 netdev@vger.kernel.org
X-In-Reply-To: <20261114040101.1043546-2-kuniyu@google.com>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list