Skip to content

Commit bec3ae2

Browse files
haiyangzgregkh
authored andcommitted
hv_netvsc: fix race of netvsc and VF register_netdevice
[ Upstream commit d30fb71 ] The rtnl lock also needs to be held before rndis_filter_device_add() which advertises nvsp_2_vsc_capability / sriov bit, and triggers VF NIC offering and registering. If VF NIC finished register_netdev() earlier it may cause name based config failure. To fix this issue, move the call to rtnl_lock() before rndis_filter_device_add(), so VF will be registered later than netvsc / synthetic NIC, and gets a name numbered (ethX) after netvsc. Cc: stable@vger.kernel.org Fixes: e04e7a7 ("hv_netvsc: Fix a deadlock by getting rtnl lock earlier in netvsc_probe()") Reported-by: Dexuan Cui <decui@microsoft.com> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Dexuan Cui <decui@microsoft.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 69732d2 commit bec3ae2

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

drivers/net/hyperv/netvsc_drv.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,25 +2563,30 @@ static int netvsc_probe(struct hv_device *dev,
25632563
goto devinfo_failed;
25642564
}
25652565

2566-
nvdev = rndis_filter_device_add(dev, device_info);
2567-
if (IS_ERR(nvdev)) {
2568-
ret = PTR_ERR(nvdev);
2569-
netdev_err(net, "unable to add netvsc device (ret %d)\n", ret);
2570-
goto rndis_failed;
2571-
}
2572-
2573-
memcpy(net->dev_addr, device_info->mac_adr, ETH_ALEN);
2574-
25752566
/* We must get rtnl lock before scheduling nvdev->subchan_work,
25762567
* otherwise netvsc_subchan_work() can get rtnl lock first and wait
25772568
* all subchannels to show up, but that may not happen because
25782569
* netvsc_probe() can't get rtnl lock and as a result vmbus_onoffer()
25792570
* -> ... -> device_add() -> ... -> __device_attach() can't get
25802571
* the device lock, so all the subchannels can't be processed --
25812572
* finally netvsc_subchan_work() hangs forever.
2573+
*
2574+
* The rtnl lock also needs to be held before rndis_filter_device_add()
2575+
* which advertises nvsp_2_vsc_capability / sriov bit, and triggers
2576+
* VF NIC offering and registering. If VF NIC finished register_netdev()
2577+
* earlier it may cause name based config failure.
25822578
*/
25832579
rtnl_lock();
25842580

2581+
nvdev = rndis_filter_device_add(dev, device_info);
2582+
if (IS_ERR(nvdev)) {
2583+
ret = PTR_ERR(nvdev);
2584+
netdev_err(net, "unable to add netvsc device (ret %d)\n", ret);
2585+
goto rndis_failed;
2586+
}
2587+
2588+
memcpy(net->dev_addr, device_info->mac_adr, ETH_ALEN);
2589+
25852590
if (nvdev->num_chn > 1)
25862591
schedule_work(&nvdev->subchan_work);
25872592

@@ -2615,9 +2620,9 @@ static int netvsc_probe(struct hv_device *dev,
26152620
return 0;
26162621

26172622
register_failed:
2618-
rtnl_unlock();
26192623
rndis_filter_device_remove(dev, nvdev);
26202624
rndis_failed:
2625+
rtnl_unlock();
26212626
netvsc_devinfo_put(device_info);
26222627
devinfo_failed:
26232628
free_percpu(net_device_ctx->vf_stats);

0 commit comments

Comments
 (0)