From: Alexander Duyck <aduyck@mirantis.com>
To: bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 5/5] iov: Update sriov_enable to correctly handle offset and stride
Date: Tue, 27 Oct 2015 13:52:40 -0700 [thread overview]
Message-ID: <20151027205240.14626.85603.stgit@localhost.localdomain> (raw)
In-Reply-To: <20151027204607.14626.59671.stgit@localhost.localdomain>
As per the SR-IOV spec the values for offset and stride are undefined until
ARI and numVFs have been set. As such we should not be reading them until
the values have been assigned to the hardware. In addition if numVFs is 0
the values for offset and stride are defined as unused.
This change corrects a spot where we were reading the offset and stride
even though we had left numVFs set to 0.
Signed-off-by: Alexander Duyck <aduyck@mirantis.com>
---
drivers/pci/iov.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index c0fc88fa7c4d..030568520772 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -241,11 +241,11 @@ int __weak pcibios_sriov_disable(struct pci_dev *pdev)
static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
{
- u16 offset, stride, initial;
struct resource *res;
struct pci_dev *pdev;
struct pci_sriov *iov = dev->sriov;
int rc, i, nres, bars, bus;
+ u16 initial;
if (!nr_virtfn)
return 0;
@@ -262,11 +262,6 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
(!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial)))
return -EINVAL;
- pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_OFFSET, &offset);
- pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_STRIDE, &stride);
- if (!offset || (nr_virtfn > 1 && !stride))
- return -EIO;
-
for (nres = 0, bars = 0, i = PCI_SRIOV_NUM_BARS; i--;) {
bars |= (1 << (i + PCI_IOV_RESOURCES));
res = &dev->resource[i + PCI_IOV_RESOURCES];
@@ -278,16 +273,6 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
return -ENOMEM;
}
- iov->offset = offset;
- iov->stride = stride;
-
- bus = pci_iov_virtfn_bus(dev, nr_virtfn - 1);
- if (bus > dev->bus->busn_res.end) {
- dev_err(&dev->dev, "can't enable %d VFs (bus %02x out of range of %pR)\n",
- nr_virtfn, bus, &dev->bus->busn_res);
- return -ENOMEM;
- }
-
if (pci_enable_resources(dev, bars)) {
dev_err(&dev->dev, "SR-IOV: IOV BARS not allocated\n");
return -ENOMEM;
@@ -311,6 +296,15 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
}
pci_iov_set_numvfs(dev, nr_virtfn);
+
+ bus = pci_iov_virtfn_bus(dev, nr_virtfn - 1);
+ if (bus > dev->bus->busn_res.end) {
+ dev_err(&dev->dev, "can't enable %d VFs (bus %02x out of range of %pR)\n",
+ nr_virtfn, bus, &dev->bus->busn_res);
+ rc = -ENOMEM;
+ goto err_bus;
+ }
+
iov->ctrl |= PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE;
pci_cfg_access_lock(dev);
pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);
@@ -350,7 +344,7 @@ err_pcibios:
pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);
ssleep(1);
pci_cfg_access_unlock(dev);
-
+err_bus:
if (iov->link != dev->devfn)
sysfs_remove_link(&dev->dev.kobj, "dep_link");
prev parent reply other threads:[~2015-10-27 20:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-27 20:52 [PATCH 0/5] Various of SR-IOV fixes and cleanup Alexander Duyck
2015-10-27 20:52 ` [PATCH 1/5] iov: Update virtfn_max_buses to validate offset and stride Alexander Duyck
2015-10-28 16:32 ` Bjorn Helgaas
2015-10-28 17:57 ` Alexander Duyck
2015-10-28 18:43 ` Bjorn Helgaas
2015-10-28 21:46 ` Alexander Duyck
2015-10-29 19:50 ` Bjorn Helgaas
2015-10-27 20:52 ` [PATCH 2/5] iov: Reset resources to 0 if totalVFs increases after enabling ARI Alexander Duyck
2015-10-28 16:37 ` Bjorn Helgaas
2015-10-28 18:32 ` Alexander Duyck
2015-10-28 19:52 ` Bjorn Helgaas
2015-10-28 21:37 ` Alexander Duyck
2015-10-27 20:52 ` [PATCH 3/5] iov: Fix sriov_enable exception handling path Alexander Duyck
2015-10-29 16:32 ` Bjorn Helgaas
2015-10-29 16:54 ` Alex Duyck
2015-10-29 20:41 ` Bjorn Helgaas
2015-10-27 20:52 ` [PATCH 4/5] iov: Variable and loop cleanup for sriov_disable and sriov_enable Alexander Duyck
2015-10-29 21:43 ` Bjorn Helgaas
2015-10-29 23:19 ` Alexander Duyck
2015-10-27 20:52 ` Alexander Duyck [this message]
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=20151027205240.14626.85603.stgit@localhost.localdomain \
--to=aduyck@mirantis.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
/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).