🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7383

[PATCH net-next] ipvs: annotate the lockless read of sysctl_sync_threshold[0]

#7383
From: Linkui Xiao
Date: Mon, 26 Oct 2026 08:37
50 lines
10318 bytes
From: Linkui Xiao <xiaolinkui@kylinos.cn>

sysctl_sync_threshold() reads ipvs->sysctl_sync_threshold[0] from the
packet path without any synchronization: ip_vs_sync_conn_needed(),
ip_vs_sync_conn_v0() and ip_vs_sync_conn() run in softirq context on
behalf of ip_vs_in_hook(), ip_vs_conn_expire() is a timer callback and
ip_vs_proc_conn() runs in the backup sync kthread. The only writer,
proc_do_sync_threshold(), updates the array with a plain memcpy() while
holding ipvs->sync_mutex, a mutex none of the readers ever take.

Commit 749c42b620a9 ("ipvs: reduce sync rate with time thresholds")
already recognized this race, but only for the second element of the
array: "As the sysctl_sync_period now can be 0 use ACCESS_ONCE to avoid
division by zero". sysctl_sync_threshold() was left with a plain access
even though both elements live in the same array and are written by the
same memcpy().

A stale value is not dangerous here: the element is only compared
against a packet counter and stored into cp->in_pkts, and an aligned int
cannot tear on any supported architecture. What the missing annotation
does allow is for the compiler to reload the element, so the two
comparisons in ip_vs_sync_conn_needed() can observe different values
for one and the same packet, and KCSAN reports the unsynchronized
access.

Read the element once with READ_ONCE(), exactly like the adjacent
sysctl_sync_period() has done since 749c42b620a9.

Fixes: 749c42b620a9 ("ipvs: reduce sync rate with time thresholds")
Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
---
 include/net/ip_vs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 9a83bff32569..5aa6a94ed104 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -1353,7 +1353,7 @@ static inline int sysctl_conn_max(struct netns_ipvs *ipvs)
 
 static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
 {
-	return ipvs->sysctl_sync_threshold[0];
+	return READ_ONCE(ipvs->sysctl_sync_threshold[0]);
 }
 
 static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
-- 
2.25.1
Technical Details
Message-ID: <20261026083708.617278-1-xiaolinkui@126.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-351762-linux-kernel-netdev=dewy.ru

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-351762-linux-kernel-netdev=dewy.ru
From: xiaolinkui@126.com (Linkui Xiao)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next] ipvs: annotate the lockless read of sysctl_sync_threshold[0]
Date: Mon, 26 Oct 2026 16:37:08 +0800
Organization: Usenet Network
Message-ID: <20261026083708.617278-1-xiaolinkui@126.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1263643"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:JDtWA2NQLA3touq9aMIYMqzyldI= sha256:Go6nct+h7FduqH6LGaX0idh7StV94azzK0y155IztJo=
	sha1:oDptIBhzYnumYZw1EPxjdmsTDng= sha256:utvj5TQ1GTX+V2mImNqQVTiWRCSROPQwRmEetBlEZ+I=
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 873E9125B91; Mon, 26 Oct 2026 11:44:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.047
X-Spam-Status: No, score=-3.047 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, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, 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, UNPARSEABLE_RELAY=0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=126.com
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 juP_MEFs_9su;
	Mon, 26 Oct 2026 11:44:43 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-351762-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=126.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id C0907125B7B; Mon, 26 Oct 2026 11:44:33 +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 08DC23C60D; Mon, 26 Oct 2026 08:38:45 +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=1793003922;
	b=ntZfs3oFAxXd71Zl8IY4MYm7JbUxQ5cX/FhxEfVKzn9Lvr6uzHfw8fWERp4MUlACIn8L
	 DT6cf08tqNtMH61evhC7/E6p/UHld4r2QvpbsMmEx1EMYRpRDa+xKYhTOXgzaMrFEmebI
	 NM57znKcQmV/p9G6fsxqbkNWH+l289bL1GP2OwTjo+IVQUVeaK946tQBtvnz025ddbIcH
	 zZ74iD0m6trHTE7qF+2LsVBHXOMhGt0oG5RirvCxFxCM10tVM4qxw3PC32/PzCkUUs0El
	 /1+flVIBR51xo0qt9TZ02mLibSBnHfs8uNmryujRIdfGJQk4TJtDQpT2vP7+aIQc0EQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793003922;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To:
	 Cc:Subject:Date:Message-Id:X-Mailer:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding:X-CM-TRANSID:
	 X-Coremail-Antispam:X-CM-SenderInfo;
	bh=coeVfKNB1bEP2tEL7RGoajkOYYpgAEhPrKIKA7ffVew=;
	b=eSoOPq0J42lgyQ45BBL6ydTDKV/T5MpDbHm6dos27caBVKijl6ucDzeDvNqozVXgzl4a
	 nuy5N4oz63x2A1JOim6GuHXdUgBH4IqX+gr/Q/iQZc3DCoYuJqylpa1v9kZB4OMvvX7vx
	 DP6EkeMw+WDLBn2J8r4aQS1c08gFY3vtjw2v+l3ROEFWE5MYLD2iNfy152ARcyfrQhn8Z
	 vzYPVVsIriTH97Or0iXBhMZbkJjeM10j7S5gl9UMKo6+RkVQMHU1SRzs8pj3sg6uTvUD7
	 sTKDX4WTTTj9RVPXMPdLfOQ7ITAPbPqNKo2BiTE1fgZ9xjWEdsLZhsOXtszhCX728yA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=HjYoLhxe;
	dmarc=pass header.from=126.com;
	spf=pass smtp.mailfrom=126.com;
	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 52492606A32C;
	Mon, 26 Oct 2026 08:38:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=HjYoLhxe
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.8
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793003921;
	b=zulY26lsOaPU4/yscFtJF24LRzqIPmMh7sQ/zTIb2yjH/o8DH34x4uDBYOr0rJZGkW/c
	 nV7+Fk6dvZLY2epAI8S8sQhdbNdb4dd/WE+/kWpTrq/xRBGM5yDjhmZwEIZAdnVL+8LkD
	 OPFy4KYHo2Smxnu9f8Ab24jirWTlwLqreMYmDuKiETjhkbATFYLPmK8w4Q5xFniKlVNCX
	 JDU6J6xKTrmiEZSiJ/LQveR4RDYL9DvDVHs5m3AfjsnLxEZDg281MTPknlWovz/9fL7+1
	 8HdPeFF/bDDFn+n/TbF0a5AC/BmZbWZikh61fwm4PeotZRNFL8OHhjWOhjfuZjV0XvA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793003921;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding:
	 X-CM-TRANSID:X-Coremail-Antispam:X-CM-SenderInfo;
	bh=coeVfKNB1bEP2tEL7RGoajkOYYpgAEhPrKIKA7ffVew=;
	b=oLZcPTBSKgmn14+fKpF//YLkEdtVfuGVVthCvVQAobXQnJmrhLNpvBwQ+GgLUTG8kT3O
	 Ox9vBNUsgPXOhZrn7h0HZpSlZomKQgVHhpCvZjKhZAvTmjUwrbqx8eMgloQ3yhGR+M18y
	 9OIuMLtRm27hKO2CqP2C8Ub9WqKEKvFq/UFHNf29BEoDCPszXFVoqcxSyNgCf1Xvn9OFt
	 O+wU89ZVhKyKA+bC5a1+XdiBTPlUxWvS1Gajo+hdSyFl2+HmL4NgRiuerrE8WabCLsUPd
	 PyJCKAQzNgTIHn74MNAKKJjfLemI3YbKHXAhhIW3dSrgnQ5EQgvdkfu+fLEtyKWcKjA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=126.com;
	spf=pass smtp.mailfrom=126.com;
	dkim=pass header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=HjYoLhxe;
	arc=none smtp.remote-ip=117.135.210.8
X-Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.8])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA3D2606A31A;
	Mon, 26 Oct 2026 08:38:37 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA3D2606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com;
	s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=co
	eVfKNB1bEP2tEL7RGoajkOYYpgAEhPrKIKA7ffVew=; b=HjYoLhxecT72kvAGe2
	3UKM8NdPrKHWEUYKWFDOs+c9R5ulO1pd+ZyybInYPo4dTCHiB54/7YBDJVPl02Lj
	o0OCAMwIHf//S7UE2f/2iouj/aIUn2/W8vQmAk0Q7avlEty9yUHKcJOhD+TtYzqw
	/h2R6RdhFPO+vsHFD25D0t/jU=
X-Received: from localhost.localdomain (unknown [])
	by gzsmtp3 (Coremail) with SMTP id PikvCgD3v_01Ed9qmtQJCQ--.65058S2;
	Mon, 26 Oct 2026 16:37:11 +0800 (CST)
X-Cc: netdev@vger.kernel.org,
	lvs-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Linkui Xiao <xiaolinkui@kylinos.cn>
X-Mailer: git-send-email 2.25.1
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-CM-TRANSID: PikvCgD3v_01Ed9qmtQJCQ--.65058S2
X-Coremail-Antispam: 1Uf129KBjvJXoW7ZF15Cw43Zw47uw4DJF17GFg_yoW8tr4xpr
	W5Jr9xAr4Du3y7Xr4DJFy29rWSvw4kG3y7KF98Kr4rA3WDJr98trySyFy0kFW29rn7AFWS
	vFZ8ta4Fka98AFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
	9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UlhFsUUUUU=
X-CM-SenderInfo: p0ld0z5lqn3xa6rslhhfrp/xtbBqBfjumrfETfT4wAA3F