Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp438765ybv; Fri, 7 Feb 2020 02:11:29 -0800 (PST) X-Google-Smtp-Source: APXvYqywI3YoMuze5+cVrPGfeb0chtFX9c2K8ok7qB+v85xbIfPy/qSsTW2KSsiHFacdw5ZyqQ35 X-Received: by 2002:a05:6808:994:: with SMTP id a20mr1519980oic.67.1581070289124; Fri, 07 Feb 2020 02:11:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581070289; cv=none; d=google.com; s=arc-20160816; b=TxI5y9AXVghMkCMvYk589RY8XQOnCQIFFS3BMQb3r5uYhXCQaEccIz9rC/ujm+lWnY F/VPyZ7Haw5hkLInJN0UHDtylAcuntR0Plw/B0zmlU6U9+koehf6J0rymZimpzbMcjCL 3/+yZwszHXoJq8o+4plJBNna2Z/zEybwSiJKzRL+EQCl4mo9pyr+suMGiqVMUh918Hgj bycnUJCTPmjH5nYvBzrHNWtp95hwC5x4rirOBN7lFW0snSX0UJT1WDG7EuRJja7A2DUj LHweMNBernJbxPEDNv+v068h8YdbQrymh7VxM2COrqnZJgr0kjiEnBXSsLSdoB66Sadv uvhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=7d5j/iiDfvJfHlV/cu8dxpGvlfWO4YVz/1TPSIWbW2E=; b=ENDnkvrJcCTD+FvUeZ01ciWULjYg1ZAyFJGRg9LHOhJBJxIqDfDmc47EdYBZ9/P7HL /3GxHoax/SGTKqsYfgx0igl2IsYJw6ldiv2ZqknpNiCDEiPiWYpthklUMSnT928PRegb EQAu891hMZKnDCQpmUTu/kNwBcsInntKTK66Odz2NAx/y78FYb2CPa5ZOeTX3tFdQS41 yUXAgXb1fkr3LWdF+hOD7x9Kw8CTNgd1b/4BKYjomi633cO6CDgJ6PG+bHCO1kcT/Frj icbx9DIHck8hY8Z2FL6FSgHFiwSTR6bqAqPVE5/+YLdZmbdFgK5d+aW4JV+DG6psiFAO r7Kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j25si3506829oij.242.2020.02.07.02.11.16; Fri, 07 Feb 2020 02:11:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726951AbgBGKKU (ORCPT + 99 others); Fri, 7 Feb 2020 05:10:20 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:42217 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726587AbgBGKKU (ORCPT ); Fri, 7 Feb 2020 05:10:20 -0500 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j00aS-0007Hs-5H; Fri, 07 Feb 2020 10:10:12 +0000 From: Kai-Heng Feng To: davem@davemloft.net, mkubecek@suse.cz, jeffrey.t.kirsher@intel.com Cc: Kai-Heng Feng , intel-wired-lan@lists.osuosl.org (moderated list:INTEL ETHERNET DRIVERS), netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 1/2] igb: Use device_lock() insead of rtnl_lock() Date: Fri, 7 Feb 2020 18:10:03 +0800 Message-Id: <20200207101005.4454-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 9474933caf21 ("igb: close/suspend race in netif_device_detach") fixed race condition between close and power management ops by using rtnl_lock(). However we can achieve the same by using device_lock() since all power management ops are protected by device_lock(). This fix is a preparation for next patch, to prevent a dead lock under rtnl_lock() when calling runtime resume routine. Signed-off-by: Kai-Heng Feng --- v3: - Fix unreleased lock reported by 0-day test bot. v2: - No change. drivers/net/ethernet/intel/igb/igb_main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index b46bff8fe056..661255500d66 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -4026,9 +4026,15 @@ static int __igb_close(struct net_device *netdev, bool suspending) int igb_close(struct net_device *netdev) { + struct igb_adapter *adapter = netdev_priv(netdev); + struct device *dev = &adapter->pdev->dev; + int err = 0; + + device_lock(dev); if (netif_device_present(netdev) || netdev->dismantle) - return __igb_close(netdev, false); - return 0; + err = __igb_close(netdev, false); + device_unlock(dev); + return err; } /** @@ -8760,7 +8766,6 @@ static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake, u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol; bool wake; - rtnl_lock(); netif_device_detach(netdev); if (netif_running(netdev)) @@ -8769,7 +8774,6 @@ static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake, igb_ptp_suspend(adapter); igb_clear_interrupt_scheme(adapter); - rtnl_unlock(); status = rd32(E1000_STATUS); if (status & E1000_STATUS_LU) @@ -8897,13 +8901,11 @@ static int __maybe_unused igb_resume(struct device *dev) wr32(E1000_WUS, ~0); - rtnl_lock(); if (!err && netif_running(netdev)) err = __igb_open(netdev, true); if (!err) netif_device_attach(netdev); - rtnl_unlock(); return err; } -- 2.17.1