Skip to content

Commit 9bfc9d6

Browse files
edumazetkuba-moo
authored andcommitted
hamradio: use netdev_lockdep_set_classes() helper
It is time to use netdev_lockdep_set_classes() in bpqether.c List of related commits: 0bef512 ("net: add netdev_lockdep_set_classes() to virtual drivers") c74e103 ("net: bridge: use netdev_lockdep_set_classes()") 9a3c93a ("vlan: use netdev_lockdep_set_classes()") 0d7dd79 ("net: ipvlan: call netdev_lockdep_set_classes()") 24ffd75 ("net: macvlan: call netdev_lockdep_set_classes()") 78e7a2a ("net: vrf: call netdev_lockdep_set_classes()") d3fff6c ("net: add netdev_lockdep_set_classes() helper") syzbot reported: WARNING: possible recursive locking detected 6.14.0-rc5-syzkaller-01064-g2525e16a2bae #0 Not tainted dhcpcd/5501 is trying to acquire lock: ffff8880797e2d28 (&dev->lock){+.+.}-{4:4}, at: netdev_lock include/linux/netdevice.h:2765 [inline] ffff8880797e2d28 (&dev->lock){+.+.}-{4:4}, at: register_netdevice+0x12d8/0x1b70 net/core/dev.c:11008 but task is already holding lock: ffff88802e530d28 (&dev->lock){+.+.}-{4:4}, at: netdev_lock include/linux/netdevice.h:2765 [inline] ffff88802e530d28 (&dev->lock){+.+.}-{4:4}, at: netdev_lock_ops include/linux/netdevice.h:2804 [inline] ffff88802e530d28 (&dev->lock){+.+.}-{4:4}, at: dev_change_flags+0x120/0x270 net/core/dev_api.c:65 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&dev->lock); lock(&dev->lock); *** DEADLOCK *** May be due to missing lock nesting notation 2 locks held by dhcpcd/5501: #0: ffffffff8fed6848 (rtnl_mutex){+.+.}-{4:4}, at: rtnl_net_lock include/linux/rtnetlink.h:130 [inline] #0: ffffffff8fed6848 (rtnl_mutex){+.+.}-{4:4}, at: devinet_ioctl+0x34c/0x1d80 net/ipv4/devinet.c:1121 #1: ffff88802e530d28 (&dev->lock){+.+.}-{4:4}, at: netdev_lock include/linux/netdevice.h:2765 [inline] #1: ffff88802e530d28 (&dev->lock){+.+.}-{4:4}, at: netdev_lock_ops include/linux/netdevice.h:2804 [inline] #1: ffff88802e530d28 (&dev->lock){+.+.}-{4:4}, at: dev_change_flags+0x120/0x270 net/core/dev_api.c:65 stack backtrace: CPU: 1 UID: 0 PID: 5501 Comm: dhcpcd Not tainted 6.14.0-rc5-syzkaller-01064-g2525e16a2bae #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2025 Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120 print_deadlock_bug+0x483/0x620 kernel/locking/lockdep.c:3039 check_deadlock kernel/locking/lockdep.c:3091 [inline] validate_chain+0x15e2/0x5920 kernel/locking/lockdep.c:3893 __lock_acquire+0x1397/0x2100 kernel/locking/lockdep.c:5228 lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5851 __mutex_lock_common kernel/locking/mutex.c:585 [inline] __mutex_lock+0x19c/0x1010 kernel/locking/mutex.c:730 netdev_lock include/linux/netdevice.h:2765 [inline] register_netdevice+0x12d8/0x1b70 net/core/dev.c:11008 bpq_new_device drivers/net/hamradio/bpqether.c:499 [inline] bpq_device_event+0x4b1/0x8d0 drivers/net/hamradio/bpqether.c:542 notifier_call_chain+0x1a5/0x3f0 kernel/notifier.c:85 __dev_notify_flags+0x207/0x400 netif_change_flags+0xf0/0x1a0 net/core/dev.c:9442 dev_change_flags+0x146/0x270 net/core/dev_api.c:66 devinet_ioctl+0xea2/0x1d80 net/ipv4/devinet.c:1200 inet_ioctl+0x3d7/0x4f0 net/ipv4/af_inet.c:1001 sock_do_ioctl+0x158/0x460 net/socket.c:1190 sock_ioctl+0x626/0x8e0 net/socket.c:1309 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:906 [inline] __se_sys_ioctl+0xf5/0x170 fs/ioctl.c:892 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f Fixes: 7e4d784 ("net: hold netdev instance lock during rtnetlink operations") Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Stanislav Fomichev <sdf@fomichev.me> Link: https://patch.msgid.link/20250307160358.3153859-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent b3aaf3c commit 9bfc9d6

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

drivers/net/hamradio/bpqether.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,6 @@ struct bpqdev {
107107

108108
static LIST_HEAD(bpq_devices);
109109

110-
/*
111-
* bpqether network devices are paired with ethernet devices below them, so
112-
* form a special "super class" of normal ethernet devices; split their locks
113-
* off into a separate class since they always nest.
114-
*/
115-
static struct lock_class_key bpq_netdev_xmit_lock_key;
116-
static struct lock_class_key bpq_netdev_addr_lock_key;
117-
118-
static void bpq_set_lockdep_class_one(struct net_device *dev,
119-
struct netdev_queue *txq,
120-
void *_unused)
121-
{
122-
lockdep_set_class(&txq->_xmit_lock, &bpq_netdev_xmit_lock_key);
123-
}
124-
125-
static void bpq_set_lockdep_class(struct net_device *dev)
126-
{
127-
lockdep_set_class(&dev->addr_list_lock, &bpq_netdev_addr_lock_key);
128-
netdev_for_each_tx_queue(dev, bpq_set_lockdep_class_one, NULL);
129-
}
130-
131110
/* ------------------------------------------------------------------------ */
132111

133112

@@ -454,6 +433,8 @@ static const struct net_device_ops bpq_netdev_ops = {
454433

455434
static void bpq_setup(struct net_device *dev)
456435
{
436+
netdev_lockdep_set_classes(dev);
437+
457438
dev->netdev_ops = &bpq_netdev_ops;
458439
dev->needs_free_netdev = true;
459440

@@ -499,7 +480,6 @@ static int bpq_new_device(struct net_device *edev)
499480
err = register_netdevice(ndev);
500481
if (err)
501482
goto error;
502-
bpq_set_lockdep_class(ndev);
503483

504484
/* List protected by RTNL */
505485
list_add_rcu(&bpq->bpq_list, &bpq_devices);

0 commit comments

Comments
 (0)