sky2: Avoid race in sky2_change_mtu
Subsystems (2)
PATCH 1/1 sky2: Avoid race in sky2_change_mtu
netif_stop_queue does not ensure all in-progress transmits are complete,
so use netif_tx_disable() instead.
Make sure NAPI polls are disabled, otherwise NAPI might trigger a TX
restart between when we stop the queue and NAPI is disabled.
--- drivers/net/sky2.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/sky2.c +1 -1
@@ -2236,8 +2236,8 @@ static int sky2_change_mtu(struct net_device *dev, int new_mtu)sky2_write32 (hw,B0_IMSK ,0 ); dev->trans_start = jiffies;/* prevent tx timeout */ -netif_stop_queue (dev);napi_disable (&hw->napi); +netif_tx_disable (dev);synchronize_irq (hw->pdev->irq);
Signature · 1 line
1.5.6.5
David Miller
maintainerFrom: Mike McCormack <[email protected]>
Date: Mon, 03 May 2010 23:18:56 +0900
Quoted 7 lines
netif_stop_queuedoes not ensure all in-progress transmits are complete,
so usenetif_tx_disable()instead.Make sure NAPI polls are disabled, otherwise NAPI might trigger a TX
restart between when we stop the queue and NAPI is disabled.Signed-off-by Mike McCormack <[email protected]>
This looks quite reasonable, Stephen please review.
Quoted 5 lines · On Mon, 03 May 2010 23:18:56 +0900 Mike McCormack <[email protected]> wrote:
netif_stop_queuedoes not ensure all in-progress transmits are complete,
so usenetif_tx_disable()instead.Make sure NAPI polls are disabled, otherwise NAPI might trigger a TX
restart between when we stop the queue and NAPI is disabled.
How could NAPI trigger a TX restart? Restart is a timer, not controlled by NAPI. There is a different race that your patch isn't covering.
If a large MTU send is in progress while mtu is changing, the changes to the GMAC store and forward (sky2_set_tx_stfwd) are not synchronized with hardware queued transmits.
So I think a there needs to be another spinloop.
drivers/net/sky2.c +5 -1
@@ -2274,8 +2274,12 @@ static int sky2_change_mtu(struct net_de imask =sky2_read32 (hw,B0_IMSK );sky2_write32 (hw,B0_IMSK ,0 ); - dev->trans_start = jiffies;/* prevent tx timeout */ netif_stop_queue (dev); + +/* Wait for ongoing Tx to complete */ +while (sky2->tx_cons != sky2->tx_prod) +udelay (10 ); +napi_disable (&hw->napi);synchronize_irq (hw->pdev->irq);
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Mon, 3 May 2010 16:26:34 -0700
Quoted 11 lines
Quoted 5 lines · On Mon, 03 May 2010 23:18:56 +0900 Mike McCormack <[email protected]> wrote:
netif_stop_queuedoes not ensure all in-progress transmits are complete,
so usenetif_tx_disable()instead.Make sure NAPI polls are disabled, otherwise NAPI might trigger a TX
restart between when we stop the queue and NAPI is disabled.How could NAPI trigger a TX restart? Restart is a timer, not controlled by NAPI. There is a different race that your patch isn't covering.
I think he meant to say that NAPI can trigger a TX queue wake, which indeed it can, and it will if there is space in the TX queue and we happen to see the TXIDLE status at this time.