mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jianbo Liu <jianbol@nvidia.com>
To: <netdev@vger.kernel.org>, <ipsec@lists.linux.dev>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, Florian Westphal <fw@strlen.de>,
	<linux-kernel@vger.kernel.org>, Jianbo Liu <jianbol@nvidia.com>,
	Carolina Jubran <cjubran@nvidia.com>
Subject: [PATCH ipsec 3/4] xfrm: Wait for an RCU grace period before freeing device state
Date: Wed, 25 Nov 2026 03:34:11 +0200	[thread overview]
Message-ID: <20261125013412.1123866-4-jianbol@nvidia.com> (raw)
In-Reply-To: <20261125013412.1123866-1-jianbol@nvidia.com>

xfrm_dev_state_flush() can call xdo_dev_state_free() immediately after
xdo_dev_state_delete(), without waiting for pre-existing RCU readers
of the driver's SA state to complete.

The normal state GC path waits for an RCU grace period before
destroying the state, but the device flush path does not.

Remove the immediate xfrm_dev_state_free() following
xfrm_state_delete(). The delete path queues the state on
xfrm_state_dev_gc_list. The subsequent collection pass picks it up if
a reference is left. If the flush dropped the last one, the state GC
frees it after its own grace period and xfrm_flush_gc() waits for it.

Wait for one RCU grace period after collecting the states and before
freeing them. This establishes the required
xdo_dev_state_delete() -> synchronize_rcu() -> xdo_dev_state_free()
ordering while using a single grace period for the whole flush.

Fixes: 07b87f9eea0c ("xfrm: Fix unregister netdevice hang on hardware offload.")
Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
---
 net/xfrm/xfrm_state.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 8465ae064742..9883fb3545f8 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -1000,7 +1000,6 @@ int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_vali
 				spin_unlock_bh(&net->xfrm.xfrm_state_lock);
 
 				err = xfrm_state_delete(x);
-				xfrm_dev_state_free(x);
 
 				xfrm_audit_state_delete(x, err ? 0 : 1,
 							task_valid);
@@ -1038,6 +1037,9 @@ 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();
+
 	hlist_for_each_entry_safe(x, tmp, &flush_list, gclist) {
 		hlist_del_init(&x->gclist);
 		xfrm_dev_state_free(x);
-- 
2.39.3


  parent reply	other threads:[~2026-11-25  1:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  1:34 [PATCH ipsec 0/4] xfrm: Fix device state teardown races Jianbo Liu
2026-11-25  1:34 ` [PATCH ipsec 1/4] xfrm: Give GC list nodes their own storage Jianbo Liu
2026-11-25  1:34 ` [PATCH ipsec 2/4] xfrm: Serialize device state teardown Jianbo Liu
2026-11-25  1:34 ` Jianbo Liu [this message]
2026-11-25  1:34 ` [PATCH ipsec 4/4] Revert "xfrm: serialize state GC with device state flush" Jianbo Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125013412.1123866-4-jianbol@nvidia.com \
    --to=jianbol@nvidia.com \
    --cc=cjubran@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=ipsec@lists.linux.dev \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=steffen.klassert@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®