Skip to contentSkip to conversation

ipv6: reorder ip6_route_dev_notifier after ipv6_dev_notf

PATCH Superseded Cong Wang 2 participants 4 messages May 4, 2017

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 ipv6: reorder ip6_route_dev_notifier after ipv6_dev_notf

For each netns (except init_net), we initialize its null entry in 3 places:

1) The template itself, as we use kmemdup()
2) Code around dst_init_metrics() in ip6_route_net_init()
3) ip6_route_dev_notify(), which is supposed to initialize it after loopback registers

Unfortunately the last one still happens in a wrong order because we expect to initialize net->ipv6.ip6_null_entry->rt6i_idev to net->loopback_dev's idev, so we have to do that after we add idev to it. However, this notifier has priority == 0 same as ipv6_dev_notf, and ipv6_dev_notf is registered after ip6_route_dev_notifier so it is called actually after ip6_route_dev_notifier.

Fix it by specifying a smaller priority for ip6_route_dev_notifier.

---
 net/ipv6/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
index 2f11366..4dbf7e2 100644
@@ -4024,7 +4024,7 @@ static struct pernet_operations ip6_route_net_late_ops = {
 
 static struct notifier_block ip6_route_dev_notifier = {
 	.notifier_call = ip6_route_dev_notify,
-	.priority = 0,
+	.priority = -10, /* Must be called after addrconf_notify!! */
 };
 
 void __init ip6_route_init_special_entries(void)
Signature · 1 line
2.5.5
#1 lore raw
Quoted 6 lines · Cong Wang
net/ipv6/route.c +0 -0
index 2f11366..4dbf7e2 100644

net/ipv6/route.c static struct pernet_operations ip6_route_net_late_ops = { · line 4030

Quoted 8 lines
net/ipv6/route.c +1 -1
@@ -4024,7 +4024,7 @@ static struct pernet_operations ip6_route_net_late_ops = {
 
 static struct notifier_block ip6_route_dev_notifier = {
 	.notifier_call = ip6_route_dev_notify,
-	.priority = 0,
+	.priority = -10, /* Must be called after addrconf_notify!! */
 };
 
 void __init ip6_route_init_special_entries(void)

That should be codified such that if someone changes the priority of the addrconf notifier, it fixes up the route notifier as well. e.g.,

include/net/addrconf.h +2 -0
index 1aeb25dd42a7..6c0ee3ccbe0f 100644
@@ -20,6 +20,8 @@
 #define ADDRCONF_TIMER_FUZZ            (HZ / 4)
 #define ADDRCONF_TIMER_FUZZ_MAX                (HZ)
+#define ADDRCONF_NOTIFY_PRIORITY       0
+
 #include <linux/in.h>
 #include <linux/in6.h>
 
net/ipv6/addrconf.c +0 -0
index a2a370b71249..7a4e6b2996a1 100644
@@ -3548,6 +3548,7 @@ static int addrconf_notify(struct notifier_block

*this, unsigned long event,
*/
static struct notifier_block ipv6_dev_notf = {
.notifier_call = addrconf_notify,
+ .priority = ADDRCONF_NOTIFY_PRIORITY,
};

static void addrconf_type_change(struct net_device *dev, unsigned long
event)

net/ipv6/route.c +0 -0
index a1bf426c959b..e0d83f8bc01a 100644
@@ -4024,7 +4024,7 @@ static struct pernet_operations

ip6_route_net_late_ops = {

static struct notifier_block ip6_route_dev_notifier = {
.notifier_call = ip6_route_dev_notify,
- .priority = 0,
+ .priority = ADDRCONF_NOTIFY_PRIORITY - 10,
};

And you marked this as a patch for net; I think this should go into net-next.

#2 lore raw
In reply to Cong Wang
Quoted 29 lines · Cong Wang

For each netns (except init_net), we initialize its null entry in 3 places:

1) The template itself, as we use kmemdup()
2) Code around dst_init_metrics() in ip6_route_net_init()
3) ip6_route_dev_notify(), which is supposed to initialize it after loopback registers

Unfortunately the last one still happens in a wrong order because we expect to initialize net->ipv6.ip6_null_entry->rt6i_idev to net->loopback_dev's idev, so we have to do that after we add idev to it. However, this notifier has priority == 0 same as ipv6_dev_notf, and ipv6_dev_notf is registered after ip6_route_dev_notifier so it is called actually after ip6_route_dev_notifier.

Fix it by specifying a smaller priority for ip6_route_dev_notifier.

---
 net/ipv6/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +0 -0
index 2f11366..4dbf7e2 100644

net/ipv6/route.c static struct pernet_operations ip6_route_net_late_ops = { · line 4030

Quoted 8 lines
net/ipv6/route.c +1 -1
@@ -4024,7 +4024,7 @@ static struct pernet_operations ip6_route_net_late_ops = {
 
 static struct notifier_block ip6_route_dev_notifier = {
 	.notifier_call = ip6_route_dev_notify,
-	.priority = 0,
+	.priority = -10, /* Must be called after addrconf_notify!! */
 };
 
 void __init ip6_route_init_special_entries(void)

And I see a refcnt problem with this change:

root@kenny-jessie2:~# unshare -n
root@kenny-jessie2:~# logout
root@kenny-jessie2:~# unshare -n

Message from syslogd@kenny-jessie2 at May 4 07:04:38 ...
kernel:[ 62.581552] unregister_netdevice: waiting for lo to become
free. Usage count = 1

author
#3 lore raw
Quoted 41 lines · David Ahern
Quoted 29 lines · Cong Wang

For each netns (except init_net), we initialize its null entry in 3 places:

1) The template itself, as we use kmemdup()
2) Code around dst_init_metrics() in ip6_route_net_init()
3) ip6_route_dev_notify(), which is supposed to initialize it after loopback registers

Unfortunately the last one still happens in a wrong order because we expect to initialize net->ipv6.ip6_null_entry->rt6i_idev to net->loopback_dev's idev, so we have to do that after we add idev to it. However, this notifier has priority == 0 same as ipv6_dev_notf, and ipv6_dev_notf is registered after ip6_route_dev_notifier so it is called actually after ip6_route_dev_notifier.

Fix it by specifying a smaller priority for ip6_route_dev_notifier.

---
 net/ipv6/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +0 -0
index 2f11366..4dbf7e2 100644

net/ipv6/route.c static struct pernet_operations ip6_route_net_late_ops = { · line 4030

Quoted 8 lines
net/ipv6/route.c +1 -1
@@ -4024,7 +4024,7 @@ static struct pernet_operations ip6_route_net_late_ops = {
 
 static struct notifier_block ip6_route_dev_notifier = {
      .notifier_call = ip6_route_dev_notify,
-     .priority = 0,
+     .priority = -10, /* Must be called after addrconf_notify!! */
 };
 
 void __init ip6_route_init_special_entries(void)

And I see a refcnt problem with this change:

Quoted 7 lines
root@kenny-jessie2:~# unshare -n
root@kenny-jessie2:~# logout
root@kenny-jessie2:~# unshare -n

Message from syslogd@kenny-jessie2 at May 4 07:04:38 ...
kernel:[ 62.581552] unregister_netdevice: waiting for lo to become
free. Usage count = 1

Ah, looks like we need to put the refcnt for UNREGISTER too.

Will send v2 to include your ADDRCONF_NOTIFY_PRIORITY suggestion.