netpoll/netconsole fixes
Subsystems (3)
cover netpoll/netconsole fixes
The netpoll transmit skb management is a mess, it has two paths and it's on Txq. These patches try and clean this up.
--
PATCH 1/3 netpoll: initialize skb for UDP
Need to fully initialize skb to keep lower layers and queueing happy.
net/core/netpoll.c +4 -4
@@ -331,13 +331,13 @@memcpy (skb->data, msg, len); skb->len += len; - udph = (struct udphdr *)skb_push (skb,sizeof (*udph)); + skb->h.uh = udph = (struct udphdr *)skb_push (skb,sizeof (*udph)); udph->source =htons (np->local_port); udph->dest =htons (np->remote_port); udph->len =htons (udp_len); udph->check =0 ; - iph = (struct iphdr *)skb_push (skb,sizeof (*iph)); + skb->nh.iph = iph = (struct iphdr *)skb_push (skb,sizeof (*iph));/* iph->version = 4; iph->ihl = 5; */ put_unaligned (0x45 , (unsigned char *)iph);
@@ -353,8 +353,8 @@ iph->check =ip_fast_csum ((unsigned char *)iph, iph->ihl); eth = (struct ethhdr *)skb_push (skb,ETH_HLEN ); - - eth->h_proto =htons (ETH_P_IP ); + skb->mac.raw = skb->data; + skb->protocol = eth->h_proto =htons (ETH_P_IP );memcpy (eth->h_source, np->local_mac,6 );memcpy (eth->h_dest, np->remote_mac,6 );
--
Re: [PATCH 1/3] netpoll: initialize skb for UDP
From: Stephen Hemminger <[email protected]>
Date: Thu, 19 Oct 2006 10:15:42 -0700
Quoted 3 lines
Need to fully initialize skb to keep lower layers and queueing happy.
Signed-off-by Stephen Hemminger <[email protected]>
Applied, thanks Stephen.
PATCH 2/3 netpoll: rework skb transmit queue
In reply to Stephen HemmingerThe original skb management for netpoll was a mess, it had two queue paths and a callback. This changes it to have a per-instance transmit queue and use a tasklet rather than a work queue for the congested case.
--- drivers/net/netconsole.c | 1 include/linux/netpoll.h | 3 - net/core/netpoll.c | 123 +++++++++++++++-------------------------------- 3 files changed, 42 insertions(+), 85 deletions(-)
drivers/net/netconsole.c +0 -1
@@ -60,7 +60,6 @@ .local_port = 6665, .remote_port = 6666, .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, - .drop = netpoll_queue, };static int configured =0 ;
include/linux/netpoll.h +2 -1
@@ -27,11 +27,12 @@struct netpoll_info {spinlock_t poll_lock;int poll_owner; -int tries;int rx_flags;spinlock_t rx_lock;struct netpoll *rx_np;/* netpoll that registered an rx_hook */ struct sk_buff_head arp_tx;/* list of arp requests to reply to */ +struct sk_buff_head tx_q; +struct tasklet_struct tx_task; };void netpoll_poll (struct netpoll *np);
net/core/netpoll.c +40 -83
181 lines not on this page · raw message
--
David Miller
maintainerRe: [PATCH 2/3] netpoll: rework skb transmit queue
From: Stephen Hemminger <[email protected]>
Date: Thu, 19 Oct 2006 10:15:43 -0700
Quoted 5 lines
The original skb management for netpoll was a mess, it had two queue paths and a callback. This changes it to have a per-instance transmit queue and use a tasklet rather than a work queue for the congested case.
Signed-off-by Stephen Hemminger <[email protected]>
I think you mis-diffed this one:
- WARN_ON(skb->protocol == 0);
That line doesn't exist in my copy of net/core/netpoll.c even with your first patch applied.
Also, you forgot to remove the ->drop callback pointer from struct netpoll, which you should do if it really isn't used any more.
I think you might run into problems there, as I believe the netdump stuff does make non-trivial use of the ->drop callback. Indeed, it uses the ->dump callback for invoking a special netpoll_start_netdump() function. I'm pretty sure ->dump was created specifically to accomodate netdump.
So this is something else which will need to be worked out before we can apply this patch.
Re: [PATCH 2/3] netpoll: rework skb transmit queue
Quoted 20 lines · On Fri, 20 Oct 2006 00:15:30 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Thu, 19 Oct 2006 10:15:43 -0700Quoted 5 lines
The original skb management for netpoll was a mess, it had two queue paths and a callback. This changes it to have a per-instance transmit queue and use a tasklet rather than a work queue for the congested case.
Signed-off-by Stephen Hemminger <[email protected]>I think you mis-diffed this one:
net/core/netpoll.c +0
-1-WARN_ON (skb->protocol ==0 );That line doesn't exist in my copy of
net/core/netpoll.ceven with your first patch applied.Also, you forgot to remove the ->drop callback pointer from struct netpoll, which you should do if it really isn't used any more.
Quoted 6 lines
I think you might run into problems there, as I believe the netdump stuff does make non-trivial use of the ->drop callback. Indeed, it uses the ->dump callback for invoking a special
netpoll_start_netdump()function. I'm pretty sure ->dump was created specifically to accomodate netdump.
Netdump is not in the tree, so I can't fix it. Also netdump is pretty much superseded by kdump.
Quoted 2 lines
So this is something else which will need to be worked out before we can apply this patch.
David Miller
maintainerRe: [PATCH 2/3] netpoll: rework skb transmit queue
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 08:18:57 -0700
Quoted 2 lines
Netdump is not in the tree, so I can't fix it. Also netdump is pretty much superseded by kdump.
Unless kdump is %100 ready you can be sure vendors will ship netdump for a little while longer. I think gratuitously breaking netdump is not the best idea.
It's not like netdump is some binary blob you can't get the source to easily. :-)
Re: [PATCH 2/3] netpoll: rework skb transmit queue
Quoted 6 lines · On Fri, 20 Oct 2006 12:24:27 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 08:18:57 -0700Quoted 2 lines
Netdump is not in the tree, so I can't fix it. Also netdump is pretty much superseded by kdump.
Quoted 7 lines
Unless kdump is %100 ready you can be sure vendors will ship netdump for a little while longer. I think gratuitously breaking netdump is not the best idea.
It's not like netdump is some binary blob you can't get the source to easily. :-)
Sorry, but why should we treat out-of-tree vendor code any differently than out-of-tree other code.
David Miller
maintainerRe: [PATCH 2/3] netpoll: rework skb transmit queue
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 12:25:27 -0700
Quoted 2 lines
Sorry, but why should we treat out-of-tree vendor code any differently than out-of-tree other code.
I think what netdump was trying to do, provide a way to requeue instead of fully drop the SKB, is quite reasonable. Don't you think?
Re: [PATCH 2/3] netpoll: rework skb transmit queue
Quoted 9 lines · On Fri, 20 Oct 2006 12:52:26 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 12:25:27 -0700Quoted 2 lines
Sorry, but why should we treat out-of-tree vendor code any differently than out-of-tree other code.
I think what netdump was trying to do, provide a way to requeue instead of fully drop the SKB, is quite reasonable. Don't you think?
Yes, but the queued vs non-queued stuff showed up out of order. The queued messages go through the wrong Tx path. ie. they end up going into to NIT etc, since the deferred send uses a work queue it wouldn't work for last-gasp messages or netdump since getting a work queue to run requires going back to scheduler and processes running... and it should use skb_buff_head instead
of roll your own queueing.
The other alternative would be to make the send logic non-blocking and fully push retry to the caller.
I'll make a fix to netdump, if I can find it.
Signature · 1 line
Stephen Hemminger <[email protected]>
Re: [PATCH 2/3] netpoll: rework skb transmit queue
In reply to David MillerQuoted 9 lines · On Fri, 20 Oct 2006 12:52:26 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 12:25:27 -0700Quoted 2 lines
Sorry, but why should we treat out-of-tree vendor code any differently than out-of-tree other code.
I think what netdump was trying to do, provide a way to requeue instead of fully drop the SKB, is quite reasonable. Don't you think?
Netdump doesn't even exist in the current Fedora source rpm. I think Dave dropped it.
Re: [PATCH 2/3] netpoll: rework skb transmit queue
Quoted 9 lines · Stephen Hemminger
Quoted 6 lines · On Fri, 20 Oct 2006 12:52:26 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 12:25:27 -0700Quoted 2 lines
Sorry, but why should we treat out-of-tree vendor code any differently than out-of-tree other code.
Quoted 7 lines
Quoted 3 lines
I think what netdump was trying to do, provide a way to requeue instead of fully drop the SKB, is quite reasonable. Don't you think?
Netdump doesn't even exist in the current Fedora source rpm. I think Dave dropped it.
Indeed. Practically no-one cared about it, so it bit-rotted really fast after we shipped RHEL4. That, along with the focus shifting to making kdump work seemed to kill it off over the last 12 months.
Dave
Signature · 1 line
http://www.codemonkey.org.uk
David Miller
maintainerRe: [PATCH 2/3] netpoll: rework skb transmit queue
From: Dave Jones <[email protected]>
Date: Sat, 21 Oct 2006 01:00:16 -0400
Quoted 3 lines
Practically no-one cared about it, so it bit-rotted really fast after we shipped RHEL4. That, along with the focus shifting to making kdump work seemed to kill it off over the last 12 months.
Then we can truly kill off the ->drop() callback as part of Stephen's patches.
Stephen, I'll review your new set over the weekend.
PATCH 2/3 netpoll: rework skb transmit queue
In reply to David MillerChange netpoll to use a skb queue for transmit. This solves problems where there are two tx paths that can cause things to get out of order and different semantics when netconsole output goes through fast and slow paths.
The only user of the drop hook was netconsole, and I fixed that path. This probably breaks netdump, but that is out of tree, so it needs to fix itself.
--- drivers/net/netconsole.c | 1 include/linux/netpoll.h | 3 + net/core/netpoll.c | 109 ++++++++++++---------------------------------- 3 files changed, 31 insertions(+), 82 deletions(-)
drivers/net/netconsole.c +0 -1
@@ -60,7 +60,6 @@ static struct netpoll np = { .local_port = 6665, .remote_port = 6666, .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, - .drop = netpoll_queue, };static int configured =0 ;
include/linux/netpoll.h +2 -1
@@ -27,11 +27,12 @@ struct netpoll {struct netpoll_info {spinlock_t poll_lock;int poll_owner; -int tries;int rx_flags;spinlock_t rx_lock;struct netpoll *rx_np;/* netpoll that registered an rx_hook */ struct sk_buff_head arp_tx;/* list of arp requests to reply to */ +struct sk_buff_head tx_q; +struct tasklet_struct tx_task; };void netpoll_poll (struct netpoll *np);
net/core/netpoll.c +29 -80
158 lines not on this page · raw message
Signature · 1 line
1.4.2.4
David Miller
maintainerRe: [PATCH 2/3] netpoll: rework skb transmit queue
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 08:40:15 -0700
Quoted 3 lines
The only user of the drop hook was netconsole, and I fixed that path. This probably breaks netdump, but that is out of tree, so it needs to fix itself.
I believe that netdump needs to requeue things because dropping the packet is simply not allowed, and the ->drop callback gives the netdump code a way to handle things without actually dropping the packet. If that's true, you can't just free the SKB on it.
Are you sure your new TX strategy can avoid such drops properly?
Please take a quick peek at the netdump code, it's available, and make some reasonable effort to determine whether it can still work with your new code.
Re: [PATCH 2/3] netpoll: rework skb transmit queue
Quoted 7 lines · On Fri, 20 Oct 2006 12:27:53 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 08:40:15 -0700Quoted 3 lines
The only user of the drop hook was netconsole, and I fixed that path. This probably breaks netdump, but that is out of tree, so it needs to fix itself.
Quoted 6 lines
I believe that netdump needs to requeue things because dropping the packet is simply not allowed, and the ->drop callback gives the netdump code a way to handle things without actually dropping the packet. If that's true, you can't just free the SKB on it.
Are you sure your new TX strategy can avoid such drops properly?
Yes, it has a queue. if it can't send it waits and retries.
Quoted 4 lines
Please take a quick peek at the netdump code, it's available, and make some reasonable effort to determine whether it can still work with your new code.
Where, I'm not digging in side some RHEL rpm patch pile to find it.
Signature · 1 line
Stephen Hemminger <[email protected]>
David Miller
maintainerRe: [PATCH 2/3] netpoll: rework skb transmit queue
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 08:40:15 -0700
Quoted 3 lines
net/core/netpoll.c +1
-1-static void queue_process (void *p) +static void netpoll_run (unsigned long arg) {
...
net/core/netpoll.c #define MAX_SKB_SIZE \ · line 74
Quoted 9 lines
net/core/netpoll.c +8
-1-spin_unlock_irqrestore (&queue_lock, flags); +netif_tx_lock (dev); +if (netif_queue_stopped (dev) || + dev->hard_start_xmit (skb, dev) !=NETDEV_TX_OK ) { +skb_queue_head (&npinfo->tx_q, skb); +netif_tx_unlock (dev); +tasklet_schedule (&npinfo->tx_task); +return ; + }
We really can't handle TX stopped this way from the netpoll_send_skb() path. All that old retry logic in netpoll_send_skb() is really necessary.
If we are in deep IRQ context, took an OOPS, and are trying to get a netpoll packet out for the kernel log message, we have to try as hard as possible to get the packet out then and there, even if that means waiting some amount of time for netif_queue_stopped() to become false.
That is what the existing code is trying to do.
If you defer to a tasklet, the kernel state from the OOPS can be so corrupted that the tasklet will never run and we'll never get the netconsole message needed to debug the problem.
Also, if we tasklet schedule from the tasklet, we'll just keep looping in the tasklet and never leave softirq context, which is also bad behavior. Even in the tasklet, we should spin and poll when possible like the current netpoll_send_skb() code does.
So we really can't apply this patch.
Re: [PATCH 2/3] netpoll: rework skb transmit queue
Quoted 21 lines · On Fri, 20 Oct 2006 13:42:09 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 08:40:15 -0700Quoted 3 lines
net/core/netpoll.c +1
-1-static void queue_process (void *p) +static void netpoll_run (unsigned long arg) {...
net/core/netpoll.c #define MAX_SKB_SIZE \ · line 74
Quoted 9 lines
net/core/netpoll.c +8
-1-spin_unlock_irqrestore (&queue_lock, flags); +netif_tx_lock (dev); +if (netif_queue_stopped (dev) || + dev->hard_start_xmit (skb, dev) !=NETDEV_TX_OK ) { +skb_queue_head (&npinfo->tx_q, skb); +netif_tx_unlock (dev); +tasklet_schedule (&npinfo->tx_task); +return ; + }We really can't handle TX stopped this way from the
netpoll_send_skb()path. All that old retry logic innetpoll_send_skb()is really necessary.
Quoted 5 lines
If we are in deep IRQ context, took an OOPS, and are trying to get a netpoll packet out for the kernel log message, we have to try as hard as possible to get the packet out then and there, even if that means waiting some amount of time for
netif_queue_stopped()to become false.
But, it also violates the assumptions of the network devices. It calls NAPI poll back with IRQ's disabled and potentially doesn't obey the semantics about only running on the same CPU as the received packet.
Quoted 5 lines
That is what the existing code is trying to do.
If you defer to a tasklet, the kernel state from the OOPS can be so corrupted that the tasklet will never run and we'll never get the netconsole message needed to debug the problem.
So we can try once and if that fails we have to defer to tasklet. We can't call NAPI, we can't try and cleanup the device will need an IRQ to get unblocked.
Or add another device callback that just to handle that case.
Quoted 6 lines
Also, if we tasklet schedule from the tasklet, we'll just keep looping in the tasklet and never leave softirq context, which is also bad behavior. Even in the tasklet, we should spin and poll when possible like the current
netpoll_send_skb()code does.So we really can't apply this patch.
Signature · 1 line
Stephen Hemminger <[email protected]>
Re: [PATCH 2/3] netpoll: rework skb transmit queue
Quoted 5 lines
But, it also violates the assumptions of the network devices. It calls NAPI poll back with IRQ's disabled and potentially doesn't obey the semantics about only running on the same CPU as the received packet.
netpoll always played a little fast'n'lose with various locking rules. Also often inside the drivers are a little sloppy in the poll path.
That's fine for getting an oops out, but risky for normal kernel messages when the driver must be still working afterwards.
The standard console code makes this conditional on oops_in_progress - it breaks locks when true and otherwise it follows the safe approach.
Perhaps it would be better to use different paths in netconsole too depending on whether oops_in_progress is true or not.
e.g. if !oops_in_progress (use the standard output path) else use current path.
That would avoid breaking the driver during normal operation and also have the advantage that the normal netconsole messages would go through the queueing disciplines etc.
-Andi
David Miller
maintainerRe: [PATCH 2/3] netpoll: rework skb transmit queue
From: Andi Kleen <[email protected]>
Date: Fri, 20 Oct 2006 23:01:29 +0200
Quoted 1 line
netpoll always played a little fast'n'lose with various locking rules.
The current code is fine, it never reenters ->poll, because it maintains a "->poll_owner" which it checks in netpoll_send_skb() before trying to call back into ->poll.
Every call to ->poll first sets ->poll_owner to the current cpu id. netpoll_send_skb() aborts and does a drop if ->poll_owner is set to the current smp_processor_id().
I sometimes feel like I'm the only person actually reading the sources and past threads on this topic before replying.
Re: [PATCH 2/3] netpoll: rework skb transmit queue
Quoted 8 lines · David Miller
From: Andi Kleen <[email protected]>
Date: Fri, 20 Oct 2006 23:01:29 +0200Quoted 1 line
netpoll always played a little fast'n'lose with various locking rules.
The current code is fine, it never reenters ->poll, because it maintains a "->poll_owner" which it checks in
netpoll_send_skb()before trying to call back into ->poll.
I was more thinking of reentry of the interrupt handler in the driver etc. A lot of them also do printk, but that is fortunately caught higher level.
-Andi
Re: [PATCH 2/3] netpoll: rework skb transmit queue
Quoted 10 lines · On Fri, 20 Oct 2006 23:16:03 +0200 Andi Kleen <[email protected]> wrote:
Quoted 8 lines · David Miller
From: Andi Kleen <[email protected]>
Date: Fri, 20 Oct 2006 23:01:29 +0200Quoted 1 line
netpoll always played a little fast'n'lose with various locking rules.
The current code is fine, it never reenters ->poll, because it maintains a "->poll_owner" which it checks in
netpoll_send_skb()before trying to call back into ->poll.
Quoted 5 lines
I was more thinking of reentry of the interrupt handler in the driver etc. A lot of them also do printk, but that is fortunately caught higher level.
-Andi
One problem is that with netconsole the NAPI poll routine can be called with IRQ's disabled. This means that calls to dev_kfree_skb() are incorrect in this context. The driver would have to use dev_kfree_skb_any() instead.
David Miller
maintainerRe: [PATCH 2/3] netpoll: rework skb transmit queue
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 13:48:26 -0700
Quoted 12 lines
Quoted 8 lines · On Fri, 20 Oct 2006 13:42:09 -0700 (PDT) David Miller <[email protected]>…
We really can't handle TX stopped this way from the
netpoll_send_skb()path. All that old retry logic innetpoll_send_skb()is really necessary.If we are in deep IRQ context, took an OOPS, and are trying to get a netpoll packet out for the kernel log message, we have to try as hard as possible to get the packet out then and there, even if that means waiting some amount of time for
netif_queue_stopped()to become false.
Quoted 4 lines
But, it also violates the assumptions of the network devices. It calls NAPI poll back with IRQ's disabled and potentially doesn't obey the semantics about only running on the same CPU as the received packet.
Actually, all the locking here is fine, that's why it checks poll_owner for current smp_processor_id().
Otherwise it is safe to sit and spin waiting for link up/down or TX full conditions to pass.
Quoted 1 line
So we can try once and if that fails we have to defer to tasklet.
Not true, we should spin and retry for some reasonable amount of time. That "reasonable amount of time" should be the maximum of the time it takes to free up space from a TX full condition and the time it takes to bring the link up.
That is what the current code is trying to do, and you've erroneously deleted all of that logic.
PATCH 1/3 netpoll: use sk_buff_head for txq
This is similar in spirit to earlier patches with less changes. Get rid of DIY queue for skb's used in netpoll. Add missing code to cleanup queue on shutdown.
net/core/netpoll.c +20 -38
@@ -37,10 +37,7 @@#define MAX_RETRIES 20000static struct sk_buff_head netpoll_pool; - -static DEFINE_SPINLOCK (queue_lock); -static int queue_depth; -static struct sk_buff *queue_head, *queue_tail; +static struct sk_buff_head netpoll_txq;static atomic_t trapped;
@@ -56,44 +53,18 @@ static void arp_reply(struct sk_buff *skstatic void queue_process (void *p) { -unsigned long flags;struct sk_buff *skb; -while (queue_head) { -spin_lock_irqsave (&queue_lock, flags); - - skb = queue_head; - queue_head = skb->next; -if (skb == queue_tail) - queue_head =NULL ; - - queue_depth--; - -spin_unlock_irqrestore (&queue_lock, flags); - +while ((skb =skb_dequeue (&netpoll_txq)))dev_queue_xmit (skb); - } + } static DECLARE_WORK(send_queue, queue_process, NULL);void netpoll_queue (struct sk_buff *skb) { -unsigned long flags; - -if (queue_depth ==MAX_QUEUE_DEPTH ) { -__kfree_skb (skb); -return ; - } - -spin_lock_irqsave (&queue_lock, flags); -if (!queue_head) - queue_head = skb; -else - queue_tail->next = skb; - queue_tail = skb; - queue_depth++; -spin_unlock_irqrestore (&queue_lock, flags); +skb_queue_tail (&netpoll_txq, skb);schedule_work (&send_queue); }
@@ -745,6 +716,7 @@ int netpoll_setup(struct netpoll *np) }static int __init netpoll_init (void ) { +skb_queue_head_init (&netpoll_txq);skb_queue_head_init (&netpoll_pool);return 0 ; }
@@ -752,20 +724,30 @@ core_initcall(netpoll_init);void netpoll_cleanup (struct netpoll *np) { -struct netpoll_info *npinfo; +struct net_device *dev = np->dev; +struct sk_buff *skb, *next;unsigned long flags; -if (np->dev) { - npinfo = np->dev->npinfo; +if (dev) { +struct netpoll_info *npinfo = dev->npinfo; +if (npinfo && npinfo->rx_np == np) {spin_lock_irqsave (&npinfo->rx_lock, flags); npinfo->rx_np =NULL ; npinfo->rx_flags &= ~NETPOLL_RX_ENABLED ;spin_unlock_irqrestore (&npinfo->rx_lock, flags); } -dev_put (np->dev); +dev_put (dev); + +spin_lock_irqsave (&netpoll_txq.lock, flags); +for (skb = (struct sk_buff *)netpoll_txq.next; + skb != (struct sk_buff *)&netpoll_txq; skb = next) { + next = skb->next; +if (skb->dev == dev) +skb_unlink (skb, &netpoll_txq); + } +spin_unlock_irqrestore (&netpoll_txq.lock, flags); } - np->dev =NULL ; }
David Miller
maintainerRe: [PATCH 1/3] netpoll: use sk_buff_head for txq
From: Stephen Hemminger <[email protected]>
Date: Fri, 20 Oct 2006 15:30:27 -0700
net/core/netpoll.c core_initcall(netpoll_init); · line 750
Quoted 9 lines
net/core/netpoll.c +8
-0+spin_lock_irqsave (&netpoll_txq.lock, flags); +for (skb = (struct sk_buff *)netpoll_txq.next; + skb != (struct sk_buff *)&netpoll_txq; skb = next) { + next = skb->next; +if (skb->dev == dev) +skb_unlink (skb, &netpoll_txq); + } +spin_unlock_irqrestore (&netpoll_txq.lock, flags); }
All SKBs removed here will be leaked, nothing frees them up.
Since #2 and #3 depend upon this patch, I'll hold off on those until you fix this bug.
Thanks.
PATCH 1/5 netpoll: use sk_buff_head for txq
This is the 3rd version of the netpoll patches. The first patch switches from open-coded skb list to using a skb_buff_head. It also flushes packets from queue when device is removed from netpoll.
net/core/netpoll.c +26 -35
@@ -37,10 +37,7 @@#define MAX_RETRIES 20000static struct sk_buff_head netpoll_pool; - -static DEFINE_SPINLOCK (queue_lock); -static int queue_depth; -static struct sk_buff *queue_head, *queue_tail; +static struct sk_buff_head netpoll_txq;static atomic_t trapped;
@@ -56,44 +53,35 @@ static void arp_reply(struct sk_buff *skstatic void queue_process (void *p) { -unsigned long flags;struct sk_buff *skb; -while (queue_head) { -spin_lock_irqsave (&queue_lock, flags); - - skb = queue_head; - queue_head = skb->next; -if (skb == queue_tail) - queue_head =NULL ; +while ((skb =skb_dequeue (&netpoll_txq))) +dev_queue_xmit (skb); - queue_depth--; +} -spin_unlock_irqrestore (&queue_lock, flags); +static void queue_purge (struct net_device *dev) +{ +struct sk_buff *skb, *next; +unsigned long flags; -dev_queue_xmit (skb); +spin_lock_irqsave (&netpoll_txq.lock, flags); +for (skb = (struct sk_buff *)netpoll_txq.next; + skb != (struct sk_buff *)&netpoll_txq; skb = next) { + next = skb->next; +if (skb->dev == dev) { +skb_unlink (skb, &netpoll_txq); +kfree_skb (skb); + } } +spin_unlock_irqrestore (&netpoll_txq.lock, flags); } static DECLARE_WORK(send_queue, queue_process, NULL);void netpoll_queue (struct sk_buff *skb) { -unsigned long flags; - -if (queue_depth ==MAX_QUEUE_DEPTH ) { -__kfree_skb (skb); -return ; - } - -spin_lock_irqsave (&queue_lock, flags); -if (!queue_head) - queue_head = skb; -else - queue_tail->next = skb; - queue_tail = skb; - queue_depth++; -spin_unlock_irqrestore (&queue_lock, flags); +skb_queue_tail (&netpoll_txq, skb);schedule_work (&send_queue); }
@@ -745,6 +733,7 @@ int netpoll_setup(struct netpoll *np) }static int __init netpoll_init (void ) { +skb_queue_head_init (&netpoll_txq);skb_queue_head_init (&netpoll_pool);return 0 ; }
@@ -752,20 +741,22 @@ core_initcall(netpoll_init);void netpoll_cleanup (struct netpoll *np) { -struct netpoll_info *npinfo; +struct net_device *dev = np->dev;unsigned long flags; -if (np->dev) { - npinfo = np->dev->npinfo; +if (dev) { +struct netpoll_info *npinfo = dev->npinfo; +if (npinfo && npinfo->rx_np == np) {spin_lock_irqsave (&npinfo->rx_lock, flags); npinfo->rx_np =NULL ; npinfo->rx_flags &= ~NETPOLL_RX_ENABLED ;spin_unlock_irqrestore (&npinfo->rx_lock, flags); } -dev_put (np->dev); - } +dev_put (dev); +queue_purge (dev); + } np->dev =NULL ; }
PATCH 5/5 netpoll: interface cleanup
Trivial cleanup of netpoll interface. Use constants for size, to make usage clear.
include/linux/netpoll.h +3 -4
@@ -12,15 +12,14 @@#include <linux/rcupdate.h> #include <linux/list.h> -struct netpoll ; -struct netpoll {struct net_device *dev; -char dev_name[16 ], *name; +char dev_name[IFNAMSIZ ]; +const char *name;void (*rx_hook)(struct netpoll *,int ,char *,int );u32 local_ip, remote_ip;u16 local_port, remote_port; -unsigned char local_mac[6 ], remote_mac[6 ]; +u8 local_mac[ETH_ALEN ], remote_mac[ETH_ALEN ]; };struct netpoll_info {
David Miller
maintainerRe: [PATCH 1/5] netpoll: use sk_buff_head for txq
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
Date: Mon, 23 Oct 2006 12:02:53 -0700
net/core/netpoll.c static void arp_reply(struct sk_buff *sk · line 77
Quoted 10 lines
net/core/netpoll.c +9
-0+spin_lock_irqsave (&netpoll_txq.lock, flags); +for (skb = (struct sk_buff *)netpoll_txq.next; + skb != (struct sk_buff *)&netpoll_txq; skb = next) { + next = skb->next; +if (skb->dev == dev) { +skb_unlink (skb, &netpoll_txq); +kfree_skb (skb); + } } +spin_unlock_irqrestore (&netpoll_txq.lock, flags);
IRQ's are disabled, I think we can't call kfree_skb() in such a context.
That's why zap_completion_queue() has all of these funny skb->destructor checks and such, all of this stuff potentially runs in IRQ context.
Re: [PATCH 1/5] netpoll: use sk_buff_head for txq
Quoted 16 lines · On Mon, 23 Oct 2006 23:03:50 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Mon, 23 Oct 2006 12:02:53 -0700net/core/netpoll.c static void arp_reply(struct sk_buff *sk · line 77
Quoted 10 lines
net/core/netpoll.c +9
-0+spin_lock_irqsave (&netpoll_txq.lock, flags); +for (skb = (struct sk_buff *)netpoll_txq.next; + skb != (struct sk_buff *)&netpoll_txq; skb = next) { + next = skb->next; +if (skb->dev == dev) { +skb_unlink (skb, &netpoll_txq); +kfree_skb (skb); + } } +spin_unlock_irqrestore (&netpoll_txq.lock, flags);IRQ's are disabled, I think we can't call
kfree_skb()in such a context.
It is save since the skb's only come from this code (no destructors).
Quoted 4 lines
That's why
zap_completion_queue()has all of these funnyskb->destructorchecks and such, all of this stuff potentially runs in IRQ context.
It should use __kfree_skb in the purge routine (like other places).
Re: [PATCH 1/5] netpoll: use sk_buff_head for txq
Quoted 20 lines · On Tue, 24 Oct 2006 07:51:30 -0700 Stephen Hemminger <[email protected]>…
Quoted 16 lines · On Mon, 23 Oct 2006 23:03:50 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Mon, 23 Oct 2006 12:02:53 -0700net/core/netpoll.c static void arp_reply(struct sk_buff *sk · line 77
Quoted 10 lines
net/core/netpoll.c +9
-0+spin_lock_irqsave (&netpoll_txq.lock, flags); +for (skb = (struct sk_buff *)netpoll_txq.next; + skb != (struct sk_buff *)&netpoll_txq; skb = next) { + next = skb->next; +if (skb->dev == dev) { +skb_unlink (skb, &netpoll_txq); +kfree_skb (skb); + } } +spin_unlock_irqrestore (&netpoll_txq.lock, flags);IRQ's are disabled, I think we can't call
kfree_skb()in such a context.
Quoted 2 lines
It is save since the skb's only come from this code (no destructors).
Actually it does use destructors... I am doing a better version (per-device).
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 2/5 netpoll: cleanup queued transmit
This patch changes the queued transmit path of netpoll, to use similar logic to the non-queued path. We don't want netpoll messages going into NIT and network qdisc logic.
net/core/netpoll.c +16 -4
@@ -51,13 +51,27 @@ static atomic_t trapped;static void zap_completion_queue (void );static void arp_reply (struct sk_buff *skb); +static void queue_process (void *); +static DECLARE_WORK(send_queue, queue_process, NULL); +static void queue_process (void *p) {struct sk_buff *skb; -while ((skb =skb_dequeue (&netpoll_txq))) -dev_queue_xmit (skb); +while ((skb =skb_dequeue (&netpoll_txq))) { +struct net_device *dev = skb->dev; +netif_tx_lock_bh (dev); +if (netif_queue_stopped (dev) || + dev->hard_start_xmit (skb, dev) !=NETDEV_TX_OK ) { +skb_queue_head (&netpoll_txq, skb); +netif_tx_unlock_bh (dev); + +schedule_delayed_work (&send_queue,1 ); +return ; + } +netif_tx_unlock_bh (dev); + } }static void queue_purge (struct net_device *dev)
@@ -77,8 +91,6 @@ static void queue_purge(struct net_devicspin_unlock_irqrestore (&netpoll_txq.lock, flags); } -static DECLARE_WORK(send_queue, queue_process, NULL); -void netpoll_queue (struct sk_buff *skb) {skb_queue_tail (&netpoll_txq, skb);
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 3/5 netpoll: cleanup transmit retry logic
Change netpoll transmit logic so:
* retries are per attempt not global. don't want to start drop packets just because of temporary blockage.
* acquire xmit_lock correctly
* if device is not available just drop
* always queue if send fails, don't drop
include/linux/netpoll.h +0 -1
@@ -27,7 +27,6 @@ struct netpoll {struct netpoll_info {spinlock_t poll_lock;int poll_owner; -int tries;int rx_flags;spinlock_t rx_lock;struct netpoll *rx_np;/* netpoll that registered an rx_hook */
net/core/netpoll.c +28 -36
85 lines not on this page · raw message
PATCH 4/5 netpoll: move drop hook inline
In reply to a message not in the archiveRather than have separate drop callback hook, just put the logic inline in netpoll. The code is cleaner and netconsole is the only user of netpoll.
drivers/net/netconsole.c +0 -1
@@ -60,7 +60,6 @@ static struct netpoll np = { .local_port = 6665, .remote_port = 6666, .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, - .drop = netpoll_queue, };static int configured =0 ;
include/linux/netpoll.h +0 -1
@@ -18,7 +18,6 @@ struct netpoll {struct net_device *dev;char dev_name[16 ], *name;void (*rx_hook)(struct netpoll *,int ,char *,int ); -void (*drop)(struct sk_buff *skb);u32 local_ip, remote_ip;u16 local_port, remote_port;unsigned char local_mac[6 ], remote_mac[6 ];
net/core/netpoll.c +4 -12
@@ -91,13 +91,6 @@ static void queue_purge(struct net_devicspin_unlock_irqrestore (&netpoll_txq.lock, flags); } -void netpoll_queue (struct sk_buff *skb) -{ -skb_queue_tail (&netpoll_txq, skb); - -schedule_work (&send_queue); -} -static int checksum_udp (struct sk_buff *skb,struct udphdr *uh,unsigned short ulen,u32 saddr,u32 daddr) {
@@ -282,10 +275,10 @@ static void netpoll_send_skb(struct netpudelay (50 ); }while (--tries >0 ); -if (np->drop) - np->drop (skb); -else -__kfree_skb (skb); +/* if transmitter is busy, try send later. */ +skb_queue_tail (&netpoll_txq, skb); + +schedule_work (&send_queue); }void netpoll_send_udp (struct netpoll *np,const char *msg,int len)
@@ -784,4 +777,3 @@ EXPORT_SYMBOL(netpoll_setup);EXPORT_SYMBOL (netpoll_cleanup);EXPORT_SYMBOL (netpoll_send_udp);EXPORT_SYMBOL (netpoll_poll); -EXPORT_SYMBOL (netpoll_queue);
PATCH 2/3 netpoll: use device xmit directly
In reply to David MillerFor most normal sends, the netpoll code was using the dev->hard_start_xmit directly. If it got busy, it would process later, but this code path uses dev_queue_xmit() and that code would send the skb through NIT and other stuff that netpoll doesn't want.
net/core/netpoll.c +15 -4
@@ -51,17 +51,28 @@ static atomic_t trapped;static void zap_completion_queue (void );static void arp_reply (struct sk_buff *skb); +static void queue_process (void *); +static DECLARE_WORK(send_queue, queue_process, NULL); +static void queue_process (void *p) {struct sk_buff *skb; -while ((skb =skb_dequeue (&netpoll_txq))) -dev_queue_xmit (skb); +while ((skb =skb_dequeue (&netpoll_txq))) { +struct net_device *dev = skb->dev; +netif_tx_lock_bh (dev); +if (netif_queue_stopped (dev) || + dev->hard_start_xmit (skb, dev) !=NETDEV_TX_OK ) { +skb_queue_head (&netpoll_txq, skb); +netif_tx_unlock_bh (dev); +schedule_delayed_work (&send_queue,1 ); +break ; + } +netif_tx_unlock_bh (dev); + } } -static DECLARE_WORK(send_queue, queue_process, NULL); -void netpoll_queue (struct sk_buff *skb) {skb_queue_tail (&netpoll_txq, skb);
PATCH 3/3 netpoll: retry logic cleanup
In reply to David MillerChange retry logic of netpoll. Always requeue if unable to send instead of dropping. Make retry counter per send rather than causing mass migration when tries gets less than zero. Since callers are either netpoll_send_arp or netpoll_send_udp, we knwo that np and np->dev can't be null.
include/linux/netpoll.h +0 -1
@@ -27,7 +27,6 @@ struct netpoll {struct netpoll_info {spinlock_t poll_lock;int poll_owner; -int tries;int rx_flags;spinlock_t rx_lock;struct netpoll *rx_np;/* netpoll that registered an rx_hook */
net/core/netpoll.c +22 -29
79 lines not on this page · raw message
PATCH 3/3 netpoll: use skb_buff_head for skb cache
In reply to Stephen HemmingerThe private skb cache should be managed with normal skb_buff_head rather than a DIY queue. If pool is exhausted, don't print anything that just makes the problem worse. After a number of attempts, punt and drop the message (callers handle it already).
--- net/core/netpoll.c | 55 +++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 33 deletions(-)
net/core/netpoll.c +22 -33
@@ -36,9 +36,7 @@#define MAX_QUEUE_DEPTH (MAX_SKBS / 2)#define MAX_RETRIES 20000 -static DEFINE_SPINLOCK (skb_list_lock); -static int nr_skbs; -static struct sk_buff *skbs; +static struct sk_buff_head skb_list;static atomic_t trapped;
@@ -51,6 +49,7 @@static void zap_completion_queue (void );static void arp_reply (struct sk_buff *skb); +static void refill_skbs (void );static void netpoll_run (unsigned long arg) {
@@ -79,6 +78,7 @@break ; } } +refill_skbs (); } static int checksum_udp(struct sk_buff *skb, struct udphdr *uh,
@@ -169,19 +169,14 @@static void refill_skbs (void ) {struct sk_buff *skb; -unsigned long flags; -spin_lock_irqsave (&skb_list_lock, flags); -while (nr_skbs <MAX_SKBS ) { +while (skb_queue_len (&skb_list) <MAX_SKBS ) { skb =alloc_skb (MAX_SKB_SIZE ,GFP_ATOMIC );if (!skb)break ; - skb->next = skbs; - skbs = skb; - nr_skbs++; +skb_queue_tail (&skb_list, skb); } -spin_unlock_irqrestore (&skb_list_lock, flags); }static void zap_completion_queue (void )
@@ -210,37 +205,24 @@put_cpu_var (softnet_data); } -static struct sk_buff *find_skb (struct netpoll *np,int len,int reserve) +static struct sk_buff *find_skb (struct netpoll *np,int len,int reserve) { -int once =1 , count =0 ; -unsigned long flags; -struct sk_buff *skb =NULL ; +struct sk_buff *skb; +int tries =0 ;zap_completion_queue (); -repeat: -if (nr_skbs <MAX_SKBS ) -refill_skbs (); +repeat: skb =alloc_skb (len,GFP_ATOMIC ); - -if (!skb) { -spin_lock_irqsave (&skb_list_lock, flags); - skb = skbs; -if (skb) { - skbs = skb->next; - skb->next =NULL ; - nr_skbs--; - } -spin_unlock_irqrestore (&skb_list_lock, flags); - } +if (!skb) + skb =skb_dequeue (&skb_list);if (!skb) { - count++; -if (once && (count ==1000000 )) { -printk ("out of netpoll skbs!\n" ); - once =0 ; - } +if (++tries >MAX_RETRIES ) +return NULL ; +netpoll_poll (np); +tasklet_schedule (&np->dev->npinfo->tx_task); goto repeat; }
@@ -589,6 +571,13 @@return -1 ; } +static __init int netpoll_init (void ) +{ +skb_queue_head_init (&skb_list); +return 0 ; +} +core_initcall (netpoll_init); +int netpoll_setup (struct netpoll *np) {struct net_device *ndev =NULL ;
--
Quoted 3 lines · On Thu, 19 Oct 2006 10:15:41 -0700 Stephen Hemminger <[email protected]>…
The netpoll transmit skb management is a mess, it has two paths and it's on Txq. These patches try and clean this up.
I got a reject storm when applying the third patch then screwed it up rather than fixing it up.
A rediff and resend is needed, please. Make sure it's against the latest -linus or -davem, thanks.
David Miller
maintainerFrom: Andrew Morton <[email protected]>
Date: Thu, 19 Oct 2006 23:57:19 -0700
Quoted 5 lines
I got a reject storm when applying the third patch then screwed it up rather than fixing it up.
A rediff and resend is needed, please. Make sure it's against the latest -linus or -davem, thanks.
And I got rejects on #2 :-)
His first patch is in my net-2.6 tree as of a few minutes ago, that one was fine.