Skip to content
/ linux Public

Commit 7c37920

Browse files
niklas88Sasha Levin
authored andcommitted
PCI/IOV: Fix race between SR-IOV enable/disable and hotplug
[ Upstream commit a5338e3 ] Commit 0570327 ("PCI/IOV: Add PCI rescan-remove locking when enabling/disabling SR-IOV") tried to fix a race between the VF removal inside sriov_del_vfs() and concurrent hot unplug by taking the PCI rescan/remove lock in sriov_del_vfs(). Similarly the PCI rescan/remove lock was also taken in sriov_add_vfs() to protect addition of VFs. This approach however causes deadlock on trying to remove PFs with SR-IOV enabled because PFs disable SR-IOV during removal and this removal happens under the PCI rescan/remove lock. So the original fix had to be reverted. Instead of taking the PCI rescan/remove lock in sriov_add_vfs() and sriov_del_vfs(), fix the race that occurs with SR-IOV enable and disable vs hotplug higher up in the callchain by taking the lock in sriov_numvfs_store() before calling into the driver's sriov_configure() callback. Fixes: 0570327 ("PCI/IOV: Add PCI rescan-remove locking when enabling/disabling SR-IOV") Reported-by: Benjamin Block <bblock@linux.ibm.com> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Benjamin Block <bblock@linux.ibm.com> Reviewed-by: Gerd Bayer <gbayer@linux.ibm.com> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20251216-revert_sriov_lock-v3-2-dac4925a7621@linux.ibm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 83651d3 commit 7c37920

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/pci/iov.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,9 @@ static ssize_t sriov_numvfs_store(struct device *dev,
448448

449449
if (num_vfs == 0) {
450450
/* disable VFs */
451+
pci_lock_rescan_remove();
451452
ret = pdev->driver->sriov_configure(pdev, 0);
453+
pci_unlock_rescan_remove();
452454
goto exit;
453455
}
454456

@@ -460,7 +462,9 @@ static ssize_t sriov_numvfs_store(struct device *dev,
460462
goto exit;
461463
}
462464

465+
pci_lock_rescan_remove();
463466
ret = pdev->driver->sriov_configure(pdev, num_vfs);
467+
pci_unlock_rescan_remove();
464468
if (ret < 0)
465469
goto exit;
466470

0 commit comments

Comments
 (0)