Skip to content

Commit d30fb71

Browse files
haiyangzPaolo Abeni
authored andcommitted
hv_netvsc: fix race of netvsc and VF register_netdevice
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: [email protected] Fixes: e04e7a7 ("hv_netvsc: Fix a deadlock by getting rtnl lock earlier in netvsc_probe()") Reported-by: Dexuan Cui <[email protected]> Signed-off-by: Haiyang Zhang <[email protected]> Reviewed-by: Wojciech Drewek <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Dexuan Cui <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent c0e2926 commit d30fb71

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

drivers/net/hyperv/netvsc_drv.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,25 +2531,30 @@ static int netvsc_probe(struct hv_device *dev,
25312531
goto devinfo_failed;
25322532
}
25332533

2534-
nvdev = rndis_filter_device_add(dev, device_info);
2535-
if (IS_ERR(nvdev)) {
2536-
ret = PTR_ERR(nvdev);
2537-
netdev_err(net, "unable to add netvsc device (ret %d)\n", ret);
2538-
goto rndis_failed;
2539-
}
2540-
2541-
eth_hw_addr_set(net, device_info->mac_adr);
2542-
25432534
/* We must get rtnl lock before scheduling nvdev->subchan_work,
25442535
* otherwise netvsc_subchan_work() can get rtnl lock first and wait
25452536
* all subchannels to show up, but that may not happen because
25462537
* netvsc_probe() can't get rtnl lock and as a result vmbus_onoffer()
25472538
* -> ... -> device_add() -> ... -> __device_attach() can't get
25482539
* the device lock, so all the subchannels can't be processed --
25492540
* finally netvsc_subchan_work() hangs forever.
2541+
*
2542+
* The rtnl lock also needs to be held before rndis_filter_device_add()
2543+
* which advertises nvsp_2_vsc_capability / sriov bit, and triggers
2544+
* VF NIC offering and registering. If VF NIC finished register_netdev()
2545+
* earlier it may cause name based config failure.
25502546
*/
25512547
rtnl_lock();
25522548

2549+
nvdev = rndis_filter_device_add(dev, device_info);
2550+
if (IS_ERR(nvdev)) {
2551+
ret = PTR_ERR(nvdev);
2552+
netdev_err(net, "unable to add netvsc device (ret %d)\n", ret);
2553+
goto rndis_failed;
2554+
}
2555+
2556+
eth_hw_addr_set(net, device_info->mac_adr);
2557+
25532558
if (nvdev->num_chn > 1)
25542559
schedule_work(&nvdev->subchan_work);
25552560

@@ -2586,9 +2591,9 @@ static int netvsc_probe(struct hv_device *dev,
25862591
return 0;
25872592

25882593
register_failed:
2589-
rtnl_unlock();
25902594
rndis_filter_device_remove(dev, nvdev);
25912595
rndis_failed:
2596+
rtnl_unlock();
25922597
netvsc_devinfo_put(device_info);
25932598
devinfo_failed:
25942599
free_percpu(net_device_ctx->vf_stats);

0 commit comments

Comments
 (0)