fix tiny races in MAC drivers
Subsystems (2)
cover fix tiny races in MAC drivers
In course of adding transmit time stamping, some unrelated problems were uncovered. Drivers which free transmit buffers in an ISR must not access the buffers after giving them to the hardware.
Richard Cochran (2):
pxa168_eth: fix race in transmit path.
mv643xx_eth: fix race in trasmit path.
drivers/net/mv643xx_eth.c | 6 ++++-- drivers/net/pxa168_eth.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
PATCH 1/2 pxa168_eth: fix race in transmit path.
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
--- drivers/net/pxa168_eth.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/pxa168_eth.c +1 -1
@@ -1273,7 +1273,7 @@ static int pxa168_eth_start_xmit(struct sk_buff *skb, struct net_device *dev)wmb ();wrl (pep,SDMA_CMD ,SDMA_CMD_TXDH |SDMA_CMD_ERD ); - stats->tx_bytes += skb->len; + stats->tx_bytes += length; stats->tx_packets++; dev->trans_start = jiffies;if (pep->tx_ring_size - pep->tx_desc_count <=1 ) {
Signature · 1 line
1.7.0.4
Re: [PATCH 1/2] pxa168_eth: fix race in transmit path.
Quoted 8 lines · Richard Cochran
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
Cc Sachin Sanap <[email protected]>Cc Zhangfei Gao <[email protected]>Cc Philip Rakity <[email protected]>Signed-off-by Richard Cochran <[email protected]>
Re: [PATCH 1/2] pxa168_eth: fix race in transmit path.
From: Eric Dumazet <[email protected]>
Date: Mon, 20 Jun 2011 17:49:17 +0200
Quoted 11 lines · Richard Cochran
Quoted 8 lines
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
Cc Sachin Sanap <[email protected]>Cc Zhangfei Gao <[email protected]>Cc Philip Rakity <[email protected]>Signed-off-by Richard Cochran <[email protected]>Acked-by Eric Dumazet <[email protected]>
Applied.
PATCH 2/2 mv643xx_eth: fix race in trasmit path.
In reply to Richard CochranBecause the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
--- drivers/net/mv643xx_eth.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/net/mv643xx_eth.c +4 -2
@@ -859,7 +859,7 @@ no_csum:static netdev_tx_t mv643xx_eth_xmit (struct sk_buff *skb,struct net_device *dev) {struct mv643xx_eth_private *mp =netdev_priv (dev); -int queue; +int length, queue;struct tx_queue *txq;struct netdev_queue *nq;
@@ -881,10 +881,12 @@ static netdev_tx_t mv643xx_eth_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } + length = skb->len; +if (!txq_submit_skb (txq, skb)) {int entries_left; - txq->tx_bytes += skb->len; + txq->tx_bytes += length; txq->tx_packets++; entries_left = txq->tx_ring_size - txq->tx_desc_count;
Signature · 1 line
1.7.0.4
Re: [PATCH 2/2] mv643xx_eth: fix race in trasmit path.
Quoted 10 lines · Richard Cochran
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
Cc Lennert Buytenhek <[email protected]>Signed-off-by Richard Cochran <[email protected]>--- drivers/net/mv643xx_eth.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
Re: [PATCH 2/2] mv643xx_eth: fix race in trasmit path.
In reply to Richard CochranOn Mon, 2011-06-20 at 09:48 +0200, Richard Cochran wrote:
Hi Richard,
Quoted 2 lines
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
I don't see why.
skb is freed from txq_reclaim() which grabs the tx queue lock before, (hence the lockless __skb_queue_xxx() in both functions)
What am I missing ?
Quoted 34 lines
Cc Lennert Buytenhek <[email protected]>Signed-off-by Richard Cochran <[email protected]>--- drivers/net/mv643xx_eth.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)drivers/net/mv643xx_eth.c +4
-2@@ -859,7 +859,7 @@ no_csum:static netdev_tx_t mv643xx_eth_xmit (struct sk_buff *skb,struct net_device *dev) {struct mv643xx_eth_private *mp =netdev_priv (dev); -int queue; +int length, queue;struct tx_queue *txq;struct netdev_queue *nq;@@ -881,10 +881,12 @@ static netdev_tx_t mv643xx_eth_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } + length = skb->len; +if (!txq_submit_skb (txq, skb)) {int entries_left; - txq->tx_bytes += skb->len; + txq->tx_bytes += length; txq->tx_packets++; entries_left = txq->tx_ring_size - txq->tx_desc_count;
Signature · 1 line
Maxime
Re: [PATCH 2/2] mv643xx_eth: fix race in trasmit path.
Quoted 7 lines · Maxime Bizon
On Mon, 2011-06-20 at 09:48 +0200, Richard Cochran wrote:
Hi Richard,
Quoted 2 lines
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
Quoted 6 lines
I don't see why.
skb is freed from
txq_reclaim()which grabs the tx queue lock before, (hence the lockless__skb_queue_xxx()in both functions)What am I missing ?
You are right, this driver still takes tx queue lock in its TX completion path.
txq_reclaim() can currently run for a very long time, blocking other cpus to make progress if blocked on tx queue lock.
So consider this patch as a cleanup :
Its better to make all drivers behave the same way
1) Either increment tx stats in their start_xmit(), and making sure they dont access skb->len too late.
2) increment tx stats in their TX completion path.
Then we can work on making TX completion path not taking tx queue lock in its fast path.
Re: [PATCH 2/2] mv643xx_eth: fix race in trasmit path.
In reply to Richard CochranQuoted 2 lines · Richard Cochran
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
Maybe I'm missing something here, but mv643xx_eth TX reclaim is done from NAPI poll, under __netif_tx_lock(), while mv643xx_eth_xmit() also runs under __netif_tx_lock().
Re: [PATCH 2/2] mv643xx_eth: fix race in trasmit path.
Quoted 8 lines · Lennert Buytenhek
Quoted 2 lines · Richard Cochran
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
Maybe I'm missing something here, but
mv643xx_ethTX reclaim is done from NAPI poll, under__netif_tx_lock(), whilemv643xx_eth_xmit()also runs under__netif_tx_lock().
See my previous answer. Its true this driver _currently_ holds tx queue lock in its TX completion. But that might/should change.
Goal is to make tx completion not use tx queue lock in fast path, like its done in tg3, bnx2, bnx2x ... and other recent drivers.
Its obviously correct to move skb->len access in start_xmit() before starting the IO, even if not a bug fix, it makes all drivers behave the same : When reviewing them, its easier not to worry about these possible use after free.
Re: [PATCH 2/2] mv643xx_eth: fix race in trasmit path.
Quoted 13 lines · Eric Dumazet
Quoted 8 lines · Lennert Buytenhek
Quoted 2 lines · Richard Cochran
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
Maybe I'm missing something here, but
mv643xx_ethTX reclaim is done from NAPI poll, under__netif_tx_lock(), whilemv643xx_eth_xmit()also runs under__netif_tx_lock().See my previous answer. Its true this driver _currently_ holds tx queue lock in its TX completion. But that might/should change.
Quoted 9 lines
Goal is to make tx completion not use tx queue lock in fast path, like its done in tg3, bnx2, bnx2x ... and other recent drivers.
Its obviously correct to move
skb->lenaccess instart_xmit()before starting the IO, even if not a bug fix, it makes all drivers behave the same : When reviewing them, its easier not to worry about these possible use after free.
One random example found in drivers/staging/hv/netvsc_drv.c
Is the "net->stats.tx_bytes += skb->len;" found in line 188 is correct ?
Who knows ?
I believe its not correct ;)
David Miller
maintainerRe: [PATCH 2/2] mv643xx_eth: fix race in trasmit path.
In reply to Richard CochranFrom: Richard Cochran <[email protected]>
Date: Mon, 20 Jun 2011 09:48:07 +0200
Quoted 4 lines
Because the socket buffer is freed in the completion interrupt, it is not safe to access it after submitting it to the hardware.
Signed-off-by Richard Cochran <[email protected]>
Since this isn't actually a bonafide bug fix I've applied this to net-next-2.6