From: Bjorn Helgaas Date: Mon, 26 Oct 2015 03:43:22 +0000 (+0900) Subject: PCI: Set SR-IOV NumVFs to zero after enumeration X-Git-Tag: v4.1.12-92~237^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=82022e587c851d0dc8142fdaa3d34bd8a349f951;p=users%2Fjedix%2Flinux-maple.git PCI: Set SR-IOV NumVFs to zero after enumeration Orabug: 21547430 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. Set NumVFs to zero after virtfn_max_buses() computes the maximum number of buses. Fixes: 4449f079722c ("PCI: Calculate maximum number of buses required for VFs") Based-on-patch-by: Ethan Zhao Signed-off-by: Bjorn Helgaas Signed-off-by: Ethan Zhao --- diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index ee0ebff103a4..3abe15e46dc6 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -384,7 +384,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; @@ -414,11 +414,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; pci_read_config_dword(dev, pos + PCI_SRIOV_SUP_PGSIZE, &pgsz); i = PAGE_SHIFT > 12 ? PAGE_SHIFT - 12 : 0; @@ -456,8 +451,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); @@ -475,6 +468,11 @@ found: dev->sriov = iov; dev->is_physfn = 1; iov->max_VF_buses = virtfn_max_buses(dev); + pci_iov_set_numvfs(dev, 0); + if (!iov->offset || (total > 1 && !iov->stride)) { + rc = -EIO; + goto failed; + } return 0; @@ -483,7 +481,7 @@ failed: res = &dev->resource[i + PCI_IOV_RESOURCES]; res->flags = 0; } - + dev->sriov = NULL; kfree(iov); return rc; }