netdev: get rid of read_lock(&dev_base_lock) usages
Subsystems (10)
cover netdev: get rid of read_lock(&dev_base_lock) usages
The goal is to eliminate dev_base_lock completely, and just use RCU and rtnl_mutex for network devices. This series gets rid of the many of the users of dev_base_lock just for reading.
PATCH 1/10 netdev: add netdev_continue_rcu
This adds an RCU macro for continuing search, useful for some network devices like vlan.
include/linux/netdevice.h +2 -0
@@ -1079,6 +1079,8 @@ extern rwlock_t dev_base_lock; /* De list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)#define for_each_netdev_continue (net, d) \ list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list) +#define for_each_netdev_continue_rcu (net, d) \ + list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)#define net_device_entry (lh) list_entry(lh, struct net_device, dev_list)static inline struct net_device *next_net_device (struct net_device *dev)
include/linux/rculist.h +14 -0
@@ -262,6 +262,20 @@ static inline void list_splice_init_rcu( (pos) = rcu_dereference((pos)->next))/** +* list_for_each_entry_continue_rcu - continue iteration over list of given type +* @pos: the type * to use as a loop cursor. +* @head: the head for your list. +* @member: the name of the list_struct within the struct. +* +* Continue to iterate over list of given type, continuing after +* the current position. +*/ +#define list_for_each_entry_continue_rcu (pos, head, member) \ + for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \ + prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) + +/** * hlist_del_rcu - deletes entry from hash list without re-initialization * @n: the element to delete from the hash list. *
Re: [PATCH 01/10] netdev: add netdev_continue_rcu
Quoted 5 lines · Stephen Hemminger
This adds an RCU macro for continuing search, useful for some network devices like vlan.
Signed-off-by Stephen Hemminger <[email protected]>
Re: [PATCH 01/10] netdev: add netdev_continue_rcu
From: Eric Dumazet <[email protected]>
Date: Tue, 10 Nov 2009 19:19:22 +0100
Quoted 8 lines
Quoted 5 lines · Stephen Hemminger
This adds an RCU macro for continuing search, useful for some network devices like vlan.
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Eric Dumazet <[email protected]>
Applied.
Re: [PATCH 01/10] netdev: add netdev_continue_rcu
In reply to Stephen HemmingerQuoted 2 lines · Stephen Hemminger
This adds an RCU macro for continuing search, useful for some network devices like vlan.
Looks good!!!
Of course, you need to either have a single RCU read-side critical section cover all the chained list_for_each_entry_continue_rcu() invocations, or you need to do something (e.g., reference count) to make sure that the element in question doesn't disappear in the meantime, right?
Thanx, Paul
Quoted 39 lines
Signed-off-by Stephen Hemminger <[email protected]>include/linux/netdevice.h +2
-0@@ -1079,6 +1079,8 @@ extern rwlock_t dev_base_lock; /* De list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)#define for_each_netdev_continue (net, d) \ list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list) +#define for_each_netdev_continue_rcu (net, d) \ + list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)#define net_device_entry (lh) list_entry(lh, struct net_device, dev_list)static inline struct net_device *next_net_device (struct net_device *dev)include/linux/rculist.h +14
-0@@ -262,6 +262,20 @@ static inline void list_splice_init_rcu( (pos) = rcu_dereference((pos)->next))/** +* list_for_each_entry_continue_rcu - continue iteration over list of given type +* @pos: the type * to use as a loop cursor. +* @head: the head for your list. +* @member: the name of the list_struct within the struct. +* +* Continue to iterate over list of given type, continuing after +* the current position. +*/ +#define list_for_each_entry_continue_rcu (pos, head, member) \ + for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \ + prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) + +/** * hlist_del_rcu - deletes entry from hash list without re-initialization * @n: the element to delete from the hash list. * Signature · 1 line
--
PATCH 2/10 vlan: eliminate use of dev_base_lock
In reply to Stephen HemmingerDo not need to use read_lock(&dev_base_lock), use RCU instead.
net/8021q/vlanproc.c +6 -7
@@ -201,18 +201,17 @@ int vlan_proc_rem_dev(struct net_device/* start read of /proc/net/vlan/config */ static void *vlan_seq_start (struct seq_file *seq,loff_t *pos) -__acquires (dev_base_lock) +__acquires (rcu) {struct net_device *dev;struct net *net =seq_file_net (seq);loff_t i =1 ; -read_lock (&dev_base_lock); - +rcu_read_lock ();if (*pos ==0 )return SEQ_START_TOKEN ; -for_each_netdev (net, dev) { +for_each_netdev_rcu (net, dev) {if (!is_vlan_dev (dev))continue ;
@@ -234,7 +233,7 @@ static void *vlan_seq_next(struct seq_fiif (v ==SEQ_START_TOKEN ) dev =net_device_entry (&net->dev_base_head); -for_each_netdev_continue (net, dev) { +for_each_netdev_continue_rcu (net, dev) {if (!is_vlan_dev (dev))continue ;
@@ -245,9 +244,9 @@ static void *vlan_seq_next(struct seq_fi }static void vlan_seq_stop (struct seq_file *seq,void *v) -__releases (dev_base_lock) +__releases (rcu) { -read_unlock (&dev_base_lock); +rcu_read_unlock (); }static int vlan_seq_show (struct seq_file *seq,void *v)
Re: [PATCH 02/10] vlan: eliminate use of dev_base_lock
Quoted 3 lines · Stephen Hemminger
Do not need to use
read_lock(&dev_base_lock), use RCU instead.Signed-off-by Stephen Hemminger <[email protected]>
Re: [PATCH 02/10] vlan: eliminate use of dev_base_lock
From: Eric Dumazet <[email protected]>
Date: Tue, 10 Nov 2009 19:20:15 +0100
Quoted 6 lines
Quoted 3 lines · Stephen Hemminger
Do not need to use
read_lock(&dev_base_lock), use RCU instead.Signed-off-by Stephen Hemminger <[email protected]>Acked-by Eric Dumazet <[email protected]>
Applied.
PATCH 3/10 net: use rcu for network scheduler API
In reply to Stephen HemmingerUse RCU to walk list of network devices in qdisc dump. This could be optimized for large number of devices.
net/sched/sch_api.c +4 -3
@@ -1279,9 +1279,10 @@ static int tc_dump_qdisc(struct sk_buff s_idx = cb->args[0 ]; s_q_idx = q_idx = cb->args[1 ]; -read_lock (&dev_base_lock); + +rcu_read_lock (); idx =0 ; -for_each_netdev (&init_net, dev) { +for_each_netdev_rcu (&init_net, dev) {struct netdev_queue *dev_queue;if (idx < s_idx)
@@ -1302,7 +1303,7 @@ cont: } done: -read_unlock (&dev_base_lock); +rcu_read_unlock (); cb->args[0 ] = idx; cb->args[1 ] = q_idx;
Re: [PATCH 03/10] net: use rcu for network scheduler API
Quoted 5 lines · Stephen Hemminger
Use RCU to walk list of network devices in qdisc dump. This could be optimized for large number of devices.
Signed-off-by Stephen Hemminger <[email protected]>
Re: [PATCH 03/10] net: use rcu for network scheduler API
From: Eric Dumazet <[email protected]>
Date: Tue, 10 Nov 2009 19:20:57 +0100
Quoted 8 lines
Quoted 5 lines · Stephen Hemminger
Use RCU to walk list of network devices in qdisc dump. This could be optimized for large number of devices.
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Eric Dumazet <[email protected]>
Applied.
PATCH 4/10 AOE: use rcu to find network device
In reply to Stephen HemmingerThis gets rid of another use of read_lock(&dev_base_lock) by using RCU. Also, it only increments the reference count of the device actually used rather than holding and releasing every device
Compile tested only.
drivers/block/aoe/aoecmd.c +7 -9
@@ -296,17 +296,18 @@ aoecmd_cfg_pkts(ushort aoemajor, unsignestruct sk_buff *skb;struct net_device *ifp; -read_lock (&dev_base_lock); -for_each_netdev (&init_net, ifp) { -dev_hold (ifp); +rcu_read_lock (); +for_each_netdev_rcu (&init_net, ifp) {if (!is_aoe_netif (ifp)) - goto cont; +continue ; skb =new_skb (sizeof *h +sizeof *ch);if (skb ==NULL ) {printk (KERN_INFO "aoe: skb alloc failure\n" ); - goto cont; +continue ; } + +dev_hold (ifp);skb_put (skb,sizeof *h +sizeof *ch); skb->dev = ifp;__skb_queue_tail (queue, skb);
@@ -320,11 +321,8 @@ aoecmd_cfg_pkts(ushort aoemajor, unsigne h->major =cpu_to_be16 (aoemajor); h->minor = aoeminor; h->cmd =AOECMD_CFG ; - -cont: -dev_put (ifp); } -read_unlock (&dev_base_lock); +rcu_read_unlock (); } static void
Re: [PATCH 04/10] AOE: use rcu to find network device
Quoted 9 lines · Stephen Hemminger
This gets rid of another use of
read_lock(&dev_base_lock)by using RCU. Also, it only increments the reference count of the device actually used rather than holding and releasing every deviceCompile tested only.
Signed-off-by Stephen Hemminger <[email protected]>
Re: [PATCH 04/10] AOE: use rcu to find network device
In reply to Stephen HemmingerQuoted 5 lines · On Tue Nov 10 13:07:37 EST 2009, [email protected] wrote:
This gets rid of another use of
read_lock(&dev_base_lock)by using RCU. Also, it only increments the reference count of the device actually used rather than holding and releasing every deviceCompile tested only.
This function runs once a minute when the aoe driver is loaded, if you'd like to test it a bit more.
It looks like there's no dev_put corresponding to the dev_hold after the changes.
Signature · 1 line
Ed
Re: [PATCH 04/10] AOE: use rcu to find network device
Quoted 5 lines · On Tue, 10 Nov 2009 15:01:49 -0500 Ed Cashin <[email protected]> wrote:
Quoted 4 lines · On Tue Nov 10 13:07:37 EST 2009, [email protected] wrote:
This gets rid of another use of
read_lock(&dev_base_lock)by using RCU. Also, it only increments the reference count of the device actually used rather than holding and releasing every device
Quoted 8 lines
Quoted 1 line
Compile tested only.
This function runs once a minute when the aoe driver is loaded, if you'd like to test it a bit more.
It looks like there's no
dev_putcorresponding to thedev_holdafter the changes.
Hmm, looks like AOE actually is not ref counting the network device. So my patch is incorrect.
As it stands (before my patch), it is UNSAFE. It can decide to queue packets to a device that is removed out from underneath it causing reference to freed memory.
Moving the rcu_read_lock up to aoecmd_cfg() would solve that but the whole driver appears to be unsafe about device refcounting and handling device removal properly.
It needs to:
1. Get a device ref count when it remembers a device: (ie addif)
2. Install a notifier that looks for device removal events
3. In notifier, remove interface, including flushing all pending skb's for that device.
This obviously is beyond the scope of the RCU stuff.
Re: [PATCH 04/10] AOE: use rcu to find network device
Quoted 28 lines · On Tue, 10 Nov 2009 15:06:17 -0800 Stephen Hemminger <[email protected]>…
Quoted 5 lines · On Tue, 10 Nov 2009 15:01:49 -0500 Ed Cashin <[email protected]> wrote:
Quoted 4 lines · On Tue Nov 10 13:07:37 EST 2009, [email protected] wrote:
This gets rid of another use of
read_lock(&dev_base_lock)by using RCU. Also, it only increments the reference count of the device actually used rather than holding and releasing every deviceQuoted 8 lines
Quoted 1 line
Compile tested only.
This function runs once a minute when the aoe driver is loaded, if you'd like to test it a bit more.
It looks like there's no
dev_putcorresponding to thedev_holdafter the changes.Hmm, looks like AOE actually is not ref counting the network device. So my patch is incorrect.
As it stands (before my patch), it is UNSAFE. It can decide to queue packets to a device that is removed out from underneath it causing reference to freed memory.
Moving the
rcu_read_lockup toaoecmd_cfg()would solve that but the whole driver appears to be unsafe about device refcounting and handling device removal properly.
Quoted 8 lines
It needs to:
1. Get a device ref count when it remembers a device: (ie addif)
2. Install a notifier that looks for device removal events
3. In notifier, remove interface, including flushing all pending skb's for that device.This obviously is beyond the scope of the RCU stuff.
Here is a patch to get you going, it does compile but it probably won't work because the code doesn't handle the case of the last device going away from a target. This is yet another pre-existing bug, since if a timeout happens: ejectif() is called to remove a device, resend() will BUG in ifrotate() if all devices are gone.
--- drivers/block/aoe/aoe.h | 2 ++ drivers/block/aoe/aoecmd.c | 19 +++++++++++++++++++ drivers/block/aoe/aoedev.c | 14 ++++++++++++++ drivers/block/aoe/aoemain.c | 24 ++++++++++++++++++++++++ 4 files changed, 59 insertions(+)
drivers/block/aoe/aoecmd.c +19 -0
@@ -413,6 +413,8 @@ addif(struct aoetgt *t, struct net_devic p =getif (t,NULL );if (!p)return NULL ; + +dev_hold (nd); p->nd = nd; p->maxbcnt =DEFAULTBCNT ; p->lost =0 ;
@@ -424,12 +426,29 @@ static void ejectif(struct aoetgt *t, struct aoeif *ifp) { struct aoeif *e; +struct net_device *nd;ulong n; e = t->ifs +NAOEIFS -1 ; + nd = e->nd; n = (e - ifp) *sizeof *ifp;memmove (ifp, ifp+1 , n); e->nd =NULL ; +dev_put (nd); +} + +void aoecmd_flushnet (struct aoedev *d,struct net_device *nd) +{ +struct aoetgt **tt, **te; + tt = d->targets; + te = tt +NTARGETS ; +for (; tt < te && *tt; tt++) { +struct aoetgt *t = *tt; +struct aoeif *ifp; + +while ( (ifp =getif (t, nd)) ) +ejectif (t, ifp); + } } static int
drivers/block/aoe/aoemain.c +24 -0
@@ -8,6 +8,8 @@#include <linux/blkdev.h> #include <linux/module.h> #include <linux/skbuff.h> +#include <linux/notifier.h> +#include <linux/netdevice.h> #include "aoe.h" MODULE_LICENSE ("GPL" );
@@ -54,11 +56,28 @@ discover_timer(ulong vp) } } +/* Callback on change of state of network device. */ +static int aoe_device_event (struct notifier_block *unused, +unsigned long event,void *ptr) +{ +struct net_device *nd = ptr; + +if (is_aoe_netif (nd) && event ==NETDEV_UNREGISTER ) +aoedev_ejectnet (nd); + +return NOTIFY_DONE ; +} + +static struct notifier_block aoe_notifier = { + .notifier_call = aoe_device_event, +}; +static void aoe_exit (void ) {discover_timer (TKILL ); +unregister_netdevice_notifier (&aoe_notifier);aoenet_exit ();unregister_blkdev (AOE_MAJOR ,DEVICE_NAME );aoechr_exit ();
@@ -83,6 +102,9 @@ aoe_init(void) ret =aoenet_init ();if (ret) goto net_fail; + ret =register_netdevice_notifier (&aoe_notifier); +if (ret) + goto notifier_fail; ret =register_blkdev (AOE_MAJOR ,DEVICE_NAME );if (ret <0 ) {printk (KERN_ERR "aoe: can't register major\n" );
@@ -94,6 +116,8 @@ aoe_init(void)return 0 ; blkreg_fail: +unregister_netdevice_notifier (&aoe_notifier); + notifier_fail:aoenet_exit (); net_fail:aoeblk_exit ();
drivers/block/aoe/aoe.h +2 -0
@@ -186,6 +186,7 @@ void aoecmd_ata_rsp(struct sk_buff *);void aoecmd_cfg_rsp (struct sk_buff *);void aoecmd_sleepwork (struct work_struct *);void aoecmd_cleanslate (struct aoedev *); +void aoecmd_flushnet (struct aoedev *,struct net_device *);struct sk_buff *aoecmd_ata_id (struct aoedev *);int aoedev_init (void );
@@ -194,6 +195,7 @@ struct aoedev *aoedev_by_aoeaddr(int majstruct aoedev *aoedev_by_sysminor_m (ulong sysminor);void aoedev_downdev (struct aoedev *d);int aoedev_flush (const char __user *str,size_t size); +void aoedev_ejectnet (struct net_device *);int aoenet_init (void );void aoenet_exit (void );
drivers/block/aoe/aoedev.c +14 -0
@@ -162,6 +162,20 @@ aoedev_flush(const char __user *str, sizreturn 0 ; } +void aoedev_ejectnet (struct net_device *nd) +{ +struct aoedev *d; +unsigned long flags; + +spin_lock_irqsave (&devlist_lock, flags); +for (d = devlist; d; d = d->next) { +spin_lock (&d->lock); +aoecmd_flushnet (d, nd); +spin_unlock (&d->lock); + } +spin_unlock_irqrestore (&d->lock, flags); +} +/* I'm not really sure that this is a realistic problem, but if the network driver goes gonzo let's just leak memory after complaining. */ static void
David Miller
maintainerRe: [PATCH 04/10] AOE: use rcu to find network device
From: Stephen Hemminger <[email protected]>
Date: Tue, 10 Nov 2009 15:53:16 -0800
Quoted 38 lines
Quoted 35 lines · On Tue, 10 Nov 2009 15:06:17 -0800 Stephen Hemminger <[email protected]>…
Quoted 5 lines · On Tue, 10 Nov 2009 15:01:49 -0500 Ed Cashin <[email protected]> wrote:
Quoted 4 lines · On Tue Nov 10 13:07:37 EST 2009, [email protected] wrote:
This gets rid of another use of
read_lock(&dev_base_lock)by using RCU. Also, it only increments the reference count of the device actually used rather than holding and releasing every deviceQuoted 8 lines
Quoted 1 line
Compile tested only.
This function runs once a minute when the aoe driver is loaded, if you'd like to test it a bit more.
It looks like there's no
dev_putcorresponding to thedev_holdafter the changes.Hmm, looks like AOE actually is not ref counting the network device. So my patch is incorrect.
As it stands (before my patch), it is UNSAFE. It can decide to queue packets to a device that is removed out from underneath it causing reference to freed memory.
Moving the
rcu_read_lockup toaoecmd_cfg()would solve that but the whole driver appears to be unsafe about device refcounting and handling device removal properly.It needs to:
1. Get a device ref count when it remembers a device: (ie addif)
2. Install a notifier that looks for device removal events
3. In notifier, remove interface, including flushing all pending skb's for that device.
Quoted 7 lines
Quoted 1 line
This obviously is beyond the scope of the RCU stuff.
Here is a patch to get you going, it does compile but it probably won't work because the code doesn't handle the case of the last device going away from a target. This is yet another pre-existing bug, since if a timeout happens:
ejectif()is called to remove a device,resend()will BUG inifrotate()if all devices are gone.
I'm holding off on the RCU patch until these known refcount bugs are fixed
Re: [PATCH 04/10] AOE: use rcu to find network device
In reply to Stephen HemmingerThanks again for providing this patch to help get things started. It's very helpful. I appreciate the way it reflects and fits into the rest of the driver, too.
In the patch, there's a loop around getif, ejectif inside the new aoecmd_flushnet function:
void aoecmd_flushnet(struct aoedev *d, struct net_device *nd)
{
struct aoetgt **tt, **te;
tt = d->targets;
te = tt + NTARGETS;
for (; tt < te && *tt; tt++) {
struct aoetgt *t = *tt;
struct aoeif *ifp;
while ( (ifp = getif(t, nd)) )
ejectif(t, ifp);
}
}... but an "if" seems appropriate, since duplicates are avoided when network devices are added in aoecmd_cfg_rsp:
ifp = getif(t, skb->dev);
if (!ifp) {
ifp = addif(t, skb->dev);If there's some other reason for it to be "while" in aoecmd_flushnet that I'm missing, please let me know.
Regarding the new aoe_device_event function,
/* Callback on change of state of network device. */ static int aoe_device_event(struct notifier_block *unused,
unsigned long event, void *ptr)
{
struct net_device *nd = ptr;
if (is_aoe_netif(nd) && event == NETDEV_UNREGISTER) aoedev_ejectnet(nd); return NOTIFY_DONE; }
... the is_aoe_netif function really answers the question, "Are we allowed by the user to do AoE on this local network interface?" The user can modify the list of allowable interfaces at runtime via sysfs, as it's a module parameter. So I don't think we can use is_aoe_netif in the new aoe_device_event function. We should eject a net_device in this handler even if the user has decided not to use it for AoE. Please let me know if I'm missing the point.
You said that,
Quoted 6 lines
It needs to:
1. Get a device ref count when it remembers a device: (ie addif)
2. Install a notifier that looks for device removal events
3. In notifier, remove interface, including flushing all pending skb's for that device.
For 3, does the starter patch flush all pending skbs? Perhaps you could elaborate on what you had in mind?
I am trying to find the best way for the aoe driver to handle the situation where ther are no usable local network interfaces. It does seem to me that the user would benefit from a notice letting them know that they're trying to do AoE without any usable ethernet. I'm thinking that doing something like a printk_once would be appropriate.
(But probably not printk_once itself, because if they add a local interface and then it goes away later, they should be told again that something's wrong.)
Signature · 3 lines
Ed Cashin <[email protected]> http://www.coraid.com/ http://noserose.net/e/
Re: [PATCH 04/10] AOE: use rcu to find network device
Quoted 21 lines · On Thu, 12 Nov 2009 09:33:16 -0500 Ed Cashin <[email protected]> wrote:
Thanks again for providing this patch to help get things started. It's very helpful. I appreciate the way it reflects and fits into the rest of the driver, too.
In the patch, there's a loop around getif, ejectif inside the new
aoecmd_flushnetfunction:void aoecmd_flushnet(struct aoedev *d, struct net_device *nd) { struct aoetgt **tt, **te; tt = d->targets; te = tt + NTARGETS; for (; tt < te && *tt; tt++) { struct aoetgt *t = *tt; struct aoeif *ifp; while ( (ifp = getif(t, nd)) ) ejectif(t, ifp); } }
Quoted 6 lines
... but an "if" seems appropriate, since duplicates are avoided when network devices are added in
aoecmd_cfg_rsp:ifp = getif(t, skb->dev); if (!ifp) { ifp = addif(t, skb->dev);
Yeah if works, wasn't sure if you could have multiples.
Quoted 18 lines
If there's some other reason for it to be "while" in
aoecmd_flushnetthat I'm missing, please let me know.Regarding the new
aoe_device_eventfunction,/* Callback on change of state of network device. */ static int aoe_device_event(struct
notifier_block*unused,
unsigned long event, void *ptr)
{
structnet_device*nd = ptr;if (is_aoe_netif(nd) && event == NETDEV_UNREGISTER) aoedev_ejectnet(nd); return NOTIFY_DONE; }
Quoted 7 lines
... the
is_aoe_netiffunction really answers the question, "Are we allowed by the user to do AoE on this local network interface?" The user can modify the list of allowable interfaces at runtime via sysfs, as it's a module parameter. So I don't think we can useis_aoe_netifin the newaoe_device_eventfunction. We should eject anet_devicein this handler even if the user has decided not to use it for AoE. Please let me know if I'm missing the point.
Ok, you know the code better, I just wanted to avoid doing unnecessary work.
Quoted 11 lines
You said that,
Quoted 6 lines
It needs to:
1. Get a device ref count when it remembers a device: (ie addif)
2. Install a notifier that looks for device removal events
3. In notifier, remove interface, including flushing all pending skb's for that device.For 3, does the starter patch flush all pending skbs? Perhaps you could elaborate on what you had in mind?
I wasn't sure if you ended up queuing skb's, but it looks like the code queues requests not skb's. But you may need to disable preempt over code the work queue code that processes requests, to make sure that device doesn't disappear while doing stuff.
Quoted 6 lines
I am trying to find the best way for the aoe driver to handle the situation where ther are no usable local network interfaces. It does seem to me that the user would benefit from a notice letting them know that they're trying to do AoE without any usable ethernet. I'm thinking that doing something like a
printk_oncewould be appropriate.
Since it is emulating a block device, why not propgate error back up the stack like a disk that's offline.
Re: [PATCH 04/10] AOE: use rcu to find network device
Thanks for the responses.
On Thu Nov 12 12:11:12 EST 2009, [email protected] wrote:
...
Quoted 2 lines
Since it is emulating a block device, why not propgate error back up the stack like a disk that's offline.
The lack of local interfaces to use for AoE might be temporary. For example, the admin might be loading a new network driver, or a new link might go online through which the AoE target can be reached.
If AoE command packets are not sent or resent but instead are effectively dropped while there are no local interfaces through which to send, then the AoE commands will timeout through the normal mechanisms, at which time the error will be signaled to the block layer. It will be like normal unreliable ethernet transport.
In the common case, I think that's going to be the expected behavior, but a printk would probably still be helpful in case the admin doesn't realize why the AoE device is timing out.
Signature · 3 lines
Ed Cashin <[email protected]> http://www.coraid.com/ http://noserose.net/e/
Re: [PATCH 04/10] AOE: use rcu to find network device
Quoted 17 lines · On Thu, 12 Nov 2009 13:07:35 -0500 Ed Cashin <[email protected]> wrote:
Thanks for the responses.
On Thu Nov 12 12:11:12 EST 2009, [email protected] wrote:
...Quoted 2 lines
Since it is emulating a block device, why not propgate error back up the stack like a disk that's offline.
The lack of local interfaces to use for AoE might be temporary. For example, the admin might be loading a new network driver, or a new link might go online through which the AoE target can be reached.
If AoE command packets are not sent or resent but instead are effectively dropped while there are no local interfaces through which to send, then the AoE commands will timeout through the normal mechanisms, at which time the error will be signaled to the block layer. It will be like normal unreliable ethernet transport.
Quoted 4 lines
In the common case, I think that's going to be the expected behavior, but a printk would probably still be helpful in case the admin doesn't realize why the AoE device is timing out.
Okay, you might want to ratelimit the printk
Re: [PATCH 04/10] AOE: use rcu to find network device
In reply to Stephen HemmingerOn Tue Nov 10 18:53:43 EST 2009, [email protected] wrote:
...
Quoted 2 lines
drivers/block/aoe/aoecmd.c +0
-0
...
Quoted 4 lines
drivers/block/aoe/aoecmd.c +0
-0@@ -424,12 +426,29 @@ static void ejectif(struct aoetgt *t, struct aoeif *ifp) { struct aoeif *e;
drivers/block/aoe/aoecmd.c static void · line 438
Quoted 10 lines
drivers/block/aoe/aoecmd.c +4
-0+struct net_device *nd;ulong n; e = t->ifs +NAOEIFS -1 ; + nd = e->nd; n = (e - ifp) *sizeof *ifp;memmove (ifp, ifp+1 , n); e->nd =NULL ; +dev_put (nd); +}
I didn't notice this before, but e->nd will be the net_device pointer from the last ifp in the allocated array, whether it's NULL or not, and usually won't be ifp->nd, the one we need to give to dev_put. I think that's why I see an oops when testing the version of the patch that I sent last. The test is doing rmmod on the interface that's being used to create an ext2 fs on an AoE target.
I'll use ifp->nd instead of e->nd and test again tomorrow. I have to step away from the computer today.
Signature · 1 line
Ed
Re: [PATCH 04/10] AOE: use rcu to find network device
In reply to Stephen HemmingerOn Tue Nov 10 18:06:41 EST 2009, [email protected] wrote:
...
Quoted 6 lines
Hmm, looks like AOE actually is not ref counting the network device. So my patch is incorrect.
As it stands (before my patch), it is UNSAFE. It can decide to queue packets to a device that is removed out from underneath it causing reference to freed memory.
Yes, that's right. I will look at the patch you sent in the follow up. Thanks.
Signature · 1 line
Ed
Re: [PATCH 04/10] AOE: use rcu to find network device
I will be testing the patch below on Monday. It is based on Stephen Hemminger's starter patch (Thanks!). It adds handling for the case where all of the local network interfaces have become unusable. In that case, sent packets and retransmitted packets are effectively dropped, and the driver's handling of ethernet's unreliability takes care of things as usual. If a local interface becomes usable in time no I/O will fail.
After testing I'll make a proper changelog entry. In brief this patch allows the aoe driver to correctly take references on the net_device's that it uses, handle their removal via a callback, and handle their complete absence, too.
Signature · 1 line
Ed
drivers/block/aoe/aoe.h +2 -0
@@ -186,6 +186,7 @@ void aoecmd_ata_rsp(struct sk_buff *);void aoecmd_cfg_rsp (struct sk_buff *);void aoecmd_sleepwork (struct work_struct *);void aoecmd_cleanslate (struct aoedev *); +void aoecmd_flushnet (struct aoedev *,struct net_device *);struct sk_buff *aoecmd_ata_id (struct aoedev *);int aoedev_init (void );
@@ -194,6 +195,7 @@ struct aoedev *aoedev_by_aoeaddr(int maj, int min);struct aoedev *aoedev_by_sysminor_m (ulong sysminor);void aoedev_downdev (struct aoedev *d);int aoedev_flush (const char __user *str,size_t size); +void aoedev_ejectnet (struct net_device *);int aoenet_init (void );void aoenet_exit (void );
drivers/block/aoe/aoecmd.c +27 -6
@@ -93,16 +93,16 @@ put_lba(struct aoe_atahdr *ah, sector_t lba) ah->lba5 = lba >>=8 ; } -static void +static struct net_device *ifrotate (struct aoetgt *t) { t->ifp++;if (t->ifp >= &t->ifs[NAOEIFS ] || t->ifp->nd ==NULL ) t->ifp = t->ifs; -if (t->ifp->nd ==NULL ) { -printk (KERN_INFO "aoe: no interface to rotate to\n" ); -BUG (); - } +if (t->ifp->nd ==NULL &&net_ratelimit ()) +printk (KERN_WARNING +"aoe: no local interface to send through\n" ); +return t->ifp->nd; } static void
@@ -336,7 +336,8 @@ resend(struct aoedev *d, struct aoetgt *t, struct frame *f)char buf[128 ];u32 n; -ifrotate (t); +if (!ifrotate (t)) +return ;/* no usable local network interfaces */ n =newtag (t); skb = f->skb; h = (struct aoe_hdr *)skb_mac_header (skb);
@@ -413,6 +414,8 @@ addif(struct aoetgt *t, struct net_device *nd) p =getif (t,NULL );if (!p)return NULL ; + +dev_hold (nd); p->nd = nd; p->maxbcnt =DEFAULTBCNT ; p->lost =0 ;
@@ -424,12 +427,30 @@ static void ejectif(struct aoetgt *t, struct aoeif *ifp) { struct aoeif *e; +struct net_device *nd;ulong n; e = t->ifs +NAOEIFS -1 ; + nd = e->nd; n = (e - ifp) *sizeof *ifp;memmove (ifp, ifp+1 , n); e->nd =NULL ; +dev_put (nd); +} + +void +aoecmd_flushnet (struct aoedev *d,struct net_device *nd) +{ +struct aoetgt **tt, **te; + tt = d->targets; + te = tt +NTARGETS ; +for (; tt < te && *tt; tt++) { +struct aoetgt *t = *tt; +struct aoeif *ifp; + +if ( (ifp =getif (t, nd)) ) +ejectif (t, ifp); + } } static int
drivers/block/aoe/aoedev.c +15 -0
@@ -162,6 +162,21 @@ aoedev_flush(const char __user *str, size_t cnt)return 0 ; } +void +aoedev_ejectnet (struct net_device *nd) +{ +struct aoedev *d; +unsigned long flags; + +spin_lock_irqsave (&devlist_lock, flags); +for (d = devlist; d; d = d->next) { +spin_lock (&d->lock); +aoecmd_flushnet (d, nd); +spin_unlock (&d->lock); + } +spin_unlock_irqrestore (&d->lock, flags); +} +/* I'm not really sure that this is a realistic problem, but if the network driver goes gonzo let's just leak memory after complaining. */ static void
drivers/block/aoe/aoemain.c +25 -0
@@ -8,6 +8,8 @@#include <linux/blkdev.h> #include <linux/module.h> #include <linux/skbuff.h> +#include <linux/notifier.h> +#include <linux/netdevice.h> #include "aoe.h" MODULE_LICENSE ("GPL" );
@@ -54,11 +56,29 @@ discover_timer(ulong vp) } } +/* Callback on change of state of network device. */ +static int +aoe_device_event (struct notifier_block *unused, +unsigned long event,void *ptr) +{ +struct net_device *nd = ptr; + +if (event ==NETDEV_UNREGISTER ) +aoedev_ejectnet (nd); + +return NOTIFY_DONE ; +} + +static struct notifier_block aoe_notifier = { + .notifier_call = aoe_device_event, +}; +static void aoe_exit (void ) {discover_timer (TKILL ); +unregister_netdevice_notifier (&aoe_notifier);aoenet_exit ();unregister_blkdev (AOE_MAJOR ,DEVICE_NAME );aoechr_exit ();
@@ -83,6 +103,9 @@ aoe_init(void) ret =aoenet_init ();if (ret) goto net_fail; + ret =register_netdevice_notifier (&aoe_notifier); +if (ret) + goto notifier_fail; ret =register_blkdev (AOE_MAJOR ,DEVICE_NAME );if (ret <0 ) {printk (KERN_ERR "aoe: can't register major\n" );
@@ -94,6 +117,8 @@ aoe_init(void)return 0 ; blkreg_fail: +unregister_netdevice_notifier (&aoe_notifier); + notifier_fail:aoenet_exit (); net_fail:aoeblk_exit ();
drivers/block/aoe/aoenet.c +4 -1
@@ -90,7 +90,10 @@ aoenet_xmit(struct sk_buff_head *queue) skb_queue_walk_safe(queue, skb, tmp) {__skb_unlink (skb, queue); -dev_queue_xmit (skb); +if (skb->dev) +dev_queue_xmit (skb); +else +dev_kfree_skb (skb); } }
Re: [PATCH 04/10] AOE: use rcu to find network device
Quoted 8 lines · On Fri, 13 Nov 2009 16:39:49 -0500 Ed Cashin <[email protected]> wrote:
I will be testing the patch below on Monday. It is based on Stephen Hemminger's starter patch (Thanks!). It adds handling for the case where all of the local network interfaces have become unusable. In that case, sent packets and retransmitted packets are effectively dropped, and the driver's handling of ethernet's unreliability takes care of things as usual. If a local interface becomes usable in time no I/O will fail.
Quoted 4 lines
After testing I'll make a proper changelog entry. In brief this patch allows the aoe driver to correctly take references on the net_device's that it uses, handle their removal via a callback, and handle their complete absence, too.
Looks good, good luck with testing.
PATCH 5/10 parisc: use RCU to find network device
In reply to Stephen HemmingerAnother place where RCU can be used instead of read_lock(&dev_base_lock) This is by inspection, don't have platform or cross-build environment to validate.
drivers/parisc/led.c +1 -3
@@ -354,9 +354,8 @@ static __inline__ int led_get_net_activi/* we are running as a workqueue task, so locking dev_base * for reading should be OK */ -read_lock (&dev_base_lock);rcu_read_lock (); -for_each_netdev (&init_net, dev) { +for_each_netdev_rcu (&init_net, dev) {const struct net_device_stats *stats;struct in_device *in_dev =__in_dev_get_rcu (dev);if (!in_dev || !in_dev->ifa_list)
@@ -368,7 +367,6 @@ static __inline__ int led_get_net_activi tx_total += stats->tx_packets; }rcu_read_unlock (); -read_unlock (&dev_base_lock); retval =0 ;
Re: [PATCH 05/10] parisc: use RCU to find network device
Stephen Hemminger a =E9crit :
Quoted 1 line
Another place where RCU can be used instead of read_lock(&dev_base_lo=
ck)
Quoted 5 lines
This is by inspection, don't have platform or cross-build environment to validate.
=20Signed-off-by Stephen Hemminger <[email protected]>=20
Duplicate of previously posted patch...
Re: [PATCH 05/10] parisc: use RCU to find network device
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
Date: Tue, 10 Nov 2009 09:54:51 -0800
Quoted 5 lines
Another place where RCU can be used instead of
read_lock(&dev_base_lock)This is by inspection, don't have platform or cross-build environment to validate.Signed-off-by Stephen Hemminger <[email protected]>
Applied.
PATCH 6/10 s390: use RCU to walk list of network devices
In reply to Stephen HemmingerThis is similar to other cases where for_each_netdev_rcu can be used when gathering information.
By inspection, don't have platform or cross-build environment to validate.
arch/s390/appldata/appldata_net_sum.c +5 -3
@@ -83,8 +83,9 @@ static void appldata_get_net_sum_data(vo rx_dropped =0 ; tx_dropped =0 ; collisions =0 ; -read_lock (&dev_base_lock); -for_each_netdev (&init_net, dev) { + +rcu_read_lock (); +for_each_netdev_rcu (&init_net, dev) {const struct net_device_stats *stats =dev_get_stats (dev); rx_packets += stats->rx_packets;
@@ -98,7 +99,8 @@ static void appldata_get_net_sum_data(vo collisions += stats->collisions; i++; } -read_unlock (&dev_base_lock); +rcu_read_unlock (); + net_data->nr_interfaces = i; net_data->rx_packets = rx_packets; net_data->tx_packets = tx_packets;
Re: [PATCH 06/10] s390: use RCU to walk list of network devices
Quoted 25 lines · Stephen Hemminger
This is similar to other cases where
for_each_netdev_rcucan be used when gathering information.By inspection, don't have platform or cross-build environment to validate.
Signed-off-by Stephen Hemminger <[email protected]>arch/s390/appldata/appldata_net_sum.c +3
-2@@ -83,8 +83,9 @@ static void appldata_get_net_sum_data(vo rx_dropped =0 ; tx_dropped =0 ; collisions =0 ; -read_lock (&dev_base_lock); -for_each_netdev (&init_net, dev) { + +rcu_read_lock (); +for_each_netdev_rcu (&init_net, dev) {const struct net_device_stats *stats =dev_get_stats (dev); rx_packets += stats->rx_packets;
arch/s390/appldata/appldata_net_sum.c static void appldata_get_net_sum_data(vo · line 106
Quoted 9 lines
arch/s390/appldata/appldata_net_sum.c +2
-1@@ -98,7 +99,8 @@ static void appldata_get_net_sum_data(vo collisions += stats->collisions; i++; } -read_unlock (&dev_base_lock); +rcu_read_unlock (); + net_data->nr_interfaces = i; net_data->rx_packets = rx_packets; net_data->tx_packets = tx_packets;
Not sure if dev_get_stats(dev) could sleep on some devices...
Re: [PATCH 06/10] s390: use RCU to walk list of network devices
Quoted 23 lines · On Tue, 10 Nov 2009 19:27:11 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 22 lines · Stephen Hemminger
This is similar to other cases where
for_each_netdev_rcucan be used when gathering information.By inspection, don't have platform or cross-build environment to validate.
Signed-off-by Stephen Hemminger <[email protected]>arch/s390/appldata/appldata_net_sum.c +3
-2@@ -83,8 +83,9 @@ static void appldata_get_net_sum_data(vo rx_dropped =0 ; tx_dropped =0 ; collisions =0 ; -read_lock (&dev_base_lock); -for_each_netdev (&init_net, dev) { + +rcu_read_lock (); +for_each_netdev_rcu (&init_net, dev) {const struct net_device_stats *stats =dev_get_stats (dev);
Quoted 15 lines
arch/s390/appldata/appldata_net_sum.c static void appldata_get_net_sum_data(vo · line 106
Quoted 12 lines
arch/s390/appldata/appldata_net_sum.c +2
-1rx_packets += stats->rx_packets;@@ -98,7 +99,8 @@ static void appldata_get_net_sum_data(vo collisions += stats->collisions; i++; } -read_unlock (&dev_base_lock); +rcu_read_unlock (); + net_data->nr_interfaces = i; net_data->rx_packets = rx_packets; net_data->tx_packets = tx_packets;Not sure if
dev_get_stats(dev)could sleep on some devices...
It would have already been broken since dev_get_stats is previously called with read_lock(), and sleeping with any lock held causes warning.
Re: [PATCH 06/10] s390: use RCU to walk list of network devices
In reply to Stephen HemmingerQuoted 9 lines · Stephen Hemminger
This is similar to other cases where
for_each_netdev_rcucan be used when gathering information.By inspection, don't have platform or cross-build environment to validate.
Signed-off-by Stephen Hemminger <[email protected]>
Re: [PATCH 06/10] s390: use RCU to walk list of network devices
From: Eric Dumazet <[email protected]>
Date: Tue, 10 Nov 2009 19:40:42 +0100
Quoted 4 lines
Quoted 3 lines · Stephen Hemminger
This is similar to other cases where
for_each_netdev_rcucan be used when gathering information.
Quoted 8 lines
Quoted 6 lines
By inspection, don't have platform or cross-build environment to validate.
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Eric Dumazet <[email protected]>
Applied.
PATCH 7/10 decnet: use RCU to find network devices
In reply to Stephen HemmingerWhen showing device statistics use RCU rather than read_lock(&dev_base_lock) Compile tested only.
net/decnet/dn_dev.c +6 -8
@@ -856,9 +856,7 @@ int dn_dev_bind_default(__le16 *addr) dev =dn_dev_get_default (); last_chance:if (dev) { -read_lock (&dev_base_lock); rv =dn_dev_get_first (dev, addr); -read_unlock (&dev_base_lock);dev_put (dev);if (rv ==0 || dev == init_net.loopback_dev)return rv;
@@ -1323,18 +1321,18 @@ static inline int is_dn_dev(struct net_d }static void *dn_dev_seq_start (struct seq_file *seq,loff_t *pos) - __acquires(&dev_base_lock) +__acquires (rcu) {int i;struct net_device *dev; -read_lock (&dev_base_lock); +rcu_read_lock ();if (*pos ==0 )return SEQ_START_TOKEN ; i =1 ; -for_each_netdev (&init_net, dev) { +for_each_netdev_rcu (&init_net, dev) {if (!is_dn_dev (dev))continue ;
@@ -1355,7 +1353,7 @@ static void *dn_dev_seq_next(struct seq_if (v ==SEQ_START_TOKEN ) dev =net_device_entry (&init_net.dev_base_head); -for_each_netdev_continue (&init_net, dev) { +for_each_netdev_continue_rcu (&init_net, dev) {if (!is_dn_dev (dev))continue ;
@@ -1366,9 +1364,9 @@ static void *dn_dev_seq_next(struct seq_ }static void dn_dev_seq_stop (struct seq_file *seq,void *v) - __releases(&dev_base_lock) +__releases (rcu) { -read_unlock (&dev_base_lock); +rcu_read_unlock (); }static char *dn_type2asc (char type)
Re: [PATCH 07/10] decnet: use RCU to find network devices
net/decnet/dn_dev.c static inline int is_dn_dev(struct net_d
Quoted 18 lines · Stephen Hemminger
When showing device statistics use RCU rather than
read_lock(&dev_base_lock)Compile tested only.Signed-off-by Stephen Hemminger <[email protected]>net/decnet/dn_dev.c +0
-2@@ -856,9 +856,7 @@ int dn_dev_bind_default(__le16 *addr) dev =dn_dev_get_default (); last_chance:if (dev) { -read_lock (&dev_base_lock); rv =dn_dev_get_first (dev, addr); -read_unlock (&dev_base_lock);dev_put (dev);if (rv ==0 || dev == init_net.loopback_dev)return rv;@@ -1323,18 +1321,18 @@ static inline int is_dn_dev(struct net_d
I dont understand this part. Why previous locking can be avoided ?
Re: [PATCH 07/10] decnet: use RCU to find network devices
Quoted 6 lines · On Tue, 10 Nov 2009 19:43:21 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 5 lines · Stephen Hemminger
When showing device statistics use RCU rather than
read_lock(&dev_base_lock)Compile tested only.Signed-off-by Stephen Hemminger <[email protected]>
Quoted 16 lines
net/decnet/dn_dev.c static inline int is_dn_dev(struct net_d
Quoted 13 lines
net/decnet/dn_dev.c +0
-2@@ -856,9 +856,7 @@ int dn_dev_bind_default(__le16 *addr) dev =dn_dev_get_default (); last_chance:if (dev) { -read_lock (&dev_base_lock); rv =dn_dev_get_first (dev, addr); -read_unlock (&dev_base_lock);dev_put (dev);if (rv ==0 || dev == init_net.loopback_dev)return rv;@@ -1323,18 +1321,18 @@ static inline int is_dn_dev(struct net_dI dont understand this part. Why previous locking can be avoided ?
dn_dev_get_default acquires a reference on dev so the device can not go away.
It could be the original author meant to ensure the address list doesn't change. If so, then rtnl_lock() should have been used.
Re: [PATCH 07/10] decnet: use RCU to find network devices
Quoted 25 lines · Stephen Hemminger
Quoted 6 lines · On Tue, 10 Nov 2009 19:43:21 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 5 lines · Stephen Hemminger
When showing device statistics use RCU rather than
read_lock(&dev_base_lock)Compile tested only.Signed-off-by Stephen Hemminger <[email protected]>Quoted 15 lines
net/decnet/dn_dev.c static inline int is_dn_dev(struct net_d
Quoted 13 lines
net/decnet/dn_dev.c +0
-2@@ -856,9 +856,7 @@ int dn_dev_bind_default(__le16 *addr) dev =dn_dev_get_default (); last_chance:if (dev) { -read_lock (&dev_base_lock); rv =dn_dev_get_first (dev, addr); -read_unlock (&dev_base_lock);dev_put (dev);if (rv ==0 || dev == init_net.loopback_dev)return rv;@@ -1323,18 +1321,18 @@ static inline int is_dn_dev(struct net_dI dont understand this part. Why previous locking can be avoided ?
Quoted 5 lines
dn_dev_get_defaultacquires a reference on dev so the device can not go away.It could be the original author meant to ensure the address list doesn't change. If so, then
rtnl_lock()should have been used.
Hmm... I spot some bugs during my previous round of patches, so maybe this is a real bug... We should double check.
Re: [PATCH 07/10] decnet: use RCU to find network devices
In reply to Stephen HemmingerHi,
Quoted 26 lines · Stephen Hemminger
Quoted 6 lines · On Tue, 10 Nov 2009 19:43:21 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 5 lines · Stephen Hemminger
When showing device statistics use RCU rather than
read_lock(&dev_base_lock)Compile tested only.Signed-off-by Stephen Hemminger <[email protected]>Quoted 16 lines
net/decnet/dn_dev.c static inline int is_dn_dev(struct net_d
Quoted 13 lines
net/decnet/dn_dev.c +0
-2@@ -856,9 +856,7 @@ int dn_dev_bind_default(__le16 *addr) dev =dn_dev_get_default (); last_chance:if (dev) { -read_lock (&dev_base_lock); rv =dn_dev_get_first (dev, addr); -read_unlock (&dev_base_lock);dev_put (dev);if (rv ==0 || dev == init_net.loopback_dev)return rv;@@ -1323,18 +1321,18 @@ static inline int is_dn_dev(struct net_dI dont understand this part. Why previous locking can be avoided ?
Quoted 5 lines
dn_dev_get_defaultacquires a reference on dev so the device can not go away.It could be the original author meant to ensure the address list doesn't change. If so, then
rtnl_lock()should have been used.
The original author has tried to remember what he was thinking when he wrote this code :-)
I think you are right that it should be rtnl_lock() as we don't want the address list changing at this point. On the other hand I notice also that other bits of the code seem to be using dev_base_lock too.
Maybe this is a hang over from another era? I'll have to refresh my memory some more before I can give a verdict on that I'm afraid,
Steve.
PATCH 1/2 decnet: add RTNL lock when reading address list
Add missing locking in the case of auto binding to the default device. The address list might change while this code is looking at the list.
Compile tested only, I am not a decnet user.
net/decnet/dn_dev.c +4 -0
@@ -828,13 +828,17 @@ static int dn_dev_get_first(struct net_dstruct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;struct dn_ifaddr *ifa;int rv = -ENODEV ; +if (dn_db ==NULL ) goto out; + +rtnl_lock (); ifa = dn_db->ifa_list;if (ifa !=NULL ) { *addr = ifa->ifa_local; rv =0 ; } +rtnl_unlock (); out:return rv; }
PATCH 2/2 decnet: convert dndev_lock to spinlock
There is no reason for this lock to be reader/writer since the reader only has lock held for a very brief period. The overhead of read_lock is more expensive than spinlock.
Compile tested only, I am not a decnet user.
net/decnet/dn_dev.c +12 -7
@@ -68,7 +68,7 @@ extern struct neigh_table dn_neigh_table*/ __le16 decnet_address =0 ; -static DEFINE_RWLOCK (dndev_lock); +static DEFINE_SPINLOCK (dndev_lock);static struct net_device *decnet_default_device;static BLOCKING_NOTIFIER_HEAD (dnaddr_chain);
@@ -557,7 +557,8 @@ rarok:struct net_device *dn_dev_get_default (void ) {struct net_device *dev; -read_lock (&dndev_lock); + +spin_lock (&dndev_lock); dev = decnet_default_device;if (dev) {if (dev->dn_ptr)
@@ -565,7 +566,8 @@ struct net_device *dn_dev_get_default(voelse dev =NULL ; } -read_unlock (&dndev_lock); +spin_unlock (&dndev_lock); +return dev; }
@@ -575,13 +577,15 @@ int dn_dev_set_default(struct net_deviceint rv = -EBUSY ;if (!dev->dn_ptr)return -ENODEV ; -write_lock (&dndev_lock); + +spin_lock (&dndev_lock);if (force || decnet_default_device ==NULL ) { old = decnet_default_device; decnet_default_device = dev; rv =0 ; } -write_unlock (&dndev_lock); +spin_unlock (&dndev_lock); +if (old)dev_put (old);return rv;
@@ -589,13 +593,14 @@ int dn_dev_set_default(struct net_devicestatic void dn_dev_check_default (struct net_device *dev) { -write_lock (&dndev_lock); +spin_lock (&dndev_lock);if (dev == decnet_default_device) { decnet_default_device =NULL ; }else { dev =NULL ; } -write_unlock (&dndev_lock); +spin_unlock (&dndev_lock); +if (dev)dev_put (dev); }
Re: [PATCH 2/2] decnet: convert dndev_lock to spinlock
From: Stephen Hemminger <[email protected]>
Date: Wed, 11 Nov 2009 09:40:36 -0800
Quoted 7 lines
There is no reason for this lock to be reader/writer since the reader only has lock held for a very brief period. The overhead of
read_lockis more expensive than spinlock.Compile tested only, I am not a decnet user.
Signed-off-by Stephen Hemminger <[email protected]>
Applied to net-next-2.6
Re: [PATCH 1/2] decnet: add RTNL lock when reading address list
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
Date: Wed, 11 Nov 2009 09:39:27 -0800
Quoted 7 lines
Add missing locking in the case of auto binding to the default device. The address list might change while this code is looking at the list.
Compile tested only, I am not a decnet user.
Signed-off-by Stephen Hemminger <[email protected]>
Applied to net-next-2.6
Re: [PATCH 07/10] decnet: use RCU to find network devices
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
Date: Tue, 10 Nov 2009 09:54:53 -0800
Quoted 4 lines
When showing device statistics use RCU rather than
read_lock(&dev_base_lock)Compile tested only.Signed-off-by Stephen Hemminger <[email protected]>
Applied.
PATCH 8/10 ipv6: use RCU to walk list of network devices
In reply to Stephen HemmingerNo longer need read_lock(&dev_base_lock), use RCU instead. This also needs to be optimized for large number of devices.
net/ipv6/addrconf.c +3 -3
@@ -3828,9 +3828,9 @@ static int inet6_dump_ifinfo(struct sk_bstruct net_device *dev;struct inet6_dev *idev; -read_lock (&dev_base_lock); +rcu_read_lock (); idx =0 ; -for_each_netdev (net, dev) { +for_each_netdev_rcu (net, dev) {if (idx < s_idx) goto cont;if ((idev =in6_dev_get (dev)) ==NULL )
@@ -3843,7 +3843,7 @@ static int inet6_dump_ifinfo(struct sk_b cont: idx++; } -read_unlock (&dev_base_lock); +rcu_read_unlock (); cb->args[0 ] = idx;return skb->len;
net/ipv6/anycast.c +5 -5
@@ -431,7 +431,7 @@ static inline struct ifacaddr6 *ac6_get_struct net *net =seq_file_net (seq); state->idev =NULL ; -for_each_netdev (net, state->dev) { +for_each_netdev_rcu (net, state->dev) {struct inet6_dev *idev; idev =in6_dev_get (state->dev);if (!idev)
@@ -482,9 +482,9 @@ static struct ifacaddr6 *ac6_get_idx(str }static void *ac6_seq_start (struct seq_file *seq,loff_t *pos) -__acquires (dev_base_lock) +__acquires (rcu) { -read_lock (&dev_base_lock); +rcu_read_lock ();return ac6_get_idx (seq, *pos); }
@@ -497,14 +497,14 @@ static void *ac6_seq_next(struct seq_fil }static void ac6_seq_stop (struct seq_file *seq,void *v) -__releases (dev_base_lock) +__releases (rcu) {struct ac6_iter_state *state =ac6_seq_private (seq);if (likely (state->idev !=NULL )) {read_unlock_bh (&state->idev->lock);in6_dev_put (state->idev); } -read_unlock (&dev_base_lock); +rcu_read_unlock (); }static int ac6_seq_show (struct seq_file *seq,void *v)
net/ipv6/mcast.c +10 -10
@@ -2375,7 +2375,7 @@ static inline struct ifmcaddr6 *igmp6_mcstruct net *net =seq_file_net (seq); state->idev =NULL ; -for_each_netdev (net, state->dev) { +for_each_netdev_rcu (net, state->dev) {struct inet6_dev *idev; idev =in6_dev_get (state->dev);if (!idev)
@@ -2426,9 +2426,9 @@ static struct ifmcaddr6 *igmp6_mc_get_id }static void *igmp6_mc_seq_start (struct seq_file *seq,loff_t *pos) -__acquires (dev_base_lock) +__acquires (rcu) { -read_lock (&dev_base_lock); +rcu_read_lock ();return igmp6_mc_get_idx (seq, *pos); }
@@ -2441,7 +2441,7 @@ static void *igmp6_mc_seq_next(struct se }static void igmp6_mc_seq_stop (struct seq_file *seq,void *v) -__releases (dev_base_lock) +__releases (rcu) {struct igmp6_mc_iter_state *state =igmp6_mc_seq_private (seq);if (likely (state->idev !=NULL )) {
@@ -2450,7 +2450,7 @@ static void igmp6_mc_seq_stop(struct seq state->idev =NULL ; } state->dev =NULL ; -read_unlock (&dev_base_lock); +rcu_read_unlock (); }static int igmp6_mc_seq_show (struct seq_file *seq,void *v)
@@ -2507,7 +2507,7 @@ static inline struct ip6_sf_list *igmp6_ state->idev =NULL ; state->im =NULL ; -for_each_netdev (net, state->dev) { +for_each_netdev_rcu (net, state->dev) {struct inet6_dev *idev; idev =in6_dev_get (state->dev);if (unlikely (idev ==NULL ))
@@ -2573,9 +2573,9 @@ static struct ip6_sf_list *igmp6_mcf_get }static void *igmp6_mcf_seq_start (struct seq_file *seq,loff_t *pos) -__acquires (dev_base_lock) +__acquires (rcu) { -read_lock (&dev_base_lock); +rcu_read_lock ();return *pos ?igmp6_mcf_get_idx (seq, *pos -1 ) :SEQ_START_TOKEN ; }
@@ -2591,7 +2591,7 @@ static void *igmp6_mcf_seq_next(struct s }static void igmp6_mcf_seq_stop (struct seq_file *seq,void *v) -__releases (dev_base_lock) +__releases (rcu) {struct igmp6_mcf_iter_state *state =igmp6_mcf_seq_private (seq);if (likely (state->im !=NULL )) {
@@ -2604,7 +2604,7 @@ static void igmp6_mcf_seq_stop(struct se state->idev =NULL ; } state->dev =NULL ; -read_unlock (&dev_base_lock); +rcu_read_unlock (); }static int igmp6_mcf_seq_show (struct seq_file *seq,void *v)
David Miller
maintainerRe: [PATCH 08/10] ipv6: use RCU to walk list of network devices
From: Stephen Hemminger <[email protected]>
Date: Tue, 10 Nov 2009 09:54:54 -0800
Quoted 4 lines
No longer need
read_lock(&dev_base_lock), use RCU instead. This also needs to be optimized for large number of devices.Signed-off-by Stephen Hemminger <[email protected]>
As Eric mentioned, superceded by his patch.
PATCH 1/1 ipv6: use RCU to walk list of network devices
In reply to Stephen HemmingerQuoted 4 lines · Stephen Hemminger
No longer need
read_lock(&dev_base_lock), use RCU instead. This also needs to be optimized for large number of devices.Signed-off-by Stephen Hemminger <[email protected]>
I gave a look at your patch Stephen and found we need a new next_net_device_rcu(struct net_device *dev) as well, as next_net_device() is not RCU safe.
(followup patch is probably needed to use it in net/ipv4/igmp.c, after commit 61fbab77a843d2e77232 : IPV4: use rcu to walk list of devices in IGMP)
We also can avoid taking references on inet6_dev structs.
[PATCH net-next-2.6] ipv6: use RCU to walk list of network devices
No longer need read_lock(&dev_base_lock), use RCU instead. We also can avoid taking references on inet6_dev structs.
--- include/linux/netdevice.h | 10 +++++++ net/ipv6/anycast.c | 29 +++++++++----------- net/ipv6/mcast.c | 51 ++++++++++++++++-------------------- 3 files changed, 47 insertions(+), 43 deletions(-)
include/linux/netdevice.h +10 -0
@@ -1093,6 +1093,16 @@ static inline struct net_device *next_net_device(struct net_device *dev)return lh == &net->dev_base_head ?NULL :net_device_entry (lh); } +static inline struct net_device *next_net_device_rcu (struct net_device *dev) +{ +struct list_head *lh; +struct net *net; + + net =dev_net (dev); + lh =rcu_dereference (dev->dev_list.next); +return lh == &net->dev_base_head ?NULL :net_device_entry (lh); +} +static inline struct net_device *first_net_device (struct net *net) { return list_empty(&net->dev_base_head) ? NULL :
net/ipv6/anycast.c +14 -15
@@ -431,9 +431,9 @@ static inline struct ifacaddr6 *ac6_get_first(struct seq_file *seq)struct net *net =seq_file_net (seq); state->idev =NULL ; -for_each_netdev (net, state->dev) { +for_each_netdev_rcu (net, state->dev) {struct inet6_dev *idev; - idev =in6_dev_get (state->dev); + idev =__in6_dev_get (state->dev);if (!idev)continue ;read_lock_bh (&idev->lock);
@@ -443,7 +443,6 @@ static inline struct ifacaddr6 *ac6_get_first(struct seq_file *seq)break ; }read_unlock_bh (&idev->lock); -in6_dev_put (idev); }return im; }
@@ -454,16 +453,15 @@ static struct ifacaddr6 *ac6_get_next(struct seq_file *seq, struct ifacaddr6 *im im = im->aca_next;while (!im) { -if (likely (state->idev !=NULL )) { +if (likely (state->idev !=NULL ))read_unlock_bh (&state->idev->lock); -in6_dev_put (state->idev); - } - state->dev =next_net_device (state->dev); + + state->dev =next_net_device_rcu (state->dev);if (!state->dev) { state->idev =NULL ;break ; } - state->idev =in6_dev_get (state->dev); + state->idev =__in6_dev_get (state->dev);if (!state->idev)continue ;read_lock_bh (&state->idev->lock);
@@ -482,29 +480,30 @@ static struct ifacaddr6 *ac6_get_idx(struct seq_file *seq, loff_t pos) }static void *ac6_seq_start (struct seq_file *seq,loff_t *pos) -__acquires (dev_base_lock) +__acquires (RCU ) { -read_lock (&dev_base_lock); +rcu_read_lock ();return ac6_get_idx (seq, *pos); }static void *ac6_seq_next (struct seq_file *seq,void *v,loff_t *pos) { -struct ifacaddr6 *im; - im =ac6_get_next (seq, v); +struct ifacaddr6 *im =ac6_get_next (seq, v); + ++*pos;return im; }static void ac6_seq_stop (struct seq_file *seq,void *v) -__releases (dev_base_lock) +__releases (RCU ) {struct ac6_iter_state *state =ac6_seq_private (seq); +if (likely (state->idev !=NULL )) {read_unlock_bh (&state->idev->lock); -in6_dev_put (state->idev); + state->idev =NULL ; } -read_unlock (&dev_base_lock); +rcu_read_unlock (); }static int ac6_seq_show (struct seq_file *seq,void *v)
net/ipv6/mcast.c +23 -28
145 lines not on this page · raw message
Re: [PATCH net-next-2.6] ipv6: use RCU to walk list of network devices
From: Eric Dumazet <[email protected]>
Date: Thu, 12 Nov 2009 04:34:30 +0100
Quoted 6 lines
[PATCH net-next-2.6] ipv6: use RCU to walk list of network devices
No longer need
read_lock(&dev_base_lock), use RCU instead. We also can avoid taking references oninet6_devstructs.Signed-off-by Eric Dumazet <[email protected]>
Applied.
PATCH 9/10 IPV4: use rcu to walk list of devices in IGMP
In reply to Stephen HemmingerThis also needs to be optimized for large number of devices.
net/ipv4/igmp.c +10 -8
@@ -2311,7 +2311,7 @@ static inline struct ip_mc_list *igmp_mcstruct igmp_mc_iter_state *state =igmp_mc_seq_private (seq); state->in_dev =NULL ; -for_each_netdev (net, state->dev) { +for_each_netdev_rcu (net, state->dev) {struct in_device *in_dev; in_dev =in_dev_get (state->dev);if (!in_dev)
@@ -2361,9 +2361,9 @@ static struct ip_mc_list *igmp_mc_get_id }static void *igmp_mc_seq_start (struct seq_file *seq,loff_t *pos) -__acquires (dev_base_lock) +__acquires (rcu) { -read_lock (&dev_base_lock); +rcu_read_lock ();return *pos ?igmp_mc_get_idx (seq, *pos -1 ) :SEQ_START_TOKEN ; }
@@ -2379,7 +2379,7 @@ static void *igmp_mc_seq_next(struct seq }static void igmp_mc_seq_stop (struct seq_file *seq,void *v) -__releases (dev_base_lock) +__releases (rcu) {struct igmp_mc_iter_state *state =igmp_mc_seq_private (seq);if (likely (state->in_dev !=NULL )) {
@@ -2388,7 +2388,7 @@ static void igmp_mc_seq_stop(struct seq_ state->in_dev =NULL ; } state->dev =NULL ; -read_unlock (&dev_base_lock); +rcu_read_unlock (); }static int igmp_mc_seq_show (struct seq_file *seq,void *v)
@@ -2462,7 +2462,7 @@ static inline struct ip_sf_list *igmp_mc state->idev =NULL ; state->im =NULL ; -for_each_netdev (net, state->dev) { +for_each_netdev_rcu (net, state->dev) {struct in_device *idev; idev =in_dev_get (state->dev);if (unlikely (idev ==NULL ))
@@ -2528,8 +2528,9 @@ static struct ip_sf_list *igmp_mcf_get_i }static void *igmp_mcf_seq_start (struct seq_file *seq,loff_t *pos) +__acquires (rcu) { -read_lock (&dev_base_lock); +rcu_read_lock ();return *pos ?igmp_mcf_get_idx (seq, *pos -1 ) :SEQ_START_TOKEN ; }
@@ -2545,6 +2546,7 @@ static void *igmp_mcf_seq_next(struct se }static void igmp_mcf_seq_stop (struct seq_file *seq,void *v) +__releases (rcu) {struct igmp_mcf_iter_state *state =igmp_mcf_seq_private (seq);if (likely (state->im !=NULL )) {
@@ -2557,7 +2559,7 @@ static void igmp_mcf_seq_stop(struct seq state->idev =NULL ; } state->dev =NULL ; -read_unlock (&dev_base_lock); +rcu_read_unlock (); }static int igmp_mcf_seq_show (struct seq_file *seq,void *v)
Re: [PATCH 09/10] IPV4: use rcu to walk list of devices in IGMP
Review
Quoted 7 lines · Stephen Hemminger
This also needs to be optimized for large number of devices.
Signed-off-by Stephen Hemminger <[email protected]>static void
igmp_mcf_seq_stop(struct seq_file *seq, void *v)(quoted diff) +1
-0+ __releases(rcu)
Minor note : we usually use RCU instead of rcu, but it doesnt really matter.
Re: [PATCH 09/10] IPV4: use rcu to walk list of devices in IGMP
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
Date: Tue, 10 Nov 2009 09:54:55 -0800
Quoted 3 lines
This also needs to be optimized for large number of devices.
Signed-off-by Stephen Hemminger <[email protected]>
Applied.
PATCH 10/10 CAN: use dev_get_by_index_rcu
In reply to Stephen HemmingerUse new function to avoid doing read_lock().
net/can/bcm.c +3 -3
@@ -139,13 +139,13 @@ static char *bcm_proc_getifname(char *reif (!ifindex)return "any" ; -read_lock (&dev_base_lock); - dev =__dev_get_by_index (&init_net, ifindex); +rcu_read_lock (); + dev =dev_get_by_index_rcu (&init_net, ifindex);if (dev)strcpy (result, dev->name);else strcpy (result,"???" ); -read_unlock (&dev_base_lock); +rcu_read_unlock ();return result; }
Re: [PATCH 10/10] CAN: use dev_get_by_index_rcu
Quoted 14 lines · Stephen Hemminger
Use new function to avoid doing
read_lock().Signed-off-by Stephen Hemminger <[email protected]>net/can/bcm.c +1
-2@@ -139,13 +139,13 @@ static char *bcm_proc_getifname(char *reif (!ifindex)return "any" ; -read_lock (&dev_base_lock); - dev =__dev_get_by_index (&init_net, ifindex); +rcu_read_lock ();
net/can/bcm.c static char *bcm_proc_getifname(char *re · line 151
Quoted 10 lines
net/can/bcm.c +2
-1+ dev =dev_get_by_index_rcu (&init_net, ifindex);if (dev)strcpy (result, dev->name);else strcpy (result,"???" ); -read_unlock (&dev_base_lock); +rcu_read_unlock ();return result; }
I was pretty sure I had already done this one...
Ah yes, that was planned after a bugfix for net-2.6.
Re: [PATCH 10/10] CAN: use dev_get_by_index_rcu
Quoted 28 lines · Eric Dumazet
Quoted 14 lines · Stephen Hemminger
Use new function to avoid doing
read_lock().Signed-off-by Stephen Hemminger <[email protected]>net/can/bcm.c +1
-2@@ -139,13 +139,13 @@ static char *bcm_proc_getifname(char *reif (!ifindex)return "any" ; -read_lock (&dev_base_lock); - dev =__dev_get_by_index (&init_net, ifindex); +rcu_read_lock ();net/can/bcm.c static char *bcm_proc_getifname(char *re · line 151
Quoted 10 lines
net/can/bcm.c +2
-1+ dev =dev_get_by_index_rcu (&init_net, ifindex);if (dev)strcpy (result, dev->name);else strcpy (result,"???" ); -read_unlock (&dev_base_lock); +rcu_read_unlock ();return result; }I was pretty sure I had already done this one...
Quoted 4 lines
Ah yes, that was planned after a bugfix for net-2.6.
Acked-by Eric Dumazet <[email protected]>
Thanks everyone!
Re: [PATCH 10/10] CAN: use dev_get_by_index_rcu
From: Oliver Hartkopp <[email protected]>
Date: Wed, 11 Nov 2009 06:54:24 +0100
Quoted 5 lines
Quoted 4 lines · Eric Dumazet
Quoted 3 lines · Stephen Hemminger
Use new function to avoid doing
read_lock().Signed-off-by Stephen Hemminger <[email protected]>
...
Quoted 6 lines
Quoted 2 lines
Acked-by Eric Dumazet <[email protected]>Thanks everyone!
Signed-off-by Oliver Hartkopp <[email protected]>
Applied.
Quoted 4 lines · Stephen Hemminger
The goal is to eliminate
dev_base_lockcompletely, and just use RCU andrtnl_mutexfor network devices. This series gets rid of the many of the users ofdev_base_lockjust for reading.
Nice, but I was doing all this work Stephen... maybe I am too slow ?
I believe you missed one of my patch (but David is traveling)
[PATCH net-next-2.6] ipv6: speedup inet6_dump_ifinfo()
This conflicts with your :
[PATCH 08/10] ipv6: use RCU to walk list of network devices
Quoted 8 lines · On Tue, 10 Nov 2009 19:18:14 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 4 lines · Stephen Hemminger
The goal is to eliminate
dev_base_lockcompletely, and just use RCU andrtnl_mutexfor network devices. This series gets rid of the many of the users ofdev_base_lockjust for reading.Nice, but I was doing all this work Stephen... maybe I am too slow ?
Quoted 8 lines
I believe you missed one of my patch (but David is traveling)
[PATCH net-next-2.6] ipv6: speedup
inet6_dump_ifinfo()This conflicts with your :
[PATCH 08/10] ipv6: use RCU to walk list of network devices
Inflight conflict.
I was just trying to pick up the stragglers you left behind :-)
The nasty cases left are bonding (whose existing locking model is a pile of crap), and sysfs (slightly less stinky). The bonding code just needs to be rewritten to have a sane/simple model.
Quoted 6 lines · Stephen Hemminger
I was just trying to pick up the stragglers you left behind :-)
The nasty cases left are bonding (whose existing locking model is a pile of crap), and sysfs (slightly less stinky). The bonding code just needs to be rewritten to have a sane/simple model.
I was thinking of improving bonding, so it might be good to coordinate our work :)
1) Get rid of rwlock in tx fast path. (RCU ? did I said RCU)
2) multi queue support (Got two dual 82599 dual ports cards from Intel :) )
Quoted 9 lines · On Tue, 10 Nov 2009 19:39:20 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 6 lines · Stephen Hemminger
I was just trying to pick up the stragglers you left behind :-)
The nasty cases left are bonding (whose existing locking model is a pile of crap), and sysfs (slightly less stinky). The bonding code just needs to be rewritten to have a sane/simple model.
I was thinking of improving bonding, so it might be good to coordinate our work :)
I'll be happy to review, but was avoiding doing any serious work on it.
Quoted 4 lines
1) Get rid of rwlock in tx fast path. (RCU ? did I said RCU)
2) multi queue support (Got two dual 82599 dual ports cards from Intel :) )
I hope to get back to doing netlink interface for bridging, then bonding over next few weeks.