Skip to contentSkip to conversation

net: avoid updating qdisc_xmit_lock_key in netdev_update_lockdep_key()

PATCH In review Cong Wang 3 participants 3 messages Jan 15, 2020 – Jan 17, 2020

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net: avoid updating qdisc_xmit_lock_key in netdev_update_lockdep_key()

syzbot reported some bogus lockdep warnings, for example bad unlock balance in sch_direct_xmit(). They are due to a race condition between slow path and fast path, that is qdisc_xmit_lock_key gets re-registered in netdev_update_lockdep_key() on slow path, while we could still acquire the queue->_xmit_lock on fast path in this small window:

CPU A CPU B

						__netif_tx_lock();
lockdep_unregister_key(qdisc_xmit_lock_key);
						__netif_tx_unlock();

lockdep_register_key(qdisc_xmit_lock_key);

In fact, unlike the addr_list_lock which has to be reordered when the master/slave device relationship changes, queue->_xmit_lock is only acquired on fast path and only when NETIF_F_LLTX is not set, so there is likely no nested locking for it.

Therefore, we can just get rid of re-registration of qdisc_xmit_lock_key.

Reported-by [email protected]
Fixes ab92d68fc22f ("net: core: add generic lockdep keys")
Cc Taehee Yoo <[email protected]>
---
 net/core/dev.c | 12 ------------
 1 file changed, 12 deletions(-)
net/core/dev.c +0 -12
index 0ad39c87b7fd..7e885d069707 100644
@@ -9177,22 +9177,10 @@ static void netdev_unregister_lockdep_key(struct net_device *dev)
 
 void netdev_update_lockdep_key(struct net_device *dev)
 {
-	struct netdev_queue *queue;
-	int i;
-
-	lockdep_unregister_key(&dev->qdisc_xmit_lock_key);
 	lockdep_unregister_key(&dev->addr_list_lock_key);
-
-	lockdep_register_key(&dev->qdisc_xmit_lock_key);
 	lockdep_register_key(&dev->addr_list_lock_key);
 
 	lockdep_set_class(&dev->addr_list_lock, &dev->addr_list_lock_key);
-	for (i = 0; i < dev->num_tx_queues; i++) {
-		queue = netdev_get_tx_queue(dev, i);
-
-		lockdep_set_class(&queue->_xmit_lock,
-				  &dev->qdisc_xmit_lock_key);
-	}
 }
 EXPORT_SYMBOL(netdev_update_lockdep_key);
 
Signature · 1 line
2.21.1
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Cong Wang

syzbot reported some bogus lockdep warnings, for example bad unlock balance in sch_direct_xmit(). They are due to a race condition between slow path and fast path, that is qdisc_xmit_lock_key gets re-registered in netdev_update_lockdep_key() on slow path, while we could still acquire the queue->_xmit_lock on fast path in this small window:

CPU A CPU B

                                                __netif_tx_lock();
lockdep_unregister_key(qdisc_xmit_lock_key);
                                                __netif_tx_unlock();

lockdep_register_key(qdisc_xmit_lock_key);

In fact, unlike the addr_list_lock which has to be reordered when the master/slave device relationship changes, queue->_xmit_lock is only acquired on fast path and only when NETIF_F_LLTX is not set, so there is likely no nested locking for it.

Quoted 5 lines

Therefore, we can just get rid of re-registration of qdisc_xmit_lock_key.

Reported-by [email protected]
Fixes ab92d68fc22f ("net: core: add generic lockdep keys")

Thank you for fixing this bug!

maintainer
#2 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 15 Jan 2020 13:02:38 -0800

Quoted 17 lines

syzbot reported some bogus lockdep warnings, for example bad unlock balance in sch_direct_xmit(). They are due to a race condition between slow path and fast path, that is qdisc_xmit_lock_key gets re-registered in netdev_update_lockdep_key() on slow path, while we could still acquire the queue->_xmit_lock on fast path in this small window:

CPU A CPU B

						__netif_tx_lock();
lockdep_unregister_key(qdisc_xmit_lock_key);
						__netif_tx_unlock();

lockdep_register_key(qdisc_xmit_lock_key);

In fact, unlike the addr_list_lock which has to be reordered when the master/slave device relationship changes, queue->_xmit_lock is only acquired on fast path and only when NETIF_F_LLTX is not set, so there is likely no nested locking for it.

Quoted 7 lines

Therefore, we can just get rid of re-registration of qdisc_xmit_lock_key.

Reported-by [email protected]
Fixes ab92d68fc22f ("net: core: add generic lockdep keys")
Cc Taehee Yoo <[email protected]>

Applied and queued up for -stable, thanks.