Skip to contentSkip to conversation

rtnetlink: do not use RTNL in rtnl_af_register() and rtnl_af_unregister()

PATCH Applied Eric Dumazet 3 participants 3 messages May 21 – May 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtnetlink: do not use RTNL in rtnl_af_register() and rtnl_af_unregister()

rtnl_af_lookup() does not rely on RTNL anymoe, remove the stale ASSERT_RTNL().

Add a private spinlock (rtnl_af_ops_lock) to protect rtnl_af_ops list instead of using RTNL.

---
 net/core/rtnetlink.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
net/core/rtnetlink.c +5 -6
index d64600aa8adfe9ce7a0c45677ae36db73ee3d886..d1edb1aeb0ce8d9c42c788f632cd2a654d7f9c7c 100644
@@ -750,13 +750,12 @@ static size_t rtnl_link_get_size(const struct net_device *dev)
 }
 
 static LIST_HEAD(rtnl_af_ops);
+static DEFINE_SPINLOCK(rtnl_af_ops_lock);
 
 static struct rtnl_af_ops *rtnl_af_lookup(const int family, int *srcu_index)
 {
 	struct rtnl_af_ops *ops;
 
-	ASSERT_RTNL();
-
 	rcu_read_lock();
 
 	list_for_each_entry_rcu(ops, &rtnl_af_ops, list) {
@@ -791,9 +790,9 @@ int rtnl_af_register(struct rtnl_af_ops *ops)
 	if (err)
 		return err;
 
-	rtnl_lock();
+	spin_lock(&rtnl_af_ops_lock);
 	list_add_tail_rcu(&ops->list, &rtnl_af_ops);
-	rtnl_unlock();
+	spin_unlock(&rtnl_af_ops_lock);
 
 	return 0;
 }
@@ -805,9 +804,9 @@ EXPORT_SYMBOL_GPL(rtnl_af_register);
  */
 void rtnl_af_unregister(struct rtnl_af_ops *ops)
 {
-	rtnl_lock();
+	spin_lock(&rtnl_af_ops_lock);
 	list_del_rcu(&ops->list);
-	rtnl_unlock();
+	spin_unlock(&rtnl_af_ops_lock);
 
 	synchronize_rcu();
 	synchronize_srcu(&ops->srcu);
Signature · 1 line
2.54.0.746.g67dd491aae-goog
#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Thu, 21 May 2026 17:40:38 +0000 you wrote:

rtnl_af_lookup() does not rely on RTNL anymoe, remove the stale ASSERT_RTNL().

Add a private spinlock (rtnl_af_ops_lock) to protect rtnl_af_ops list instead of using RTNL.

[...]

Here is the summary with links:
- [net-next] rtnetlink: do not use RTNL in rtnl_af_register() and rtnl_af_unregister()

    https://git.kernel.org/netdev/net-next/c/b8de39a06535

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html