@@ -12399,6 +12399,7 @@ static void __net_exit default_device_exit_batch(struct list_head *net_list)
* Do this across as many network namespaces as possible to
* improve batching efficiency.
*/
+ struct nd_lock *nd_lock;
struct net_device *dev;
struct net *net;
LIST_HEAD(dev_kill_list);
@@ -12411,10 +12412,12 @@ static void __net_exit default_device_exit_batch(struct list_head *net_list)
list_for_each_entry(net, net_list, exit_list) {
for_each_netdev_reverse(net, dev) {
+ lock_netdev(dev, &nd_lock);
if (dev->rtnl_link_ops && dev->rtnl_link_ops->dellink)
dev->rtnl_link_ops->dellink(dev, &dev_kill_list);
else
unregister_netdevice_queue(dev, &dev_kill_list);
+ unlock_netdev(nd_lock);
}
}
unregister_netdevice_many(&dev_kill_list);
@@ -449,12 +449,15 @@ EXPORT_SYMBOL_GPL(rtnl_link_register);
static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops)
{
+ struct nd_lock *nd_lock;
struct net_device *dev;
LIST_HEAD(list_kill);
for_each_netdev(net, dev) {
+ lock_netdev(dev, &nd_lock);
if (dev->rtnl_link_ops == ops)
ops->dellink(dev, &list_kill);
+ unlock_netdev(nd_lock);
}
unregister_netdevice_many(&list_kill);
}
@@ -3260,9 +3263,12 @@ static int rtnl_group_dellink(const struct net *net, int group)
for_each_netdev_safe(net, dev, aux) {
if (dev->group == group) {
const struct rtnl_link_ops *ops;
+ struct nd_lock *nd_lock;
ops = dev->rtnl_link_ops;
+ lock_netdev(dev, &nd_lock);
ops->dellink(dev, &list_kill);
+ unlock_netdev(nd_lock);
}
}
unregister_netdevice_many(&list_kill);
@@ -3273,13 +3279,17 @@ static int rtnl_group_dellink(const struct net *net, int group)
int rtnl_delete_link(struct net_device *dev, u32 portid, const struct nlmsghdr *nlh)
{
const struct rtnl_link_ops *ops;
+ struct nd_lock *nd_lock;
LIST_HEAD(list_kill);
ops = dev->rtnl_link_ops;
if (!ops || !ops->dellink)
return -EOPNOTSUPP;
+ lock_netdev(dev, &nd_lock);
ops->dellink(dev, &list_kill);
+ unlock_netdev(nd_lock);
+
unregister_netdevice_many_notify(&list_kill, portid, nlh);
return 0;
After previous patches all linked devices share the same lock. Here we add nd_lock around dellink to start making calls of unregister_netdevice() under nd_lock is locked. One more good thing is many netdev_upper_dev_unlink() becomes called under nd_lock is held, but not all yet. Note, that ->dellink called from netdevice notifiers are not braced yet. Signed-off-by: Kirill Tkhai <tkhai@ya.ru> --- net/core/dev.c | 3 +++ net/core/rtnetlink.c | 10 ++++++++++ 2 files changed, 13 insertions(+)