Re: [PATCH 0/9] PCI: controller: Add missing rescan lock around root bus removal
From: Bjorn Helgaas
Date: Mon Jun 22 2026 - 13:13:35 EST
On Fri, Jun 19, 2026 at 11:20:33PM +0800, Hans Zhang wrote:
> On 6/19/26 00:59, Bjorn Helgaas wrote:
> > On Fri, May 22, 2026 at 12:18:13AM +0800, Hans Zhang wrote:
> > > Several PCIe host controller drivers call pci_stop_root_bus() and
> > > pci_remove_root_bus() without holding the global PCI rescan lock
> > > (pci_rescan_remove_global_lock). This can cause race conditions with
> > > concurrent PCI rescan or hotplug operations triggered via sysfs,
> > > potentially leading to use-after-free or system crashes.
> ...
> > Thanks for this work. I amended the commit logs of the eight applied
> > patches so they're all the same (since all the patches do exactly the
> > same thing) and so they all mention the reason for the change.
> >
> > There are only four callers of pci_stop_root_bus() and
> > pci_remove_root_bus() that would not be able to use a trivial helper
> > function that does the lock/stop/remove/unlock internally:
> >
> > zpci_bus_release
> > acpi_pci_root_remove
> > hv_pci_remove
> > vmd_remove
> >
> > It would be nice to analyze those to see if they could use the same
> > pattern, which could be done inside a helper function that would avoid
> > the possibility of adding the same bug elsewhere.
>
> Thank you for reviewing the series and for the constructive suggestion
> regarding the common helper function.
>
> I fully agree that introducing a helper (e.g., pci_remove_root_bus_safe())
> to encapsulate the lock/unlock logic is a cleaner and more maintainable
> approach, and it would help prevent similar issues in the future.
>
> Since we are now in the merge window, I would prefer to hold off on this
> further refactoring until the next cycle to avoid introducing any
> unnecessary risks or conflicts at this late stage.
Definitely. This series is already merged, so this is just potential
future work. I'm not sure I would even add such a helper unless those
last four cases (zpci, acpi, etc) could also use it. Having two
patterns would be only a marginal benefit.