ip6mr_net_ops uses ->exit_batch() to acquire RTNL only once for dying network namespaces. ip6mr does not depend on the ordering of ->exit_rtnl() and ->exit_batch() of other pernet_operations (unlike fib_net_ops). Once ip6mr_free_table() is called and all devices are queued for destruction in ->exit_rtnl(), later during NETDEV_UNREGISTER, ip6mr_device_event() will not see anything in vif table and just do nothing. Let's convert ip6mr_net_exit_batch() to ->exit_rtnl(). Note that fib_rules_unregister() does not need RTNL and we will remove RTNL and unregister_netdevice_many() in ip6mr_rules_init(). Signed-off-by: Kuniyuki Iwashima --- net/ipv6/ip6mr.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 30e1aece5f53..2220a2049781 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -272,18 +272,17 @@ static int __net_init ip6mr_rules_init(struct net *net) return err; } -static void __net_exit ip6mr_rules_exit(struct net *net) +static void __net_exit ip6mr_rules_exit_rtnl(struct net *net, + struct list_head *dev_kill_list) { struct mr_table *mrt, *next; - LIST_HEAD(dev_kill_list); ASSERT_RTNL(); list_for_each_entry_safe(mrt, next, &net->ipv6.mr6_tables, list) { list_del(&mrt->list); - ip6mr_free_table(mrt, &dev_kill_list); + ip6mr_free_table(mrt, dev_kill_list); } - unregister_netdevice_many(&dev_kill_list); fib_rules_unregister(net->ipv6.mr6_rules_ops); } @@ -341,13 +340,11 @@ static int __net_init ip6mr_rules_init(struct net *net) return 0; } -static void __net_exit ip6mr_rules_exit(struct net *net) +static void __net_exit ip6mr_rules_exit_rtnl(struct net *net, + struct list_head *dev_kill_list) { - LIST_HEAD(dev_kill_list); - ASSERT_RTNL(); - ip6mr_free_table(net->ipv6.mrt6, &dev_kill_list); - unregister_netdevice_many(&dev_kill_list); + ip6mr_free_table(net->ipv6.mrt6, dev_kill_list); net->ipv6.mrt6 = NULL; } @@ -1340,6 +1337,7 @@ static void __net_exit ip6mr_notifier_exit(struct net *net) /* Setup for IP multicast routing */ static int __net_init ip6mr_net_init(struct net *net) { + LIST_HEAD(dev_kill_list); int err; err = ip6mr_notifier_init(net); @@ -1367,7 +1365,8 @@ static int __net_init ip6mr_net_init(struct net *net) remove_proc_entry("ip6_mr_vif", net->proc_net); proc_vif_fail: rtnl_lock(); - ip6mr_rules_exit(net); + ip6mr_rules_exit_rtnl(net, &dev_kill_list); + unregister_netdevice_many(&dev_kill_list); rtnl_unlock(); #endif ip6mr_rules_fail: @@ -1384,20 +1383,16 @@ static void __net_exit ip6mr_net_exit(struct net *net) ip6mr_notifier_exit(net); } -static void __net_exit ip6mr_net_exit_batch(struct list_head *net_list) +static void __net_exit ip6mr_net_exit_rtnl(struct net *net, + struct list_head *dev_kill_list) { - struct net *net; - - rtnl_lock(); - list_for_each_entry(net, net_list, exit_list) - ip6mr_rules_exit(net); - rtnl_unlock(); + ip6mr_rules_exit_rtnl(net, dev_kill_list); } static struct pernet_operations ip6mr_net_ops = { .init = ip6mr_net_init, .exit = ip6mr_net_exit, - .exit_batch = ip6mr_net_exit_batch, + .exit_rtnl = ip6mr_net_exit_rtnl, }; static const struct rtnl_msg_handler ip6mr_rtnl_msg_handlers[] __initconst_or_module = { -- 2.53.0.1213.gd9a14994de-goog