🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24997

Re: [PATCH ipsec] xfrm: Serialize offload stats updates with x->lock

#24997
From: Steffen Klassert
Date: Tue, 01 Dec 2026 06:34
53 lines
12267 bytes
On Wed, Nov 25, 2026 at 04:08:35AM +0200, Jianbo Liu wrote:
> xfrm_dev_state_update_stats() calls into the driver, which adds to
> x->curlft and x->stats what the device counted since the last call.
> Callers use different locks, so two of them can refresh the same
> state at once and count the same packets twice, and a dump can copy
> the counters while another caller updates them.
> 
> Serialize all device stats refreshes with x->lock and assert it in
> xfrm_dev_state_update_stats(). Build the SA message of a netlink
> dump, get or notification under the same lock.
> 
> The SA dump and xfrm_state_update_stats() walk the states under
> xfrm_state_lock, where x->lock cannot be taken: the lock order is
> x->lock, then xfrm_state_lock. Add xfrm_state_walk_batch(), which
> takes references on at most 32 states per xfrm_state_lock hold, and
> handle each state under x->lock after the list lock is dropped.
> States rejected by the dump filter count against the 32, so a filter
> that matches few states cannot keep the list lock held over the whole
> list. xfrm_state_walk() cannot give this bound: it calls back only
> for states that pass the filter. Walk markers and states being
> deleted do not count, so a call always covers 32 states or reaches
> the end of the list.
> 
> Keep the refresh right before each state is copied, so every part of
> a multi-part dump still has current counters. When a state does not
> fit into the skb, put the walk marker back in front of it and drop
> the references, so no state stays referenced between two dump calls.
> If the state was unlinked meanwhile, skip it and go on.
> 
> copy_to_user_state() cannot take x->lock itself: build_expire() calls
> it with the lock held. Move the refresh out of it and let each caller
> refresh under x->lock. PF_KEY never refreshed and does not change.
> 
> Fixes: c9fa320b00cf ("xfrm: copy_to_user_state fetch offloaded SA packets/bytes statistics")
> Fixes: f9f221c98fd8 ("xfrm: get global statistics from the offloaded device")
> Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
> Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
> ---
> Cen Zhang's "[PATCH ipsec v2 1/2] xfrm: protect offload statistics
> updates from device teardown" [1] adds x->lock around the same two
> calls in xfrm_state_netlink() and xfrm_notify_sa(), so only one of
> the two patches can be applied. This patch takes the lock in the SA
> dump and in xfrm_state_update_stats() as well.
> 
> [1] https://lore.kernel.org/netdev/pm-xfrm-core-objects-candidate-0050-v4-3c6b8c5369a802e9be0e-1@gmail.com/
> 
>  include/net/xfrm.h    | 12 ++++++
>  net/xfrm/xfrm_state.c | 87 +++++++++++++++++++++++++++++++++++++++----
>  net/xfrm/xfrm_user.c  | 45 ++++++++++++++++++++--
>  3 files changed, 133 insertions(+), 11 deletions(-)

Applied, thanks a lot!
Technical Details
Message-ID: <aw5qktTFvRuukgT_@gauss4>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374734-linux-kernel-netdev=dewy.ru
References: <20261125020835.1132797-1-jianbol@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374734-linux-kernel-netdev=dewy.ru
From: steffen.klassert@secunet.com (Steffen Klassert)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH ipsec] xfrm: Serialize offload stats updates with x->lock
Date: Tue, 1 Dec 2026 07:34:58 +0100
Organization: Usenet Network
Message-ID: <aw5qktTFvRuukgT_@gauss4>
References: <20261125020835.1132797-1-jianbol@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Injection-Info: usenet.network;
	logging-data="1636281"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:N6fMW8dnRRWhsOmrYTejnCg+djQ= sha256:34UeXUeXLsEg4ySyF7PLd9cR09czJMAqI5grMxYJo54=
	sha1:zRbl/b/GOUP3lPt4/8adEcBsnN0= sha256:Kw9BY+a/26mCB56jSGXuWg5P1hgPEAh06w458awXyIE=
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 8C6B8117260; Tue,  1 Dec 2026 09:35:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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 (2048-bit key)
	header.d=secunet.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 HmX3Dsvgfm7Q;
	Tue,  1 Dec 2026 09:35:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374734-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=secunet.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id BB6F5116DAC; Tue,  1 Dec 2026 09:35:17 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 1F82E26663; Tue,  1 Dec 2026 06:35:15 +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=1796106914;
	b=TBALlmsLaLau3Rt1Cz2l2i9ZCC8eopbBqVn3jsz+/6vU8bPD7TxhtgymwZ0ex3ZLCZIq
	 uWgQ6o5+REiFTgD5ZW7vZ5STpkkt2/CE5XufXwl0q7A/SL52DDi55+Jb71R/L+RW3sWro
	 Z3jUrOPGgovPUX40GO6Y5Ne64NoNm0lmeq9e5mD+kW4bT6qrjSV2PXv5GBKtvNBF7y3lL
	 L4C2Bk0Nf0Km73Jz7jQG9ho71pLr9mea2gh5TBp6SwPqlaqvHf+0UW/tDQ9XkUDZm0hwr
	 nfl0f1IbdWFjA6q2zBXvNdY9Qj3EeFAma+o9TK7WIBgK/YKogVDUkE95jMJ3VugVOSA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796106914;
	h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned:
	 Received:Received:DKIM-Filter:DKIM-Signature:Received:Received: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:
	 X-ClientProxiedBy;
	bh=QDq+ALc/96PAN/wlzFMiyODso/vyAdhmaHNBrJ1AEEI=;
	b=ucaNeBRXMvZas1bkYcj3VoXrDOnleGFqQGGzlNonLLaspunUs+FR8AIIFG9uOv5npu/Y
	 kJQFwblk5Ig4WKbGnfC6lDvJRAJ6bNQ6NWMckF0wQVqivDsZjBOonO/chUf81TfZaZFNd
	 l0JFj1QbfucS5SPDVQryjM7J2XahNK+4kebxAmqf6SXisFwI4Pyhyx5s8jiRrd5mGqc2l
	 nwXMYEXNEBdozMYFPnAZpjeIaUXahEeVVMHKBj2dvTGs1arsvr6vqN5o4bkB1FsqTuyPX
	 uYtxVXgweAirCUkRowgX9LzI58Fs+QJyQgHu9FFC745Hlqy+LeDEXjiS9SAW2zpj1nw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=c+uwUA7w;
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.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 104E5606A327;
	Tue,  1 Dec 2026 06:35:14 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=c+uwUA7w
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796106903;
	b=MHKyv38yt4I9C+Oti801K1cjdwPNrH5JvzGGtI+BJhSycKZYQzGw0hi69caiikaUIXSm
	 gF3+zWvZlTgO2J27Ddae2kU42DxJ2vJLqs3T+Saw4NRobKyhRSWtZLGNZ0ayQWWjqUvHu
	 /z9LyFj+zQnkcLoWca52MevQD/zyIc3NvFN9qXBFIdjrMwngEnkYnlrJGSzj0MdSRFn5B
	 twg3lPIJz3JiUioUdMi5xbfC132AyQ87yE6jY8eemHvp1c4NX0BjGGnknxG/hY/MtEsaR
	 qCS1iA2KrnCbI/o7zFoUSxIYNUV8fV02Olu8gMTETHlYkaaxNZqMtmpaD5Z7ghmbK7g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796106903;
	h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter:
	 DKIM-Signature:Received:Received:Date:From:To:CC:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:
	 X-ClientProxiedBy;
	bh=QDq+ALc/96PAN/wlzFMiyODso/vyAdhmaHNBrJ1AEEI=;
	b=fa/tu/obWFJ/1k6GasPF5EbhnT5Rn7k7THGIen5mQ6rQfScPIoavfgJs3FCmbzKUFtfX
	 w0gGFDUq0gSQhHymhQwnBRexDfYXLS9GSi3rUkoMTTiFvSDGZlfXvC1umnv1xqxkQjYps
	 g59F9hL+2tZcfE34yTBAdblD7pak7wrl5nC2psIchjBEL8qv4dkYATk3rZxxFnk6igUES
	 vwyyIUX8B0S5MvytZaocWiQdkWCM9x+FBNFsFMaMf9utBroGZ2Ry6vbqgPkiCPsbvvHU+
	 /2gNKB4MEhweooBmEsl9uuhGDx36dOhZ01gjGv6dmYDBXmkeFEVM56w8xEPglYKNrdw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.com;
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=c+uwUA7w;
	arc=none smtp.remote-ip=62.96.220.36
X-Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F7A4606A336;
	Tue,  1 Dec 2026 06:35:02 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2F7A4606A336
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com
X-Received: from localhost (localhost [127.0.0.1])
	by mx1.secunet.com (Postfix) with ESMTP id D94D520684;
	Tue,  1 Dec 2026 07:35:00 +0100 (CET)
X-Virus-Scanned: by secunet
X-Received: from mx1.secunet.com ([127.0.0.1])
 by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id L0sHlidqSDrr; Tue,  1 Dec 2026 07:34:59 +0100 (CET)
X-Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by mx1.secunet.com (Postfix) with ESMTPS id D61B120590;
	Tue,  1 Dec 2026 07:34:59 +0100 (CET)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com D61B120590
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com;
	s=202301; t=1796106899;
	bh=QDq+ALc/96PAN/wlzFMiyODso/vyAdhmaHNBrJ1AEEI=;
	h=Date:From:To:CC:Subject:References:In-Reply-To:From;
	b=c+uwUA7wqAxS4Y8H2HnD4abDMPK/CaXICqDGyF/4kr/EYbJ/3m8wur8ffZt9AH3P3
	 hOY+bsEHnUF+z44vRIxFZdKo9S0i1cA1dM0iysUxC2BQzNJ3iUujsqpOtTXZOxCbpo
	 Jv6FStWr3WveG0gDegrQ/TJWPjNc3Gjel//3WEFg0N6VBhjz7IotTi0YhwY/+oopGH
	 xcA0w/+ALgmzLcPOU+3GqlxDJ991wSEW8UoGM83ZZaDkEM0XGtAFEtww6hFXBM99Qx
	 /5gGieYAgcRKXSaat3XHs0RkTKdYiMzENdnRKihT6GsT2JeEMvBaeO7dMYJiytW7jF
	 32DqiFdyXHfrg==
X-Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Tue, 1 Dec
 2026 07:34:59 +0100
X-Received: (nullmailer pid 779723 invoked by uid 1000);
	Tue, 01 Dec 2026 06:34:58 -0000
X-CC: <netdev@vger.kernel.org>, <ipsec@lists.linux.dev>, Herbert Xu
	<herbert@gondor.apana.org.au>, "David S. Miller" <davem@davemloft.net>, Eric
 Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni
	<pabeni@redhat.com>, Simon Horman <horms@kernel.org>, Leon Romanovsky
	<leon@kernel.org>, Raed Salem <raeds@nvidia.com>, Saeed Mahameed
	<saeedm@nvidia.com>, Cen Zhang <zzzccc427@gmail.com>,
	<linux-kernel@vger.kernel.org>, Carolina Jubran <cjubran@nvidia.com>
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: <20261125020835.1132797-1-jianbol@nvidia.com>
X-ClientProxiedBy: EXCH-02.secunet.de (10.32.0.172) To EXCH-01.secunet.de
 (10.32.0.171)