Commit 9b5b3637 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

ip_tunnel: use exit_batch_rtnl() method

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.

This patch takes care of ipip, ip_vti, and ip_gre tunnels.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarAntoine Tenart <atenart@kernel.org>
Link: https://lore.kernel.org/r/20240206144313.2050392-15-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent de02deab
...@@ -284,7 +284,8 @@ int ip_tunnel_init_net(struct net *net, unsigned int ip_tnl_net_id, ...@@ -284,7 +284,8 @@ int ip_tunnel_init_net(struct net *net, unsigned int ip_tnl_net_id,
struct rtnl_link_ops *ops, char *devname); struct rtnl_link_ops *ops, char *devname);
void ip_tunnel_delete_nets(struct list_head *list_net, unsigned int id, void ip_tunnel_delete_nets(struct list_head *list_net, unsigned int id,
struct rtnl_link_ops *ops); struct rtnl_link_ops *ops,
struct list_head *dev_to_kill);
void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
const struct iphdr *tnl_params, const u8 protocol); const struct iphdr *tnl_params, const u8 protocol);
......
...@@ -1025,14 +1025,16 @@ static int __net_init ipgre_init_net(struct net *net) ...@@ -1025,14 +1025,16 @@ static int __net_init ipgre_init_net(struct net *net)
return ip_tunnel_init_net(net, ipgre_net_id, &ipgre_link_ops, NULL); return ip_tunnel_init_net(net, ipgre_net_id, &ipgre_link_ops, NULL);
} }
static void __net_exit ipgre_exit_batch_net(struct list_head *list_net) static void __net_exit ipgre_exit_batch_rtnl(struct list_head *list_net,
struct list_head *dev_to_kill)
{ {
ip_tunnel_delete_nets(list_net, ipgre_net_id, &ipgre_link_ops); ip_tunnel_delete_nets(list_net, ipgre_net_id, &ipgre_link_ops,
dev_to_kill);
} }
static struct pernet_operations ipgre_net_ops = { static struct pernet_operations ipgre_net_ops = {
.init = ipgre_init_net, .init = ipgre_init_net,
.exit_batch = ipgre_exit_batch_net, .exit_batch_rtnl = ipgre_exit_batch_rtnl,
.id = &ipgre_net_id, .id = &ipgre_net_id,
.size = sizeof(struct ip_tunnel_net), .size = sizeof(struct ip_tunnel_net),
}; };
...@@ -1697,14 +1699,16 @@ static int __net_init ipgre_tap_init_net(struct net *net) ...@@ -1697,14 +1699,16 @@ static int __net_init ipgre_tap_init_net(struct net *net)
return ip_tunnel_init_net(net, gre_tap_net_id, &ipgre_tap_ops, "gretap0"); return ip_tunnel_init_net(net, gre_tap_net_id, &ipgre_tap_ops, "gretap0");
} }
static void __net_exit ipgre_tap_exit_batch_net(struct list_head *list_net) static void __net_exit ipgre_tap_exit_batch_rtnl(struct list_head *list_net,
struct list_head *dev_to_kill)
{ {
ip_tunnel_delete_nets(list_net, gre_tap_net_id, &ipgre_tap_ops); ip_tunnel_delete_nets(list_net, gre_tap_net_id, &ipgre_tap_ops,
dev_to_kill);
} }
static struct pernet_operations ipgre_tap_net_ops = { static struct pernet_operations ipgre_tap_net_ops = {
.init = ipgre_tap_init_net, .init = ipgre_tap_init_net,
.exit_batch = ipgre_tap_exit_batch_net, .exit_batch_rtnl = ipgre_tap_exit_batch_rtnl,
.id = &gre_tap_net_id, .id = &gre_tap_net_id,
.size = sizeof(struct ip_tunnel_net), .size = sizeof(struct ip_tunnel_net),
}; };
...@@ -1715,14 +1719,16 @@ static int __net_init erspan_init_net(struct net *net) ...@@ -1715,14 +1719,16 @@ static int __net_init erspan_init_net(struct net *net)
&erspan_link_ops, "erspan0"); &erspan_link_ops, "erspan0");
} }
static void __net_exit erspan_exit_batch_net(struct list_head *net_list) static void __net_exit erspan_exit_batch_rtnl(struct list_head *net_list,
struct list_head *dev_to_kill)
{ {
ip_tunnel_delete_nets(net_list, erspan_net_id, &erspan_link_ops); ip_tunnel_delete_nets(net_list, erspan_net_id, &erspan_link_ops,
dev_to_kill);
} }
static struct pernet_operations erspan_net_ops = { static struct pernet_operations erspan_net_ops = {
.init = erspan_init_net, .init = erspan_init_net,
.exit_batch = erspan_exit_batch_net, .exit_batch_rtnl = erspan_exit_batch_rtnl,
.id = &erspan_net_id, .id = &erspan_net_id,
.size = sizeof(struct ip_tunnel_net), .size = sizeof(struct ip_tunnel_net),
}; };
......
...@@ -1130,19 +1130,17 @@ static void ip_tunnel_destroy(struct net *net, struct ip_tunnel_net *itn, ...@@ -1130,19 +1130,17 @@ static void ip_tunnel_destroy(struct net *net, struct ip_tunnel_net *itn,
} }
void ip_tunnel_delete_nets(struct list_head *net_list, unsigned int id, void ip_tunnel_delete_nets(struct list_head *net_list, unsigned int id,
struct rtnl_link_ops *ops) struct rtnl_link_ops *ops,
struct list_head *dev_to_kill)
{ {
struct ip_tunnel_net *itn; struct ip_tunnel_net *itn;
struct net *net; struct net *net;
LIST_HEAD(list);
rtnl_lock(); ASSERT_RTNL();
list_for_each_entry(net, net_list, exit_list) { list_for_each_entry(net, net_list, exit_list) {
itn = net_generic(net, id); itn = net_generic(net, id);
ip_tunnel_destroy(net, itn, &list, ops); ip_tunnel_destroy(net, itn, dev_to_kill, ops);
} }
unregister_netdevice_many(&list);
rtnl_unlock();
} }
EXPORT_SYMBOL_GPL(ip_tunnel_delete_nets); EXPORT_SYMBOL_GPL(ip_tunnel_delete_nets);
......
...@@ -510,14 +510,16 @@ static int __net_init vti_init_net(struct net *net) ...@@ -510,14 +510,16 @@ static int __net_init vti_init_net(struct net *net)
return 0; return 0;
} }
static void __net_exit vti_exit_batch_net(struct list_head *list_net) static void __net_exit vti_exit_batch_rtnl(struct list_head *list_net,
struct list_head *dev_to_kill)
{ {
ip_tunnel_delete_nets(list_net, vti_net_id, &vti_link_ops); ip_tunnel_delete_nets(list_net, vti_net_id, &vti_link_ops,
dev_to_kill);
} }
static struct pernet_operations vti_net_ops = { static struct pernet_operations vti_net_ops = {
.init = vti_init_net, .init = vti_init_net,
.exit_batch = vti_exit_batch_net, .exit_batch_rtnl = vti_exit_batch_rtnl,
.id = &vti_net_id, .id = &vti_net_id,
.size = sizeof(struct ip_tunnel_net), .size = sizeof(struct ip_tunnel_net),
}; };
......
...@@ -592,14 +592,16 @@ static int __net_init ipip_init_net(struct net *net) ...@@ -592,14 +592,16 @@ static int __net_init ipip_init_net(struct net *net)
return ip_tunnel_init_net(net, ipip_net_id, &ipip_link_ops, "tunl0"); return ip_tunnel_init_net(net, ipip_net_id, &ipip_link_ops, "tunl0");
} }
static void __net_exit ipip_exit_batch_net(struct list_head *list_net) static void __net_exit ipip_exit_batch_rtnl(struct list_head *list_net,
struct list_head *dev_to_kill)
{ {
ip_tunnel_delete_nets(list_net, ipip_net_id, &ipip_link_ops); ip_tunnel_delete_nets(list_net, ipip_net_id, &ipip_link_ops,
dev_to_kill);
} }
static struct pernet_operations ipip_net_ops = { static struct pernet_operations ipip_net_ops = {
.init = ipip_init_net, .init = ipip_init_net,
.exit_batch = ipip_exit_batch_net, .exit_batch_rtnl = ipip_exit_batch_rtnl,
.id = &ipip_net_id, .id = &ipip_net_id,
.size = sizeof(struct ip_tunnel_net), .size = sizeof(struct ip_tunnel_net),
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment