Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3467883ybv; Tue, 25 Feb 2020 01:52:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxBbzu6yOCZMzJPEjEu3zBz/Pr32X7i315t6Js3X8KM7Rt7qkMnQ691ckfDjutvSrjRy33G X-Received: by 2002:aca:3f54:: with SMTP id m81mr2691492oia.73.1582624327598; Tue, 25 Feb 2020 01:52:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582624327; cv=none; d=google.com; s=arc-20160816; b=PQapXd5YX2AfDFz2vuVeuYSDlVhuGviiX8BIkUfHtPeE//DANM4afrHg0vG8qCltVa urPE5J3FPvk/LXbqQHUkoZgjGwlmj53DhzJEVbz/3Me0TIeTWUPClG3dr5K8fBZ8H2WL aukV7L/ZupqwoRh0EmxFigqksG38L/7rwkG5dhL+GY5wt7yFYeQmq7y3zLjLg14YpmiO QansZs8v96JUpi08+n1yyyiQ6/JK36sPkH1nVzAtmBk9NEaiuj4Gd0MBL9G+4JDZXPBa O5zxc0vOlHTO1c6wnv3FYUs2DvoGRD7Bz+IbSmYlvTI7bOfRkvnegnIN61vG+kht25kG JL3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=0Rll/xl1jqbSFi67S9smeHzcQpfen7V2nPxeKU92cS4=; b=l80cbkij252pmnFLE9f7AEHTIxJGNMq7VonApvoi4YgdHgPa3j5TnehwNpiLAomUlD zyWgpN1duzAtySisQbFrLPxU8DkQt02sGB2c51n/JE50l/dx4sFWgVDZAhHrLzjSMKsk SxoQTo9QVEIfyJYY+KP8S/t2h0lSRWVEjvZygiKcHSSIm9R+3l20Tl52tnG3JfGbQfsf HbFPEL/UmKNtOGXDlsgceOhdbdAiuZRNL5p26e+WrIl0G/DJ417uOzk1lyOmdqO1vRel ivV1FDxVVnVsHncumz24c9+HgAaImHrBPZvJscX0ZbqTflMXDiZAfFtqh0M/lA/BCS50 TEdg== 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 j13si7169165otq.146.2020.02.25.01.51.54; Tue, 25 Feb 2020 01:52:07 -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 S1729790AbgBYJmf convert rfc822-to-8bit (ORCPT + 99 others); Tue, 25 Feb 2020 04:42:35 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:55397 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729072AbgBYJme (ORCPT ); Tue, 25 Feb 2020 04:42:34 -0500 Received: from mail-pl1-f198.google.com ([209.85.214.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j6WjY-0007FT-Dk for linux-kernel@vger.kernel.org; Tue, 25 Feb 2020 09:42:32 +0000 Received: by mail-pl1-f198.google.com with SMTP id g5so7044915plq.17 for ; Tue, 25 Feb 2020 01:42:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=qW9RGA2yoPMiW3Kx/nzk+m/gnWxZba3lZu/gpv/Ykio=; b=R0BZXoXQEAqXJzCbSJhkSG5MP4Tde9MPffcQgN4V2yngbi1pKQWOYdMpyY4m5dsTyL I5rVEVLTJsZ4ddf/+Oh4V9Ju4DgQ3IVzXIByECwy2cGB/eDzta8YfszfbzyiTTf4jnr/ 7Nya6JrzoaOD7PChdpmbpLy1Ng9W0E33dt4dnXYuiwptfwSCeDpXfmAM2hs1Dro+Z7qQ ZA8g+UCVnhVNzpgLKbgoJVaQimDLuwirZQJ1wwpPw51neF3Cqck2cTf596KjEo6HLdMC 2oI0qXxAd4ennlLrssJxe5fEwusOeuHfF5yKycs0eZunJ+Iv3yRGU/satL0j9ihOW28c xf7w== X-Gm-Message-State: APjAAAWgVi1Y19vQG3DSlFFeWZXqmRYh8fEhrmiOlx2vwlem8jkySxmC uqbu65Nq6Y4C6CibLDAIC1QBABV4mp4nzX+mx/SJRnlvAUlPymJwgoOpJddojdfVwsE6e3AhtpV iBd706AnsCjjqadbJpQjJhyRFKNhW1H41llmt5dwuLQ== X-Received: by 2002:a17:902:b089:: with SMTP id p9mr54667616plr.42.1582623751054; Tue, 25 Feb 2020 01:42:31 -0800 (PST) X-Received: by 2002:a17:902:b089:: with SMTP id p9mr54667588plr.42.1582623750614; Tue, 25 Feb 2020 01:42:30 -0800 (PST) Received: from 2001-b011-380f-3214-6d62-6b9e-e5b8-db59.dynamic-ip6.hinet.net (2001-b011-380f-3214-6d62-6b9e-e5b8-db59.dynamic-ip6.hinet.net. [2001:b011:380f:3214:6d62:6b9e:e5b8:db59]) by smtp.gmail.com with ESMTPSA id e18sm16697476pfm.24.2020.02.25.01.42.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Feb 2020 01:42:30 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: [RFC PATCH v2] e1000e: Use rtnl_lock to prevent race conditions between net and pci/pm From: Kai-Heng Feng In-Reply-To: <20191007172559.11166.29328.stgit@localhost.localdomain> Date: Tue, 25 Feb 2020 17:42:26 +0800 Cc: Alexander Duyck , zdai@linux.vnet.ibm.com, "open list:NETWORKING DRIVERS" , open list , "moderated list:INTEL ETHERNET DRIVERS" , "Kirsher, Jeffrey T" , zdai@us.ibm.com, David Miller Content-Transfer-Encoding: 8BIT Message-Id: <681404C7-9015-4C64-B8FE-2C93D75A7318@canonical.com> References: <20191007172559.11166.29328.stgit@localhost.localdomain> To: Greg Kroah-Hartman , stable X-Mailer: Apple Mail (2.3608.60.0.2.5) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg, > On Oct 8, 2019, at 01:27, Alexander Duyck wrote: > > From: Alexander Duyck > > This patch is meant to address possible race conditions that can exist > between network configuration and power management. A similar issue was > fixed for igb in commit 9474933caf21 ("igb: close/suspend race in > netif_device_detach"). > > In addition it consolidates the code so that the PCI error handling code > will essentially perform the power management freeze on the device prior to > attempting a reset, and will thaw the device afterwards if that is what it > is planning to do. Otherwise when we call close on the interface it should > see it is detached and not attempt to call the logic to down the interface > and free the IRQs again. > >> From what I can tell the check that was adding the check for __E1000_DOWN > in e1000e_close was added when runtime power management was added. However > it should not be relevant for us as we perform a call to > pm_runtime_get_sync before we call e1000_down/free_irq so it should always > be back up before we call into this anyway. > > Signed-off-by: Alexander Duyck Please merge this commit, a7023819404ac9bd2bb311a4fafd38515cfa71ec to stable v5.14. `modprobe -r e1000e` triggers a null pointer dereference [1] after the the following two patches are applied to v5.4.y: d635e7c4b34e6a630c7a1e8f1a8fd52c3e3ceea7 e1000e: Revert "e1000e: Make watchdog use delayed work" 21c6137939723ed6f5e4aec7882cdfc247304c27 e1000e: Drop unnecessary __E1000_DOWN bit twiddling [1] https://bugs.launchpad.net/bugs/1864303 Kai-Heng > --- > > RFC v2: Dropped some unused variables > Added logic to check for device present before removing to pm_freeze > Fixed misplaced err_irq to before rtnl_unlock() > > drivers/net/ethernet/intel/e1000e/netdev.c | 40 +++++++++++++++------------- > 1 file changed, 21 insertions(+), 19 deletions(-) > > diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c > index d7d56e42a6aa..8b4e589aca36 100644 > --- a/drivers/net/ethernet/intel/e1000e/netdev.c > +++ b/drivers/net/ethernet/intel/e1000e/netdev.c > @@ -4715,12 +4715,12 @@ int e1000e_close(struct net_device *netdev) > > pm_runtime_get_sync(&pdev->dev); > > - if (!test_bit(__E1000_DOWN, &adapter->state)) { > + if (netif_device_present(netdev)) { > e1000e_down(adapter, true); > e1000_free_irq(adapter); > > /* Link status message must follow this format */ > - pr_info("%s NIC Link is Down\n", adapter->netdev->name); > + pr_info("%s NIC Link is Down\n", netdev->name); > } > > napi_disable(&adapter->napi); > @@ -6298,10 +6298,14 @@ static int e1000e_pm_freeze(struct device *dev) > { > struct net_device *netdev = dev_get_drvdata(dev); > struct e1000_adapter *adapter = netdev_priv(netdev); > + bool present; > > + rtnl_lock(); > + > + present = netif_device_present(netdev); > netif_device_detach(netdev); > > - if (netif_running(netdev)) { > + if (present && netif_running(netdev)) { > int count = E1000_CHECK_RESET_COUNT; > > while (test_bit(__E1000_RESETTING, &adapter->state) && count--) > @@ -6313,6 +6317,8 @@ static int e1000e_pm_freeze(struct device *dev) > e1000e_down(adapter, false); > e1000_free_irq(adapter); > } > + rtnl_unlock(); > + > e1000e_reset_interrupt_capability(adapter); > > /* Allow time for pending master requests to run */ > @@ -6626,27 +6632,31 @@ static int __e1000_resume(struct pci_dev *pdev) > return 0; > } > > -#ifdef CONFIG_PM_SLEEP > static int e1000e_pm_thaw(struct device *dev) > { > struct net_device *netdev = dev_get_drvdata(dev); > struct e1000_adapter *adapter = netdev_priv(netdev); > + int rc = 0; > > e1000e_set_interrupt_capability(adapter); > - if (netif_running(netdev)) { > - u32 err = e1000_request_irq(adapter); > > - if (err) > - return err; > + rtnl_lock(); > + if (netif_running(netdev)) { > + rc = e1000_request_irq(adapter); > + if (rc) > + goto err_irq; > > e1000e_up(adapter); > } > > netif_device_attach(netdev); > +err_irq: > + rtnl_unlock(); > > - return 0; > + return rc; > } > > +#ifdef CONFIG_PM_SLEEP > static int e1000e_pm_suspend(struct device *dev) > { > struct pci_dev *pdev = to_pci_dev(dev); > @@ -6818,16 +6828,11 @@ static void e1000_netpoll(struct net_device *netdev) > static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, > pci_channel_state_t state) > { > - struct net_device *netdev = pci_get_drvdata(pdev); > - struct e1000_adapter *adapter = netdev_priv(netdev); > - > - netif_device_detach(netdev); > + e1000e_pm_freeze(&pdev->dev); > > if (state == pci_channel_io_perm_failure) > return PCI_ERS_RESULT_DISCONNECT; > > - if (netif_running(netdev)) > - e1000e_down(adapter, true); > pci_disable_device(pdev); > > /* Request a slot slot reset. */ > @@ -6893,10 +6898,7 @@ static void e1000_io_resume(struct pci_dev *pdev) > > e1000_init_manageability_pt(adapter); > > - if (netif_running(netdev)) > - e1000e_up(adapter); > - > - netif_device_attach(netdev); > + e1000e_pm_thaw(&pdev->dev); > > /* If the controller has AMT, do not set DRV_LOAD until the interface > * is up. For all other cases, let the f/w know that the h/w is now >