linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gavin Shan <gwshan@linux.vnet.ibm.com>
To: linux-pci@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org, bhelgaas@google.com,
	benh@kernel.crashing.org, mpe@ellerman.id.au, clsoto@us.ibm.com,
	Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: [PATCH v3 2/2] PCI: Disable VF's memory space on updating IOV BAR in pci_update_resource()
Date: Wed, 26 Oct 2016 12:15:36 +1100	[thread overview]
Message-ID: <1477444536-29612-3-git-send-email-gwshan@linux.vnet.ibm.com> (raw)
In-Reply-To: <1477444536-29612-1-git-send-email-gwshan@linux.vnet.ibm.com>

pci_update_resource() might be called to update (shift) IOV BARs
in PPC PowerNV specific pcibios_sriov_enable() when enabling PF's
SRIOV capability. At that point, the PF have been functional if
the SRIOV is enabled through sysfs entry "sriov_numvfs". The PF's
memory decoding (0x2 in PCI_COMMAND) shouldn't be disabled when
updating its IOV BARs with pci_update_resource(). Otherwise, we
receives EEH error caused by MMIO access to PF's memory BARs during
the window when PF's memory decoding is disabled.

   sriov_numvfs_store
   pdev->driver->sriov_configure
   mlx5_core_sriov_configure
   pci_enable_sriov
   sriov_enable
   pcibios_sriov_enable
   pnv_pci_sriov_enable
   pnv_pci_vf_resource_shift
   pci_update_resource

This disables VF's memory space instead of PF's memory decoding
when 64-bits IOV BARs are updated in pci_update_resource().

Reported-by: Carol Soto <clsoto@us.ibm.com>
Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Tested-by: Carol Soto <clsoto@us.ibm.com>
---
 drivers/pci/setup-res.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 66c4d8f..1456896 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -29,10 +29,10 @@
 void pci_update_resource(struct pci_dev *dev, int resno)
 {
 	struct pci_bus_region region;
-	bool disable;
-	u16 cmd;
+	bool disable = false;
+	u16 cmd, bit;
 	u32 new, check, mask;
-	int reg;
+	int reg, cmd_reg;
 	enum pci_bar_type type;
 	struct resource *res = dev->resource + resno;
 
@@ -81,11 +81,23 @@ void pci_update_resource(struct pci_dev *dev, int resno)
 	 * disable decoding so that a half-updated BAR won't conflict
 	 * with another device.
 	 */
-	disable = (res->flags & IORESOURCE_MEM_64) && !dev->mmio_always_on;
+	if (res->flags & IORESOURCE_MEM_64) {
+		if (resno <= PCI_ROM_RESOURCE) {
+			disable = !dev->mmio_always_on;
+			cmd_reg = PCI_COMMAND;
+			bit = PCI_COMMAND_MEMORY;
+		} else {
+#ifdef CONFIG_PCI_IOV
+			disable = true;
+			cmd_reg = dev->sriov->pos + PCI_SRIOV_CTRL;
+			bit = PCI_SRIOV_CTRL_MSE;
+#endif
+		}
+	}
+
 	if (disable) {
-		pci_read_config_word(dev, PCI_COMMAND, &cmd);
-		pci_write_config_word(dev, PCI_COMMAND,
-				      cmd & ~PCI_COMMAND_MEMORY);
+		pci_read_config_word(dev, cmd_reg, &cmd);
+		pci_write_config_word(dev, cmd_reg, cmd & ~bit);
 	}
 
 	pci_write_config_dword(dev, reg, new);
@@ -107,7 +119,7 @@ void pci_update_resource(struct pci_dev *dev, int resno)
 	}
 
 	if (disable)
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
+		pci_write_config_word(dev, cmd_reg, cmd);
 }
 
 int pci_claim_resource(struct pci_dev *dev, int resource)
-- 
2.1.0


  parent reply	other threads:[~2016-10-26  1:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-26  1:15 [PATCH v3 0/2] Disable VF's memory space on updating IOV BARs Gavin Shan
2016-10-26  1:15 ` [PATCH v3 1/2] PCI: Call pcibios_sriov_enable() before IOV BARs are enabled Gavin Shan
2016-10-26  1:15 ` Gavin Shan [this message]
2016-11-23 23:49 ` [PATCH v3 0/2] Disable VF's memory space on updating IOV BARs Bjorn Helgaas
2016-11-29  3:48   ` Bjorn Helgaas

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=1477444536-29612-3-git-send-email-gwshan@linux.vnet.ibm.com \
    --to=gwshan@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=bhelgaas@google.com \
    --cc=clsoto@us.ibm.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    /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).