* [PATCH] b44: netpoll locking fix
@ 2007-05-29 21:14 Francois Romieu
2007-05-29 21:27 ` Stephen Hemminger
0 siblings, 1 reply; 5+ messages in thread
From: Francois Romieu @ 2007-05-29 21:14 UTC (permalink / raw)
To: Gary Zambrano; +Cc: jgarzik, akpm, netdev
The irq handling thread (b44_interrupt) uses the same lock as the NAPI
thread. This change should prevent a deadlock if something interrupts
the b44 NAPI thread and tries to printk through netconsole.
Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
---
drivers/net/b44.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 879a2ff..64d75e4 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -853,16 +853,18 @@ static int b44_rx(struct b44 *bp, int budget)
static int b44_poll(struct net_device *netdev, int *budget)
{
struct b44 *bp = netdev_priv(netdev);
+ unsigned long flags;
int done;
- spin_lock_irq(&bp->lock);
+ spin_lock_irqsave(&bp->lock, flags);
if (bp->istat & (ISTAT_TX | ISTAT_TO)) {
/* spin_lock(&bp->tx_lock); */
b44_tx(bp);
/* spin_unlock(&bp->tx_lock); */
}
- spin_unlock_irq(&bp->lock);
+
+ spin_unlock_irqrestore(&bp->lock, flags);
done = 1;
if (bp->istat & ISTAT_RX) {
@@ -882,8 +884,6 @@ static int b44_poll(struct net_device *netdev, int *budget)
}
if (bp->istat & ISTAT_ERRORS) {
- unsigned long flags;
-
spin_lock_irqsave(&bp->lock, flags);
b44_halt(bp);
b44_init_rings(bp);
--
1.5.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] b44: netpoll locking fix
2007-05-29 21:14 [PATCH] b44: netpoll locking fix Francois Romieu
@ 2007-05-29 21:27 ` Stephen Hemminger
2007-05-29 22:20 ` Francois Romieu
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2007-05-29 21:27 UTC (permalink / raw)
To: Francois Romieu; +Cc: Gary Zambrano, jgarzik, akpm, netdev
On Tue, 29 May 2007 23:14:58 +0200
Francois Romieu <romieu@fr.zoreil.com> wrote:
> The irq handling thread (b44_interrupt) uses the same lock as the NAPI
> thread. This change should prevent a deadlock if something interrupts
> the b44 NAPI thread and tries to printk through netconsole.
>
> Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
Better to just get rid of using the lock as a transmit lock and
use netif_tx_lock instead.
--- a/drivers/net/b44.c 2007-05-29 09:51:43.000000000 -0700
+++ b/drivers/net/b44.c 2007-05-29 14:26:03.000000000 -0700
@@ -607,6 +607,7 @@ static void b44_tx(struct b44 *bp)
{
u32 cur, cons;
+ netif_tx_lock(bp->dev);
cur = br32(bp, B44_DMATX_STAT) & DMATX_STAT_CDMASK;
cur /= sizeof(struct dma_desc);
@@ -622,7 +623,7 @@ static void b44_tx(struct b44 *bp)
skb->len,
PCI_DMA_TODEVICE);
rp->skb = NULL;
- dev_kfree_skb_irq(skb);
+ dev_kfree_skb_any(skb);
}
bp->tx_cons = cons;
@@ -631,6 +632,7 @@ static void b44_tx(struct b44 *bp)
netif_wake_queue(bp->dev);
bw32(bp, B44_GPTIMER, 0);
+ netif_tx_unlock(bp->dev);
}
/* Works like this. This chip writes a 'struct rx_header" 30 bytes
@@ -855,14 +857,8 @@ static int b44_poll(struct net_device *n
struct b44 *bp = netdev_priv(netdev);
int done;
- spin_lock_irq(&bp->lock);
-
- if (bp->istat & (ISTAT_TX | ISTAT_TO)) {
- /* spin_lock(&bp->tx_lock); */
+ if (bp->istat & (ISTAT_TX | ISTAT_TO))
b44_tx(bp);
- /* spin_unlock(&bp->tx_lock); */
- }
- spin_unlock_irq(&bp->lock);
done = 1;
if (bp->istat & ISTAT_RX) {
@@ -970,21 +966,19 @@ static int b44_start_xmit(struct sk_buff
{
struct b44 *bp = netdev_priv(dev);
struct sk_buff *bounce_skb;
- int rc = NETDEV_TX_OK;
dma_addr_t mapping;
u32 len, entry, ctrl;
- len = skb->len;
- spin_lock_irq(&bp->lock);
-
- /* This is a hard error, log it. */
if (unlikely(TX_BUFFS_AVAIL(bp) < 1)) {
- netif_stop_queue(dev);
- printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
- dev->name);
- goto err_out;
+ if (!netif_queue_stopped(dev)) {
+ netif_stop_queue(dev);
+ printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
+ dev->name);
+ }
+ return NETDEV_TX_BUSY;
}
+ len = skb->len;
mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
if (dma_mapping_error(mapping) || mapping + len > DMA_30BIT_MASK) {
/* Chip can't handle DMA to/from >1GB, use bounce buffer */
@@ -1044,16 +1038,14 @@ static int b44_start_xmit(struct sk_buff
if (TX_BUFFS_AVAIL(bp) < 1)
netif_stop_queue(dev);
- dev->trans_start = jiffies;
-
-out_unlock:
- spin_unlock_irq(&bp->lock);
+ mmiowb();
- return rc;
+ dev->trans_start = jiffies;
+ return NETDEV_TX_OK;
err_out:
- rc = NETDEV_TX_BUSY;
- goto out_unlock;
+ dev_kfree_skb(skb);
+ return NETDEV_TX_OK;
}
static int b44_change_mtu(struct net_device *dev, int new_mtu)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] b44: netpoll locking fix
2007-05-29 21:27 ` Stephen Hemminger
@ 2007-05-29 22:20 ` Francois Romieu
2007-05-29 22:30 ` Stephen Hemminger
2007-05-29 23:13 ` John W. Linville
0 siblings, 2 replies; 5+ messages in thread
From: Francois Romieu @ 2007-05-29 22:20 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Gary Zambrano, jgarzik, akpm, netdev
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=unknown-8bit, Size: 941 bytes --]
Stephen Hemminger <shemminger@linux-foundation.org> :
⅜...]
> Better to just get rid of using the lock as a transmit lock and
> use netif_tx_lock instead.
> --- a/drivers/net/b44.c 2007-05-29 09:51:43.000000000 -0700
> +++ b/drivers/net/b44.c 2007-05-29 14:26:03.000000000 -0700
> @@ -607,6 +607,7 @@ static void b44_tx(struct b44 *bp)
> {
> u32 cur, cons;
>
> + netif_tx_lock(bp->dev);
> cur = br32(bp, B44_DMATX_STAT) & DMATX_STAT_CDMASK;
> cur /= sizeof(struct dma_desc);
>
(damn, you are quick)
I am not completely convinced.
1. netpoll_send_skb (calls netif_tx_trylock(dev))
-> netpoll_poll(np)
-> poll_napi(np)
-> np->dev->poll(np->dev, &budget) ( == b44_poll)
-> b44_tx
-> netif_tx_lock(bp->dev) *deadlock*
2. Hunk #5 clashes with John Linville's wireless-dev#master
3. Moderately appropriate for 2.6.22-rc (imho, fwiw, etc.)
--
Ueimor
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] b44: netpoll locking fix
2007-05-29 22:20 ` Francois Romieu
@ 2007-05-29 22:30 ` Stephen Hemminger
2007-05-29 23:13 ` John W. Linville
1 sibling, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2007-05-29 22:30 UTC (permalink / raw)
To: Francois Romieu; +Cc: Gary Zambrano, jgarzik, akpm, netdev
On Wed, 30 May 2007 00:20:41 +0200
Francois Romieu <romieu@fr.zoreil.com> wrote:
> Stephen Hemminger <shemminger@linux-foundation.org> :
> ⅜...]
> > Better to just get rid of using the lock as a transmit lock and
> > use netif_tx_lock instead.
> > --- a/drivers/net/b44.c 2007-05-29 09:51:43.000000000 -0700
> > +++ b/drivers/net/b44.c 2007-05-29 14:26:03.000000000 -0700
> > @@ -607,6 +607,7 @@ static void b44_tx(struct b44 *bp)
> > {
> > u32 cur, cons;
> >
> > + netif_tx_lock(bp->dev);
> > cur = br32(bp, B44_DMATX_STAT) & DMATX_STAT_CDMASK;
> > cur /= sizeof(struct dma_desc);
> >
>
> (damn, you are quick)
>
> I am not completely convinced.
>
> 1. netpoll_send_skb (calls netif_tx_trylock(dev))
> -> netpoll_poll(np)
> -> poll_napi(np)
> -> np->dev->poll(np->dev, &budget) ( == b44_poll)
> -> b44_tx
> -> netif_tx_lock(bp->dev) *deadlock*
Netpoll needs to be fixed. (or scrapped), as is it will break drivers
trying to use tx_lock in poll routine. I know sky2 would get borked.
Something like this:
--- a/net/core/netpoll.c 2007-05-08 14:19:32.000000000 -0700
+++ b/net/core/netpoll.c 2007-05-29 15:28:22.000000000 -0700
@@ -250,22 +250,23 @@ static void netpoll_send_skb(struct netp
unsigned long flags;
local_irq_save(flags);
- if (netif_tx_trylock(dev)) {
- /* try until next clock tick */
- for (tries = jiffies_to_usecs(1)/USEC_PER_POLL;
- tries > 0; --tries) {
+ /* try until next clock tick */
+ for (tries = jiffies_to_usecs(1)/USEC_PER_POLL;
+ tries > 0; --tries) {
+ if (netif_tx_trylock(dev)) {
if (!netif_queue_stopped(dev))
status = dev->hard_start_xmit(skb, dev);
+ netif_tx_unlock(dev);
if (status == NETDEV_TX_OK)
break;
- /* tickle device maybe there is some cleanup */
- netpoll_poll(np);
-
- udelay(USEC_PER_POLL);
}
- netif_tx_unlock(dev);
+
+ /* tickle device maybe there is some cleanup */
+ netpoll_poll(np);
+
+ udelay(USEC_PER_POLL);
}
local_irq_restore(flags);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] b44: netpoll locking fix
2007-05-29 22:20 ` Francois Romieu
2007-05-29 22:30 ` Stephen Hemminger
@ 2007-05-29 23:13 ` John W. Linville
1 sibling, 0 replies; 5+ messages in thread
From: John W. Linville @ 2007-05-29 23:13 UTC (permalink / raw)
To: Francois Romieu; +Cc: Stephen Hemminger, Gary Zambrano, jgarzik, akpm, netdev
On Wed, May 30, 2007 at 12:20:41AM +0200, Francois Romieu wrote:
> 2. Hunk #5 clashes with John Linville's wireless-dev#master
Let's not worry too much about this fact -- I'll (make Michael)
fix-up things in my tree as appropriate. :-)
John
--
John W. Linville
linville@tuxdriver.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-05-29 23:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-29 21:14 [PATCH] b44: netpoll locking fix Francois Romieu
2007-05-29 21:27 ` Stephen Hemminger
2007-05-29 22:20 ` Francois Romieu
2007-05-29 22:30 ` Stephen Hemminger
2007-05-29 23:13 ` John W. Linville
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).