Article View: linux.kernel.netdev
Article #24042Re: [PATCH ipsec 4/4] Revert "xfrm: serialize state GC with device state flush"
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 02:14
Date: Sun, 29 Nov 2026 02:14
106 lines
11832 bytes
11832 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() (net/xfrm/xfrm_state.c:1018-1044) now
skips any matching state on xfrm_state_dev_gc_list whose refcount is…
--
Revert "xfrm: serialize state GC with device state flush"
This reverts the mutex that serialized xfrm_state_gc_task() with the
dev_gclist pass in xfrm_dev_state_flush(). It depends on "xfrm: Serialize
device state teardown". In that patch the flush takes a reference on each
state it frees and skips states whose refcount has already reached zero.
Link: https://lore.kernel.org/netdev/aqfZNeR58HLm2x1o@secunet.com/
> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> index 9883fb3545f8f..717c0bdb95597 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]
Without the mutex, the dev_gclist pass in xfrm_dev_state_flush() relies
on the refcount skip added by "xfrm: Serialize device state teardown":
net/xfrm/xfrm_state.c:xfrm_dev_state_flush() {
...
if (xso->dev == dev) {
if (!refcount_inc_not_zero(&x->refcnt))
continue;
...
xfrm_flush_gc();
}
A skipped state is left to the state GC. The only wait is xfrm_flush_gc(),
which is just flush_work(&xfrm_state_gc_work).
Can that wait miss the skipped state? xfrm_state_put() makes the zero
refcount visible before the state is queued for GC:
xfrm_state_put()
refcount_dec_and_test(&x->refcnt)
__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);
Another context can drop the last reference, for example a dst bundle
destroy, a secpath free, or a netlink getsa put. Suppose it is preempted
or delayed between refcount_dec_and_test() and schedule_work() while the
flush is running. The flush then skips the state, and flush_work() finds
the work idle and returns at once.
In that case the NETDEV_DOWN or NETDEV_UNREGISTER notifier returns while
xdo_dev_state_free() and netdev_put(dev, &xso->dev_tracker) for that SA
are still waiting to run from the GC work.
For NETDEV_UNREGISTER, unregister_netdevice_many_notify() calls
ndo_uninit right after the notifiers. For bonding that is bond_uninit(),
which does:
mutex_destroy(&bond->ipsec_lock);
A late call chain
xfrm_state_gc_task()->xfrm_state_gc_destroy()->xfrm_dev_state_free()->bond_ipsec_free_sa()
would then lock bond->ipsec_lock after it has been destroyed.
Before the series, the device state of every matching dev_gclist entry
was freed synchronously, whatever its refcount. The series says skipped
states are freed by the state GC and that xfrm_flush_gc() waits for them.
Does that wait only hold when the flush itself dropped the last
reference?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125013412.1123866-1-jianbol%40nvidia.com
Technical Details
Message-ID:
<179591848374.3135.14266299641095938448@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373341-linux-kernel-netdev=dewy.ruReferences:
<20261125013412.1123866-5-jianbol@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373341-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH ipsec 4/4] Revert "xfrm: serialize state GC with device state flush" Date: Sun, 29 Nov 2026 02:14:43 +0000 Organization: Usenet Network Message-ID: <179591848374.3135.14266299641095938448@kernel.org> References: <20261125013412.1123866-5-jianbol@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1082473"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:v741grn40xt2e9yG+sRKNYLlO0U= sha256:IPm0X/d1PyjZvENWINJG9GZLX3lRXgqcKfZYS1qVVio= sha1:zDYryGAtqUcJaoyJFcPIVBupcJA= sha256:8eMRmQmCPxKxf3CYCj8JCrhTj1i0eMzHKfU6WdFsF28= 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 87B72125F90; Sun, 29 Nov 2026 05:15:11 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[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 zRj-UY3et8M2; Sun, 29 Nov 2026 05:15:08 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-373341-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 2A548125F8C; Sun, 29 Nov 2026 05:14:59 +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 E3ACE27C70; Sun, 29 Nov 2026 02:14:53 +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=1795918486; b=y2u99shjFad93+gpKebzCCtMyYbnerFSywzTUGvvujkpxprn+wcRpdHgpyc3ecgCXO1q Tr8RKE3GwSIpVQu+2Gg+fIE9rkmeoBJ28/r0Y9mzDuKx79D9iQ95YQOKnUIQjUFaCu04N SFitWZKd6sRShqDKNYpG2Zn6MS8iJyk+lvFY10BkYeSOvLyKbZF5tuJRNPyRlT5DiDvQv mnjL/s5OMRODBw4I2xiWyAKIxjZH9M+McTuW7VNDvULm/l5qsi5lCADa4cwYVXTQos87I m2jfnri4gLuTKwXwsBVeW3Jum+MlgVXDt9FMPMwxXm34CpfusNaW6pWrw/toDo41VSg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795918486; 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=GpS1LN7EG5qPDNAMQU6Ai4ZeukyCVpaP2kKMtcmasXM=; b=GN/PJnToAAkSuXf6XFeWNlm0sQJi44UfN8wCreolxKucOX49DDuPnpCZYxSLkuNqa9bo 9ybCNHjlndiqyzNfrev95Q4JgIwjNWZCaoGnJSeSC7PvHxM/EmkXvO4Y7cUzgPuzuLruP dt5Hi+7o+LsHhQwA2SL1WT4EdFGVe1YQqxV+RD4DnBqgdy4qwGwCZVMdSVSE5hrFEOC2D CIslrooB9t4/g7UQxxbp1/yjMwDqamRRv7VYzZBxzEhdxfJ8LQDzTY/AE9hqO85nY68QC EJY6sVKbciiHDS6AcMpERNjiwQMMe74Z8+f1HIP2NmThkt7mrHea8VFvLQnDdzcH2WA== 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=PtoF8tjA; 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 DFA4F606A333; Sun, 29 Nov 2026 02:14:45 +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=PtoF8tjA 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=1795918485; b=AYMbpRDg+HX6riDWKh+7GhUV8f/QrCu0sJqkpi/F2Cdl4GdqiVqZzUinOcoVq99e/58w Hnyvz5iIshd1qh6eBkZERV/JLtdbrrYANZoBH/6GK9TFglEk9nqDRk4lyya6HYLSi1IuG ysafdMC0EHOScQ5B1em4zVezumEIeM9JN3aMx1s4O/1UrAydEh7/mSzpSTMWjSqMsCUoY 3hQQBfZNN9JWKhTuDF/LgJp/zGs4AjnSi+NCdZtdPrCfaGFPAFHBNf7PfOvOGjnx1Oo2t J3eHWf+AFGofvoIwVGuw22qmTkztDIkg1MVrnfOG/galVej85Rrd/FCCozwXb1b7e2w== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795918485; 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=GpS1LN7EG5qPDNAMQU6Ai4ZeukyCVpaP2kKMtcmasXM=; b=JcL96vdv3fDg+HonUBupPD5TtV311MHrNr93Vp2YQCUF/vMz/5hXmsOPqYBE6wbw5ayh KhyjxVIkS1hUoVqofUnMZpLqS8axVmqqbdKTmOyPA5AQEmmQAorQBYx9zVUZN3H3pnt4K 06wh29CcwG1krdeDmuJCX2r2u3jzkhnge6dvKeqJhTlMYZzhODmSP6tmiB0TuRN5h/U44 tUuoLPaoZo2SfXjiMsFhQiHYP7XVX9oLVMbv/ons9j1ql30CxVnW0efe+H3rFYgMKmkh7 pv1kRlpEf6sqXlOf9hHt5LBLrUcSgwQlLVeDyuPmN6mguZomwU967PFTEpkJPIrMS5g== 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=PtoF8tjA; 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 0BCF5606A69D; Sun, 29 Nov 2026 02:14:45 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F6CE1F00898; Sun, 29 Nov 2026 02:14:44 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795918484; bh=GpS1LN7EG5qPDNAMQU6Ai4ZeukyCVpaP2kKMtcmasXM=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=PtoF8tjAWaLi4UXWV1DiLc573ULgWyamKgfEdfzAs+q5LruThj7huAtC+jQWE4Z82 m/BBtAE6YaMEaxx1NneAWJs83SwltSmG+oHLgleIxXLt6ZdicMu7kcbWsj8/YilIPl YFFTy+uE+euKctmJmHJuPl1oVTAuf+CYFBKXfSVPe32i+EmytwwHqSL1ZcLSZXi8Qq ZCkpKAEWBL5mEXZ+2aIExvvQkwDIBgzn8yQr7xK1lHYONbqaT24nXCXC2sl2y2dVeF 9MyX+d7C6cjN4LcuDc0Ls4oKiXTEOOuollvJ5w1FrkbUcG+O9kt0ufYEw0Nj7fiDsD yYxJakvbuimMg== X-Cc: netdev@vger.kernel.org, ipsec@lists.linux.dev, steffen.klassert@secunet.com, herbert@gondor.apana.org.au, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, fw@strlen.de, linux-kernel@vger.kernel.org, cjubran@nvidia.com X-In-Reply-To: <20261125013412.1123866-5-jianbol@nvidia.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