Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp369920ybl; Thu, 9 Jan 2020 23:43:29 -0800 (PST) X-Google-Smtp-Source: APXvYqybeewuCrRdfWlbfRfg+vVIJax2z1EJcDOxOCA7WoGbVlFdUtb3zF9Jgku3fLU4kQFne8f3 X-Received: by 2002:aca:db43:: with SMTP id s64mr1167252oig.144.1578642209668; Thu, 09 Jan 2020 23:43:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578642209; cv=none; d=google.com; s=arc-20160816; b=bIPvcw2gr3XeVC4Jqk6XPqlHB7b2z5I0tethGpxWXSoUhVBmu1xpjjtbWumK3YZNDn x5ZElF6D/b85Z6xDUnm3tkDzYt08sMqoD64+BgwjTLUk4WNLmsVushMf/cXFb+vBVy1e 1EkIeB1SOEcm1D3EcmfBeaKV+Dud4yn/fXJT3wPcIyNpLtLBJTwiduu8YKfiB1kksgGA wW1elAd0VDTQxk9ix/yEDCbYmp35LXsR6ChVLBhL2IXKfJwHyCze+lvp6uPZPwEj42VP ovG0YZEsVwQhwhLES3sd8kMO9o5enV9g6MeNa4fFniSlsA1GOiEZQQh3MJAb4Ll0FjSN RyBg== 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=EvNbRu5BGUEtQEOKxEQiBaZD/F8UkuFEo4rmLARjPPw=; b=LYhwBoA648LbRotqtUoWpX1RD8F34S7QCRY4G9VguUW3dci3/7PW/VhbhYbv2wu08X hhR0sWfEYt2Wwpyv3kPNBZOvlD8Ku92J3fhQayuOR4z2WL8pJL8zAtgOsBcLxUQ0vq7w +Lg4mGosS2KOfKqG7L+Cnoa2ecYp8O4w+9SB4MRR4bEYtWRYEA1+tT+uSeH4EsAd4MSC Oe/CRx5XZED7jaDW0rXZsOl9pEsZHz/LV8GDK+QFuwT5+aHZFpSMgp1jw7/s5+BPnyWO pxnNiUR8dHHne5mrhWnGEtLoJQMwCEn6mMjFE4hsWTkH7bBkRRMWUnTJIqrt1cspWnki c+ig== 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 r6si695238otq.95.2020.01.09.23.43.17; Thu, 09 Jan 2020 23:43: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 S1726616AbgAJHmY (ORCPT + 99 others); Fri, 10 Jan 2020 02:42:24 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:41972 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbgAJHmY (ORCPT ); Fri, 10 Jan 2020 02:42:24 -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 1ipovy-0001rC-CO; Fri, 10 Jan 2020 07:42:18 +0000 From: Kai-Heng Feng To: davem@davemloft.ne, jeffrey.t.kirsher@intel.com Cc: Kai-Heng Feng , "David S. Miller" , 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 1/2] igb: Use device_lock() insead of rtnl_lock() Date: Fri, 10 Jan 2020 15:41:58 +0800 Message-Id: <20200110074159.18473-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 --- drivers/net/ethernet/intel/igb/igb_main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index b46bff8fe056..3750e2b926b1 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -4026,8 +4026,13 @@ 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; + + device_lock(dev); if (netif_device_present(netdev) || netdev->dismantle) return __igb_close(netdev, false); + device_unlock(dev); return 0; } @@ -8760,7 +8765,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 +8773,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 +8900,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