Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'dev-hold-per-netns-rtnl-in-register-netdev'

Kuniyuki Iwashima says:

====================
dev: Hold per-netns RTNL in register_netdev().

Patch 1 adds rtnl_net_lock_killable() and Patch 2 uses it in
register_netdev() and converts it and unregister_netdev() to
per-netns RTNL.

With this and the netdev notifier series [0], ASSERT_RTNL_NET()
for NETDEV_REGISTER [1] wasn't fired on a simplest QEMU setup
like e1000 + x86_64_defconfig + CONFIG_DEBUG_NET_SMALL_RTNL.

[0]: https://lore.kernel.org/netdev/20250104063735.36945-1-kuniyu@amazon.com/

[1]:
---8<---
diff --git a/net/core/rtnl_net_debug.c b/net/core/rtnl_net_debug.c
index f406045cbd0e..c0c30929002e 100644
--- a/net/core/rtnl_net_debug.c
+++ b/net/core/rtnl_net_debug.c
@@ -21,7 +21,6 @@ static int rtnl_net_debug_event(struct notifier_block *nb,
case NETDEV_DOWN:
case NETDEV_REBOOT:
case NETDEV_CHANGE:
- case NETDEV_REGISTER:
case NETDEV_UNREGISTER:
case NETDEV_CHANGEMTU:
case NETDEV_CHANGEADDR:
@@ -60,19 +59,10 @@ static int rtnl_net_debug_event(struct notifier_block *nb,
ASSERT_RTNL();
break;

- /* Once an event fully supports RTNL_NET, move it here
- * and remove "if (0)" below.
- *
- * case NETDEV_XXX:
- * ASSERT_RTNL_NET(net);
- * break;
- */
- }
-
- /* Just to avoid unused-variable error for dev and net. */
- if (0)
+ case NETDEV_REGISTER:
ASSERT_RTNL_NET(net);
+ break;
+ }

return NOTIFY_DONE;
}
---8<---
====================

Link: https://patch.msgid.link/20250104082149.48493-1-kuniyu@amazon.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

+26 -5
+6
include/linux/rtnetlink.h
··· 102 102 void rtnl_net_lock(struct net *net); 103 103 void rtnl_net_unlock(struct net *net); 104 104 int rtnl_net_trylock(struct net *net); 105 + int rtnl_net_lock_killable(struct net *net); 105 106 int rtnl_net_lock_cmp_fn(const struct lockdep_map *a, const struct lockdep_map *b); 106 107 107 108 bool rtnl_net_is_locked(struct net *net); ··· 137 136 static inline int rtnl_net_trylock(struct net *net) 138 137 { 139 138 return rtnl_trylock(); 139 + } 140 + 141 + static inline int rtnl_net_lock_killable(struct net *net) 142 + { 143 + return rtnl_lock_killable(); 140 144 } 141 145 142 146 static inline void ASSERT_RTNL_NET(struct net *net)
+10 -4
net/core/dev.c
··· 10731 10731 */ 10732 10732 int register_netdev(struct net_device *dev) 10733 10733 { 10734 + struct net *net = dev_net(dev); 10734 10735 int err; 10735 10736 10736 - if (rtnl_lock_killable()) 10737 + if (rtnl_net_lock_killable(net)) 10737 10738 return -EINTR; 10739 + 10738 10740 err = register_netdevice(dev); 10739 - rtnl_unlock(); 10741 + 10742 + rtnl_net_unlock(net); 10743 + 10740 10744 return err; 10741 10745 } 10742 10746 EXPORT_SYMBOL(register_netdev); ··· 11610 11606 */ 11611 11607 void unregister_netdev(struct net_device *dev) 11612 11608 { 11613 - rtnl_lock(); 11609 + struct net *net = dev_net(dev); 11610 + 11611 + rtnl_net_lock(net); 11614 11612 unregister_netdevice(dev); 11615 - rtnl_unlock(); 11613 + rtnl_net_unlock(net); 11616 11614 } 11617 11615 EXPORT_SYMBOL(unregister_netdev); 11618 11616
+10 -1
net/core/rtnetlink.c
··· 84 84 { 85 85 return mutex_lock_killable(&rtnl_mutex); 86 86 } 87 - EXPORT_SYMBOL(rtnl_lock_killable); 88 87 89 88 static struct sk_buff *defer_kfree_skb_list; 90 89 void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail) ··· 219 220 return ret; 220 221 } 221 222 EXPORT_SYMBOL(rtnl_net_trylock); 223 + 224 + int rtnl_net_lock_killable(struct net *net) 225 + { 226 + int ret = rtnl_lock_killable(); 227 + 228 + if (!ret) 229 + __rtnl_net_lock(net); 230 + 231 + return ret; 232 + } 222 233 223 234 static int rtnl_net_cmp_locks(const struct net *net_a, const struct net *net_b) 224 235 {