From 49c26d4bf1daa8ada5a2015646adbf7b1b716b8b Mon Sep 17 00:00:00 2001 From: Kuniyuki Iwashima Date: Fri, 3 Jul 2026 00:09:13 +0000 Subject: [PATCH] rtnetlink: Call unregister_netdevice_many() only once in rtnl_link_unregister(). When rtnl_link_unregister() is called during module unload, it calls __rtnl_kill_links() for every netns. __rtnl_kill_links() collects all devices of the unloaded module and passes them to unregister_netdevice_many(). Let's move unregister_netdevice_many() to rtnl_link_unregister() to unregister all devices across netns in a single batch. Signed-off-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260703001009.1572444-3-kuniyu@google.com Signed-off-by: Paolo Abeni --- net/core/rtnetlink.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index a5811b427680..c4528f5349a3 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -637,16 +637,15 @@ int rtnl_link_register(struct rtnl_link_ops *ops) } EXPORT_SYMBOL_GPL(rtnl_link_register); -static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops) +static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops, + struct list_head *dev_kill_list) { struct net_device *dev; - LIST_HEAD(list_kill); for_each_netdev(net, dev) { if (dev->rtnl_link_ops == ops) - ops->dellink(dev, &list_kill); + ops->dellink(dev, dev_kill_list); } - unregister_netdevice_many(&list_kill); } /* Return with the rtnl_lock held when there are no network @@ -677,6 +676,7 @@ static void rtnl_lock_unregistering_all(void) */ void rtnl_link_unregister(struct rtnl_link_ops *ops) { + LIST_HEAD(dev_kill_list); struct net *net; mutex_lock(&link_ops_mutex); @@ -691,7 +691,9 @@ void rtnl_link_unregister(struct rtnl_link_ops *ops) rtnl_lock_unregistering_all(); for_each_net(net) - __rtnl_kill_links(net, ops); + __rtnl_kill_links(net, ops, &dev_kill_list); + + unregister_netdevice_many(&dev_kill_list); rtnl_unlock(); up_write(&pernet_ops_rwsem);