Article View: linux.kernel.netdev
Article #8232Re: [PATCH net-next] ipvs: annotate the lockless read of sysctl_sync_threshold[0]
From: Simon Horman
Date: Wed, 28 Oct 2026 12:49
Date: Wed, 28 Oct 2026 12:49
62 lines
10258 bytes
10258 bytes
On Mon, Oct 26, 2026 at 04:37:08PM +0800, Linkui Xiao wrote:
> 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>
Hi,
I agree that adding a READ_ONCE annotation is appropriate in
sysctl_sync_threshold().
But I wonder if it would also be appropriate to call sysctl_sync_threshold()
only once (per-packet) in ip_vs_sync_conn_needed(). Stashing the value in
a local variable if appropriate.
> ---
> 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:
<20261028124935.GS257209@horms.kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352853-linux-kernel-netdev=dewy.ruReferences:
<20261026083708.617278-1-xiaolinkui@126.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-352853-linux-kernel-netdev=dewy.ru From: horms@kernel.org (Simon Horman) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next] ipvs: annotate the lockless read of sysctl_sync_threshold[0] Date: Wed, 28 Oct 2026 12:49:35 +0000 Organization: Usenet Network Message-ID: <20261028124935.GS257209@horms.kernel.org> References: <20261026083708.617278-1-xiaolinkui@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="1772553"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:r25g7Q6L7gfxXRPm5/24bQlr3FY= sha256:wA8n/WeurSyGKbJ+KY7aNNkg0X03RO/0XTjxkYeF39U= sha1:GgSuOubp34lNDN/fJWgQj4/XdPE= sha256:AOT6QKZ9V0nbrVRKC5Ruw740Cl0IDugNZnrIMkawEnE= Content-Disposition: inline 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 2DBFF125C36; Wed, 28 Oct 2026 15:50:48 +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 zSNMLncNwnMv; Wed, 28 Oct 2026 15:50:45 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-352853-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 66ABD125C33; Wed, 28 Oct 2026 15:50:37 +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 721F12926E; Wed, 28 Oct 2026 12:49:44 +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=1793191783; b=k7hq3Awp+I0Yq/SAtohTQJZ59eZZJ1nj0eWwbn6rQTLVc7eRmJtiFWUc5EC37fP+0Ca7 fWu6kf2nYDphZx8JYsbyipci5onBP7Qjx8ZDpYqgY6oDMFLzahRV9lOwcdx/dSSXTRjsR NwKifydJRc5/iIJ1wLc0UZ+7cmuiNdhaNsykBm0EzGfGLDNN5ZblIUSexYUzjXRqQzL5R 6VNxCW2U6hQffWVKqeDRw+qk7Pm9rdxnkL1PudEja+xCAlCWrvKNBg1KN+A7GJbVirbY+ /cUvHuawlfnQggx9V6tjV+sLRdPGkhVaGXz3/qcE7yAwg2gaRrkPybCMrCmr5lKgYFw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793191783; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=vFL6cRdxdM/GvutOrTal3gLSXRDYBsRFQAjUnosz4qU=; b=jqU09vhbNeNoYYVTS1gCRC9yKumzr6O1qWkoq/bJiK3/RGesFtd1FNEwHYxzEoGhFTcs bfs6eyjZD4Mgo/4zjrwE0ye6HYcG4iqzDtohdCcDPzFnJZKMEL9NgVYJvS6aniVEkYVFo l2lBErHsuiCneieFF/UsifSbR6P9qXWlZqKub5zPThXTu8q7g8JivDpJV5zTKcYuv8vef 6xLKPr87B+JK1FACwC7E9kmHVY8x7KRtYNMr6FNU8ZN3eMbWl8ecRubIl6rf9OY6TE2gT nYWcr8wqPltopWyj80nhCRgVWom8NUF9chOdmgMURlQF/+LkXJDguWAB1fWIrWe9+hQ== 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=iXyejjpd; 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 A083F606A322; Wed, 28 Oct 2026 12:49:43 +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=iXyejjpd 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=1793191780; b=Z3/PHq85rirxCVEQpaXGTpGvvwb0KKF1BlG9fIh+D8tFiPC8Zi6QGFAmBkp0AKnxH1tJ XT9MahrE9s07Zgp9thd/QysoeTN/Nn9lLEwXukG9jArNyzP7By30iJEAJv3sySsPIu/nU jtFdAgEk09DLPZs1J5EuH2TXPrmBm+6fPaP3WyCd6ObeOQIf15y5QJgorvADsx8w8zdtt b8Afj+hs5T9KDbjQP/zB9BlXxAG7GvWdyLRrKvOICzKhsbzHoztE+mMxjagB7iS3EVSIY jH9bqHh/q3Xh80xWDHXrRRriXsBl7wlbRts4ahXuaFjuhZ6Cg+FX2AH+Q9aUBNG273Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793191780; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=vFL6cRdxdM/GvutOrTal3gLSXRDYBsRFQAjUnosz4qU=; b=BM+zc6/Xl2KjFXsHFAxXvVbQlFoFjxSXgEM4AdImpvKJuuTtdvjD7v43JveRPFN+VsgL VrR0bQ3Hpt333gDSb8GBffrVPpYofDARiblox7t4jVmCEJosVY4GYkkrn5xXBDnpqGG5+ N2JxlKjxs8hPg0Ym2Gxd5YEJfiCC3A/tOWX9eazJH+RUDTlaK6mjiVssK7pds3zANnrvT W4mbqxB4VvhWFWnjg3vT4pxKSgESQn/Qa8oWMIDaWZ0vdQ9oHqqpkzg+GKE2fmPO+NzSn ArPZWQe0OaHGJsA9fQUjpZMAyfXY+aqiOuItPomeku5/gmiuhBcimTnoPgeticOAhNg== 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=iXyejjpd; 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 EF35C606A327; Wed, 28 Oct 2026 12:49:39 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52DD21F01828; Wed, 28 Oct 2026 12:49:37 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793191779; bh=vFL6cRdxdM/GvutOrTal3gLSXRDYBsRFQAjUnosz4qU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=iXyejjpdwmtKdyZQ4wNmhns8jXDZFgDROrNkHd+b42jEhmnvoJKsPi1NZJZyRWTMv KRRh67fHj2DXO85bKfe/HtSkJQ0a9713nl9xzTaX4nhwejrtxVFiUldfDQ/JrajZkR 9YNAGKin9nAOwzI2j3hX7vKG8qbog2rcHyH4t0c8V3cbrm4UaEdnLNt7irOhr1UORq KzOrWHiukj/wPz147KINOUEWy1UD3rN5ojmVAwA6LBnvKdpGQCeDLVZ4RoOSl45O25 Dj6dB1nw/m7/iwSQmx4Jespu/zdw0apdoopwnpapXjr85ZIjFori9yJ2ods2cDMAii nCxrM06XZlnww== X-Cc: ja@ssi.bg, dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, lvs-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Linkui Xiao <xiaolinkui@kylinos.cn> 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: <20261026083708.617278-1-xiaolinkui@126.com>