netvsc: fix rtnl deadlock on unregister of vf
authorstephen hemminger <stephen@networkplumber.org>
Fri, 4 Aug 2017 19:14:00 +0000 (12:14 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 7 Aug 2017 04:28:10 +0000 (21:28 -0700)
With new transparent VF support, it is possible to get a deadlock
when some of the deferred work is running and the unregister_vf
is trying to cancel the work element. The solution is to use
trylock and reschedule (similar to bonding and team device).

Reported-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Fixes: 0c195567a8f6 ("netvsc: transparent VF management")
Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/hyperv/netvsc_drv.c

index c71728d82049a4ffb05c77bc47d7ff7896a50c3a..e75c0f852a63f5a2020e2c8c3b17e6040faaa346 100644 (file)
@@ -1601,7 +1601,11 @@ static void netvsc_vf_setup(struct work_struct *w)
        struct net_device *ndev = hv_get_drvdata(ndev_ctx->device_ctx);
        struct net_device *vf_netdev;
 
-       rtnl_lock();
+       if (!rtnl_trylock()) {
+               schedule_work(w);
+               return;
+       }
+
        vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
        if (vf_netdev)
                __netvsc_vf_setup(ndev, vf_netdev);
@@ -1655,7 +1659,11 @@ static void netvsc_vf_update(struct work_struct *w)
        struct net_device *vf_netdev;
        bool vf_is_up;
 
-       rtnl_lock();
+       if (!rtnl_trylock()) {
+               schedule_work(w);
+               return;
+       }
+
        vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
        if (!vf_netdev)
                goto unlock;