From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796295355; b=c61OM3qezd7Kx1AwaUlNeq96TFyiw7lMPuk0DJz/V6l6jjlf259I0h+5AK6pgyS7Yfz9 zOMAP5R0wNFQ1LY48s6P9OnN6vTgypFpyUHSgjHXVOQez4cOB7By+D3L1oDvE5oFwUrds B16ZZXZaIqO/bffnuZBNMdAWAxN4JCeUYzM18ybLBFIWHAonk3n4F50D9R+ZcYTWN1bF7 xCsrxdE9B/8uHD9EpksD9gFDdE8+beToSm7sX8y8NYQnUt9mntKm8gBQQ1hClK/l89Cft 0hpBX5DsMPYFq0cGyxfofcb/sPM9n0ftm4E9Bkj/Eb7zmtgQhivlAW/KJOAB9vd6ghg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796295355; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:Message-ID:Subject:From:To:Cc:Content-Type; bh=yzQzG0NeMPVoMr++xsY373F6tTLm26n7LaIvJh+T0+A=; b=vqPGqHu9P9L/PX68hk0BYE8koK4X5qJwJ9Oz2cr33MlOBcwWh6VQmh9K3lfVvDK5xJDd KiQhaNO5hWkGYAc9bajx3nuLd9bUY3/3twUawVuC0j2ooUR9nVeVq2+S5jCXRJkRThNYt fJxGmG6ECoIiRVWm8VcAMwGECJOEDThuVLjixizRKEbQo82yG8FXsCstfoB6mo4T36ioh mXRLkdbhRBg0KqHhvKChFyTPyaU+7kOLT2I7pyDM7GWdkH9+fE/ch6jqp+eugXnuZjsP4 2x4j3Pay6YGhx1R/SZA3yTELBga0S2Y1RmdQUQpoYTgeMBRuFte2FPdGd+DxYE5UbQg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VmGepZWp; arc=none smtp.remote-ip=209.85.210.200 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (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 263B4606A322 for ; Thu, 3 Dec 2026 10:55:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 263B4606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VmGepZWp Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-8bb1a7b0e52so9655179b3a.1 for ; Thu, 03 Dec 2026 02:55:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796295354; x=1796900154; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yzQzG0NeMPVoMr++xsY373F6tTLm26n7LaIvJh+T0+A=; b=VmGepZWpkiq7N+h4tOw2YJzoBBomYvBbNGGZg3lOFZz69zJN2jJq/yKQYsZFMoDPHx zPsWHXoakw/sVgtrLz8SHIhGYpRVmT7E3KpX0OjdME/5RxEAWbGAEk8s55GQkHI/m7hf Vz8pq0qcj13W5hGg6aXAhI6MjWAHbzVkqw9LQDdnrHhXuJ6I4ogsuu/mikF/pltp33Qr 710a59Qo6OwCnhfYabZz9/qQAE5cPtXHfKxo2M2bx4NXIZg+pkoBH0B2DWMragEt8KjM FW1Yd7WXyvRLV/aHHKjKBqwHjaRbuQcS4/d+HeLXDydMiQBmkpzNliZNyXxJ4VICZu3H Yd7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796295354; x=1796900154; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yzQzG0NeMPVoMr++xsY373F6tTLm26n7LaIvJh+T0+A=; b=0gQkxmH7Au/YBZsDF7QB+5ARsAiVt/SdxzB+6Ff522G7NJDPzyr++sGhtsEZ8rw1q9 BoRUt93mdlLmHFPJarpszkFGagUKXvEfKHlCL3m9oVwXn0w2AogNL6J8LBkR0e8P4LeS Af1QsnTbLQPE9iKHlS4+OHnS8DthEzDo4/DjCRFJzMTuu+PQJy1AB/seKfX+b4kYAUyu vqDBYEEslA4/avsbJnIzHuFDQKsQ+7CBDT1kEE63dYR5jEOq6h12JbrVu1I62wwL+QVr sDkrR+uBCNcUidqnZBGijqbtnEea8d26QirkqVxNqqu9kG3zwqMmorYD84v0wnv7RxnT RgDA== X-Gm-Message-State: APuU4Z+h9mQOP7ip4nNCEWJL3gGfvfHomLhiY/xVDvT6m/q/T565F1ti OBk7NOl1ZjnCkjxDMJRznqs+zpeAhfkbLqCb35x0CE9F4X8pcMAsWQYroI5lmUHYoPQ94ODjCWq 1zBC1SQ== X-Received: from pgjk20-n2.prod.google.com ([2002:a05:6a02:81d4:20b0:cd8:c4be:4fc3]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:1605:b0:3e0:d508:59a6 with SMTP id adf61e73a8af0-4014b5642camr47633637637.13.1796295354039; Thu, 03 Dec 2026 02:55:54 -0800 (PST) Date: Thu, 3 Dec 2026 19:55:53 +0900 In-Reply-To: <20261127045059.142247-1-jiayuan.chen@linux.dev> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261127045059.142247-1-jiayuan.chen@linux.dev> Message-ID: Subject: Re: [PATCH net] tcp_metrics: fix zero snd_cwnd_clamp from a half updated entry From: Kuniyuki Iwashima To: Jiayuan Chen Cc: netdev@vger.kernel.org, Eric Dumazet , Neal Cardwell , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" 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: > > 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 > > > 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 Reviewed-by: Kuniyuki Iwashima