From patchwork Thu Jun 1 11:10:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9759383 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7DB166038E for ; Thu, 1 Jun 2017 11:10:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 707BE284C6 for ; Thu, 1 Jun 2017 11:10:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 627BE284D2; Thu, 1 Jun 2017 11:10:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AAAE284C6 for ; Thu, 1 Jun 2017 11:10:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751505AbdFALKr (ORCPT ); Thu, 1 Jun 2017 07:10:47 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:36891 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751475AbdFALKr (ORCPT ); Thu, 1 Jun 2017 07:10:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2whN+oAdDGijOnoUPVUFtZyFX48Pmt5dlkG0MkUtQLg=; b=e0Gc64qEQL05Hus1tg26CAWy1 tdAgt3H/ihIlSA3dLAeD/TNOwS6B2jXbRvcPBxHH0InGZGgI/y1KG/vmlcQPk9lwlsNTI+Xc3c2ub qKzDrDLwqAMqmp6C1UYbJngiWDSITkwu+7gCkP/17DVV0fP7Y5fs/K9sLVoDXJywatZjuoqJyc+m4 CE8I+n04JDsc1ycCI/EKjwLUPQIHokXCOYuY0zavoZkjDp0+w4MtJG4fmhh3YFygHUYHDvbxCVxGa 6aGW7pNyFZ3zjFN237sdtgvwm3rLWLElMpZ7NmMpnC/5OmFAT0o1oaFVKdcforUrTmTRFiBqCBOxy hYuPPQtsw==; Received: from clnet-p099-196.ikbnet.co.at ([83.175.99.196] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1dGO05-0007PG-Jy; Thu, 01 Jun 2017 11:10:46 +0000 From: Christoph Hellwig To: helgaas@kernel.org Cc: rakesh@tuxera.com, linux-pci@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 1/3] PCI: ensure the PCI device is locked over ->reset_notify calls Date: Thu, 1 Jun 2017 13:10:37 +0200 Message-Id: <20170601111039.8913-2-hch@lst.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170601111039.8913-1-hch@lst.de> References: <20170601111039.8913-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Without this ->notify_reset instance may race with ->remove calls, which can be easily triggered in NVMe. Reported-by: Rakesh Pandit Tested-by: Rakesh Pandit Signed-off-by: Christoph Hellwig --- drivers/pci/pci.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 563901cd9c06..92f7e5ae2e5e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4276,11 +4276,13 @@ int pci_reset_function(struct pci_dev *dev) if (rc) return rc; + pci_dev_lock(dev); pci_dev_save_and_disable(dev); - rc = pci_dev_reset(dev, 0); + rc = __pci_dev_reset(dev, 0); pci_dev_restore(dev); + pci_dev_unlock(dev); return rc; } @@ -4300,16 +4302,14 @@ int pci_try_reset_function(struct pci_dev *dev) if (rc) return rc; - pci_dev_save_and_disable(dev); + if (pci_dev_trylock(dev)) + return -EAGAIN; - if (pci_dev_trylock(dev)) { - rc = __pci_dev_reset(dev, 0); - pci_dev_unlock(dev); - } else - rc = -EAGAIN; + pci_dev_save_and_disable(dev); + rc = __pci_dev_reset(dev, 0); + pci_dev_unlock(dev); pci_dev_restore(dev); - return rc; } EXPORT_SYMBOL_GPL(pci_try_reset_function); @@ -4459,7 +4459,9 @@ static void pci_bus_save_and_disable(struct pci_bus *bus) struct pci_dev *dev; list_for_each_entry(dev, &bus->devices, bus_list) { + pci_dev_lock(dev); pci_dev_save_and_disable(dev); + pci_dev_unlock(dev); if (dev->subordinate) pci_bus_save_and_disable(dev->subordinate); } @@ -4474,7 +4476,9 @@ static void pci_bus_restore(struct pci_bus *bus) struct pci_dev *dev; list_for_each_entry(dev, &bus->devices, bus_list) { + pci_dev_lock(dev); pci_dev_restore(dev); + pci_dev_unlock(dev); if (dev->subordinate) pci_bus_restore(dev->subordinate); }