[PATCH ipsec 4/4] Revert "xfrm: serialize state GC with device state flush"
From: Jianbo Liu
Date: Tue Nov 24 2026 - 20:35:14 EST
This reverts commit 89fefad9f971bc637fb22373078144f2563c4be9.
The mutex kept the state GC from destroying a state while
xfrm_dev_state_flush() was freeing its device state. It can't cover
xfrm_state_find(), which frees device state under RCU.
The flush now holds a reference on each state it frees, and
xfrm_dev_state_free() lets only one caller free the device state.
Nothing is left for the mutex to protect, so remove it.
This needs "xfrm: Serialize device state teardown". Without that patch
the flush frees the device state of a state it holds no reference on.
Link: https://lore.kernel.org/netdev/aqfZNeR58HLm2x1o@xxxxxxxxxxx/
Signed-off-by: Jianbo Liu <jianbol@xxxxxxxxxx>
Reviewed-by: Carolina Jubran <cjubran@xxxxxxxxxx>
---
net/xfrm/xfrm_state.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 9883fb3545f8..717c0bdb9559 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -226,7 +226,6 @@ static struct xfrm_state_afinfo __rcu *xfrm_state_afinfo[NPROTO];
static DEFINE_SPINLOCK(xfrm_state_gc_lock);
static DEFINE_SPINLOCK(xfrm_state_dev_gc_lock);
-static DEFINE_MUTEX(xfrm_state_gc_mutex);
int __xfrm_state_delete(struct xfrm_state *x);
@@ -639,10 +638,8 @@ static void xfrm_state_gc_task(struct work_struct *work)
synchronize_rcu();
- mutex_lock(&xfrm_state_gc_mutex);
hlist_for_each_entry_safe(x, tmp, &gc_list, gclist)
xfrm_state_gc_destroy(x);
- mutex_unlock(&xfrm_state_gc_mutex);
}
static enum hrtimer_restart xfrm_timer_handler(struct hrtimer *me)
@@ -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();
--
2.39.3