Article View: linux.kernel.netdev
Article #9528Re: [PATCH net] tcp: initialize send sequence numbers before deferring TFO
From: Qingfang Deng
Date: Mon, 02 Nov 2026 08:13
Date: Mon, 02 Nov 2026 08:13
71 lines
11815 bytes
11815 bytes
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?
>
> The bug you found is different: with deferred TFO, the bogus values stay
> forever, until the application calls sendmsg(). Your v1 fixes this.
>
> Note that tcpi_notsent_bytes (tcp_get_info()) is also fixed by your
> patch, you might mention this in the changelog. Not a big deal if you
> do not want to send a v2.
>
> Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Technical Details
Message-ID:
<b8595ed2-6e7a-48f1-8240-3d522776e378@linux.dev>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354527-linux-kernel-netdev=dewy.ruReferences:
<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>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-354527-linux-kernel-netdev=dewy.ru From: qingfang.deng@linux.dev (Qingfang Deng) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] tcp: initialize send sequence numbers before deferring TFO Date: Mon, 2 Nov 2026 16:13:06 +0800 Organization: Usenet Network Message-ID: <b8595ed2-6e7a-48f1-8240-3d522776e378@linux.dev> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2879854"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:MRzCM1EZRpqqC1eNpzVBTSZmoqA= sha256:XKZxOpeGR6ZRWXGnYoe6ZU1tEW6oX3iPoRn/FDrc7n8= sha1:V6gks+Io5Ssd4J2KA3dTg+wQRVg= sha256:wkktt+EJChXa2rEBKHsYcP4ZnCwi24QVtrFS3aI7OIg= 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 442AA112463; Mon, 2 Nov 2026 11:19:36 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.049 X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev 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 O3MoFtpq8Z6i; Mon, 2 Nov 2026 11:19:33 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-354527-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 1E50B11243B; Mon, 2 Nov 2026 11:19:25 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 409E52A141; Mon, 2 Nov 2026 08:13:29 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1793607202; b=n8uIu54Jrq1ek+5RXGtpYvx2HEkzNo+aolIv/mzxMr4RhcnxA9gMzjjrRWtx/zCm6sDT mnRXyY+1dfQFtVsl8RHm+iS1tAO/V5sQx754dtbfF2/T+ncDv/Zk5BwJEEv70vL6FziwA q5djltKH2gu2nv46s++SPwoAjB+NxpwF3SQacndfA4tO/pSQXkQGQHX+sfGAH/2uPgQ09 y2JCiim9QIoBRNt7Ax2ygWm3YLPMAX6HNQq2jeQGE68dePhohVi20gCyZ8giyFwrYIL2F RUj2vQgxqzT7Z6Zxwo+W3Bdef+oTqU7EDiw5hXrmqbGMBaYSQiF5BxRZD/l3Zo8yEXQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793607202; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=NR2DG4to3DrgMNw96bT2GuCZ0TZVPXbJYqsaTD914z0=; b=a8HAT9FTI45K/6Lhu+T+uR7sD1F/1d8fl3gNwk/tz7TFcppYTf4HoeELCJzKo1e06Th6 UbxqbUK+0YZPdiZM1MMo6jYQYGygDRq52CC5RyqdXQkw5ORS/JKBvkTbIhgipDv6nCaZO 6B9kOYWFgAvkDkFkD8/Pe2rsVhcg309pPOyGXtHMis+mj9l8RalnqP6JWdFCUc86pqBVH 4pkHUzCJHjCfvH6aXtoktLUrA9fmFT4dzLQcJouoGzdU3EXfR6AJ/qnip6kFwXqK+DyW4 b+fmd72mVQgaSoEOG8eV68RIQDKwfQ6soOINJlNh18Yy0iNzhMXw6UEmhOY4zuy8kMA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=oDr4wuMZ; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=fail 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 C5F41606A329; Mon, 2 Nov 2026 08:13:22 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=oDr4wuMZ X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.187 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793607196; b=pC2X6yN+EzOHOj0qvdkCu0UqU2iLTWzyVd2hK/qSFC456zzV6FRCCApoqTJaQTw8YiCv Ii61SjWWNTmlsxxI4h6gNdzCuAsl7s4OLY0wzDk3CL0dGgDW98TuubYPGBbyRdtK4A+K+ xkm3tM1ihbTdckiPQhUkNZhTbAjv0F4nFR6PcKFhCbHUvTFGCEmpF+VyLJQWFvLA6rEay h9ROLelqbjBqtgqDia5c9/xr7FM3fmAwgOU0I8R7vHFt/bfq/6aYr04dkmpiEvpEjzu3k eDUd8AH7c7uXzazP+qj6TG1DMv66skRa6zJKpMQNX5gweE65Y3VmJ434+fPwKNO+xKA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793607196; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=NR2DG4to3DrgMNw96bT2GuCZ0TZVPXbJYqsaTD914z0=; b=5n39f9Utg+VuoWi6B7uBjbzabUPsPwv7XWgeBxzgHa8DtmT8BwX5Ezaxqok3Wl1m7cGv Ce5ClDoII3hl0GAAD8+PgH0oG+tN9qf0qt+vi2L/BTYGhlV86cAS3XSnZWYMCUsBVNeOq cz7gUOROut6lQhFrLj7mDaWBIFASuXAmeooQJa5J9ErReb47EcO8kJJOx8tbHF0IHmp6s kw9LaErnWiAskBizPivNtVeDxuuz50TyOIt4Mgk36c+0liVDiT1YkGfIaSZb7nbbXKTau y14amInFQ3dUZ4VENBzSBaOXQ+utEfeXln4DbymTMT3BYtGAhDsTWtROkj+Ygft8SRw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=oDr4wuMZ; arc=none smtp.remote-ip=91.218.175.187 X-Received: from mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07A48606A326 for <netdev@vger.kernel.org>; Mon, 2 Nov 2026 08:13:15 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 07A48606A326 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=JQs5O3d34CnsWeVGB2NdzABlZw7PWL1Nim0bgD3pMKQ=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793607193; v=1; x=1794211993; b=oDr4wuMZMH5849UzJ1/G4QumPUQjvw/U32C1N5y/WbL9FgfQSCOux6E4MqPojonTH5G4EwN5 Q7jAWb74cHew43NTnG2p3yerHs4ulDpIQsZDV1Pb2ATTBYplEveMm7082vQGo9iqbY2ZgEE7SC6 hGpLM14yZZOB5QUvvi6p5KPg= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id e2abdf9b3fa2c5ff; Mon, 02 Nov 2026 08:13:13 +0000 X-Mizu-Trace-ID: e2abdf9b3fa2c5ff X-Migadu-Flow: FLOW_OUT 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-User-Agent: Mozilla Thunderbird 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 X-In-Reply-To: <CAL4Wiio9VXUtGg4UrFFU1kG2JENYL8xi0DzsDmhOp=zXs0DiUg@mail.gmail.com>