linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Keith Busch <keith.busch@intel.com>
To: linux-pci@vger.kernel.org, Bjorn Helgaas <bhelgaas@google.com>
Cc: Jon Derrick <jonathan.derrick@intel.com>,
	Wei Zhang <wzhang@fb.com>, Keith Busch <keith.busch@intel.com>
Subject: [PATCHv2 2/4] pci: No config access for removed devices
Date: Tue,  6 Sep 2016 16:00:17 -0600	[thread overview]
Message-ID: <1473199219-3369-3-git-send-email-keith.busch@intel.com> (raw)
In-Reply-To: <1473199219-3369-1-git-send-email-keith.busch@intel.com>

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 <keith.busch@intel.com>
---
 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);
 }
 
-- 
2.7.2


  parent reply	other threads:[~2016-09-06 22:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-06 22:00 [PATCHv2 0/4] Limiting pci access requsets Keith Busch
2016-09-06 22:00 ` [PATCHv2 1/4] pci: Add is_removed state Keith Busch
2016-09-07 11:14   ` Lukas Wunner
2016-09-17  8:35   ` Lukas Wunner
2016-09-19 17:47     ` Keith Busch
2016-09-06 22:00 ` Keith Busch [this message]
2016-09-07 12:03   ` [PATCHv2 2/4] pci: No config access for removed devices kbuild test robot
2016-09-07 16:28     ` Keith Busch
2016-09-06 22:00 ` [PATCHv2 3/4] pcie/aer: Cache capability position Keith Busch
2016-09-07 11:30   ` Lukas Wunner
2016-09-13 22:07     ` Bjorn Helgaas
2016-09-06 22:00 ` [PATCHv2 4/4] pci/msix: Skip disabling removed devices Keith Busch
2016-09-07 13:28 ` [PATCHv2 0/4] Limiting pci access requsets Lukas Wunner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473199219-3369-3-git-send-email-keith.busch@intel.com \
    --to=keith.busch@intel.com \
    --cc=bhelgaas@google.com \
    --cc=jonathan.derrick@intel.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=wzhang@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).