From: Kuniyuki Iwashima <kuniyu@google.com>
To: Jiayuan Chen <jiayuan.chen@linux.dev>
Cc: netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>,
Neal Cardwell <ncardwell@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] tcp_metrics: fix zero snd_cwnd_clamp from a half updated entry
Date: Thu, 3 Dec 2026 19:55:53 +0900 [thread overview]
Message-ID: <axFKsB7JELrpjnRg@google.com> (raw)
In-Reply-To: <20261127045059.142247-1-jiayuan.chen@linux.dev>
On Fri, 27 Nov 2026 12:50:58 +0800, Jiayuan Chen wrote:
> tcp_init_metrics() takes snd_cwnd_clamp from the cached TCP_METRIC_CWND
> when that metric is locked, i.e. the route has "cwnd lock N".
>
> tcpm_suck_dst() refreshes a cached entry in place. It writes tcpm_lock
> first and only then updates TCP_METRIC_CWND from
> dst_metric_raw(dst, RTAX_CWND). Readers only hold rcu_read_lock(), so
> when an entry that had no cwnd metric (value 0) is refreshed from a
> route with a locked cwnd we can have:
>
> CPU0 CPU1
> tcpm_suck_dst() tcp_init_metrics()
> WRITE_ONCE(tm->tcpm_lock, val)
> tcp_metric_locked(tm, TCP_METRIC_CWND)
> -> true
> tcp_metric_get(tm, TCP_METRIC_CWND)
> -> 0, not updated yet
> tp->snd_cwnd_clamp = 0
> tcp_metric_set(tm, TCP_METRIC_CWND,
> dst_metric_raw(dst, RTAX_CWND))
>
> So tcp_init_metrics() sets snd_cwnd_clamp to 0, which is what commit
> 363c8c79220d ("net: ipv4: add zero check for snd_cwnd_clamp") tried to
> prevent.
>
> With an mdelay() added after the tcpm_lock write to widen the window,
> I can hit:
>
> WARNING: ./include/net/tcp.h:1580 at tcp_init_transfer+0xc16/0xd50
> Call Trace:
> <TASK>
> tcp_finish_connect+0xec/0x2f0
> tcp_rcv_state_process+0x8ae/0x3060
> tcp_v4_do_rcv+0xbe/0x580
> __release_sock+0x1a2/0x1d0
> release_sock+0x133/0x150
> inet_stream_connect+0x5d/0x80
> __sys_connect_file+0xad/0xf0
> __sys_connect+0xa8/0xe0
> __x64_sys_connect+0x42/0x60
> x64_sys_call+0x2554/0x27e0
> do_syscall_64+0xe4/0x470
> entry_SYSCALL_64_after_hwframe+0x76/0x7e
> </TASK>
>
> Writing the value before the lock bit does not help, changing the route
> the other way (from "cwnd lock N" to no cwnd) then gives the same 0,
> since the lock bit and the value are read separately.
>
> Commit 363c8c79220d ("net: ipv4: add zero check for snd_cwnd_clamp")
> already rejects a locked cwnd of 0 from the route config, so a 0 here
> can only come from a half updated entry. Just ignore it and keep the
> current snd_cwnd_clamp, like we already do for TCP_METRIC_SSTHRESH.
>
> Fixes: 51c5d0c4b169 ("tcp: Maintain dynamic metrics in local cache.")
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
prev parent reply other threads:[~2026-12-03 10:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 4:50 [PATCH net] tcp_metrics: fix zero snd_cwnd_clamp from a half updated entry Jiayuan Chen
2026-12-03 10:55 ` Kuniyuki Iwashima [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=axFKsB7JELrpjnRg@google.com \
--to=kuniyu@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jiayuan.chen@linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox