Skip to contentSkip to conversation

rtnetlink: Use register_pernet_subsys() in rtnl_net_debug_init().

PATCH Superseded Kuniyuki Iwashima 2 participants 3 messages Mar 28, 2025 – Mar 31, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtnetlink: Use register_pernet_subsys() in rtnl_net_debug_init().

rtnl_net_debug_init() registers rtnl_net_debug_net_ops by register_pernet_device() but calls unregister_pernet_subsys() in case register_netdevice_notifier() fails.

It corrupts pernet_list because first_device is not updated in unregister_pernet_device().

Let's fix it by calling register_pernet_subsys() instead.

The _subsys() one fits better for the use case because it keeps the notifier alive until default_device_exit_net(), giving it more chance to test NETDEV_UNREGISTER.

Fixes 03fa53485659 ("rtnetlink: Add ASSERT_RTNL_NET() placeholder for netdev notifier.")
---
 net/core/rtnl_net_debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/rtnl_net_debug.c +1 -1
index 7ecd28cc1c22..f3272b09c255 100644
@@ -102,7 +102,7 @@ static int __init rtnl_net_debug_init(void)
 {
 	int ret;
 
-	ret = register_pernet_device(&rtnl_net_debug_net_ops);
+	ret = register_pernet_subsys(&rtnl_net_debug_net_ops);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.48.1
reviewer
#1 lore raw
Quoted 6 lines · Kuniyuki Iwashima

rtnl_net_debug_init() registers rtnl_net_debug_net_ops by register_pernet_device() but calls unregister_pernet_subsys() in case register_netdevice_notifier() fails.

It corrupts pernet_list because first_device is not updated in unregister_pernet_device().

Hi Iwashima-san,

Maybe I am confused, but should the above line refer to unregister_pernet_subsys()?

And perhaps it would be yet clearer to say something like:

It corrupts pernet_list because first_device is not updated in register_pernet_device() but not unregister_pernet_subsys()?

Quoted 9 lines

Let's fix it by calling register_pernet_subsys() instead.

The _subsys() one fits better for the use case because it keeps the notifier alive until default_device_exit_net(), giving it more chance to test NETDEV_UNREGISTER.

Fixes 03fa53485659 ("rtnetlink: Add ASSERT_RTNL_NET() placeholder for netdev notifier.")

...

#2 lore raw

From: Simon Horman <[email protected]>
Date: Mon, 31 Mar 2025 16:48:49 +0100

Quoted 5 lines · Kuniyuki Iwashima
Quoted 4 lines

rtnl_net_debug_init() registers rtnl_net_debug_net_ops by register_pernet_device() but calls unregister_pernet_subsys() in case register_netdevice_notifier() fails.

Quoted 7 lines
Quoted 2 lines

It corrupts pernet_list because first_device is not updated in unregister_pernet_device().

Hi Iwashima-san,

Maybe I am confused, but should the above line refer to unregister_pernet_subsys()?

Ah, exactly :)

Quoted 5 lines

And perhaps it would be yet clearer to say something like:

It corrupts pernet_list because first_device is not updated in register_pernet_device() but not unregister_pernet_subsys()?

Will rewrite in v2.

Thanks!