Skip to contentSkip to conversation

xfrm: state: make xfrm_state_lookup_byaddr lockless

PATCH Applied Florian Westphal 2 participants 2 messages Mar 7, 2025 – Mar 15, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfrm: state: make xfrm_state_lookup_byaddr lockless

This appears to be an oversight back when the state lookup was converted to RCU, I see no reason why we need to hold the state lock here.

__xfrm_state_lookup_byaddr already uses xfrm_state_hold_rcu helper to obtain a reference, so just replace the state lock with rcu.

---
 net/xfrm/xfrm_state.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/xfrm/xfrm_state.c +2 -2
index 7b1028671144..07545944a536 100644
@@ -2313,12 +2313,12 @@ xfrm_state_lookup_byaddr(struct net *net, u32 mark,
 	struct xfrm_hash_state_ptrs state_ptrs;
 	struct xfrm_state *x;
 
-	spin_lock_bh(&net->xfrm.xfrm_state_lock);
+	rcu_read_lock();
 
 	xfrm_hash_ptrs_get(net, &state_ptrs);
 
 	x = __xfrm_state_lookup_byaddr(&state_ptrs, mark, daddr, saddr, proto, family);
-	spin_unlock_bh(&net->xfrm.xfrm_state_lock);
+	rcu_read_unlock();
 	return x;
 }
 EXPORT_SYMBOL(xfrm_state_lookup_byaddr);
Signature · 1 line
2.48.1
maintainer Applied
#1 lore raw
Quoted 9 lines · Florian Westphal

This appears to be an oversight back when the state lookup was converted to RCU, I see no reason why we need to hold the state lock here.

__xfrm_state_lookup_byaddr already uses xfrm_state_hold_rcu helper to obtain a reference, so just replace the state lock with rcu.

Applied, thanks Florian!