]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iavf: iavf_suspend(): take RTNL before netdev_lock()
authorPrzemek Kitszel <przemyslaw.kitszel@intel.com>
Fri, 4 Apr 2025 10:23:16 +0000 (12:23 +0200)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Tue, 3 Jun 2025 16:48:03 +0000 (09:48 -0700)
Fix an obvious violation of lock ordering.
Jakub's [1] added netdev_lock() call that is wrong ordered wrt RTNL,
but the Fixes tag points to crit_lock being wrongly placed (by lockdep
standards).

Actual reason we got it wrong is dated back to critical section managed by
pure flag checks, which is with us since the very beginning.

[1] afc664987ab3 ("eth: iavf: extend the netdev_lock usage")

Fixes: 5ac49f3c2702 ("iavf: use mutexes for locking of critical sections")
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Tested-by: Rafal Romanowski <rafal.romanowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/iavf/iavf_main.c

index 6d7ba4d67a193346c50907558f3d83e2b130b251..a77c726435281d0f88a1a3bb4b51ece93b580a24 100644 (file)
@@ -5596,22 +5596,27 @@ static int iavf_suspend(struct device *dev_d)
 {
        struct net_device *netdev = dev_get_drvdata(dev_d);
        struct iavf_adapter *adapter = netdev_priv(netdev);
+       bool running;
 
        netif_device_detach(netdev);
 
+       running = netif_running(netdev);
+       if (running)
+               rtnl_lock();
+
        netdev_lock(netdev);
        mutex_lock(&adapter->crit_lock);
 
-       if (netif_running(netdev)) {
-               rtnl_lock();
+       if (running)
                iavf_down(adapter);
-               rtnl_unlock();
-       }
+
        iavf_free_misc_irq(adapter);
        iavf_reset_interrupt_capability(adapter);
 
        mutex_unlock(&adapter->crit_lock);
        netdev_unlock(netdev);
+       if (running)
+               rtnl_unlock();
 
        return 0;
 }