Skip to contentSkip to conversation

rtnetlink: comment the RCU waits in unregister paths

PATCH Applied Andrea Parri 3 participants 3 messages Oct 15 – Oct 20

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

PATCH v2 1/1 rtnetlink: comment the RCU waits in unregister paths

rtnl_unregister_all() and rtnl_af_unregister() wait for RCU readers before tearing down what those readers use, but do not say which readers they are waiting for.

A missing wait is then easy to overlook: rtnl_link_unregister() lacked its synchronize_rcu() until commit 3b70edea393d ("rtnetlink: wait for RCU readers in rtnl_link_unregister()"). Add a comment to both waits, naming the readers each one waits for.

---
v2:
- Drop the comments on synchronize_srcu(), its argument already names the readers (Kuniyuki)
- Name rtnetlink_rcv_msg() and try_module_get() in the rtnl_unregister_all() comment (Kuniyuki)
- Mention the rtnl_af_ops walkers that do not take ops->srcu in the rtnl_af_unregister() comment

v1: https://lore.kernel.org/[email protected]

 net/core/rtnetlink.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/core/rtnetlink.c +6 -0
index 15bffafbf0a9c..d73dbc2c8ba0d 100644
@@ -526,6 +526,9 @@ void rtnl_unregister_all(int protocol)
 	}
 	rtnl_unlock();
 
+	/* Wait for rtnl_get_link() calls that rtnetlink_rcv_msg() makes
+	 * under RCU, before try_module_get().
+	 */
 	synchronize_net();
 
 	kfree(tab);
@@ -843,6 +846,9 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops)
 	list_del_rcu(&ops->list);
 	spin_unlock(&rtnl_af_ops_lock);
 
+	/* Wait for rtnl_af_ops walkers that invoke callbacks without
+	 * ops->srcu, and for rtnl_af_lookup() readers not yet holding it.
+	 */
 	synchronize_rcu();
 	synchronize_srcu(&ops->srcu);
 	cleanup_srcu_struct(&ops->srcu);
Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Andrea Parri

rtnl_unregister_all() and rtnl_af_unregister() wait for RCU readers before tearing down what those readers use, but do not say which readers they are waiting for.

A missing wait is then easy to overlook: rtnl_link_unregister() lacked its synchronize_rcu() until commit 3b70edea393d ("rtnetlink: wait for RCU readers in rtnl_link_unregister()"). Add a comment to both waits, naming the readers each one waits for.

Quoted 4 lines
#2 lore raw
In reply to Andrea Parri
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

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

Quoted 10 lines · On Thu, 15 Oct 2026 10:17:16 +0200 you wrote:

rtnl_unregister_all() and rtnl_af_unregister() wait for RCU readers before tearing down what those readers use, but do not say which readers they are waiting for.

A missing wait is then easy to overlook: rtnl_link_unregister() lacked its synchronize_rcu() until commit 3b70edea393d ("rtnetlink: wait for RCU readers in rtnl_link_unregister()"). Add a comment to both waits, naming the readers each one waits for.

[...]

Here is the summary with links:
- [net-next,v2] rtnetlink: comment the RCU waits in unregister paths

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

You are awesome, thank you!

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