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=1796217155; b=TH1VCSWIdS93FCtuYG907dXV0GrOGVNe5w/THYxyZBUWAXGjdh0FFcfTat3tXlUMQZWY nWv4/m1xSIVSYXvROUQAEk0anbrZ93Ndlnpv2PRa11aT4bA3QB+3nq9GCDBwd4G09zTiA xxH8szduZX2JRmaSJFePbn6/nQz1YX2TPdkm2h0Ii0Vb2oKji8SaqRLluhUvoE8Pv7Byb grISbuKy5Ed4mH7vpAX3MHWo6XOb3pPi3XypA23DOIBzQxwiVSn2nmiEyA9cIcbgGE+mX dWNKJFe1rdK/3IMzh00mUB0xO2SM15Uu/kBYJHlUix633OtXG0EVYHZZPeYk20/C+uQ== 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== 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 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 ; Wed, 2 Dec 2026 13:12:35 +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=OO9sVQCX Received: by smtp.kernel.org (Postfix) with ESMTPSA id A17E31F0089F; Wed, 2 Dec 2026 13:12:34 +0000 (UTC) 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== Subject: Re: [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush" From: netdev-bot+sashiko@kernel.org To: steffen.klassert@secunet.com Cc: davem@davemloft.net, kuba@kernel.org, herbert@gondor.apana.org.au, netdev@vger.kernel.org Date: Wed, 02 Dec 2026 13:12:34 +0000 Message-ID: <179621715417.3146.5170339497297011327@kernel.org> In-Reply-To: <20261201124252.1163254-22-steffen.klassert@secunet.com> References: <20261201124252.1163254-22-steffen.klassert@secunet.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@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() 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 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