diff mbox series

[net-next,03/15] iavf: obtain crit_section lock in iavf_close() immediately

Message ID 20210604165335.33329-3-anthony.l.nguyen@intel.com
State Under Review
Delegated to: Anthony Nguyen
Headers show
Series [net-next,01/15] iavf: correctly track whether the interface is running during resets | expand

Commit Message

Nguyen, Anthony L June 4, 2021, 4:53 p.m. UTC
From: Nicholas Nunley <nicholas.d.nunley@intel.com>

iavf_close() checks the adapter state outside of the crit_section lock
so that it can quickly bail out of the function if the interface is already
down. This doesn't work as intended, though, since it may be seeing a
transient state if iavf_reset_task() is running on a separate thread. If
this happens the driver will hit a panic later in iavf_remove() since the
active resources were never unconfigured correctly.

To fix this the adapter state is checked after grabbing the crit_section
lock.

Signed-off-by: Nicholas Nunley <nicholas.d.nunley@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index 4c55773c6ee1..f97d04b47292 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -3271,13 +3271,15 @@  static int iavf_close(struct net_device *netdev)
 	struct iavf_adapter *adapter = netdev_priv(netdev);
 	int status;
 
-	if (adapter->state <= __IAVF_DOWN_PENDING)
-		return 0;
-
 	while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
 				&adapter->crit_section))
 		usleep_range(500, 1000);
 
+	if (adapter->state <= __IAVF_DOWN_PENDING) {
+		clear_bit(__IAVF_IN_CRITICAL_TASK, &adapter->crit_section);
+		return 0;
+	}
+
 	set_bit(__IAVF_VSI_DOWN, adapter->vsi.state);
 	if (CLIENT_ENABLED(adapter))
 		adapter->flags |= IAVF_FLAG_CLIENT_NEEDS_CLOSE;