net: avoid updating qdisc_xmit_lock_key in netdev_update_lockdep_key()
Subsystems (2)
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.
--- net/core/dev.c | 12 ------------ 1 file changed, 12 deletions(-)
net/core/dev.c +0 -12
@@ -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
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 isqdisc_xmit_lock_keygets re-registered innetdev_update_lockdep_key()on slow path, while we could still acquire thequeue->_xmit_lockon 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_lockwhich has to be reordered when the master/slave device relationship changes,queue->_xmit_lockis only acquired on fast path and only whenNETIF_F_LLTXis 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!
David Miller
maintainerFrom: 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 isqdisc_xmit_lock_keygets re-registered innetdev_update_lockdep_key()on slow path, while we could still acquire thequeue->_xmit_lockon 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_lockwhich has to be reordered when the master/slave device relationship changes,queue->_xmit_lockis only acquired on fast path and only whenNETIF_F_LLTXis 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]>Signed-off-by Cong Wang <[email protected]>
Applied and queued up for -stable, thanks.