public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next-2.6] ipip: get rid of ipip_lock
@ 2010-09-15 17:27 Eric Dumazet
  2010-09-15 20:49 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2010-09-15 17:27 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

As RTNL is held while doing tunnels inserts and deletes, we can remove
ipip_lock spinlock. My initial RCU conversion was conservative and
converted the rwlock to spinlock, with no RTNL requirement.

Use appropriate rcu annotations and modern lockdep checks as well.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
Tested with CONFIG_PROVE_RCU=y

 net/ipv4/ipip.c |   71 ++++++++++++++++++++++++----------------------
 1 file changed, 38 insertions(+), 33 deletions(-)

diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 3c6f8f3..7f0e216 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -122,11 +122,11 @@
 
 static int ipip_net_id __read_mostly;
 struct ipip_net {
-	struct ip_tunnel *tunnels_r_l[HASH_SIZE];
-	struct ip_tunnel *tunnels_r[HASH_SIZE];
-	struct ip_tunnel *tunnels_l[HASH_SIZE];
-	struct ip_tunnel *tunnels_wc[1];
-	struct ip_tunnel **tunnels[4];
+	struct ip_tunnel __rcu *tunnels_r_l[HASH_SIZE];
+	struct ip_tunnel __rcu *tunnels_r[HASH_SIZE];
+	struct ip_tunnel __rcu *tunnels_l[HASH_SIZE];
+	struct ip_tunnel __rcu *tunnels_wc[1];
+	struct ip_tunnel __rcu **tunnels[4];
 
 	struct net_device *fb_tunnel_dev;
 };
@@ -135,9 +135,8 @@ static void ipip_tunnel_init(struct net_device *dev);
 static void ipip_tunnel_setup(struct net_device *dev);
 
 /*
- * Locking : hash tables are protected by RCU and a spinlock
+ * Locking : hash tables are protected by RCU and RTNL
  */
-static DEFINE_SPINLOCK(ipip_lock);
 
 #define for_each_ip_tunnel_rcu(start) \
 	for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
@@ -145,8 +144,8 @@ static DEFINE_SPINLOCK(ipip_lock);
 static struct ip_tunnel * ipip_tunnel_lookup(struct net *net,
 		__be32 remote, __be32 local)
 {
-	unsigned h0 = HASH(remote);
-	unsigned h1 = HASH(local);
+	unsigned int h0 = HASH(remote);
+	unsigned int h1 = HASH(local);
 	struct ip_tunnel *t;
 	struct ipip_net *ipn = net_generic(net, ipip_net_id);
 
@@ -169,12 +168,12 @@ static struct ip_tunnel * ipip_tunnel_lookup(struct net *net,
 	return NULL;
 }
 
-static struct ip_tunnel **__ipip_bucket(struct ipip_net *ipn,
+static struct ip_tunnel __rcu **__ipip_bucket(struct ipip_net *ipn,
 		struct ip_tunnel_parm *parms)
 {
 	__be32 remote = parms->iph.daddr;
 	__be32 local = parms->iph.saddr;
-	unsigned h = 0;
+	unsigned int h = 0;
 	int prio = 0;
 
 	if (remote) {
@@ -188,7 +187,7 @@ static struct ip_tunnel **__ipip_bucket(struct ipip_net *ipn,
 	return &ipn->tunnels[prio][h];
 }
 
-static inline struct ip_tunnel **ipip_bucket(struct ipip_net *ipn,
+static inline struct ip_tunnel __rcu **ipip_bucket(struct ipip_net *ipn,
 		struct ip_tunnel *t)
 {
 	return __ipip_bucket(ipn, &t->parms);
@@ -196,13 +195,14 @@ static inline struct ip_tunnel **ipip_bucket(struct ipip_net *ipn,
 
 static void ipip_tunnel_unlink(struct ipip_net *ipn, struct ip_tunnel *t)
 {
-	struct ip_tunnel **tp;
-
-	for (tp = ipip_bucket(ipn, t); *tp; tp = &(*tp)->next) {
-		if (t == *tp) {
-			spin_lock_bh(&ipip_lock);
-			*tp = t->next;
-			spin_unlock_bh(&ipip_lock);
+	struct ip_tunnel __rcu **tp;
+	struct ip_tunnel *iter;
+
+	for (tp = ipip_bucket(ipn, t);
+	     (iter = rcu_dereference_check(*tp, lockdep_rtnl_is_held())) != NULL;
+	     tp = &iter->next) {
+		if (t == iter) {
+			rcu_assign_pointer(*tp, t->next);
 			break;
 		}
 	}
@@ -210,12 +210,12 @@ static void ipip_tunnel_unlink(struct ipip_net *ipn, struct ip_tunnel *t)
 
 static void ipip_tunnel_link(struct ipip_net *ipn, struct ip_tunnel *t)
 {
-	struct ip_tunnel **tp = ipip_bucket(ipn, t);
+	struct ip_tunnel __rcu **tp = ipip_bucket(ipn, t);
 
-	spin_lock_bh(&ipip_lock);
-	t->next = *tp;
+	rcu_assign_pointer(t->next,
+			   rcu_dereference_check(*tp,
+						 lockdep_rtnl_is_held()));
 	rcu_assign_pointer(*tp, t);
-	spin_unlock_bh(&ipip_lock);
 }
 
 static struct ip_tunnel * ipip_tunnel_locate(struct net *net,
@@ -223,12 +223,15 @@ static struct ip_tunnel * ipip_tunnel_locate(struct net *net,
 {
 	__be32 remote = parms->iph.daddr;
 	__be32 local = parms->iph.saddr;
-	struct ip_tunnel *t, **tp, *nt;
+	struct ip_tunnel *t, *nt;
+	struct ip_tunnel __rcu **tp;
 	struct net_device *dev;
 	char name[IFNAMSIZ];
 	struct ipip_net *ipn = net_generic(net, ipip_net_id);
 
-	for (tp = __ipip_bucket(ipn, parms); (t = *tp) != NULL; tp = &t->next) {
+	for (tp = __ipip_bucket(ipn, parms);
+		 (t = rcu_dereference_check(*tp, lockdep_rtnl_is_held())) != NULL;
+		 tp = &t->next) {
 		if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr)
 			return t;
 	}
@@ -268,16 +271,15 @@ failed_free:
 	return NULL;
 }
 
+/* called with RTNL */
 static void ipip_tunnel_uninit(struct net_device *dev)
 {
 	struct net *net = dev_net(dev);
 	struct ipip_net *ipn = net_generic(net, ipip_net_id);
 
-	if (dev == ipn->fb_tunnel_dev) {
-		spin_lock_bh(&ipip_lock);
-		ipn->tunnels_wc[0] = NULL;
-		spin_unlock_bh(&ipip_lock);
-	} else
+	if (dev == ipn->fb_tunnel_dev)
+		rcu_assign_pointer(ipn->tunnels_wc[0], NULL);
+	else
 		ipip_tunnel_unlink(ipn, netdev_priv(dev));
 	dev_put(dev);
 }
@@ -741,7 +743,7 @@ static void __net_init ipip_fb_tunnel_init(struct net_device *dev)
 	iph->ihl		= 5;
 
 	dev_hold(dev);
-	ipn->tunnels_wc[0]	= tunnel;
+	rcu_assign_pointer(ipn->tunnels_wc[0], tunnel);
 }
 
 static struct xfrm_tunnel ipip_handler __read_mostly = {
@@ -760,11 +762,14 @@ static void ipip_destroy_tunnels(struct ipip_net *ipn, struct list_head *head)
 	for (prio = 1; prio < 4; prio++) {
 		int h;
 		for (h = 0; h < HASH_SIZE; h++) {
-			struct ip_tunnel *t = ipn->tunnels[prio][h];
+			struct ip_tunnel *t;
 
+			t = rcu_dereference_check(ipn->tunnels[prio][h],
+						  lockdep_rtnl_is_held());
 			while (t != NULL) {
 				unregister_netdevice_queue(t->dev, head);
-				t = t->next;
+				t = rcu_dereference_check(t->next,
+							  lockdep_rtnl_is_held());
 			}
 		}
 	}



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next-2.6] ipip: get rid of ipip_lock
  2010-09-15 17:27 [PATCH net-next-2.6] ipip: get rid of ipip_lock Eric Dumazet
@ 2010-09-15 20:49 ` Eric Dumazet
  2010-09-15 21:29   ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2010-09-15 20:49 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Le mercredi 15 septembre 2010 à 19:28 +0200, Eric Dumazet a écrit :
> As RTNL is held while doing tunnels inserts and deletes, we can remove
> ipip_lock spinlock. My initial RCU conversion was conservative and
> converted the rwlock to spinlock, with no RTNL requirement.
> 
> Use appropriate rcu annotations and modern lockdep checks as well.
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

While doing ip_gre conversion, I realize I should define a new helper

/**
 * rtnl_dereference - rcu_dereference with debug checking
 * @p: The pointer to read, prior to dereferencing
 *
 * Do an rcu_dereference(p), but check caller holds RTNL
 */
#define rtnl_dereference(p)					\
	rcu_dereference_check(p, lockdep_rtnl_is_held())



I'll submit a patch serie :

1/3) net: add rtnl_dereference
2/3) ipip: get rid of ipip_lock
3/3) gre: get rid of ipgre_lock

Thanks



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next-2.6] ipip: get rid of ipip_lock
  2010-09-15 20:49 ` Eric Dumazet
@ 2010-09-15 21:29   ` David Miller
  2010-09-15 21:31     ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2010-09-15 21:29 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Wed, 15 Sep 2010 22:49:37 +0200

> Le mercredi 15 septembre 2010 à 19:28 +0200, Eric Dumazet a écrit :
>> As RTNL is held while doing tunnels inserts and deletes, we can remove
>> ipip_lock spinlock. My initial RCU conversion was conservative and
>> converted the rwlock to spinlock, with no RTNL requirement.
>> 
>> Use appropriate rcu annotations and modern lockdep checks as well.
>> 
>> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
> 
> While doing ip_gre conversion, I realize I should define a new helper
...
> I'll submit a patch serie :
> 
> 1/3) net: add rtnl_dereference
> 2/3) ipip: get rid of ipip_lock
> 3/3) gre: get rid of ipgre_lock

Ok.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next-2.6] ipip: get rid of ipip_lock
  2010-09-15 21:29   ` David Miller
@ 2010-09-15 21:31     ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2010-09-15 21:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Le mercredi 15 septembre 2010 à 14:29 -0700, David Miller a écrit :
> From: Eric Dumazet <eric.dumazet@gmail.com>

> > While doing ip_gre conversion, I realize I should define a new helper
> ...
> > I'll submit a patch serie :
> > 
> > 1/3) net: add rtnl_dereference
> > 2/3) ipip: get rid of ipip_lock
> > 3/3) gre: get rid of ipgre_lock
> 
> Ok.

And a 4/4) sit: get rid of ipip6_lock

;)




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-09-15 21:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-15 17:27 [PATCH net-next-2.6] ipip: get rid of ipip_lock Eric Dumazet
2010-09-15 20:49 ` Eric Dumazet
2010-09-15 21:29   ` David Miller
2010-09-15 21:31     ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox