Skip to content

Commit 3897237

Browse files
Jakub Kicinskibjorn-helgaas
authored andcommitted
PCI/IOV: Reset total_VFs limit after detaching PF driver
The TotalVFs register in the SR-IOV capability is the hardware limit on the number of VFs. A PF driver can limit the number of VFs further with pci_sriov_set_totalvfs(). When the PF driver is removed, reset any VF limit that was imposed by the driver because that limit may not apply to other drivers. Before 8d85a7a ("PCI/IOV: Allow PF drivers to limit total_VFs to 0"), pci_sriov_set_totalvfs(pdev, 0) meant "we can enable TotalVFs virtual functions", and the nfp driver used that to remove the VF limit when the driver unloads. 8d85a7a broke that because instead of removing the VF limit, pci_sriov_set_totalvfs(pdev, 0) actually sets the limit to zero, and that limit persists even if another driver is loaded. We could fix that by making the nfp driver reset the limit when it unloads, but it seems more robust to do it in the PCI core instead of relying on the driver. The regression scenario is: nfp_pci_probe (driver 1) ... nfp_pci_remove pci_sriov_set_totalvfs(pf->pdev, 0) # limits VFs to 0 ... nfp_pci_probe (driver 2) nfp_rtsym_read_le("nfd_vf_cfg_max_vfs") # no VF limit from firmware Now driver 2 is broken because the VF limit is still 0 from driver 1. Fixes: 8d85a7a ("PCI/IOV: Allow PF drivers to limit total_VFs to 0") Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> [bhelgaas: changelog, rename functions] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 3dc6ddf commit 3897237

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎drivers/pci/iov.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,22 @@ void pci_iov_release(struct pci_dev *dev)
574574
sriov_release(dev);
575575
}
576576

577+
/**
578+
* pci_iov_remove - clean up SR-IOV state after PF driver is detached
579+
* @dev: the PCI device
580+
*/
581+
void pci_iov_remove(struct pci_dev *dev)
582+
{
583+
struct pci_sriov *iov = dev->sriov;
584+
585+
if (!dev->is_physfn)
586+
return;
587+
588+
iov->driver_max_VFs = iov->total_VFs;
589+
if (iov->num_VFs)
590+
pci_warn(dev, "driver left SR-IOV enabled after remove\n");
591+
}
592+
577593
/**
578594
* pci_iov_update_resource - update a VF BAR
579595
* @dev: the PCI device

‎drivers/pci/pci-driver.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ static int pci_device_remove(struct device *dev)
445445
}
446446
pcibios_free_irq(pci_dev);
447447
pci_dev->driver = NULL;
448+
pci_iov_remove(pci_dev);
448449
}
449450

450451
/* Undo the runtime PM settings in local_pci_probe() */

‎drivers/pci/pci.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ static inline void pci_restore_ats_state(struct pci_dev *dev)
311311
#ifdef CONFIG_PCI_IOV
312312
int pci_iov_init(struct pci_dev *dev);
313313
void pci_iov_release(struct pci_dev *dev);
314+
void pci_iov_remove(struct pci_dev *dev);
314315
void pci_iov_update_resource(struct pci_dev *dev, int resno);
315316
resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
316317
void pci_restore_iov_state(struct pci_dev *dev);
@@ -323,6 +324,9 @@ static inline int pci_iov_init(struct pci_dev *dev)
323324
}
324325
static inline void pci_iov_release(struct pci_dev *dev)
325326

327+
{
328+
}
329+
static inline void pci_iov_remove(struct pci_dev *dev)
326330
{
327331
}
328332
static inline void pci_restore_iov_state(struct pci_dev *dev)

0 commit comments

Comments
 (0)