* [PATCH 1/3][BNX2]: Fix panic in bnx2_tx_int().
@ 2006-12-14 2:30 Michael Chan
2006-12-14 23:57 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Michael Chan @ 2006-12-14 2:30 UTC (permalink / raw)
To: davem, agospoda, netdev; +Cc: cjk
[BNX2]: Fix panic in bnx2_tx_int().
There was an off-by-one bug in bnx2_tx_avail(). If the tx ring is
completely full, the producer and consumer indices may be apart by
256 even though the ring size is only 255. One entry in the ring is
unused and must be properly accounted for when calculating the number
of available entries. The bug caused the tx ring entries to be
reused by mistake, overwriting active entries, and ultimately causing
it to crash.
This bug rarely occurs because the tx ring is rarely completely full.
We always stop when there is less than MAX_SKB_FRAGS entries available
in the ring.
Thanks to Corey Kovacs <cjk@techma.com> and Andy Gospodarek
<agospoda@redhat.com> for reporting the problem and helping to collect
debug information.
Signed-off-by: Michael Chan <mchan@broadcom.com>
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 7d824cf..f296c37 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -217,9 +217,16 @@ static inline u32 bnx2_tx_avail(struct b
u32 diff;
smp_mb();
- diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons);
- if (diff > MAX_TX_DESC_CNT)
- diff = (diff & MAX_TX_DESC_CNT) - 1;
+
+ /* The ring uses 256 indices for 255 entries, one of them
+ * needs to be skipped.
+ */
+ diff = bp->tx_prod - bp->tx_cons;
+ if (unlikely(diff >= TX_DESC_CNT)) {
+ diff &= 0xffff;
+ if (diff == TX_DESC_CNT)
+ diff = MAX_TX_DESC_CNT;
+ }
return (bp->tx_ring_size - diff);
}
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH 1/3][BNX2]: Fix panic in bnx2_tx_int().
2006-12-14 2:30 [PATCH 1/3][BNX2]: Fix panic in bnx2_tx_int() Michael Chan
@ 2006-12-14 23:57 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2006-12-14 23:57 UTC (permalink / raw)
To: mchan; +Cc: agospoda, netdev, cjk
From: "Michael Chan" <mchan@broadcom.com>
Date: Wed, 13 Dec 2006 18:30:33 -0800
> [BNX2]: Fix panic in bnx2_tx_int().
>
> There was an off-by-one bug in bnx2_tx_avail(). If the tx ring is
> completely full, the producer and consumer indices may be apart by
> 256 even though the ring size is only 255. One entry in the ring is
> unused and must be properly accounted for when calculating the number
> of available entries. The bug caused the tx ring entries to be
> reused by mistake, overwriting active entries, and ultimately causing
> it to crash.
>
> This bug rarely occurs because the tx ring is rarely completely full.
> We always stop when there is less than MAX_SKB_FRAGS entries available
> in the ring.
>
> Thanks to Corey Kovacs <cjk@techma.com> and Andy Gospodarek
> <agospoda@redhat.com> for reporting the problem and helping to collect
> debug information.
>
> Signed-off-by: Michael Chan <mchan@broadcom.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-12-15 0:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-14 2:30 [PATCH 1/3][BNX2]: Fix panic in bnx2_tx_int() Michael Chan
2006-12-14 23:57 ` David Miller
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).