From patchwork Fri Jun 4 16:53:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 1487975 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FxTfl6gnjz9sTD for ; Sat, 5 Jun 2021 03:05:35 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 0AE39415E8; Fri, 4 Jun 2021 17:05:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F64K702t_ZNT; Fri, 4 Jun 2021 17:05:30 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp4.osuosl.org (Postfix) with ESMTP id BA7F7415E9; Fri, 4 Jun 2021 17:05:29 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 52DAD1BF863 for ; Fri, 4 Jun 2021 17:05:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 63231415B7 for ; Fri, 4 Jun 2021 17:05:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HZGN4SXfm9nG for ; Fri, 4 Jun 2021 17:05:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by smtp4.osuosl.org (Postfix) with ESMTPS id 793A1415F0 for ; Fri, 4 Jun 2021 17:05:05 +0000 (UTC) IronPort-SDR: SHOIlMiZ7EuGMge/8psTmmid8lEsoWLZm5/bRxVD8AQZx8OIa+WjXE7nviz/RMJPRytQyG8bKI 1J03cS6XX6SA== X-IronPort-AV: E=McAfee;i="6200,9189,10005"; a="191666470" X-IronPort-AV: E=Sophos;i="5.83,248,1616482800"; d="scan'208";a="191666470" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jun 2021 10:05:02 -0700 IronPort-SDR: YyHQQQYktXIXfcacpfihzBKwABsIqr5sy3bxt9nN9daO4qHEyZ/Yp/R7iGd/yavjsh3DyBs+su Wwcx5DiCcdOQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,248,1616482800"; d="scan'208";a="634086366" Received: from unknown (HELO anguy11-linux.jf.intel.com) ([10.166.244.129]) by fmsmga006.fm.intel.com with ESMTP; 04 Jun 2021 10:05:02 -0700 From: Tony Nguyen To: intel-wired-lan@lists.osuosl.org Date: Fri, 4 Jun 2021 09:53:22 -0700 Message-Id: <20210604165335.33329-2-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210604165335.33329-1-anthony.l.nguyen@intel.com> References: <20210604165335.33329-1-anthony.l.nguyen@intel.com> MIME-Version: 1.0 Subject: [Intel-wired-lan] [PATCH net-next 02/15] iavf: obtain the crit_section lock in iavf_open() immediately X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" From: Nicholas Nunley 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 Signed-off-by: Tony Nguyen --- 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;