提交 8755374c 编写于 作者: J Jakub Kicinski 提交者: Zheng Zengkai

net: allow out-of-order netdev unregistration

net-next inclusion
from net-next-v5.17-rc5
commit faab39f6
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I4VZN0?from=project-issue

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=faab39f63c1fc4bcdf135690f03bd596b578c67e

--------------------------------

Sprinkle for each loops to allow netdevices to be unregistered
out of order, as their refs are released.

This prevents problems caused by dependencies between netdevs
which want to release references in their ->priv_destructor.
See commit d6ff94af ("vlan: move dev_put into vlan_dev_uninit")
for example.

Eric has removed the only known ordering requirement in
commit c002496b ("Merge branch 'ipv6-loopback'")
so let's try this and see if anything explodes...
Reviewed-by: NEric Dumazet <edumazet@google.com>
Reviewed-by: NXin Long <lucien.xin@gmail.com>
Link: https://lore.kernel.org/r/20220215225310.3679266-2-kuba@kernel.orgSigned-off-by: NJakub Kicinski <kuba@kernel.org>
Conflicts:
	net/core/dev.c
Signed-off-by: NZiyang Xuan <william.xuanziyang@huawei.com>
Reviewed-by: NWei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 b2a7df99
...@@ -10244,8 +10244,8 @@ EXPORT_SYMBOL(netdev_refcnt_read); ...@@ -10244,8 +10244,8 @@ EXPORT_SYMBOL(netdev_refcnt_read);
#define WAIT_REFS_MIN_MSECS 1 #define WAIT_REFS_MIN_MSECS 1
#define WAIT_REFS_MAX_MSECS 250 #define WAIT_REFS_MAX_MSECS 250
/** /**
* netdev_wait_allrefs - wait until all references are gone. * netdev_wait_allrefs_any - wait until all references are gone.
* @dev: target net_device * @list: list of net_devices to wait on
* *
* This is called when unregistering network devices. * This is called when unregistering network devices.
* *
...@@ -10255,37 +10255,45 @@ EXPORT_SYMBOL(netdev_refcnt_read); ...@@ -10255,37 +10255,45 @@ EXPORT_SYMBOL(netdev_refcnt_read);
* We can get stuck here if buggy protocols don't correctly * We can get stuck here if buggy protocols don't correctly
* call dev_put. * call dev_put.
*/ */
static void netdev_wait_allrefs(struct net_device *dev) static struct net_device *netdev_wait_allrefs_any(struct list_head *list)
{ {
unsigned long rebroadcast_time, warning_time; unsigned long rebroadcast_time, warning_time;
int wait = 0, refcnt; struct net_device *dev;
int wait = 0;
linkwatch_forget_dev(dev); list_for_each_entry(dev, list, todo_list)
linkwatch_forget_dev(dev);
rebroadcast_time = warning_time = jiffies; rebroadcast_time = warning_time = jiffies;
refcnt = netdev_refcnt_read(dev);
while (refcnt != 0) { list_for_each_entry(dev, list, todo_list)
if (netdev_refcnt_read(dev) == 0)
return dev;
while (true) {
if (time_after(jiffies, rebroadcast_time + 1 * HZ)) { if (time_after(jiffies, rebroadcast_time + 1 * HZ)) {
rtnl_lock(); rtnl_lock();
/* Rebroadcast unregister notification */ /* Rebroadcast unregister notification */
call_netdevice_notifiers(NETDEV_UNREGISTER, dev); list_for_each_entry(dev, list, todo_list)
call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
__rtnl_unlock(); __rtnl_unlock();
rcu_barrier(); rcu_barrier();
rtnl_lock(); rtnl_lock();
if (test_bit(__LINK_STATE_LINKWATCH_PENDING, list_for_each_entry(dev, list, todo_list)
&dev->state)) { if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
/* We must not have linkwatch events &dev->state)) {
* pending on unregister. If this /* We must not have linkwatch events
* happens, we simply run the queue * pending on unregister. If this
* unscheduled, resulting in a noop * happens, we simply run the queue
* for this device. * unscheduled, resulting in a noop
*/ * for this device.
linkwatch_run_queue(); */
} linkwatch_run_queue();
break;
}
__rtnl_unlock(); __rtnl_unlock();
...@@ -10300,11 +10308,14 @@ static void netdev_wait_allrefs(struct net_device *dev) ...@@ -10300,11 +10308,14 @@ static void netdev_wait_allrefs(struct net_device *dev)
wait = min(wait << 1, WAIT_REFS_MAX_MSECS); wait = min(wait << 1, WAIT_REFS_MAX_MSECS);
} }
refcnt = netdev_refcnt_read(dev); list_for_each_entry(dev, list, todo_list)
if (netdev_refcnt_read(dev) == 0)
return dev;
if (refcnt && time_after(jiffies, warning_time + 10 * HZ)) { if (time_after(jiffies, warning_time + 10 * HZ)) {
pr_emerg("unregister_netdevice: waiting for %s to become free. Usage count = %d\n", list_for_each_entry(dev, list, todo_list)
dev->name, refcnt); pr_emerg("unregister_netdevice: waiting for %s to become free. Usage count = %d\n",
dev->name, netdev_refcnt_read(dev));
warning_time = jiffies; warning_time = jiffies;
} }
} }
...@@ -10372,11 +10383,9 @@ void netdev_run_todo(void) ...@@ -10372,11 +10383,9 @@ void netdev_run_todo(void)
} }
while (!list_empty(&list)) { while (!list_empty(&list)) {
dev = list_first_entry(&list, struct net_device, todo_list); dev = netdev_wait_allrefs_any(&list);
list_del(&dev->todo_list); list_del(&dev->todo_list);
netdev_wait_allrefs(dev);
/* paranoia */ /* paranoia */
BUG_ON(netdev_refcnt_read(dev)); BUG_ON(netdev_refcnt_read(dev));
BUG_ON(!list_empty(&dev->ptype_all)); BUG_ON(!list_empty(&dev->ptype_all));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册