* [PATCH net-next 1/2] Phonet: put protocols array under RCU
@ 2009-11-13 15:01 Rémi Denis-Courmont
2009-11-13 15:01 ` [PATCH net-next 2/2] Phonet: convert routing table to RCU Rémi Denis-Courmont
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Rémi Denis-Courmont @ 2009-11-13 15:01 UTC (permalink / raw)
To: netdev; +Cc: Rémi Denis-Courmont
From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
net/phonet/af_phonet.c | 20 +++++++++++---------
1 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 8d3a55b..ed65da2 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -35,7 +35,6 @@
/* Transport protocol registration */
static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
-static DEFINE_SPINLOCK(proto_tab_lock);
static struct phonet_protocol *phonet_proto_get(int protocol)
{
@@ -44,11 +43,11 @@ static struct phonet_protocol *phonet_proto_get(int protocol)
if (protocol >= PHONET_NPROTO)
return NULL;
- spin_lock(&proto_tab_lock);
+ rcu_read_lock();
pp = proto_tab[protocol];
if (pp && !try_module_get(pp->prot->owner))
pp = NULL;
- spin_unlock(&proto_tab_lock);
+ rcu_read_unlock();
return pp;
}
@@ -439,6 +438,8 @@ static struct packet_type phonet_packet_type __read_mostly = {
.func = phonet_rcv,
};
+static DEFINE_MUTEX(proto_tab_lock);
+
int __init_or_module phonet_proto_register(int protocol,
struct phonet_protocol *pp)
{
@@ -451,12 +452,12 @@ int __init_or_module phonet_proto_register(int protocol,
if (err)
return err;
- spin_lock(&proto_tab_lock);
+ mutex_lock(&proto_tab_lock);
if (proto_tab[protocol])
err = -EBUSY;
else
- proto_tab[protocol] = pp;
- spin_unlock(&proto_tab_lock);
+ rcu_assign_pointer(proto_tab[protocol], pp);
+ mutex_unlock(&proto_tab_lock);
return err;
}
@@ -464,10 +465,11 @@ EXPORT_SYMBOL(phonet_proto_register);
void phonet_proto_unregister(int protocol, struct phonet_protocol *pp)
{
- spin_lock(&proto_tab_lock);
+ mutex_lock(&proto_tab_lock);
BUG_ON(proto_tab[protocol] != pp);
- proto_tab[protocol] = NULL;
- spin_unlock(&proto_tab_lock);
+ rcu_assign_pointer(proto_tab[protocol], NULL);
+ mutex_unlock(&proto_tab_lock);
+ synchronize_rcu();
proto_unregister(pp->prot);
}
EXPORT_SYMBOL(phonet_proto_unregister);
--
1.6.3.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next 2/2] Phonet: convert routing table to RCU
2009-11-13 15:01 [PATCH net-next 1/2] Phonet: put protocols array under RCU Rémi Denis-Courmont
@ 2009-11-13 15:01 ` Rémi Denis-Courmont
2009-11-14 4:51 ` David Miller
2009-11-14 4:51 ` [PATCH net-next 1/2] Phonet: put protocols array under RCU David Miller
2009-11-16 17:26 ` Paul E. McKenney
2 siblings, 1 reply; 6+ messages in thread
From: Rémi Denis-Courmont @ 2009-11-13 15:01 UTC (permalink / raw)
To: netdev; +Cc: Rémi Denis-Courmont
From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
net/phonet/pn_dev.c | 59 +++++++++++++++++++++++++++++---------------------
1 files changed, 34 insertions(+), 25 deletions(-)
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index 6d64fda..3287f8f 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -34,7 +34,7 @@
#include <net/phonet/pn_dev.h>
struct phonet_routes {
- spinlock_t lock;
+ struct mutex lock;
struct net_device *table[64];
};
@@ -248,17 +248,22 @@ static void phonet_route_autodel(struct net_device *dev)
/* Remove left-over Phonet routes */
bitmap_zero(deleted, 64);
- spin_lock_bh(&pnn->routes.lock);
+ mutex_lock(&pnn->routes.lock);
for (i = 0; i < 64; i++)
if (dev == pnn->routes.table[i]) {
+ rcu_assign_pointer(pnn->routes.table[i], NULL);
set_bit(i, deleted);
- pnn->routes.table[i] = NULL;
- dev_put(dev);
}
- spin_unlock_bh(&pnn->routes.lock);
+ mutex_unlock(&pnn->routes.lock);
+
+ if (bitmap_empty(deleted, 64))
+ return; /* short-circuit RCU */
+ synchronize_rcu();
for (i = find_first_bit(deleted, 64); i < 64;
- i = find_next_bit(deleted, 64, i + 1))
+ i = find_next_bit(deleted, 64, i + 1)) {
rtm_phonet_notify(RTM_DELROUTE, dev, i);
+ dev_put(dev);
+ }
}
/* notify Phonet of device events */
@@ -300,7 +305,7 @@ static int phonet_init_net(struct net *net)
INIT_LIST_HEAD(&pnn->pndevs.list);
spin_lock_init(&pnn->pndevs.lock);
- spin_lock_init(&pnn->routes.lock);
+ mutex_init(&pnn->routes.lock);
net_assign_generic(net, phonet_net_id, pnn);
return 0;
}
@@ -361,13 +366,13 @@ int phonet_route_add(struct net_device *dev, u8 daddr)
int err = -EEXIST;
daddr = daddr >> 2;
- spin_lock_bh(&routes->lock);
+ mutex_lock(&routes->lock);
if (routes->table[daddr] == NULL) {
- routes->table[daddr] = dev;
+ rcu_assign_pointer(routes->table[daddr], dev);
dev_hold(dev);
err = 0;
}
- spin_unlock_bh(&routes->lock);
+ mutex_unlock(&routes->lock);
return err;
}
@@ -375,17 +380,20 @@ int phonet_route_del(struct net_device *dev, u8 daddr)
{
struct phonet_net *pnn = net_generic(dev_net(dev), phonet_net_id);
struct phonet_routes *routes = &pnn->routes;
- int err = -ENOENT;
daddr = daddr >> 2;
- spin_lock_bh(&routes->lock);
- if (dev == routes->table[daddr]) {
- routes->table[daddr] = NULL;
- dev_put(dev);
- err = 0;
- }
- spin_unlock_bh(&routes->lock);
- return err;
+ mutex_lock(&routes->lock);
+ if (dev == routes->table[daddr])
+ rcu_assign_pointer(routes->table[daddr], NULL);
+ else
+ dev = NULL;
+ mutex_unlock(&routes->lock);
+
+ if (!dev)
+ return -ENOENT;
+ synchronize_rcu();
+ dev_put(dev);
+ return 0;
}
struct net_device *phonet_route_get(struct net *net, u8 daddr)
@@ -397,9 +405,9 @@ struct net_device *phonet_route_get(struct net *net, u8 daddr)
ASSERT_RTNL(); /* no need to hold the device */
daddr >>= 2;
- spin_lock_bh(&routes->lock);
- dev = routes->table[daddr];
- spin_unlock_bh(&routes->lock);
+ rcu_read_lock();
+ dev = rcu_dereference(routes->table[daddr]);
+ rcu_read_unlock();
return dev;
}
@@ -409,11 +417,12 @@ struct net_device *phonet_route_output(struct net *net, u8 daddr)
struct phonet_routes *routes = &pnn->routes;
struct net_device *dev;
- spin_lock_bh(&routes->lock);
- dev = routes->table[daddr >> 2];
+ daddr >>= 2;
+ rcu_read_lock();
+ dev = rcu_dereference(routes->table[daddr]);
if (dev)
dev_hold(dev);
- spin_unlock_bh(&routes->lock);
+ rcu_read_unlock();
if (!dev)
dev = phonet_device_get(net); /* Default route */
--
1.6.3.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 1/2] Phonet: put protocols array under RCU
2009-11-13 15:01 [PATCH net-next 1/2] Phonet: put protocols array under RCU Rémi Denis-Courmont
2009-11-13 15:01 ` [PATCH net-next 2/2] Phonet: convert routing table to RCU Rémi Denis-Courmont
@ 2009-11-14 4:51 ` David Miller
2009-11-16 17:26 ` Paul E. McKenney
2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2009-11-14 4:51 UTC (permalink / raw)
To: remi; +Cc: netdev, remi.denis-courmont
From: Rémi Denis-Courmont <remi@remlab.net>
Date: Fri, 13 Nov 2009 17:01:18 +0200
> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
>
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 2/2] Phonet: convert routing table to RCU
2009-11-13 15:01 ` [PATCH net-next 2/2] Phonet: convert routing table to RCU Rémi Denis-Courmont
@ 2009-11-14 4:51 ` David Miller
0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2009-11-14 4:51 UTC (permalink / raw)
To: remi; +Cc: netdev, remi.denis-courmont
From: Rémi Denis-Courmont <remi@remlab.net>
Date: Fri, 13 Nov 2009 17:01:19 +0200
> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
>
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 1/2] Phonet: put protocols array under RCU
2009-11-13 15:01 [PATCH net-next 1/2] Phonet: put protocols array under RCU Rémi Denis-Courmont
2009-11-13 15:01 ` [PATCH net-next 2/2] Phonet: convert routing table to RCU Rémi Denis-Courmont
2009-11-14 4:51 ` [PATCH net-next 1/2] Phonet: put protocols array under RCU David Miller
@ 2009-11-16 17:26 ` Paul E. McKenney
2009-11-16 17:34 ` Rémi Denis-Courmont
2 siblings, 1 reply; 6+ messages in thread
From: Paul E. McKenney @ 2009-11-16 17:26 UTC (permalink / raw)
To: Rémi Denis-Courmont; +Cc: netdev, Rémi Denis-Courmont
On Fri, Nov 13, 2009 at 05:01:18PM +0200, Rémi Denis-Courmont wrote:
> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
>
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> ---
> net/phonet/af_phonet.c | 20 +++++++++++---------
> 1 files changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
> index 8d3a55b..ed65da2 100644
> --- a/net/phonet/af_phonet.c
> +++ b/net/phonet/af_phonet.c
> @@ -35,7 +35,6 @@
>
> /* Transport protocol registration */
> static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
> -static DEFINE_SPINLOCK(proto_tab_lock);
>
> static struct phonet_protocol *phonet_proto_get(int protocol)
> {
> @@ -44,11 +43,11 @@ static struct phonet_protocol *phonet_proto_get(int protocol)
> if (protocol >= PHONET_NPROTO)
> return NULL;
>
> - spin_lock(&proto_tab_lock);
> + rcu_read_lock();
> pp = proto_tab[protocol];
Don't we need an rcu_dereference() in here somewhere?
Perhaps something like the following?
pp = rcu_dereference(proto_tab[protocol]);
Thanx, Paul
> if (pp && !try_module_get(pp->prot->owner))
> pp = NULL;
> - spin_unlock(&proto_tab_lock);
> + rcu_read_unlock();
>
> return pp;
> }
> @@ -439,6 +438,8 @@ static struct packet_type phonet_packet_type __read_mostly = {
> .func = phonet_rcv,
> };
>
> +static DEFINE_MUTEX(proto_tab_lock);
> +
> int __init_or_module phonet_proto_register(int protocol,
> struct phonet_protocol *pp)
> {
> @@ -451,12 +452,12 @@ int __init_or_module phonet_proto_register(int protocol,
> if (err)
> return err;
>
> - spin_lock(&proto_tab_lock);
> + mutex_lock(&proto_tab_lock);
> if (proto_tab[protocol])
> err = -EBUSY;
> else
> - proto_tab[protocol] = pp;
> - spin_unlock(&proto_tab_lock);
> + rcu_assign_pointer(proto_tab[protocol], pp);
> + mutex_unlock(&proto_tab_lock);
>
> return err;
> }
> @@ -464,10 +465,11 @@ EXPORT_SYMBOL(phonet_proto_register);
>
> void phonet_proto_unregister(int protocol, struct phonet_protocol *pp)
> {
> - spin_lock(&proto_tab_lock);
> + mutex_lock(&proto_tab_lock);
> BUG_ON(proto_tab[protocol] != pp);
> - proto_tab[protocol] = NULL;
> - spin_unlock(&proto_tab_lock);
> + rcu_assign_pointer(proto_tab[protocol], NULL);
> + mutex_unlock(&proto_tab_lock);
> + synchronize_rcu();
> proto_unregister(pp->prot);
> }
> EXPORT_SYMBOL(phonet_proto_unregister);
> --
> 1.6.3.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 1/2] Phonet: put protocols array under RCU
2009-11-16 17:26 ` Paul E. McKenney
@ 2009-11-16 17:34 ` Rémi Denis-Courmont
0 siblings, 0 replies; 6+ messages in thread
From: Rémi Denis-Courmont @ 2009-11-16 17:34 UTC (permalink / raw)
To: paulmck; +Cc: netdev, Rémi Denis-Courmont
Le lundi 16 novembre 2009 19:26:17 Paul E. McKenney, vous avez écrit :
> On Fri, Nov 13, 2009 at 05:01:18PM +0200, Rémi Denis-Courmont wrote:
> > From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> >
> > Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> > ---
> > net/phonet/af_phonet.c | 20 +++++++++++---------
> > 1 files changed, 11 insertions(+), 9 deletions(-)
> >
> > diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
> > index 8d3a55b..ed65da2 100644
> > --- a/net/phonet/af_phonet.c
> > +++ b/net/phonet/af_phonet.c
> > @@ -35,7 +35,6 @@
> >
> > /* Transport protocol registration */
> > static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
> > -static DEFINE_SPINLOCK(proto_tab_lock);
> >
> > static struct phonet_protocol *phonet_proto_get(int protocol)
> > {
> > @@ -44,11 +43,11 @@ static struct phonet_protocol *phonet_proto_get(int
> > protocol) if (protocol >= PHONET_NPROTO)
> > return NULL;
> >
> > - spin_lock(&proto_tab_lock);
> > + rcu_read_lock();
> > pp = proto_tab[protocol];
>
> Don't we need an rcu_dereference() in here somewhere?
>
> Perhaps something like the following?
Err yes, we do.
--
Rémi Denis-Courmont
http://www.remlab.net/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-11-16 17:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-13 15:01 [PATCH net-next 1/2] Phonet: put protocols array under RCU Rémi Denis-Courmont
2009-11-13 15:01 ` [PATCH net-next 2/2] Phonet: convert routing table to RCU Rémi Denis-Courmont
2009-11-14 4:51 ` David Miller
2009-11-14 4:51 ` [PATCH net-next 1/2] Phonet: put protocols array under RCU David Miller
2009-11-16 17:26 ` Paul E. McKenney
2009-11-16 17:34 ` Rémi Denis-Courmont
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).