Skip to content

Commit cfa579f

Browse files
edumazetkuba-moo
authored andcommitted
net: no longer hold RTNL while calling flush_all_backlogs()
flush_all_backlogs() is called from unregister_netdevice_many_notify() as part of netdevice dismantles. This is currently called under RTNL, and can last up to 50 ms on busy hosts. There is no reason to hold RTNL at this stage, if our caller is cleanup_net() : netns are no more visible, devices are in NETREG_UNREGISTERING state and no other thread could mess our state while RTNL is temporarily released. In order to provide isolation, this patch provides a separate 'net_todo_list' for cleanup_net(). Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Jesse Brandeburg <jbrandeburg@cloudflare.com> Link: https://patch.msgid.link/20250114205531.967841-4-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 8a2b61e commit cfa579f

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

net/core/dev.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10124,14 +10124,37 @@ static bool from_cleanup_net(void)
1012410124
#endif
1012510125
}
1012610126

10127+
static void rtnl_drop_if_cleanup_net(void)
10128+
{
10129+
if (from_cleanup_net())
10130+
__rtnl_unlock();
10131+
}
10132+
10133+
static void rtnl_acquire_if_cleanup_net(void)
10134+
{
10135+
if (from_cleanup_net())
10136+
rtnl_lock();
10137+
}
10138+
1012710139
/* Delayed registration/unregisteration */
1012810140
LIST_HEAD(net_todo_list);
10141+
static LIST_HEAD(net_todo_list_for_cleanup_net);
10142+
10143+
/* TODO: net_todo_list/net_todo_list_for_cleanup_net should probably
10144+
* be provided by callers, instead of being static, rtnl protected.
10145+
*/
10146+
static struct list_head *todo_list(void)
10147+
{
10148+
return from_cleanup_net() ? &net_todo_list_for_cleanup_net :
10149+
&net_todo_list;
10150+
}
10151+
1012910152
DECLARE_WAIT_QUEUE_HEAD(netdev_unregistering_wq);
1013010153
atomic_t dev_unreg_count = ATOMIC_INIT(0);
1013110154

1013210155
static void net_set_todo(struct net_device *dev)
1013310156
{
10134-
list_add_tail(&dev->todo_list, &net_todo_list);
10157+
list_add_tail(&dev->todo_list, todo_list());
1013510158
}
1013610159

1013710160
static netdev_features_t netdev_sync_upper_features(struct net_device *lower,
@@ -10979,7 +11002,7 @@ void netdev_run_todo(void)
1097911002
#endif
1098011003

1098111004
/* Snapshot list, allow later requests */
10982-
list_replace_init(&net_todo_list, &list);
11005+
list_replace_init(todo_list(), &list);
1098311006

1098411007
__rtnl_unlock();
1098511008

@@ -11602,8 +11625,10 @@ void unregister_netdevice_many_notify(struct list_head *head,
1160211625
unlist_netdevice(dev);
1160311626
WRITE_ONCE(dev->reg_state, NETREG_UNREGISTERING);
1160411627
}
11605-
flush_all_backlogs();
1160611628

11629+
rtnl_drop_if_cleanup_net();
11630+
flush_all_backlogs();
11631+
rtnl_acquire_if_cleanup_net();
1160711632
synchronize_net();
1160811633

1160911634
list_for_each_entry(dev, head, unreg_list) {

0 commit comments

Comments
 (0)