🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9532

Re: [PATCH net] tcp: initialize send sequence numbers before deferring TFO

#9532
From: Eric Dumazet
Date: Mon, 02 Nov 2026 08:20
90 lines
12901 bytes
Le lun. 2 nov. 2026 à 09:13, Qingfang Deng <qingfang.deng@linux.dev> a écrit :
>
> On 2026/11/2 16:00, Eric Dumazet wrote:
> > Le lun. 2 nov. 2026 à 08:41, Qingfang Deng <qingfang.deng@linux.dev> a écrit :
> >> On 2026/11/2 14:11, Jiayuan Chen wrote:
> >>> On 11/2/26 11:59 AM, Qingfang Deng wrote:
> >>>> TCP_FASTOPEN_CONNECT can return from connect() before tcp_connect_init()
> >>>> when a cached cookie or cookieless Fast Open allows deferring the SYN.
> >>>> At this point write_seq contains the initial sequence number, while
> >>>> snd_una and snd_nxt have not been initialized to that sequence number.
> >>>>
> >>>> Consequently, inet_diag and /proc/net/tcp{,6} report the initial
> >>>> sequence number as the send queue length despite no SYN or payload being
> >>>> queued.
> >>>>
> >>>> Initialize snd_una and snd_nxt to write_seq before marking the
> >>>> connection as deferred. Both sequence-based queue lengths then remain
> >>>> zero until the first write starts the connection and runs
> >>>> tcp_connect_init().
> >>> This patch looks good to me. But idiag_wqueue can still go negative
> >>> on the normal connect path, since the socket is already hashed and
> >>> diag does not take the socket lock. We always set write_seq first,
> >>> then init snd_una later:
> >>>
> >>>     tcp_v4_connect
> >>>       WRITE_ONCE(tp->write_seq, st.seq)
> >>>       tcp_connect
> >>>         tcp_connect_init
> >>>           WRITE_ONCE(tp->snd_una, tp->write_seq)
> >>>
> >>> Can you try this instead?
> >>>
> >>>     r->idiag_wqueue = READ_ONCE(sk->sk_wmem_queued) ?
> >>>                       READ_ONCE(tp->write_seq) - READ_ONCE(tp->snd_una) : 0;
> >> This does not guarantee the load order on a weakly-ordered CPU. LLM
> >> suggests using this load-acquire/store-release sequence:
> >>
> >> r->idiag_wqueue = smp_load_acquire(&sk->sk_wmem_queued) ?
> >> READ_ONCE(tp->write_seq) - READ_ONCE(tp->snd_una) : 0;
> >>
> >> Then in tcp_connect_queue_skb(), replace sk_wmem_queued_add()
> >> with smp_store_release():
> >>
> >> /* Paired with smp_load_acquire() in tcp_diag_get_info(). */
> >> smp_store_release(&sk->sk_wmem_queued, sk->sk_wmem_queued + skb->truesize);
> >>
> >> What do you think?
> > Please do not do this.
> >
> > /proc/net/tcp and inet_diag dump sockets without holding the socket
> > lock. They provide a best effort snapshot, and transient inconsistent
> > values are expected (see the comment about rx_queue in get_tcp4_sock()).
> >
> > The window in tcp_v4_connect()/tcp_v6_connect() is a few usec, with the
> > socket lock held by the caller. Adding memory barriers in the TCP stack,
> > on a field updated in many places, to cover this is not worth it.
>
> tcp_connect_queue_skb(), as the name suggests, only queues the
> connecting SYN. So this adds a small setup cost on weakly-ordered CPUs
> (on x86, smp_store_release degrades to a compiler barrier).
>
> If strong memory ordering is not required, do you prefer Jiayuan's approach?

Neither, let's keep v1 as is.

I know tcp_connect_queue_skb() only queues the SYN. The cost is not the
problem; sk_wmem_queued has many other writers, and one release store
among them is a special ordering rule that nobody will remember the
next time this code is changed. This is too much complexity to hide a
transient value in a best-effort dump.

Without barriers, Jiayuan's version is only a heuristic: the loads are
not ordered, so it guarantees nothing. It also ties a sequence-space
value to memory accounting, and it would have to be copied into
get_tcp4_sock() and get_tcp6_sock() to be consistent.

Thanks.
Technical Details
Message-ID: <CAL4WiioRi2hZRMTv-v=iUpSZhbnj__rh=Uh+g2dOCre-YBa6Ug@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354531-linux-kernel-netdev=dewy.ru
References: <20261102035943.9700-1-qingfang.deng@linux.dev> <bfbc4b3c-fe19-4070-97b4-4ff8ded06011@linux.dev> <d6ba5426-fbee-49da-b18b-1419fd84fa0f@linux.dev> <CAL4Wiio9VXUtGg4UrFFU1kG2JENYL8xi0DzsDmhOp=zXs0DiUg@mail.gmail.com> <b8595ed2-6e7a-48f1-8240-3d522776e378@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354531-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] tcp: initialize send sequence numbers before
 deferring TFO
Date: Mon, 2 Nov 2026 09:20:41 +0100
Organization: Usenet Network
Message-ID: <CAL4WiioRi2hZRMTv-v=iUpSZhbnj__rh=Uh+g2dOCre-YBa6Ug@mail.gmail.com>
References: <20261102035943.9700-1-qingfang.deng@linux.dev>
 <bfbc4b3c-fe19-4070-97b4-4ff8ded06011@linux.dev> <d6ba5426-fbee-49da-b18b-1419fd84fa0f@linux.dev>
 <CAL4Wiio9VXUtGg4UrFFU1kG2JENYL8xi0DzsDmhOp=zXs0DiUg@mail.gmail.com> <b8595ed2-6e7a-48f1-8240-3d522776e378@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2880874"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ul9ZphNgo1LGNWJ3HBqUfWZxKYE= sha256:n0L7c6p7166Z2SgymHpe38EerFd4eZmGYkADRUsXPcE=
	sha1:b0wShSA27BbOwOVG256HtO18TXA= sha256:P91yorT+vttV8KEFBJ3CzNAATUtezShAmzrcGDLYgzw=
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 B782C11243B; Mon,  2 Nov 2026 11:25:05 +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 MaqQlT6cgBiA;
	Mon,  2 Nov 2026 11:24:59 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354531-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id A508F112453; Mon,  2 Nov 2026 11:24:50 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id A7E893700F; Mon,  2 Nov 2026 08:21:05 +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=1793607665;
	b=DKAwe+LF2Sj+T7vyBJ0urTz+IA51n6nVGiXLChP4L/A/chXW1WNzET4i+5u5/wetdFkp
	 r7zleWKZWh0O1kjoMz1JqJfy1rDLsNBA0vVbWaF8gqAgyXtmXoytpfv0/5CKPzDnqL88i
	 Uje3lrtPKqg9hyqKYINgUOuRUsoqGiLMWf0XpyLdlKQ8Gay2EYJzXkhfPccawLmeK1PWR
	 zD9BUp9kxFrpI46TmEQ94EmbvaOhHAwEbQB0voWjY8QgUaZW17asZiX/YOOCAoBqrszZk
	 UK7wILKXAxCno+GsZcNHkndNbxFRMWQl/jSMKEWeW2jozlcQS/RanIR3/vZtEwj6P+A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793607665;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:References:In-Reply-To:From:Date:
	 X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
	 Content-Type:Content-Transfer-Encoding;
	bh=a94/cjy7p6szhw9hzS0p+6MZPDElnqdXk1fwfe+RjpE=;
	b=AGCWLQvwtiKq4Kmkaxuf8KMdL9v/xNnygthixFVC83RK5nL6YVBmA+TG+5HAAfsMWWfL
	 qgrozIWSA1SNTYrz79KZ6SJQN1MRhHI7jf3ItWbikKid1Z49ctjad0SZExOe8QtXzbm1X
	 VmPCO5UuU2zIL4iUU1CuMJfBBeUYBMfOWB8jfA606jwys+07dXmnbAkdQqXhiN9NqKn/f
	 l2ovgekOekR9itZSt3HqX4vB+KErYKL5TZKr9cgJhEKp1DEI8oBuO4S5oSLzGwETSflKF
	 tY0hBGBxKSnf03f8Vcyt7fe//AaOA1wwe3QS2d9Csq+ap7D8ru5kYdLOmOrobj7ZgnQ==
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=Cf2PTmlI;
	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 5C684606A32F;
	Mon,  2 Nov 2026 08:21:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Cf2PTmlI
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=1793607654;
	b=jOWCk1XO6PPX5aalYHxFvVrbVvLYc8CPJoKavwwyuoXgYuJmDPxJJ+Lqz7jNwkG8TgFo
	 9rd9stAQyD73lsKOlRiZRhbUqDeWQFsOaE4ZVlDZdS3fR2jqHLYZWwr33zz0rqPsDMHza
	 WkrGIfLtDHdFBj+fwVd300zp/g7v5EyfW3tWaqpvj7C1L/fNF9x5lyMOIf76jz4NxA50Y
	 3kZyO9BmEWarwongSVpuCLIYiY2NunvXwzKDsGqcIpajsbURalPHvRtQXbZrIm3CERccB
	 eIK7uTIENLLx8Tm7iXkUG+u7EgvncX8FvsoSTuN9wq5ZXsr5GCYxLezk+jvVtPWmwKg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793607654;
	h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
	 X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
	 From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
	 Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
	bh=a94/cjy7p6szhw9hzS0p+6MZPDElnqdXk1fwfe+RjpE=;
	b=XCQ+qibKxgXHPlkof8zk/x+sPoImsDhSWb7tuXcX6q7TSz5lfYs7ZxG9LvNwDgIJW7E2
	 MPNM8CVjB4NACDuB4zbkZ79NuHjeuDFdz8cOEkvwEvFmNqfvqVW4bhAnR593BNHv+M1Ny
	 B8dJ8hISeRUZYULJ9j8xwnXMRjwMBXlWfrwCO/sQWeIOQzje27S8giEgWX5Koje9QbOjB
	 QYKCgMdThasJYPpp058kDESAMSq2fVgAQbNoFbNRGTBYzd/nsqslQXLT01204AhkWTqK9
	 IVVgE4SAi/ipQMDyvMMhFPIAUgpT4hMq3bd7d/KJVr4k1Aovql3VjYpKMEaPtyohSHg==
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=Cf2PTmlI;
	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 3B2C5606A326
	for <netdev@vger.kernel.org>; Mon,  2 Nov 2026 08:20:53 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8CED1F00919
	for <netdev@vger.kernel.org>; Mon,  2 Nov 2026 08:20:53 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793607653;
	bh=a94/cjy7p6szhw9hzS0p+6MZPDElnqdXk1fwfe+RjpE=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=Cf2PTmlIe9bAtwtVIP/4UYMfeT7OlrqqbEfyfEryca5kAQf+jVO4yTxKIGlbz5xwD
	 e5fnifIyXiuFTUS/6T4fQ00G4YktxBFw7XKRBqpxEq+0AEfO9ywwGWX4c8CsUHKCSP
	 jIdFRd/P/GpudO+hhvsJwF9IZd/kzkOh7wicrDVRnD2mCsrQOYMeT8RwBmuiZ/e52x
	 aLsctn9rofa8NTwkLo6O2rTeHtgUWgXcbtji5o5QdNYUuf4/FiGBxEiE4KhEpzQxO+
	 AXeL94srm/ePUZnrScaKgxWXi2p3lBX4keE5HqKLfvNQGCXmeuFIZmlSTUF1qgwhEl
	 cPubAhREL1lSQ==
X-Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-6de1ca1b05aso2071857eaf.0
        for <netdev@vger.kernel.org>; Mon, 02 Nov 2026 00:20:53 -0800 (PST)
X-Forwarded-Encrypted: i=1; AKwUvBxmWlib5akWqrWxsAg3o8uyVKWYl9ZM8dSIVPfvz3XshhS+DjTJbJz+05ItROeITiqtaFhkTco=@vger.kernel.org
X-Gm-Message-State: AFq9FYKc4vx0Om1nHNAZSHz4Wut9e3+FSxkI623UTOc+eIy5QPQ+qz2j
	FY7q6r6F9lRoicmuAAkKQyPqmbcNTi/zgkf9Ckv1KeQgl33IyUBHlodzRuoo0/VxIYg4Kl0tWRN
	4pOL0g3UlFwWLI4w1GYh+APSn11El3zQ=
X-Received: by 2002:a05:6820:a290:20b0:700:371e:ee06 with SMTP id
 006d021491bc7-714f2a6b900mr2980101eaf.80.1793607653166; Mon, 02 Nov 2026
 00:20:53 -0800 (PST)
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
X-In-Reply-To: <b8595ed2-6e7a-48f1-8240-3d522776e378@linux.dev>
X-Gmail-Original-Message-ID: <CAL4WiioRi2hZRMTv-v=iUpSZhbnj__rh=Uh+g2dOCre-YBa6Ug@mail.gmail.com>
X-Gm-Features: AclHuK8Xupe88TcKCHCib38ybjK5zp2uH3F2lIdfCw_YoWgKtjV7dTc0AeviD08
X-Cc: Jiayuan Chen <jiayuan.chen@linux.dev>, Neal Cardwell <ncardwell@google.com>, 
	Kuniyuki Iwashima <kuniyu@google.com>, "David S. Miller" <davem@davemloft.net>, 
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, 
	Yuchung Cheng <ycheng@google.com>, Wei Wang <weiwan@google.com>, netdev@vger.kernel.org, 
	linux-kernel@vger.kernel.org