xfrm: interface: use exit_batch_rtnl() method
authorEric Dumazet <edumazet@google.com>
Tue, 6 Feb 2024 14:43:12 +0000 (14:43 +0000)
committerJakub Kicinski <kuba@kernel.org>
Thu, 8 Feb 2024 02:55:12 +0000 (18:55 -0800)
exit_batch_rtnl() is called while RTNL is held,
and devices to be unregistered can be queued in the dev_kill_list.

This saves one rtnl_lock()/rtnl_unlock() pair per netns
and one unregister_netdevice_many() call.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Antoine Tenart <atenart@kernel.org>
Link: https://lore.kernel.org/r/20240206144313.2050392-17-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/xfrm/xfrm_interface_core.c

index 21d50d75c26088063538d9b9da5cba93db181a1f..dafefef3cf51a79fd6701a8b78c3f8fcfd10615d 100644 (file)
@@ -957,12 +957,12 @@ static struct rtnl_link_ops xfrmi_link_ops __read_mostly = {
        .get_link_net   = xfrmi_get_link_net,
 };
 
-static void __net_exit xfrmi_exit_batch_net(struct list_head *net_exit_list)
+static void __net_exit xfrmi_exit_batch_rtnl(struct list_head *net_exit_list,
+                                            struct list_head *dev_to_kill)
 {
        struct net *net;
-       LIST_HEAD(list);
 
-       rtnl_lock();
+       ASSERT_RTNL();
        list_for_each_entry(net, net_exit_list, exit_list) {
                struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
                struct xfrm_if __rcu **xip;
@@ -973,18 +973,16 @@ static void __net_exit xfrmi_exit_batch_net(struct list_head *net_exit_list)
                        for (xip = &xfrmn->xfrmi[i];
                             (xi = rtnl_dereference(*xip)) != NULL;
                             xip = &xi->next)
-                               unregister_netdevice_queue(xi->dev, &list);
+                               unregister_netdevice_queue(xi->dev, dev_to_kill);
                }
                xi = rtnl_dereference(xfrmn->collect_md_xfrmi);
                if (xi)
-                       unregister_netdevice_queue(xi->dev, &list);
+                       unregister_netdevice_queue(xi->dev, dev_to_kill);
        }
-       unregister_netdevice_many(&list);
-       rtnl_unlock();
 }
 
 static struct pernet_operations xfrmi_net_ops = {
-       .exit_batch = xfrmi_exit_batch_net,
+       .exit_batch_rtnl = xfrmi_exit_batch_rtnl,
        .id   = &xfrmi_net_id,
        .size = sizeof(struct xfrmi_net),
 };