Skip to content

Commit 95ecba6

Browse files
Eric DumazetPaolo Abeni
authored andcommitted
net: fix races in netdev_tx_sent_queue()/dev_watchdog()
Some workloads hit the infamous dev_watchdog() message: "NETDEV WATCHDOG: eth0 (xxxx): transmit queue XX timed out" It seems possible to hit this even for perfectly normal BQL enabled drivers: 1) Assume a TX queue was idle for more than dev->watchdog_timeo (5 seconds unless changed by the driver) 2) Assume a big packet is sent, exceeding current BQL limit. 3) Driver ndo_start_xmit() puts the packet in TX ring, and netdev_tx_sent_queue() is called. 4) QUEUE_STATE_STACK_XOFF could be set from netdev_tx_sent_queue() before txq->trans_start has been written. 5) txq->trans_start is written later, from netdev_start_xmit() if (rc == NETDEV_TX_OK) txq_trans_update(txq) dev_watchdog() running on another cpu could read the old txq->trans_start, and then see QUEUE_STATE_STACK_XOFF, because 5) did not happen yet. To solve the issue, write txq->trans_start right before one XOFF bit is set : - _QUEUE_STATE_DRV_XOFF from netif_tx_stop_queue() - __QUEUE_STATE_STACK_XOFF from netdev_tx_sent_queue() From dev_watchdog(), we have to read txq->state before txq->trans_start. Add memory barriers to enforce correct ordering. In the future, we could avoid writing over txq->trans_start for normal operations, and rename this field to txq->xoff_start_time. Fixes: bec251b ("net: no longer stop all TX queues in dev_watchdog()") Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 47dd544 commit 95ecba6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

include/linux/netdevice.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,6 +3325,12 @@ static inline void netif_tx_wake_all_queues(struct net_device *dev)
33253325

33263326
static __always_inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
33273327
{
3328+
/* Paired with READ_ONCE() from dev_watchdog() */
3329+
WRITE_ONCE(dev_queue->trans_start, jiffies);
3330+
3331+
/* This barrier is paired with smp_mb() from dev_watchdog() */
3332+
smp_mb__before_atomic();
3333+
33283334
/* Must be an atomic op see netif_txq_try_stop() */
33293335
set_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
33303336
}
@@ -3451,6 +3457,12 @@ static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
34513457
if (likely(dql_avail(&dev_queue->dql) >= 0))
34523458
return;
34533459

3460+
/* Paired with READ_ONCE() from dev_watchdog() */
3461+
WRITE_ONCE(dev_queue->trans_start, jiffies);
3462+
3463+
/* This barrier is paired with smp_mb() from dev_watchdog() */
3464+
smp_mb__before_atomic();
3465+
34543466
set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
34553467

34563468
/*

net/sched/sch_generic.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,15 @@ static void dev_watchdog(struct timer_list *t)
512512
struct netdev_queue *txq;
513513

514514
txq = netdev_get_tx_queue(dev, i);
515-
trans_start = READ_ONCE(txq->trans_start);
516515
if (!netif_xmit_stopped(txq))
517516
continue;
517+
518+
/* Paired with WRITE_ONCE() + smp_mb...() in
519+
* netdev_tx_sent_queue() and netif_tx_stop_queue().
520+
*/
521+
smp_mb();
522+
trans_start = READ_ONCE(txq->trans_start);
523+
518524
if (time_after(jiffies, trans_start + dev->watchdog_timeo)) {
519525
timedout_ms = jiffies_to_msecs(jiffies - trans_start);
520526
atomic_long_inc(&txq->trans_timeout);

0 commit comments

Comments
 (0)