From: Wei Yang <weiyang@linux.vnet.ibm.com>
To: Wei Yang <weiyang@linux.vnet.ibm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Alexander Duyck <aduyck@mirantis.com>,
linux-pci@vger.kernel.org, Ethan Zhao <ethan.zhao@oracle.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/7] PCI: Set SR-IOV NumVFs to zero after enumeration
Date: Fri, 30 Oct 2015 13:25:08 +0800 [thread overview]
Message-ID: <20151030052508.GA5269@richards-mbp.cn.ibm.com> (raw)
In-Reply-To: <20151030034821.GB3551@richards-mbp.cn.ibm.com>
On Fri, Oct 30, 2015 at 11:48:21AM +0800, Wei Yang wrote:
>On Thu, Oct 29, 2015 at 05:22:54PM -0500, Bjorn Helgaas wrote:
>>ines: 115
>>
>>From: Alexander Duyck <aduyck@mirantis.com>
>>
>>The enumeration path should leave NumVFs set to zero. But after
>>4449f079722c ("PCI: Calculate maximum number of buses required for VFs"),
>>we call virtfn_max_buses() in the enumeration path, which changes NumVFs.
>>This NumVFs change is visible via lspci and sysfs until a driver enables
>>SR-IOV.
>>
>>Iterate from TotalVFs down to zero so NumVFs is zero when we're finished
>>computing the maximum number of buses. Validate offset and stride in
>>the loop, so we can test it at every possible NumVFs setting. Rename
>>virtfn_max_buses() to compute_max_vf_buses() to hint that it does have a
>>side effect of updating iov->max_VF_buses.
>>
>>[bhelgaas: changelog, rename, allow numVF==1 && stride==0, rework loop,
>>reverse sense of error path]
>>Fixes: 4449f079722c ("PCI: Calculate maximum number of buses required for VFs")
>>Based-on-patch-by: Ethan Zhao <ethan.zhao@oracle.com>
>>Signed-off-by: Alexander Duyck <aduyck@mirantis.com>
>>Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
>>---
>> drivers/pci/iov.c | 41 ++++++++++++++++++++++-------------------
>> 1 file changed, 22 insertions(+), 19 deletions(-)
>>
>>diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
>>index 0cdb2d1..1b1acc2 100644
>>--- a/drivers/pci/iov.c
>>+++ b/drivers/pci/iov.c
>>@@ -54,24 +54,29 @@ static inline void pci_iov_set_numvfs(struct pci_dev *dev, int nr_virtfn)
>> * The PF consumes one bus number. NumVFs, First VF Offset, and VF Stride
>> * determine how many additional bus numbers will be consumed by VFs.
>> *
>>- * Iterate over all valid NumVFs and calculate the maximum number of bus
>>- * numbers that could ever be required.
>>+ * Iterate over all valid NumVFs, validate offset and stride, and calculate
>>+ * the maximum number of bus numbers that could ever be required.
>> */
>>-static inline u8 virtfn_max_buses(struct pci_dev *dev)
>>+static int compute_max_vf_buses(struct pci_dev *dev)
>> {
>> struct pci_sriov *iov = dev->sriov;
>>- int nr_virtfn;
>>- u8 max = 0;
>>- int busnr;
>>+ int nr_virtfn, busnr, rc = 0;
>>
>>- for (nr_virtfn = 1; nr_virtfn <= iov->total_VFs; nr_virtfn++) {
>>+ for (nr_virtfn = iov->total_VFs; nr_virtfn; nr_virtfn--) {
>
>Hmm... I agree to iterate the nr_virtfn from total_VFs to 0, which keep the
>original logic, before my patch.
>
>
>> pci_iov_set_numvfs(dev, nr_virtfn);
>>+ if (!iov->offset || (nr_virtfn > 1 && !iov->stride)) {
> ^^^
After reading the SPEC, I think this code is correct. The original one removed
below may not comply with the SPEC.
>
>Should be this?
> if (!iov->offset || (iov->total_VFs > 1 && !iov->stride))
>
>
>>+ rc = -EIO;
>>+ goto out;
>>+ }
>>+
>> busnr = pci_iov_virtfn_bus(dev, nr_virtfn - 1);
>>- if (busnr > max)
>>- max = busnr;
>>+ if (busnr > iov->max_VF_buses)
>>+ iov->max_VF_buses = busnr;
>> }
>>
>>- return max;
>>+out:
>>+ pci_iov_set_numvfs(dev, 0);
>>+ return rc;
>> }
>>
>> static struct pci_bus *virtfn_add_bus(struct pci_bus *bus, int busnr)
>>@@ -384,7 +389,7 @@ static int sriov_init(struct pci_dev *dev, int pos)
>> int rc;
>> int nres;
>> u32 pgsz;
>>- u16 ctrl, total, offset, stride;
>>+ u16 ctrl, total;
>> struct pci_sriov *iov;
>> struct resource *res;
>> struct pci_dev *pdev;
>>@@ -410,11 +415,6 @@ static int sriov_init(struct pci_dev *dev, int pos)
>>
>> found:
>> pci_write_config_word(dev, pos + PCI_SRIOV_CTRL, ctrl);
>>- pci_write_config_word(dev, pos + PCI_SRIOV_NUM_VF, 0);
>>- pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &offset);
>>- pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &stride);
>>- if (!offset || (total > 1 && !stride))
>>- return -EIO;
>>
>
>Original code will return when it found this condition, so that we don't need
>to bother to do those initialization and then fall back.
>
>So I suggest to keep it here.
>
>> pci_read_config_word(dev, pos + PCI_SRIOV_TOTAL_VF, &total);
>> if (!total)
>>@@ -456,8 +456,6 @@ found:
>> iov->nres = nres;
>> iov->ctrl = ctrl;
>> iov->total_VFs = total;
>>- iov->offset = offset;
>>- iov->stride = stride;
>> iov->pgsz = pgsz;
>> iov->self = dev;
>> pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap);
>>@@ -474,10 +472,15 @@ found:
>>
>> dev->sriov = iov;
>> dev->is_physfn = 1;
>>- iov->max_VF_buses = virtfn_max_buses(dev);
>>+ rc = compute_max_vf_buses(dev);
>>+ if (rc)
>>+ goto fail_max_buses;
>>
>> return 0;
>>
>>+fail_max_buses:
>>+ dev->sriov = NULL;
>
>The dev->sriov is allocated with kzalloc(), seems we forget to release it?
>
>>+ dev->is_physfn = 0;
>> failed:
>> for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
>> res = &dev->resource[i + PCI_IOV_R
>
>--
>Richard Yang
>Help you, Help me
--
Richard Yang
Help you, Help me
next prev parent reply other threads:[~2015-10-30 5:25 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-29 22:22 [PATCH v2 0/7] SR-IOV fixes and cleanup Bjorn Helgaas
2015-10-29 22:22 ` [PATCH v2 1/7] PCI: Set SR-IOV NumVFs to zero after enumeration Bjorn Helgaas
2015-10-30 3:48 ` Wei Yang
2015-10-30 5:25 ` Wei Yang [this message]
2015-10-30 15:40 ` Alexander Duyck
2015-11-02 7:28 ` Wei Yang
2015-10-29 22:23 ` [PATCH v2 2/7] PCI: Remove redundant validation of SR-IOV offset/stride registers Bjorn Helgaas
2015-10-30 5:08 ` Wei Yang
2015-10-29 22:23 ` [PATCH v2 3/7] PCI: Remove VFs in reverse order if virtfn_add() fails Bjorn Helgaas
2015-10-30 5:09 ` Wei Yang
2015-10-29 22:23 ` [PATCH v2 4/7] PCI: Reorder pcibios_sriov_disable() Bjorn Helgaas
2015-10-30 5:09 ` Wei Yang
2015-10-29 22:23 ` [PATCH v2 5/7] PCI: Wait 1 second between disabling VFs and clearing NumVFs Bjorn Helgaas
2015-10-30 5:14 ` Wei Yang
2015-10-30 6:00 ` ethan zhao
2015-10-30 15:57 ` Alexander Duyck
2015-11-02 8:33 ` Wei Yang
2015-11-02 15:46 ` Alexander Duyck
2015-11-03 2:01 ` Wei Yang
2015-11-03 2:04 ` Wei Yang
2015-10-29 22:23 ` [PATCH v2 6/7] PCI: Fix sriov_enable() error path for pcibios_enable_sriov() failures Bjorn Helgaas
2015-10-30 5:18 ` Wei Yang
2015-10-29 22:23 ` [PATCH v2 7/7] PCI: Set NumVFs before computing how many buses VFs require Bjorn Helgaas
2015-10-30 5:22 ` Wei Yang
2015-10-30 16:03 ` Alexander Duyck
2015-11-02 8:27 ` Wei Yang
2015-11-02 15:39 ` Alexander Duyck
2015-11-03 2:18 ` Wei Yang
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=20151030052508.GA5269@richards-mbp.cn.ibm.com \
--to=weiyang@linux.vnet.ibm.com \
--cc=aduyck@mirantis.com \
--cc=bhelgaas@google.com \
--cc=ethan.zhao@oracle.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
all inboxes | Powered by JetHome®