🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25802

Re: [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush"

#25802
From: netdev-bot+sashiko
Date: Wed, 02 Dec 2026 13:12
121 lines
12242 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] xfrm_dev_state_flush() in net/xfrm/xfrm_state.c no longer
  guarantees that all device offload state for `dev` has been freed when…

--

Revert "xfrm: serialize state GC with device state flush"

This reverts the xfrm_state_gc_mutex. That mutex serialized
xfrm_state_gc_task() with the dev_gclist walk in xfrm_dev_state_flush().
The flush now takes a reference on each state it frees, and it relies on
"xfrm: Serialize device state teardown" so that only one caller frees the
device state.

Link: https://lore.kernel.org/netdev/aqfZNeR58HLm2x1o@secunet.com/

> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> index 92c3631a43bf7..d48c88f2df64f 100644
> --- a/net/xfrm/xfrm_state.c
> +++ b/net/xfrm/xfrm_state.c

[ ... ]

> @@ -1018,7 +1015,6 @@ int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_vali
>  out:
>  	spin_unlock_bh(&net->xfrm.xfrm_state_lock);
>  
> -	mutex_lock(&xfrm_state_gc_mutex);
>  	spin_lock_bh(&xfrm_state_dev_gc_lock);
>  	hlist_for_each_entry_safe(x, tmp, &xfrm_state_dev_gc_list, dev_gclist) {
>  		xso = &x->xso;
> @@ -1035,7 +1031,6 @@ int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_vali
>  		}
>  	}
>  	spin_unlock_bh(&xfrm_state_dev_gc_lock);
> -	mutex_unlock(&xfrm_state_gc_mutex);
>  
>  	if (!hlist_empty(&flush_list))
>  		synchronize_rcu();

[Severity: Medium]

The commit message says "Nothing is left for the mutex to protect".
With "xfrm: Serialize device state teardown" applied, can
xfrm_dev_state_flush() still return before all of the device state for dev
has been freed?

The dev_gclist walk in xfrm_dev_state_flush() skips any matching state
whose refcount is already zero:

	if (xso->dev == dev) {
		if (!refcount_inc_not_zero(&x->refcnt))
			continue;

This relies on the state GC freeing that state, and on the trailing
xfrm_flush_gc() waiting for it. However, xfrm_state_put() drops the count
to zero before the GC work is queued:

include/net/xfrm.h:xfrm_state_put() {
	if (refcount_dec_and_test(&x->refcnt))
		__xfrm_state_destroy(x);
}

net/xfrm/xfrm_state.c:__xfrm_state_destroy() {
	...
	spin_lock_bh(&xfrm_state_gc_lock);
	hlist_add_head(&x->gclist, &xfrm_state_gc_list);
	spin_unlock_bh(&xfrm_state_gc_lock);
	schedule_work(&xfrm_state_gc_work);
}

Consider this interleaving:

CPU B (e.g. netlink delete, process context)
xfrm_state_put(x)
    refcount_dec_and_test() -> refcnt == 0
    <preempted before __xfrm_state_destroy()>

CPU A (NETDEV_DOWN or NETDEV_UNREGISTER for the same dev)
xfrm_dev_state_flush()
    refcount_inc_not_zero() fails, x is skipped
    flush_list is empty, so synchronize_rcu() is skipped
    xfrm_flush_gc()
        flush_work() returns at once, nothing is queued yet

Even when synchronize_rcu() does run because other states were collected,
it doesn't wait for a preemptible process-context putter.

In that case the flush returns while x->xso.dev, the netdev tracker
reference and the driver offload context are all still live. The driver's
xdo_dev_state_free() and netdev_put() then run later from
xfrm_state_gc_task(). That is after xfrm_dev_down(), xfrm_dev_unregister()
or bond_master_netdev_event() has already finished.

At the series base, the flush called xfrm_dev_state_free() on every
matching dev_gclist entry whatever its refcount was, and the mutex kept
the GC from destroying it at the same time.

The mutex didn't cover this gap either. The window comes from the
skip-on-refcnt==0 logic added in "xfrm: Serialize device state teardown",
which this revert depends on. The code is unchanged at the end of the
series.

If a driver tears down its offload resources once the notifier returns,
could xdo_dev_state_free() then run against that torn-down state? On
unregister, would netdev_wait_allrefs() also be delayed until the GC work
runs?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201124252.1163254-2-steffen.klassert%40secunet.com
Technical Details
Message-ID: <179621715417.3146.5170339497297011327@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375803-linux-kernel-netdev=dewy.ru
References: <20261201124252.1163254-22-steffen.klassert@secunet.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375803-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush"
Date: Wed, 02 Dec 2026 13:12:34 +0000
Organization: Usenet Network
Message-ID: <179621715417.3146.5170339497297011327@kernel.org>
References: <20261201124252.1163254-22-steffen.klassert@secunet.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1977215"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:cvqPFzEZPYgbQbnsxvigm0Eay3w= sha256:NcPOh6otugN3mY/DuQPoisGqaFgVmw69kNAE3g0SvPo=
	sha1:+CtcZciahZ/qqFgmT4ibIzd/CiE= sha256:pCPAcReZYv37oEu95OGk7TpBHENeeqPwmy9Z0rEZRRQ=
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 B6F3A1175D9; Wed,  2 Dec 2026 16:13:03 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 nG08l2T6tat6;
	Wed,  2 Dec 2026 16:13:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375803-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 F3AA6117648; Wed,  2 Dec 2026 16:12:51 +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 1DBF628F3A; Wed,  2 Dec 2026 13:12:36 +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=1796217156;
	b=cOpi4sA+wgw7xM9fJWfz/gDQyc+FcQXhuVm1/w3OZ/DRrqsgQx2NqyznRcFfg0Y0ndV6
	 FT5VVzEbrXf54l5uRFayKvDvQtt8qPYKSj8pVfjiRC3LznO7vTyKGBh1VFTrko0MDNqtO
	 MP4ba4Kg6U46FNNHwbfTdCTOXc4xdWPdSjkGoa+Nf62+CFXnveVGHnKD3YE2aNt0p98Qa
	 59iQiSF2RSINl30gPTffN1Og0gYeLmrVrBTPdSl4s1z0lBr3UP0ooY5QLRwcHZUpN/beJ
	 GF0XtjUshPVxXDRZcOKJvrdGLy0SMt3JwRwWJxS+eJKRt11gWcF/BHJhDV78MmXKgiw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796217156;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=Poo+g7kZCzZGg9BWXcbwDfGWMliExDd6apS9WLwzVDI=;
	b=Am2aqIjCNdQ5y2YzBah/AulBrO7irBJtK83dedAQnuqkOUoAyNgCnmKPGqhZ+FcffA7M
	 WR6eMO1HXABH8oOo3SkfIuG8gJwP/r3t8bVgVnrl7To4icjaHVXHtjtgLp1OEH1x3p7tA
	 9Use11DqKp3ILSVW9LAsX3vbsbqI7kWM+DNUCNfNmx2xFjSQ2jy54LfyyELfTCCrVzRWO
	 XyFdc33TV8dIA0ct4k+Vcmy65ILrU9IdwKnslC9NI0yZUApoAbT1d0AM4C27QC92CZ2WL
	 xQ1BDI35o+GTfEFNaKC2M48RZ3ISJU/kf+jA05QB1f4K+xtcwcRU+L83TKtcRH+DeUQ==
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=OO9sVQCX;
	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 EAA28606A31A;
	Wed,  2 Dec 2026 13:12:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OO9sVQCX
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=1796217155;
	b=TH1VCSWIdS93FCtuYG907dXV0GrOGVNe5w/THYxyZBUWAXGjdh0FFcfTat3tXlUMQZWY
	 nWv4/m1xSIVSYXvROUQAEk0anbrZ93Ndlnpv2PRa11aT4bA3QB+3nq9GCDBwd4G09zTiA
	 xxH8szduZX2JRmaSJFePbn6/nQz1YX2TPdkm2h0Ii0Vb2oKji8SaqRLluhUvoE8Pv7Byb
	 grISbuKy5Ed4mH7vpAX3MHWo6XOb3pPi3XypA23DOIBzQxwiVSn2nmiEyA9cIcbgGE+mX
	 dWNKJFe1rdK/3IMzh00mUB0xO2SM15Uu/kBYJHlUix633OtXG0EVYHZZPeYk20/C+uQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796217155;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=Poo+g7kZCzZGg9BWXcbwDfGWMliExDd6apS9WLwzVDI=;
	b=GTyDkObCPr68QuEetPOc4O6OzJkoN3lyOauB+oClJ9dTj+fhOvxV5L6pVA51CFo0sGrJ
	 9m2kcWpaYnymfTM7jp7+2B9k4EA8D5JYS+E1S8Jp+r6bijGT7FTADZdllxUAj7Jtrbis5
	 RjHjR71SBTluhus1b1ow+T6bujZO+cwwt7ZtwI1CiEV0vRRDKpyBeztCC4ksz3KpWH+hZ
	 T7pIZ8vKr0Vdfn2L/Vz4c9bWZlMBPWDMKnKfEuSOXelnbAxnjR7Qk30gVxKrpskV5tlwv
	 c3Ft75j/8sadv5nxm4nD3Vm55C+EZl86zFJqJ7r/Tjwhitf6G6qBTgJrdqNXY2V9e0A==
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=OO9sVQCX;
	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 19393606A333
	for <netdev@vger.kernel.org>; Wed,  2 Dec 2026 13:12:35 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A17E31F0089F;
	Wed,  2 Dec 2026 13:12:34 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796217155;
	bh=Poo+g7kZCzZGg9BWXcbwDfGWMliExDd6apS9WLwzVDI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=OO9sVQCXLW9552KnYyrPWaJX8ezhrW/fWjUtF1CK91uVxb82OV3oNwe2kZbabzSxD
	 3ghMeFsYNeVC5aP8/GSy24qAJl7rAUgJmWBPsQBsrR+iThhtPnU24s1Uyhxd0UEDu5
	 TDWdx5nBffTJUvNjNgTzQ6FVktzEls0RtGIGXp4zAYlEs0DPLWpgLjkbcnqidn2fPa
	 CTtGHTqc9H4hgeOFVN7UVPUEOxSPKM7Qeqx1aPk/LdUaK5bNvpPNeTrsA6oEw0DVJO
	 SYZWr6eSDoIKojKYv4nBKdufOGb3TmoTJ4XzrPYT6rhX9kxu91JWcPXIGBnaRo0OjL
	 AuCnRL+XASitw==
X-Cc: davem@davemloft.net, kuba@kernel.org, herbert@gondor.apana.org.au,
 netdev@vger.kernel.org
X-In-Reply-To: <20261201124252.1163254-22-steffen.klassert@secunet.com>
X-sashiko-severity: Medium
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