rtnl_link_unregister(), rtnl_af_unregister() and rtnl_unregister_all() wait for readers before tearing down what those readers use, but most of these waits 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 each wait that lacks one, naming the readers it waits for. Suggested-by: Eric Dumazet Link: https://lore.kernel.org/CAL4WiioFMQN4troVjQjCmE6Z9kwwb95SnoEupjD=PPSK6Q5f6w@mail.gmail.com Assisted-by: LLM Signed-off-by: Andrea Parri --- net/core/rtnetlink.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 15bffafbf0a9c..80f8577816760 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -526,6 +526,9 @@ void rtnl_unregister_all(int protocol) } rtnl_unlock(); + /* Wait for rtnl_get_link() callers under RCU that may still + * dereference tab. + */ synchronize_net(); kfree(tab); @@ -711,6 +714,7 @@ void rtnl_link_unregister(struct rtnl_link_ops *ops) * not yet taken ops->srcu. */ synchronize_rcu(); + /* Wait for rtnl_link_ops_get() callers to call rtnl_link_ops_put(). */ synchronize_srcu(&ops->srcu); cleanup_srcu_struct(&ops->srcu); @@ -843,7 +847,11 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops) list_del_rcu(&ops->list); spin_unlock(&rtnl_af_ops_lock); + /* Wait for RCU walkers of rtnl_af_ops, including rtnl_af_lookup() + * readers that found ops but have not yet taken ops->srcu. + */ synchronize_rcu(); + /* Wait for rtnl_af_lookup() callers to call rtnl_af_put(). */ synchronize_srcu(&ops->srcu); cleanup_srcu_struct(&ops->srcu); } -- 2.53.0