From patchwork Tue Sep 6 22:00:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 9317959 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 9E8F7607D3 for ; Tue, 6 Sep 2016 22:00:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FF1528EE5 for ; Tue, 6 Sep 2016 22:00:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FE9228F06; Tue, 6 Sep 2016 22:00:30 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 92F3C28EE5 for ; Tue, 6 Sep 2016 22:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933919AbcIFWA0 (ORCPT ); Tue, 6 Sep 2016 18:00:26 -0400 Received: from mga11.intel.com ([192.55.52.93]:65205 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933490AbcIFWA0 (ORCPT ); Tue, 6 Sep 2016 18:00:26 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 06 Sep 2016 15:00:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,293,1470726000"; d="scan'208";a="1036270889" Received: from dcgshare.lm.intel.com ([10.232.118.254]) by fmsmga001.fm.intel.com with ESMTP; 06 Sep 2016 15:00:22 -0700 Received: by dcgshare.lm.intel.com (Postfix, from userid 1017) id 29083E00EA; Tue, 6 Sep 2016 16:00:20 -0600 (MDT) From: Keith Busch To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: Jon Derrick , Wei Zhang , Keith Busch Subject: [PATCHv2 2/4] pci: No config access for removed devices Date: Tue, 6 Sep 2016 16:00:17 -0600 Message-Id: <1473199219-3369-3-git-send-email-keith.busch@intel.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1473199219-3369-1-git-send-email-keith.busch@intel.com> References: <1473199219-3369-1-git-send-email-keith.busch@intel.com> 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 If we've detected that the PCI device is removed, do not attempt to access the device's config space. On a config read, if the device is not present, the value returned will be set to all 1's. This is the same as what hardware would normally return when accessing a removed device, but we do not need to repeatedly test hardware's completion capabilities if software can take a short-cut. Signed-off-by: Keith Busch --- include/linux/pci.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index 865d3ec..1b62f7a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -932,28 +932,46 @@ struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops); static inline int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val) { + if (unlikely(dev->is_removed)) { + *val = ~0; + return -ENODEV; + } return pci_bus_read_config_byte(dev->bus, dev->devfn, where, val); } static inline int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val) { + if (unlikely(dev->is_removed)) { + *val = ~0; + return -ENODEV; + } return pci_bus_read_config_word(dev->bus, dev->devfn, where, val); } static inline int pci_read_config_dword(const struct pci_dev *dev, int where, u32 *val) { + if (unlikely(dev->is_removed)) { + *val = ~0; + return -ENODEV; + } return pci_bus_read_config_dword(dev->bus, dev->devfn, where, val); } static inline int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val) { + if (unlikely(dev->is_removed)) + return -ENODEV; return pci_bus_write_config_byte(dev->bus, dev->devfn, where, val); } static inline int pci_write_config_word(const struct pci_dev *dev, int where, u16 val) { + if (unlikely(dev->is_removed)) + return -ENODEV; return pci_bus_write_config_word(dev->bus, dev->devfn, where, val); } static inline int pci_write_config_dword(const struct pci_dev *dev, int where, u32 val) { + if (unlikely(dev->is_removed)) + return -ENODEV; return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val); }