ip6_gre: Support per-netns device unregistration.

ip6gre_exit_rtnl_net() iterates ip6gre devices and variants whose
link_net is dying and queues them for destruction.

The devices may reside in different netns.

Let's use unregister_netdevice_queue_net() to support per-netns
device unregistration.

Even after ip6gre_exit_rtnl_net() queues a cross-netns ip6gre
device, ip6gre_changelink_common(), ip6gre_dellink(), and
ip6gre_tunnel_siocdevprivate() could be called concurrently for
it (once RTNL is removed).  In such a case, __rtnl_net_unlock()
will perform the unregistration.

Also, ip6gre_tunnel_siocdevprivate() needs to check check_net(t->net),
otherwise it could create a new dev in dying netns after
ip6gre_exit_rtnl_net().

In the example below, we can see the fallback tunnel device
(ip6gre0) and the cross-netns device (ip6gre1) are unregistered
by different processes:

  # bpftrace -e '#include <linux/netdevice.h>
  kprobe:ip6gre_tunnel_uninit {
      $dev = (struct net_device *)arg0;
      printf("PID: %d | DEV: %s%s\n", pid, $dev->name, kstack());
  }
  kprobe:ip6gre_exit_rtnl_net {
      printf("PID: %d%s\n", pid, kstack());
  }' &
  # ip netns add ns1
  # ip netns add ns2
  # ip -n ns1 link add name ip6gre1 link-netns ns2 \
    type ip6gre local 2001:9292::1 remote 2001:9292::2
  # ip netns del ns2

  PID: 12
          ip6gre_exit_rtnl_net+5
          ops_undo_list+702
          cleanup_net+1122
  ...
  PID: 12 | DEV: ip6gre0  <------ fallback device (itn->fb_tunnel_dev).
          ip6gre_tunnel_uninit+5
          unregister_netdevice_many_notify+7137
          unregister_netdevice_many_net+1050
          __rtnl_net_unlock+37
          ops_undo_list+754
          cleanup_net+1122
  ...
  PID: 10 | DEV: ip6gre1
          ip6gre_tunnel_uninit+5
          unregister_netdevice_many_notify+7137
          unregister_netdevice_many_net+1050
          rtnl_net_work_func+136

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260916230353.367014-7-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Kuniyuki Iwashima 2026-09-16 23:02:25 +00:00 • committed by Jakub Kicinski
commit b27a8c6287