Skip to content

Commit

Permalink
net: no longer hold RTNL while calling flush_all_backlogs()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jesse Brandeburg <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
Eric Dumazet authored and kuba-moo committed Jan 16, 2025
1 parent 8a2b61e commit cfa579f
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -10124,14 +10124,37 @@ static bool from_cleanup_net(void)
#endif
}

static void rtnl_drop_if_cleanup_net(void)
{
if (from_cleanup_net())
__rtnl_unlock();
}

static void rtnl_acquire_if_cleanup_net(void)
{
if (from_cleanup_net())
rtnl_lock();
}

/* Delayed registration/unregisteration */
LIST_HEAD(net_todo_list);
static LIST_HEAD(net_todo_list_for_cleanup_net);

/* TODO: net_todo_list/net_todo_list_for_cleanup_net should probably
* be provided by callers, instead of being static, rtnl protected.
*/
static struct list_head *todo_list(void)
{
return from_cleanup_net() ? &net_todo_list_for_cleanup_net :
&net_todo_list;
}

DECLARE_WAIT_QUEUE_HEAD(netdev_unregistering_wq);
atomic_t dev_unreg_count = ATOMIC_INIT(0);

static void net_set_todo(struct net_device *dev)
{
list_add_tail(&dev->todo_list, &net_todo_list);
list_add_tail(&dev->todo_list, todo_list());
}

static netdev_features_t netdev_sync_upper_features(struct net_device *lower,
Expand Down Expand Up @@ -10979,7 +11002,7 @@ void netdev_run_todo(void)
#endif

/* Snapshot list, allow later requests */
list_replace_init(&net_todo_list, &list);
list_replace_init(todo_list(), &list);

__rtnl_unlock();

Expand Down Expand Up @@ -11602,8 +11625,10 @@ void unregister_netdevice_many_notify(struct list_head *head,
unlist_netdevice(dev);
WRITE_ONCE(dev->reg_state, NETREG_UNREGISTERING);
}
flush_all_backlogs();

rtnl_drop_if_cleanup_net();
flush_all_backlogs();
rtnl_acquire_if_cleanup_net();
synchronize_net();

list_for_each_entry(dev, head, unreg_list) {
Expand Down

0 comments on commit cfa579f

Please sign in to comment.