[PATCH RFC v2] PCI: pciehp: Fix AB-BA deadlocks between reset_lock, pci_rescan_remove_lock and pci_slot_mutex
Qiang Yu
qiang.yu at oss.qualcomm.com
Thu Dec 3 00:30:19 PST 2026
On Tue, Dec 01, 2026 at 12:24:49PM +0100, Lukas Wunner wrote:
> On Tue, Dec 01, 2026 at 02:29:15AM -0800, Qiang Yu wrote:
> > 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:
> > > > 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.
>
> Doesn't that apply to *any* access to the devices during reset?
> Why prevent a bus scan specifically?
>
It does apply to any access, and I'm not claiming a bus scan is special.
The point is that the other accesses are already accounted for and a bus
scan isn't.
For AER and link-down recovery, drivers are asked to quiesce MMIO via the
error_detected callback before the reset. After a hotplug removal, pciehp
marks the devices disconnected and config space access is short-circuited
in pci_{read,write}_config_*().
We obviously can't defend against arbitrary accesses -- userspace poking
config space or an MMIO mapping directly, say. But every legitimate
in-kernel access during a reset should be covered one way or another, and
a bus scan currently isn't. If there are others, I'd say they want fixing
too.
> If this is Qualcomm-specific, why is it in a generic helper?
>
The race isn't qcom-specific, the severity is. qcom's .reset_root_port()
is just an alternative way of resetting the link and is reached from the
generic pcibios_reset_secondary_bus(). A plain SBR racing a bus scan
leaves the device mis-enumerated; the same race on qcom takes the
controller's clocks and regulators away mid-scan.
> If the Root Port is hotplug-capable, pciehp is prevented from
> de-enumeration and re-enumeration by the mechanism introduced by
> 2af781a9edc4, so why acquire an extra lock to prevent the same thing?
>
I don't think it prevents the same thing. 2af781a9edc4 filters the
spurious hotplug events that an SBR causes, it doesn't stop an SBR from
happening in the middle of pci_scan_slot() or pci_bus_add_devices().
What stops the SBR there is pciehp_reset_slot() blocking on
down_write(reset_lock) -- which is what 5b3f7b7d062b introduced reset_lock
for.
> I assume the NOC error causes an NMI? Shouldn't the NMI handler catch
> that and handle it gracefully?
>
This NOC error always ends in a crash.
- Qiang Yu
More information about the linux-arm-kernel
mailing list