Skip to contentSkip to conversation

xfrm: replace xfrm_policy_afinfo_lock spinlock with mutex

PATCH In review Fan Du 3 participants 3 messages Jul 4, 2013

Subsystems (3)
lore
Share & tools
lore

Fan Du

author
#0 lore raw

PATCH 1/1 xfrm: replace xfrm_policy_afinfo_lock spinlock with mutex

---
 net/xfrm/xfrm_policy.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
net/xfrm/xfrm_policy.c +5 -5
index e52cab3..27768ba 100644
@@ -46,7 +46,7 @@ static DEFINE_SPINLOCK(xfrm_policy_sk_bundle_lock);
 static struct dst_entry *xfrm_policy_sk_bundles;
 static DEFINE_RWLOCK(xfrm_policy_lock);
 
-static DEFINE_SPINLOCK(xfrm_policy_afinfo_lock);
+static DEFINE_MUTEX(xfrm_policy_afinfo_lock);
 static struct xfrm_policy_afinfo __rcu *xfrm_policy_afinfo[NPROTO]
 						__read_mostly;
 
@@ -2687,7 +2687,7 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
 		return -EINVAL;
 	if (unlikely(afinfo->family >= NPROTO))
 		return -EAFNOSUPPORT;
-	spin_lock(&xfrm_policy_afinfo_lock);
+	mutex_lock(&xfrm_policy_afinfo_lock);
 	if (unlikely(xfrm_policy_afinfo[afinfo->family] != NULL))
 		err = -ENOBUFS;
 	else {
@@ -2710,7 +2710,7 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
 			afinfo->garbage_collect = xfrm_garbage_collect_deferred;
 		rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
 	}
-	spin_unlock(&xfrm_policy_afinfo_lock);
+	mutex_unlock(&xfrm_policy_afinfo_lock);
 
 	rtnl_lock();
 	for_each_net(net) {
@@ -2743,7 +2743,7 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
 		return -EINVAL;
 	if (unlikely(afinfo->family >= NPROTO))
 		return -EAFNOSUPPORT;
-	spin_lock(&xfrm_policy_afinfo_lock);
+	mutex_lock(&xfrm_policy_afinfo_lock);
 	if (likely(xfrm_policy_afinfo[afinfo->family] != NULL)) {
 		if (unlikely(xfrm_policy_afinfo[afinfo->family] != afinfo))
 			err = -EINVAL;
@@ -2751,7 +2751,7 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
 			RCU_INIT_POINTER(xfrm_policy_afinfo[afinfo->family],
 					 NULL);
 	}
-	spin_unlock(&xfrm_policy_afinfo_lock);
+	mutex_unlock(&xfrm_policy_afinfo_lock);
 	if (!err) {
 		struct dst_ops *dst_ops = afinfo->dst_ops;
 
Signature · 1 line
1.7.1
#2 lore raw
In reply to Fan Du
Quoted 10 lines · Fan Du
---
 net/xfrm/xfrm_policy.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
net/xfrm/xfrm_policy.c +0 -0
index e52cab3..27768ba 100644

net/xfrm/xfrm_policy.c static DEFINE_SPINLOCK(xfrm_policy_sk_bundle_lock); · line 49

Quoted 5 lines
net/xfrm/xfrm_policy.c +1 -1
@@ -46,7 +46,7 @@ static DEFINE_SPINLOCK(xfrm_policy_sk_bundle_lock);
 static struct dst_entry *xfrm_policy_sk_bundles;
 static DEFINE_RWLOCK(xfrm_policy_lock);
 
-static DEFINE_SPINLOCK(xfrm_policy_afinfo_lock);
+static DEFINE_MUTEX(xfrm_policy_afinfo_lock);

Why is it needed, and why is it safe ?

Is it a bug fix ? If answer is no please read :

http://www.spinics.net/lists/netdev/msg242161.html

This mutex or spinlock is not really needed anyway.

Check commit e0386005ff2a729 for a starting point. ("net: inet_add_protocol() can use cmpxchg()")

But do not send a patch until David reopens net-next.