Message ID | 20220325225055.37e89a72f814.Ic73d206e217db20fd22dcec14fe5442ca732804b@changeid (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: ensure net_todo_list is processed quickly | expand |
On Fri, 25 Mar 2022 22:50:55 +0100 Johannes Berg wrote: > From: Johannes Berg <johannes.berg@intel.com> > > In [1], Will raised a potential issue that the cfg80211 code, > which does (from a locking perspective) LGTM, but I think we should defer this one a week and take it to net-next when it re-opens, after the merge window.
On Fri, 2022-03-25 at 14:58 -0700, Jakub Kicinski wrote: > On Fri, 25 Mar 2022 22:50:55 +0100 Johannes Berg wrote: > > From: Johannes Berg <johannes.berg@intel.com> > > > > In [1], Will raised a potential issue that the cfg80211 code, > > which does (from a locking perspective) > > LGTM, but I think we should defer this one a week and take it > to net-next when it re-opens, after the merge window. Yeah that makes sense. Do you want me to resend it then? johannes
On Fri, 25 Mar 2022 22:59:25 +0100 Johannes Berg wrote: > On Fri, 2022-03-25 at 14:58 -0700, Jakub Kicinski wrote: > > On Fri, 25 Mar 2022 22:50:55 +0100 Johannes Berg wrote: > > > From: Johannes Berg <johannes.berg@intel.com> > > > > > > In [1], Will raised a potential issue that the cfg80211 code, > > > which does (from a locking perspective) > > > > LGTM, but I think we should defer this one a week and take it > > to net-next when it re-opens, after the merge window. > > Yeah that makes sense. Do you want me to resend it then? Yes, please!
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 59e27a2b7bf0..b6a1e7f643da 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3894,7 +3894,8 @@ void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev); extern int netdev_budget; extern unsigned int netdev_budget_usecs; -/* Called by rtnetlink.c:rtnl_unlock() */ +/* Used by rtnetlink.c:__rtnl_unlock()/rtnl_unlock() */ +extern struct list_head net_todo_list; void netdev_run_todo(void); static inline void __dev_put(struct net_device *dev) diff --git a/net/core/dev.c b/net/core/dev.c index 8c6c08446556..2ec17358d7b4 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9431,7 +9431,7 @@ static int dev_new_index(struct net *net) } /* Delayed registration/unregisteration */ -static LIST_HEAD(net_todo_list); +LIST_HEAD(net_todo_list); DECLARE_WAIT_QUEUE_HEAD(netdev_unregistering_wq); static void net_set_todo(struct net_device *dev) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 159c9c61e6af..0e4502d641eb 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -95,6 +95,39 @@ void __rtnl_unlock(void) defer_kfree_skb_list = NULL; + /* Ensure that we didn't actually add any TODO item when __rtnl_unlock() + * is used. In some places, e.g. in cfg80211, we have code that will do + * something like + * rtnl_lock() + * wiphy_lock() + * ... + * rtnl_unlock() + * + * and because netdev_run_todo() acquires the RTNL for items on the list + * we could cause a situation such as this: + * Thread 1 Thread 2 + * rtnl_lock() + * unregister_netdevice() + * __rtnl_unlock() + * rtnl_lock() + * wiphy_lock() + * rtnl_unlock() + * netdev_run_todo() + * __rtnl_unlock() + * + * // list not empty now + * // because of thread 2 + * rtnl_lock() + * while (!list_empty(...)) + * rtnl_lock() + * wiphy_lock() + * **** DEADLOCK **** + * + * However, usage of __rtnl_unlock() is rare, and so we can ensure that + * it's not used in cases where something is added to do the list. + */ + WARN_ON(!list_empty(&net_todo_list)); + mutex_unlock(&rtnl_mutex); while (head) {