]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI/IOV: Fix race between SR-IOV enable/disable and hotplug
authorNiklas Schnelle <schnelle@linux.ibm.com>
Tue, 16 Dec 2025 22:14:03 +0000 (23:14 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Sun, 1 Feb 2026 22:05:42 +0000 (16:05 -0600)
Commit 05703271c3cd ("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: 05703271c3cd ("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
drivers/pci/iov.c

index 7de5b18647beb69127ba11234fb9f1dec9b50540..4a659c34935e116dd6d0b4ce42ed12a1ba9418d1 100644 (file)
@@ -495,7 +495,9 @@ static ssize_t sriov_numvfs_store(struct device *dev,
 
        if (num_vfs == 0) {
                /* disable VFs */
+               pci_lock_rescan_remove();
                ret = pdev->driver->sriov_configure(pdev, 0);
+               pci_unlock_rescan_remove();
                goto exit;
        }
 
@@ -507,7 +509,9 @@ static ssize_t sriov_numvfs_store(struct device *dev,
                goto exit;
        }
 
+       pci_lock_rescan_remove();
        ret = pdev->driver->sriov_configure(pdev, num_vfs);
+       pci_unlock_rescan_remove();
        if (ret < 0)
                goto exit;