Article View: linux.kernel.netdev
Article #26199Re: [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush"
From: Steffen Klassert
Date: Thu, 03 Dec 2026 07:59
Date: Thu, 03 Dec 2026 07:59
127 lines
14285 bytes
14285 bytes
Ccing the author of the patch.
On Wed, Dec 02, 2026 at 01:12:34PM +0000, netdev-bot+sashiko@kernel.org wrote:
> 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.
We had this race already before this series. Should be fixed, but also
with a followup.
> 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:
<axEhb1YV8LkH8Znl@gauss4>Path:
mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376383-linux-kernel-netdev=dewy.ruReferences:
<20261201124252.1163254-22-steffen.klassert@secunet.com> <179621715417.3146.5170339497297011327@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376383-linux-kernel-netdev=dewy.ru From: steffen.klassert@secunet.com (Steffen Klassert) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush" Date: Thu, 3 Dec 2026 08:59:43 +0100 Organization: Usenet Network Message-ID: <axEhb1YV8LkH8Znl@gauss4> References: <20261201124252.1163254-22-steffen.klassert@secunet.com> <179621715417.3146.5170339497297011327@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2430396"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:lrlKKXKSp6PV/otkItF62UJ3WU8= sha256:0dcszDf4Y/7eMUzBJVqs+AXM8Xvjtx4betjhgNH5C5M= sha1:EJiEUJHd2H1HMAUCFp5A7NzjUxI= sha256:P9CrhrTPRphXJDDQyj/+ZKitMVbrNqu1p3T/WP4N+us= 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 BDD1B11786C; Thu, 3 Dec 2026 11:00:07 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.151 X-Spam-Status: No, score=-3.151 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] 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 pwzBd99MFPnN; Thu, 3 Dec 2026 11:00:03 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376383-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 51CB8117872; Thu, 3 Dec 2026 10:59:54 +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 29C03264E1; Thu, 3 Dec 2026 07:59:52 +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=1796284789; b=sKtoxv8qY8AFyvE1etZJaEaYu40HNXHFKqt10IqWUgMiIr87nd6C+S/DhT46pgAnfHIi aYmA2LvlafbvDnHPxiLR4QRX7/1JX+XSC3SdolDJ/McZWjXDFKBx1ezcaEoIn/lFQtoR3 YQ6dVaAgmYS+veUDidYstTnMpT4gNTqLrQ5fFHWTx7Jofc6xNv3Vpbwgn+kRoqCRvq4So HiAwdnUJg0uXAajqpGwxABhN5UuA9U7c3pNzOj9JpMZSKFuiEF4cHaIKCjwaZAZGgdvv3 dNxGuhD4At+z5LGcQNzJjJvRrT1tlN8RygkQQTnj5SyPFKsooYAJ7e6JM6jZfE0ZjAw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796284789; 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: Content-Transfer-Encoding:In-Reply-To:X-ClientProxiedBy; bh=aJr8PzF8nQ+GHKCHzEFarm+IPRhsXX98obS+Asyf52M=; b=dEYtBCv5uMRFb3hiMyMarPh8E0U2OxDaNzftWX7/ONeVVgbct2N1Bk9p7JOrL65NXinQ NwmhJLDg0jykxJOpA0jB61UCxavkSOWnnjfEakusc4sSOzCleVISEjqbqURRpDvMKVDXO zHho8I97O33NclJr0ChKvyrPtdkfJfPhlGSmArKl2Qk1hn9yBLQ2QBodqpZeXd202hx/V yhMY7l9h8R1sFu3IyCPfGG0G26h2YuYvLpo6j3xvwpbPmcIME7Dg5NlJ/AnAXDjfouYpw 7ffLBmTAggFcV3IR9fMuUySj/t247f0+PYGoKcivyi7bjwJ5nUHjmV0lJna1qNk/YlA== 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=m7oz8m83; 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 011BA606A336; Thu, 3 Dec 2026 07:59:49 +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=m7oz8m83 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=1796284788; b=1CRI4/OcYQHlwXLVUYI5bF92epXXdm5RRvaemVmlZM5dgPGOkZj/YL2DqG4GEHi93tzy 2A/5praW/EWEddyJLxlIhz5PQ7iUk2ZZ4maI7iDHsh/Pa25/w9xVKaLKOKz8zrd2cF63T AZ9J1tA+tMpcyb88ERPeLk5zDdUHVaew/oKjDHMba4l5UqkrUZewtWq/4ah/7Xp42BCHj CI3xjA12AuwuQHdQWJLCNRBs4pMygryDD7gzSONHyTjQNu+qdsKhP8vr3hzb+1z+qoOiq MTFlJRtIusuyOI+BTHMVSoJ19pelkQ5B+MQwIEuPawToIh5yowFT83O/E86+RSlcMJg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796284788; 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: Content-Transfer-Encoding:In-Reply-To:X-ClientProxiedBy; bh=aJr8PzF8nQ+GHKCHzEFarm+IPRhsXX98obS+Asyf52M=; b=rL+T4EBOQ6IMVgy+msS5axFzwLw6KceehwW6u48BZoe39i89edzuSC190B+4Be8Bjd53 uAKSYzEj+Op+xbZTosRWJfF/XTMCJyMSUK3D2Xz3RQ79Q1sz5BbSo5F/QwuWm9AB0V9Qh TkpdohITJFcRFEif70obL+opJPKIWeA5iKvsfnvcmLZCOxXMOGkzADK9CLOCgj+Nvw6ck EpSbD6NiTcQ6tHztqanLdPdJ9rk8nzl985njdDPdCFdFxeyt5i8qFgEHymulfct6AdqSF FHwC6xjIc60xVDIL6B6rByTb8SSUhDTyxjLVYAkBT61EtJMGii0NbNyPNeI4oueHIWA== 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=m7oz8m83; 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 D46EB606A322 for <netdev@vger.kernel.org>; Thu, 3 Dec 2026 07:59:46 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D46EB606A322 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 CFE472074F; Thu, 3 Dec 2026 08:59:44 +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 fAS22jMSoeeB; Thu, 3 Dec 2026 08:59:43 +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 CC1942067F; Thu, 3 Dec 2026 08:59:43 +0100 (CET) X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com CC1942067F X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1796284783; bh=aJr8PzF8nQ+GHKCHzEFarm+IPRhsXX98obS+Asyf52M=; h=Date:From:To:CC:Subject:References:In-Reply-To:From; b=m7oz8m832rO/OC8jbLRLJNOkPD5XqdkUrqykY6aQZd5O+wvYZViTSE+wr+sdHbjDF RGyQQjUi/WF4I2U0JfS+GwFIUL0FWP6P5Y6erH6ZdhP35y9AQTecO+d35/eXwnj8Qz p8op4h0/6Res4wKdNTLASktFvBnEPAS5eLLUL3a7lGf3VcBHjLx6ElPE6HdweYptZw CQ156KsOa91NPeX16q5ovnFVaPQ9+JM58hO2WeywTHqRkz7EhrxtlpTiNof/c4HVRD aeEaQXpQVzYOJZf4jvca68QSXc2BDW3XBzXaOrr+ifGcwTkFXAGm5K8+ApKqb+/DqD lRQeQGWwCtXKA== 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; Thu, 3 Dec 2026 08:59:43 +0100 X-Received: (nullmailer pid 1116650 invoked by uid 1000); Thu, 03 Dec 2026 07:59:43 -0000 X-CC: <davem@davemloft.net>, <kuba@kernel.org>, <herbert@gondor.apana.org.au>, <netdev@vger.kernel.org>, Jianbo Liu <jianbol@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: <179621715417.3146.5170339497297011327@kernel.org> X-ClientProxiedBy: EXCH-02.secunet.de (10.32.0.172) To EXCH-01.secunet.de (10.32.0.171)