From: Bjorn Helgaas <helgaas@kernel.org>
To: Hans Zhang <18255117159@163.com>
Cc: bhelgaas@google.com, lpieralisi@kernel.org,
kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org,
a-garg7@ti.com, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/9] PCI: controller: Add missing rescan lock around root bus removal
Date: Thu, 18 Jun 2026 11:59:14 -0500 [thread overview]
Message-ID: <20260618165914.GA394420@bhelgaas> (raw)
In-Reply-To: <20260521161822.132996-1-18255117159@163.com>
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.
>
> This series adds the missing lock pairs to all drivers currently
> exhibiting this pattern. No functional change other than proper
> synchronization.
>
> Each patch is independent and targets a specific controller driver.
> Please review and apply.
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.
> ---
> The following are the comments from the sashiko-bot@kernel.org review.
>
> https://lore.kernel.org/linux-pci/20260519132017.63E1BC2BCB3@smtp.kernel.org/
> """
> > +void cdns_pcie_hpa_host_disable(struct cdns_pcie_rc *rc)
> > +{
> > + struct pci_host_bridge *bridge;
> > +
> > + cdns_pcie_debugfs_deinit(&rc->pcie);
> > + bridge = pci_host_bridge_from_priv(rc);
> > + pci_stop_root_bus(bridge->bus);
> > + pci_remove_root_bus(bridge->bus);
> > +}
>
> Could this lead to a race condition during root bus teardown?
>
> Calling pci_stop_root_bus() and pci_remove_root_bus() without holding the
> PCI rescan lock allows race conditions with concurrent PCI rescan or hotplug
> operations triggered via sysfs.
>
> While this pattern might have been copied from a pre-existing function like
> cdns_pcie_host_disable(), does it need to be fixed here to prevent
> use-after-free or system crashes?
>
> Should these operations be protected by acquiring the lock using
> pci_lock_rescan_remove() and pci_unlock_rescan_remove()?
> """
>
>
> The function cdns_pcie_hpa_host_disable() mentioned in the bot's comment is from
> a separate patch series and will be fixed independently. This series focuses only
> on existing controller drivers in the mainline kernel.
> ---
>
> Hans Zhang (9):
> PCI: cadence: Protect root bus removal with rescan lock
> PCI: dwc: Protect root bus removal with rescan lock
> PCI: altera: Protect root bus removal with rescan lock
> PCI: brcmstb: Protect root bus removal with rescan lock
> PCI: iproc: Protect root bus removal with rescan lock
> PCI: mediatek: Protect root bus removal with rescan lock
> PCI: rockchip: Protect root bus removal with rescan lock
> PCI: vmd: Protect root bus removal with rescan lock
> PCI: plda: Protect root bus removal with rescan lock
>
> drivers/pci/controller/cadence/pcie-cadence-host.c | 2 ++
> drivers/pci/controller/dwc/pcie-designware-host.c | 2 ++
> drivers/pci/controller/pcie-altera.c | 2 ++
> drivers/pci/controller/pcie-brcmstb.c | 2 ++
> drivers/pci/controller/pcie-iproc.c | 2 ++
> drivers/pci/controller/pcie-mediatek.c | 2 ++
> drivers/pci/controller/pcie-rockchip-host.c | 2 ++
> drivers/pci/controller/plda/pcie-plda-host.c | 2 ++
> drivers/pci/controller/vmd.c | 2 ++
> 9 files changed, 18 insertions(+)
>
>
> base-commit: 6916d5703ddf9a38f1f6c2cc793381a24ee914c6
> --
> 2.34.1
>
prev parent reply other threads:[~2026-06-18 16:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 16:18 [PATCH 0/9] PCI: controller: Add missing rescan lock around root bus removal Hans Zhang
2026-05-21 16:18 ` [PATCH 1/9] PCI: cadence: Protect root bus removal with rescan lock Hans Zhang
2026-05-21 16:18 ` [PATCH 2/9] PCI: dwc: " Hans Zhang
2026-05-21 16:18 ` [PATCH 3/9] PCI: altera: " Hans Zhang
2026-05-21 18:51 ` sashiko-bot
2026-05-21 16:18 ` [PATCH 4/9] PCI: brcmstb: " Hans Zhang
2026-05-21 19:19 ` sashiko-bot
2026-05-21 16:18 ` [PATCH 5/9] PCI: iproc: " Hans Zhang
2026-05-21 16:18 ` [PATCH 6/9] PCI: mediatek: " Hans Zhang
2026-05-21 20:11 ` sashiko-bot
2026-05-21 16:18 ` [PATCH 7/9] PCI: rockchip: " Hans Zhang
2026-05-21 20:40 ` sashiko-bot
2026-05-21 16:18 ` [PATCH 8/9] PCI: vmd: " Hans Zhang
2026-05-21 21:20 ` sashiko-bot
2026-06-10 17:28 ` Manivannan Sadhasivam
2026-06-11 4:42 ` Hans Zhang
2026-06-11 6:30 ` Manivannan Sadhasivam
2026-06-11 14:00 ` Hans Zhang
2026-05-21 16:18 ` [PATCH 9/9] PCI: plda: " Hans Zhang
2026-06-11 7:04 ` (subset) [PATCH 0/9] PCI: controller: Add missing rescan lock around root bus removal Manivannan Sadhasivam
2026-06-18 16:59 ` Bjorn Helgaas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260618165914.GA394420@bhelgaas \
--to=helgaas@kernel.org \
--cc=18255117159@163.com \
--cc=a-garg7@ti.com \
--cc=bhelgaas@google.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox