All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Nguyen <anthony.l.nguyen@intel.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [PATCH net-next 02/15] iavf: obtain the crit_section lock in iavf_open() immediately
Date: Fri,  4 Jun 2021 09:53:22 -0700	[thread overview]
Message-ID: <20210604165335.33329-2-anthony.l.nguyen@intel.com> (raw)
In-Reply-To: <20210604165335.33329-1-anthony.l.nguyen@intel.com>

From: Nicholas Nunley <nicholas.d.nunley@intel.com>

iavf_open() checks for IAVF_FLAG_PF_COMMS_FAILED outside of the
crit_section lock so that it can return early if possible, without needing
to acquire the lock. This is perfectly fine, but once the lock is actually
obtained the code assumes the value hasn't changed. This is not correct,
since the IAVF_FLAG_PF_COMMS_FAILED field can certainly change by the time
the lock is obtained, especially if iavf_open() has to wait for it while
iavf_reset_task() runs on another thread.

To avoid this, simply grab the lock before checking the value.

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 | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index bf96a9dab962..4c55773c6ee1 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -3196,15 +3196,16 @@ static int iavf_open(struct net_device *netdev)
 	struct iavf_adapter *adapter = netdev_priv(netdev);
 	int err;
 
-	if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) {
-		dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
-		return -EIO;
-	}
-
 	while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
 				&adapter->crit_section))
 		usleep_range(500, 1000);
 
+	if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) {
+		dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
+		err = -EIO;
+		goto err_unlock;
+	}
+
 	if (adapter->state != __IAVF_DOWN) {
 		err = -EBUSY;
 		goto err_unlock;
-- 
2.20.1


  reply	other threads:[~2021-06-04 16:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04 16:53 [Intel-wired-lan] [PATCH net-next 01/15] iavf: correctly track whether the interface is running during resets Tony Nguyen
2021-06-04 16:53 ` Tony Nguyen [this message]
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 03/15] iavf: obtain crit_section lock in iavf_close() immediately Tony Nguyen
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 04/15] iavf: wrap driver state change in crit_section lock Tony Nguyen
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 05/15] iavf: untangle any pending iavf_open() operations from iavf_close() Tony Nguyen
2021-06-10  6:14   ` Stefan Assmann
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 06/15] iavf: disable interrupts before disabling napi Tony Nguyen
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 07/15] iavf: Restore non MAC filters after link down Tony Nguyen
2021-11-02 16:36   ` Kuruvinakunnel, George
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 08/15] iavf: restore MSI state on reset Tony Nguyen
2021-11-03 19:41   ` Kuruvinakunnel, George
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 09/15] iavf: Fix carrier on state Tony Nguyen
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 10/15] iavf: Add change MTU message Tony Nguyen
2021-11-02  0:34   ` Kuruvinakunnel, George
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 11/15] iavf: Prevent changing static ITR values if adaptive moderation is on Tony Nguyen
2021-11-02  0:21   ` Kuruvinakunnel, George
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 12/15] iavf: Log info when VF is entering and leaving Allmulti mode Tony Nguyen
2021-11-02  0:47   ` Kuruvinakunnel, George
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 13/15] iavf: Set RSS LUT and key in reset handle path Tony Nguyen
2021-08-06  7:26   ` Jankowski, Konrad0
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 14/15] iavf: return errno code instead of status code Tony Nguyen
2021-11-17 10:27   ` Jankowski, Konrad0
2021-06-04 16:53 ` [Intel-wired-lan] [PATCH net-next 15/15] iavf: don't be so alarming Tony Nguyen
2021-11-03 19:45   ` Kuruvinakunnel, George

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210604165335.33329-2-anthony.l.nguyen@intel.com \
    --to=anthony.l.nguyen@intel.com \
    --cc=intel-wired-lan@osuosl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.