From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F6CE1F00898; Sun, 29 Nov 2026 02:14:44 +0000 (UTC) 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== Subject: Re: [PATCH ipsec 4/4] Revert "xfrm: serialize state GC with device state flush" From: netdev-bot+sashiko@kernel.org To: jianbol@nvidia.com 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 Date: Sun, 29 Nov 2026 02:14:43 +0000 Message-ID: <179591848374.3135.14266299641095938448@kernel.org> In-Reply-To: <20261125013412.1123866-5-jianbol@nvidia.com> References: <20261125013412.1123866-5-jianbol@nvidia.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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