[PATCH v6 1/2] PCI: endpoint: pci-epf-vntb: Serialize virtual PCI bus scan

From: Koichiro Den

Date: Tue Sep 01 2026 - 02:34:51 EST


The virtual PCI bus is scanned without holding the PCI rescan/remove
lock. This can race with other PCI topology changes.

Hold the lock across the bus scan and device addition.

Fixes: e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP")
Suggested-by: Manivannan Sadhasivam <mani@xxxxxxxxxx>
Link: https://lore.kernel.org/r/3tgrcel5fl55ulf3zjya4fkz4t2ms7iwwjif5rnzn2rafsydd6@i4e5etm7uqvz/
Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
---
Changes in v6:
- New patch based on Mani's review of v5 patch 4.

drivers/pci/endpoint/functions/pci-epf-vntb.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
index c3caec927d74..412e8cc6fb1d 100644
--- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
+++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
@@ -1332,14 +1332,19 @@ static int vpci_scan_bus(void *sysdata)
struct pci_bus *vpci_bus;
struct epf_ntb *ndev = sysdata;

+ pci_lock_rescan_remove();
+
vpci_bus = pci_scan_bus(ndev->vbus_number, &vpci_ops, sysdata);
if (!vpci_bus) {
pr_err("create pci bus failed\n");
+ pci_unlock_rescan_remove();
return -EINVAL;
}

pci_bus_add_devices(vpci_bus);

+ pci_unlock_rescan_remove();
+
return 0;
}

--
2.51.0