gianfar: Some fixes
Subsystems (2)
cover gianfar: Some fixes
Hi all,
Here are some fixes for the gianfar driver, patches on the way.
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
PATCH 1/6 skbuff: Do not allow skb recycling with disabled IRQs
NAPI drivers try to recycle SKBs in their polling routine, but we generally don't know the context in which the polling will be called, and the skb recycling itself may require IRQs to be enabled.
This patch adds irqs_disabled() test to the skb_recycle_check() routine, so that we'll not let the drivers hit the skb recycling path with IRQs disabled.
As a side effect, this patch actually disables skb recycling for some [broken] drivers. E.g. gianfar driver grabs an irqsave spinlock during TX ring processing, and then tries to recycle an skb, and that caused the following badness:
nf_conntrack version 0.5.0 (1008 buckets, 4032 max)
------------[ cut here ]------------ Badness at kernel/softirq.c:143 NIP: c003e3c4 LR: c423a528 CTR: c003e344 ... NIP [c003e3c4] local_bh_enable+0x80/0xc4 LR [c423a528] destroy_conntrack+0xd4/0x13c [nf_conntrack] Call Trace: [c15d1b60] [c003e32c] local_bh_disable+0x1c/0x34 (unreliable) [c15d1b70] [c423a528] destroy_conntrack+0xd4/0x13c [nf_conntrack] [c15d1b80] [c02c6370] nf_conntrack_destroy+0x3c/0x70
--- Exception: c428168c at 0xc15d1c50
LR = 0xc15d1c40
[c15d1ba0] [c0286f3c] skb_release_head_state+0x100/0x104 (unreliable) [c15d1bb0] [c0288340] skb_recycle_check+0x8c/0x10c [c15d1bc0] [c01e1688] gfar_poll+0x190/0x384
[c15d1c10] [c02935ac] net_rx_action+0xec/0x22c
[c15d1c50] [c003dd8c] __do_softirq+0xe8/0x224
...
--- net/core/skbuff.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
net/core/skbuff.c +3 -0
@@ -493,6 +493,9 @@ int skb_recycle_check(struct sk_buff *skb, int skb_size) {struct skb_shared_info *shinfo; +if (irqs_disabled ()) +return 0 ; +if (skb_is_nonlinear (skb) || skb->fclone !=SKB_FCLONE_UNAVAILABLE )return 0 ;
Signature · 1 line
1.6.3.3
PATCH 2/6 gianfar: Remove 'Interrupt problem!' warning
In reply to Anton VorontsovIt is OK to poll with disabled IRQs, so remove the warning.
--- drivers/net/gianfar.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/net/gianfar.c +0 -2
@@ -2504,8 +2504,6 @@ int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit)skb_put (skb, pkt_len); dev->stats.rx_bytes += pkt_len; -if (in_irq () ||irqs_disabled ()) -printk ("Interrupt problem!\n" );gfar_process_frame (dev, skb, amount_pull); }else {
Signature · 1 line
1.6.3.3
PATCH 3/6 gianfar: Fix build with CONFIG_PM=y
In reply to Anton Vorontsovcommit fba4ed030cfae7efdb6b79a57b0c5a9d72c9 ("gianfar: Add Multiple Queue Support") introduced the following build failure:
CC gianfar.ogianfar.c: In function 'gfar_restore':
gianfar.c:1249: error: request for member 'napi' in something not a structure or union
This patch fixes the issue.
--- drivers/net/gianfar.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/gianfar.c +1 -1
@@ -1246,7 +1246,7 @@ static int gfar_restore(struct device *dev)phy_start (priv->phydev);netif_device_attach (ndev); -napi_enable (&priv->gfargrp.napi); +enable_napi (priv);return 0 ; }
Signature · 1 line
1.6.3.3
PATCH 4/6 gianfar: Fix thinko in gfar_set_rx_stash_index()
In reply to Anton VorontsovWe obviously want to write a modified 'temp' value back to the register, not the saved IRQ flags.
--- drivers/net/gianfar_sysfs.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/gianfar_sysfs.c +1 -1
@@ -186,7 +186,7 @@ static ssize_t gfar_set_rx_stash_index(struct device *dev, temp =gfar_read (®s->attreli); temp &= ~ATTRELI_EI_MASK ; temp |=ATTRELI_EI (index); -gfar_write (®s->attreli, flags); +gfar_write (®s->attreli, temp); out:unlock_rx_qs (priv);
Signature · 1 line
1.6.3.3
PATCH 5/6 gianfar: Fix race between gfar_error() and gfar_start_xmit()
In reply to Anton Vorontsovgfar_error() can arrive at the middle of gfar_start_xmit() processing, and so it can trigger transfers of BDs that we don't yet expect to be transmitted.
Fix this by locking the tx queues in gfar_error().
--- drivers/net/gianfar.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/net/gianfar.c +8 -0
@@ -2943,14 +2943,22 @@ static irqreturn_t gfar_error(int irq, void *grp_id)if (events &IEVENT_CRL ) dev->stats.tx_aborted_errors++;if (events &IEVENT_XFUN ) { +unsigned long flags; +if (netif_msg_tx_err (priv))printk (KERN_DEBUG "%s: TX FIFO underrun, " "packet dropped.\n" , dev->name); dev->stats.tx_dropped++; priv->extra_stats.tx_underrun++; +local_irq_save (flags); +lock_tx_qs (priv); +/* Reactivate the Tx Queues */ gfar_write (®s->tstat, gfargrp->tstat); + +unlock_tx_qs (priv); +local_irq_restore (flags); }if (netif_msg_tx_err (priv))printk (KERN_DEBUG "%s: Transmit Error\n" , dev->name);
Signature · 1 line
1.6.3.3
PATCH 6/6 gianfar: Revive SKB recycling
In reply to Anton VorontsovBefore calling gfar_clean_tx_ring() the driver grabs an irqsave spinlock, and then tries to recycle skbs. But since skb_recycle_check() returns 0 with IRQs disabled, we'll never recycle any skbs.
It appears that gfar_clean_tx_ring() and gfar_start_xmit() are mostly idependent and can work in parallel, except when they modify num_txbdfree.
So we can drop the lock from most sections and thus fix the skb recycling.
--- drivers/net/gianfar.c | 31 +++++++++++++++++++------------ 1 files changed, 19 insertions(+), 12 deletions(-)
drivers/net/gianfar.c +19 -12
@@ -1928,14 +1928,11 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)/* total number of fragments in the SKB */ nr_frags =skb_shinfo (skb)->nr_frags; -spin_lock_irqsave (&tx_queue->txlock, flags); -/* check if there is space to queue this packet */ if ((nr_frags+1 ) > tx_queue->num_txbdfree) {/* no space, stop the queue */ netif_tx_stop_queue (txq); dev->stats.tx_fifo_errors++; -spin_unlock_irqrestore (&tx_queue->txlock, flags);return NETDEV_TX_BUSY ; }
@@ -1999,6 +1996,20 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev) lstatus |=BD_LFLAG (TXBD_CRC |TXBD_READY ) |skb_headlen (skb);/* +* We can work in parallel with gfar_clean_tx_ring(), except +* when modifying num_txbdfree. Note that we didn't grab the lock +* when we were reading the num_txbdfree and checking for available +* space, that's because outside of this function it can only grow, +* and once we've got needed space, it cannot suddenly disappear. +* +* The lock also protects us from gfar_error(), which can modify +* regs->tstat and thus retrigger the transfers, which is why we +* also must grab the lock before setting ready bit for the first +* to be transmitted BD. +*/ +spin_lock_irqsave (&tx_queue->txlock, flags); + +/* * The powerpc-specific eieio() is used, as wmb() has too strong * semantics (it requires synchronization between cacheable and * uncacheable mappings, which eieio doesn't provide and which we
@@ -2225,6 +2236,8 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue) skb_dirtytx = tx_queue->skb_dirtytx;while ((skb = tx_queue->tx_skbuff[skb_dirtytx])) { +unsigned long flags; + frags =skb_shinfo (skb)->nr_frags; lbdp =skip_txbd (bdp, frags, base, tx_ring_size);
@@ -2269,7 +2282,9 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)TX_RING_MOD_MASK (tx_ring_size); howmany++; +spin_lock_irqsave (&tx_queue->txlock, flags); tx_queue->num_txbdfree += frags +1 ; +spin_unlock_irqrestore (&tx_queue->txlock, flags); }/* If we freed a buffer, we can restart transmission, if necessary */
@@ -2548,7 +2563,6 @@ static int gfar_poll(struct napi_struct *napi, int budget)int tx_cleaned =0 , i, left_over_budget = budget;unsigned long serviced_queues =0 ;int num_queues =0 ; -unsigned long flags; num_queues = gfargrp->num_rx_queues; budget_per_queue = budget/num_queues;
@@ -2568,14 +2582,7 @@ static int gfar_poll(struct napi_struct *napi, int budget) rx_queue = priv->rx_queue[i]; tx_queue = priv->tx_queue[rx_queue->qindex]; -/* If we fail to get the lock, -* don't bother with the TX BDs */ -if (spin_trylock_irqsave (&tx_queue->txlock, flags)) { - tx_cleaned +=gfar_clean_tx_ring (tx_queue); -spin_unlock_irqrestore (&tx_queue->txlock, - flags); - } - + tx_cleaned +=gfar_clean_tx_ring (tx_queue); rx_cleaned_per_queue =gfar_clean_rx_ring (rx_queue, budget_per_queue); rx_cleaned += rx_cleaned_per_queue;
Signature · 1 line
1.6.3.3
RE: [PATCH 6/6] gianfar: Revive SKB recycling
Quoted 125 lines
-----Original Message-----
From: Anton Vorontsov [mailto:[email protected]]
Sent: Wednesday, November 11, 2009 5:41 AM
To: David Miller
Cc: Fleming Andy-AFLEMING; Jon Loeliger; Kumar Gopalpet-B05799; Lennert Buytenhek; Stephen Hemminger; [email protected]; [email protected]
Subject: [PATCH 6/6] gianfar: Revive SKB recyclingBefore calling
gfar_clean_tx_ring()the driver grabs an irqsave spinlock, and then tries to recycle skbs. But sinceskb_recycle_check()returns 0 with IRQs disabled, we'll never recycle any skbs.It appears that
gfar_clean_tx_ring()andgfar_start_xmit()are mostly idependent and can work in parallel, except when they modifynum_txbdfree.So we can drop the lock from most sections and thus fix the skb recycling.
Signed-off-by Anton Vorontsov <[email protected]>---
drivers/net/gianfar.c| 31 +++++++++++++++++++------------1 files changed, 19 insertions(+), 12 deletions(-)drivers/net/gianfar.c +2
-3@@ -1928,14 +1928,11 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)/* total number of fragments in the SKB */ nr_frags =skb_shinfo (skb)->nr_frags; -spin_lock_irqsave (&tx_queue->txlock, flags); -/* check if there is space to queue this packet */ if ((nr_frags+1 ) > tx_queue->num_txbdfree) {/* no space, stop the queue */ netif_tx_stop_queue (txq); dev->stats.tx_fifo_errors++; -spin_unlock_irqrestore (&tx_queue->txlock, flags);return NETDEV_TX_BUSY ; }@@ -1999,6 +1996,20 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev) lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);/* +* We can work in parallel with gfar_clean_tx_ring(), except +* when modifying num_txbdfree. Note that we didn't grab the lock
drivers/net/gianfar.c +1
-0+* when we were reading the num_txbdfree and checking for available
drivers/net/gianfar.c +1
-0+* space, that's because outside of this function it can only grow,
drivers/net/gianfar.c +1
-0+* and once we've got needed space, it cannot suddenly disappear.
drivers/net/gianfar.c +4
-0+* +* The lock also protects us from gfar_error(), which can modify +* regs->tstat and thus retrigger the transfers, which is why we +* also must grab the lock before setting ready bit for the first
drivers/net/gianfar.c +5
-0+* to be transmitted BD. +*/ +spin_lock_irqsave (&tx_queue->txlock, flags); + +/* * The powerpc-specific
eieio()is used, aswmb()has too strong
* semantics (it requires synchronization between cacheable and
* uncacheable mappings, which eieio doesn't provide
and which we @@ -2225,6 +2236,8 @@ static intgfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)skb_dirtytx = tx_queue->skb_dirtytx; while ((skb = tx_queue->tx_skbuff[skb_dirtytx])) {drivers/net/gianfar.c +2
-0+unsigned long flags; +frags = skb_shinfo(skb)->nr_frags; lbdp = skip_txbd(bdp, frags, base, tx_ring_size);drivers/net/gianfar.c +2
-0@@ -2269,7 +2282,9 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)TX_RING_MOD_MASK (tx_ring_size ); howmany++; +spin_lock_irqsave (&tx_queue->txlock, flags); tx_queue->num_txbdfree += frags +1 ; +spin_unlock_irqrestore (&tx_queue->txlock, flags); }/* If we freed a buffer, we can restart transmission, if necessary */ @@ -2548,7 +2563,6 @@ static int gfar_poll(struct napi_struct *napi, int budget) int tx_cleaned = 0, i, left_over_budget = budget; unsigned long serviced_queues = 0; int num_queues = 0;drivers/net/gianfar.c +0
-1-unsigned long flags;num_queues = gfargrp->num_rx_queues; budget_per_queue = budget/num_queues;drivers/net/gianfar.c +1
-8@@ -2568,14 +2582,7 @@ static int gfar_poll(struct napi_struct *napi, int budget) rx_queue = priv->rx_queue[i]; tx_queue = priv->tx_queue[rx_queue->qindex]; -/* If we fail to get the lock, -* don't bother with the TX BDs */ -if (spin_trylock_irqsave(&tx_queue->txlock, flags)) { - tx_cleaned +=gfar_clean_tx_ring (tx_queue); -spin_unlock_irqrestore (&tx_queue->txlock, - flags); - } - + tx_cleaned += gfar_clean_tx_ring(tx_queue);
rx_cleaned_per_queue=
gfar_clean_rx_ring(rx_queue,
Quoted 3 lines
budget_per_queue); rx_cleaned += rx_cleaned_per_queue;--
Anton, we tried some experiments too at our end, and removing the spinlocks did help improve the performance and recycling was effective although, I don't have exact numbers to specify.
But overall I agree with you in removing the spinlocks from the gfar_poll context.
--
Thanks
Sandeep
RE: [PATCH 3/6] gianfar: Fix build with CONFIG_PM=y
In reply to Anton VorontsovQuoted 31 lines
-----Original Message-----
From: Anton Vorontsov [mailto:[email protected]]
Sent: Wednesday, November 11, 2009 5:41 AM
To: David Miller
Cc: Fleming Andy-AFLEMING; Jon Loeliger; Kumar Gopalpet-B05799; Lennert Buytenhek; Stephen Hemminger; [email protected]; [email protected]
Subject: [PATCH 3/6] gianfar: Fix build withCONFIG_PM=ycommit
fba4ed030cfae7efdb6b79a57b0c5a9d72c9("gianfar: Add Multiple Queue Support") introduced the following build failure:CC gianfar.o
gianfar.c: In function 'gfar_restore':
gianfar.c:1249: error: request for member 'napi' in something not a structure or unionThis patch fixes the issue.
Signed-off-by Anton Vorontsov <[email protected]>---
drivers/net/gianfar.c| 2 +-1 files changed, 1 insertions(+), 1 deletions(-)drivers/net/gianfar.c +0
-0
drivers/net/gianfar.c static int gfar_restore(struct device *dev) · line 1252
Quoted 8 lines
drivers/net/gianfar.c +1
-1@@ -1246,7 +1246,7 @@ static int gfar_restore(struct device *dev)phy_start (priv->phydev);netif_device_attach (ndev); -napi_enable (&priv->gfargrp.napi); +enable_napi (priv);return 0 ; }
I am extreemely sorry for introducing this error, I missed it while porting my last set of patches.
Thanks for fixing it.
--
Thanks
Sandeep
Quoted 5 lines · Anton Vorontsov
Hi all,
Here are some fixes for the gianfar driver, patches on the way.
Thanks,
- k
David Miller
maintainerFrom: Kumar Gala <[email protected]>
Date: Wed, 11 Nov 2009 09:16:41 -0600
Quoted 10 lines · Anton Vorontsov
Quoted 6 lines
Hi all,
Here are some fixes for the gianfar driver, patches on the way.
Thanks,
Acked-by Kumar Gala <[email protected]>
All applied to net-next-2.6, thanks.