Skip to content

Commit ba184ac

Browse files
Florian WestphalNipaLocal
authored andcommitted
net: core: split unregister_netdevice list into smaller chunks
Since blamed commit, unregister_netdevice_many_notify() takes the netdev mutex if the device needs it. This isn't a problem in itself, the problem is that the list can be very long, so it may lock a LOT of mutexes, but lockdep engine can only deal with MAX_LOCK_DEPTH held locks: unshare -n bash -c 'for i in $(seq 1 100);do ip link add foo$i type dummy;done' BUG: MAX_LOCK_DEPTH too low! turning off the locking correctness validator. depth: 48 max: 48! 48 locks held by kworker/u16:1/69: #0: ffff8880010b7148 ((wq_completion)netns){+.+.}-{0:0}, at: process_one_work+0x7ed/0x1350 kernel-patches#1: ffffc900004a7d40 (net_cleanup_work){+.+.}-{0:0}, at: process_one_work+0xcf3/0x1350 kernel-patches#2: ffffffff8bc6fbd0 (pernet_ops_rwsem){++++}-{4:4}, at: cleanup_net+0xab/0x7f0 kernel-patches#3: ffffffff8bc8daa8 (rtnl_mutex){+.+.}-{4:4}, at: default_device_exit_batch+0x7e/0x2e0 kernel-patches#4: ffff88800b5e9cb0 (&dev_instance_lock_key#3){+.+.}-{4:4}, at: unregister_netdevice_many_notify+0x1056/0x1b00 [..] Work around this limitation by chopping the list into smaller chunks and process them individually for LOCKDEP enabled kernels. Fixes: 7e4d784 ("net: hold netdev instance lock during rtnetlink operations") Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: NipaLocal <nipa@local>
1 parent 064ca25 commit ba184ac

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

net/core/dev.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12208,6 +12208,38 @@ static void unregister_netdevice_close_many(struct list_head *head)
1220812208
}
1220912209
}
1221012210

12211+
static void unregister_netdevice_close_many_lockdep(struct list_head *head)
12212+
{
12213+
#ifdef CONFIG_LOCKDEP
12214+
unsigned int lock_depth = lockdep_depth(current);
12215+
unsigned int lock_count = lock_depth;
12216+
struct net_device *dev, *tmp;
12217+
LIST_HEAD(done_head);
12218+
12219+
list_for_each_entry_safe(dev, tmp, head, unreg_list) {
12220+
if (netdev_need_ops_lock(dev))
12221+
lock_count++;
12222+
12223+
/* we'll run out of lockdep keys, reduce size. */
12224+
if (lock_count >= MAX_LOCK_DEPTH - 1) {
12225+
LIST_HEAD(tmp_head);
12226+
12227+
list_cut_before(&tmp_head, head, &dev->unreg_list);
12228+
unregister_netdevice_close_many(&tmp_head);
12229+
lock_count = lock_depth;
12230+
list_splice_tail(&tmp_head, &done_head);
12231+
}
12232+
}
12233+
12234+
unregister_netdevice_close_many(head);
12235+
12236+
list_for_each_entry_safe_reverse(dev, tmp, &done_head, unreg_list)
12237+
list_move(&dev->unreg_list, head);
12238+
#else
12239+
unregister_netdevice_close_many(head);
12240+
#endif
12241+
}
12242+
1221112243
void unregister_netdevice_many_notify(struct list_head *head,
1221212244
u32 portid, const struct nlmsghdr *nlh)
1221312245
{
@@ -12237,7 +12269,7 @@ void unregister_netdevice_many_notify(struct list_head *head,
1223712269
BUG_ON(dev->reg_state != NETREG_REGISTERED);
1223812270
}
1223912271

12240-
unregister_netdevice_close_many(head);
12272+
unregister_netdevice_close_many_lockdep(head);
1224112273

1224212274
flush_all_backlogs();
1224312275

0 commit comments

Comments
 (0)