When netvsc device is removed during mtu change or channels setup we get
into troubles as both paths are trying to remove the device. Synchronize
them with start_remove flag and rtnl lock.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
        int ret = 0;
        bool recovering = false;
 
-       if (!nvdev || nvdev->destroy)
+       if (net_device_ctx->start_remove || !nvdev || nvdev->destroy)
                return -ENODEV;
 
        num_chn = nvdev->num_chn;
        u32 num_chn;
        int ret = 0;
 
-       if (nvdev == NULL || nvdev->destroy)
+       if (ndevctx->start_remove || !nvdev || nvdev->destroy)
                return -ENODEV;
 
        if (nvdev->nvsp_version >= NVSP_PROTOCOL_VERSION_2)
        ndev_ctx = netdev_priv(net);
        net_device = ndev_ctx->nvdev;
 
+       /* Avoid racing with netvsc_change_mtu()/netvsc_set_channels()
+        * removing the device.
+        */
+       rtnl_lock();
        ndev_ctx->start_remove = true;
+       rtnl_unlock();
 
        cancel_delayed_work_sync(&ndev_ctx->dwork);
        cancel_work_sync(&ndev_ctx->work);