netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] net: avoid updating qdisc_xmit_lock_key in netdev_update_lockdep_key()
@ 2020-01-15 21:02 Cong Wang
  2020-01-16 14:58 ` Taehee Yoo
  2020-01-17 10:04 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2020-01-15 21:02 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, syzbot+4ec99438ed7450da6272, Taehee Yoo

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: syzbot+4ec99438ed7450da6272@syzkaller.appspotmail.com
Fixes: ab92d68fc22f ("net: core: add generic lockdep keys")
Cc: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/core/dev.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 0ad39c87b7fd..7e885d069707 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -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);
 
-- 
2.21.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch net] net: avoid updating qdisc_xmit_lock_key in netdev_update_lockdep_key()
  2020-01-15 21:02 [Patch net] net: avoid updating qdisc_xmit_lock_key in netdev_update_lockdep_key() Cong Wang
@ 2020-01-16 14:58 ` Taehee Yoo
  2020-01-17 10:04 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Taehee Yoo @ 2020-01-16 14:58 UTC (permalink / raw)
  To: Cong Wang; +Cc: Netdev, syzbot

On Thu, 16 Jan 2020 at 06:02, Cong Wang <xiyou.wangcong@gmail.com> wrote:
>
> 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: syzbot+4ec99438ed7450da6272@syzkaller.appspotmail.com
> Fixes: ab92d68fc22f ("net: core: add generic lockdep keys")

Thank you for fixing this bug!

Acked-by: Taehee Yoo <ap420073@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch net] net: avoid updating qdisc_xmit_lock_key in netdev_update_lockdep_key()
  2020-01-15 21:02 [Patch net] net: avoid updating qdisc_xmit_lock_key in netdev_update_lockdep_key() Cong Wang
  2020-01-16 14:58 ` Taehee Yoo
@ 2020-01-17 10:04 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-01-17 10:04 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, syzbot+4ec99438ed7450da6272, ap420073

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 15 Jan 2020 13:02:38 -0800

> 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: syzbot+4ec99438ed7450da6272@syzkaller.appspotmail.com
> Fixes: ab92d68fc22f ("net: core: add generic lockdep keys")
> Cc: Taehee Yoo <ap420073@gmail.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-17 10:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 21:02 [Patch net] net: avoid updating qdisc_xmit_lock_key in netdev_update_lockdep_key() Cong Wang
2020-01-16 14:58 ` Taehee Yoo
2020-01-17 10:04 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).