geneve: use exit_batch_rtnl() method
authorEric Dumazet <edumazet@google.com>
Tue, 6 Feb 2024 14:43:02 +0000 (14:43 +0000)
committerJakub Kicinski <kuba@kernel.org>
Thu, 8 Feb 2024 02:55:11 +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,
and one unregister_netdevice_many() call.

Note: it should be possible to remove the synchronize_net()
call from geneve_sock_release() in a future patch.

v4: move WARN_ON_ONCE(!list_empty(&gn->sock_list))
   into geneve_exit_net(), after devices have been unregistered.
   (Antoine Tenart feedback)

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

index 32c51c244153bd760b9f58001906c04c8b0f37ff..23e97c2e4f6fcb90a8bbb117d7520397f560f15f 100644 (file)
@@ -1900,29 +1900,26 @@ static void geneve_destroy_tunnels(struct net *net, struct list_head *head)
        }
 }
 
-static void __net_exit geneve_exit_batch_net(struct list_head *net_list)
+static void __net_exit geneve_exit_batch_rtnl(struct list_head *net_list,
+                                             struct list_head *dev_to_kill)
 {
        struct net *net;
-       LIST_HEAD(list);
 
-       rtnl_lock();
        list_for_each_entry(net, net_list, exit_list)
-               geneve_destroy_tunnels(net, &list);
-
-       /* unregister the devices gathered above */
-       unregister_netdevice_many(&list);
-       rtnl_unlock();
+               geneve_destroy_tunnels(net, dev_to_kill);
+}
 
-       list_for_each_entry(net, net_list, exit_list) {
-               const struct geneve_net *gn = net_generic(net, geneve_net_id);
+static void __net_exit geneve_exit_net(struct net *net)
+{
+       const struct geneve_net *gn = net_generic(net, geneve_net_id);
 
-               WARN_ON_ONCE(!list_empty(&gn->sock_list));
-       }
+       WARN_ON_ONCE(!list_empty(&gn->sock_list));
 }
 
 static struct pernet_operations geneve_net_ops = {
        .init = geneve_init_net,
-       .exit_batch = geneve_exit_batch_net,
+       .exit_batch_rtnl = geneve_exit_batch_rtnl,
+       .exit = geneve_exit_net,
        .id   = &geneve_net_id,
        .size = sizeof(struct geneve_net),
 };