Re: [PATCH RFC v2] PCI: pciehp: Fix AB-BA deadlocks between reset_lock, pci_rescan_remove_lock and pci_slot_mutex
From: Qiang Yu
Date: Tue Dec 01 2026 - 05:29:24 EST
On Sun, Nov 29, 2026 at 10:06:33PM +0100, Lukas Wunner wrote:
> On Thu, Nov 26, 2026 at 12:26:45AM -0800, Qiang Yu wrote:
> > Commit 5b3f7b7d062b ("PCI: pciehp: Avoid slot access during reset")
> > introduced ctrl->reset_lock to serialize a Secondary Bus Reset (SBR)
> > with the pciehp code paths that read the Link Active and Presence
> > Detect bits, both of which flap during an SBR.
> >
> > pciehp_ist() holds reset_lock across the whole event handling,
> > including enumerating or de-enumerating the hotplugged devices. That
> > nests two PCI core locks inside reset_lock, each taken in the opposite
> > order by a concurrent SBR, causing two AB-BA deadlocks.
>
> It looks like you're trying to fix two separate deadlocks in a single
> patch. Can this be split in two patches?
>
Both deadlocks are fixed by the same hunk: in pciehp_configure_device()
and pciehp_unconfigure_device(), the up_read() / down_read_nested() pair
is moved so that it wraps the whole pci_lock_rescan_remove() section.
reset_lock then no longer nests pci_rescan_remove_lock or
pci_slot_mutex, which breaks both AB-BA chains at once.
What that hunk gives up is the serialization between a bridge reset and
bus scanning, which reset_lock used to provide. The pci.c changes add
it back via pci_rescan_remove_lock, so they belong with the same hunk --
hence one patch.
> > A Root Port reset from link-down recovery takes them the other way
> > round, pci_rescan_remove_lock -> reset_lock (the boot path, via
> > pci_host_probe(), takes the same reverse order):
> >
> > qcom_pcie_global_irq_thread()
> > pci_host_handle_link_down()
> > pci_host_reset_root_port()
> > pci_lock_rescan_remove() # pci_rescan_remove_lock
> > pci_bus_error_reset()
> > pci_reset_bridge()
> > pci_slot_reset()
> > pci_reset_hotplug_slot()
> > pciehp_reset_slot() # down_write(reset_lock)
>
> Why is it necessary to lock rescan/remove for a reset?
> This looks wrong. I suggest removing pci_lock_rescan_remove()
> from pci_host_reset_root_port().
>
It's needed because on qcom the reset goes through host->reset_root_port()
-> qcom_pcie_reset_root_port() which powers down the PHY, disables clocks
and regulators before re-training. So a concurrent bus scan would access
config space and lead to NOC error in that window.
- Qiang Yu