Re: [PATCH v5 4/5] PCI: endpoint: pci-epf-vntb: Switch vpci_scan_bus() to use pci_scan_root_bus()
Koichiro Den <[email protected]> Tue, 3 Mar 2026 13:45:53 +0900
| Newsgroups | dev.linux.lists.ntb,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci |
|---|---|
| Message-ID | <eb7iqd7odcyojhybz2w6uqtbqfh5hayou6qpvyq6wtsokv4b4c@dput6rhnc5vt> |
On Mon, Mar 02, 2026 at 09:39:26PM +0530, Manivannan Sadhasivam wrote: > On Thu, Feb 26, 2026 at 05:41:41PM +0900, Koichiro Den wrote: > > vpci_scan_bus() currently uses pci_scan_bus(), which creates a root bus > > without a parent struct device. In a subsequent change we want to tear > > down the virtual PCI root bus using pci_remove_root_bus(). For that to > > work correctly, the root bus must be associated with a parent device, > > similar to what the removed pci_scan_bus_parented() helper used to do. > > > > Switch vpci_scan_bus() to use pci_scan_root_bus() and pass > > &ndev->epf->epc->dev as the parent. Build the resource list in the same > > way as pci_scan_bus(), so the behavior is unchanged except that the > > virtual root bus now has a proper parent device. This avoids crashes in > > the pci_epf_unbind() -> epf_ntb_unbind() -> pci_remove_root_bus() -> > > pci_bus_release_domain_nr() path once we start removing the root bus in > > a follow-up patch. > > > > Reviewed-by: Frank Li <[email protected]> > > Signed-off-by: Koichiro Den <[email protected]> > > --- > > Changes since v4: > > - Correct the subject prefix > > s/NTB: epf: vntb:/PCI: endpoint: pci-epf-vntb:/ > > > > drivers/pci/endpoint/functions/pci-epf-vntb.c | 15 +++++++++++++-- > > 1 file changed, 13 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c > > index 805353528967..f353e9a57194 100644 > > --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c > > +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c > > @@ -1220,8 +1220,19 @@ static int vpci_scan_bus(void *sysdata) > > { > > struct pci_bus *vpci_bus; > > struct epf_ntb *ndev = sysdata; > > - > > - vpci_bus = pci_scan_bus(ndev->vbus_number, &vpci_ops, sysdata); > > + LIST_HEAD(resources); > > + static struct resource busn_res = { > > + .start = 0, > > + .end = 255, > > + .flags = IORESOURCE_BUS, > > + }; > > + > > + pci_add_resource(&resources, &ioport_resource); > > + pci_add_resource(&resources, &iomem_resource); > > + pci_add_resource(&resources, &busn_res); > > + > > + vpci_bus = pci_scan_root_bus(&ndev->epf->epc->dev, ndev->vbus_number, > > + &vpci_ops, sysdata, &resources); > > Don't you need pci_lock_rescan_remove()/pci_unlock_rescan_remove()? Yes, we do need them. Thanks for pointing this out. This locking was already missing before this series (when vpci_scan_bus() used pci_scan_bus()), so I'll add a separate fix patch between Patch 3 and Patch 4, likely with: Fixes: e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP"). ---8<--- diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c index 805353528967..469b6e2b8d45 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -1221,14 +1221,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; } ---8<--- Also, while respinning, I'll fix the error path in the pci_scan_root_bus() version to free the temporary resource list when pci_scan_root_bus() fails, since it doesn't free it on behalf of the caller. I noticed this while revisiting the patch. Best regards, Koichiro > > - Mani > > -- > மணிவண்ணன் சதாசிவம்