Re: [PATCH] PCI: Stop waiting for link status after config read failure

From: Lukas Wunner

Date: Sat Sep 05 2026 - 06:10:07 EST


On Fri, Sep 04, 2026 at 04:36:12PM +0100, Yury M. wrote:
> On 9/4/26 13:20, Lukas Wunner wrote:
> > On Fri, Sep 04, 2026 at 11:13:18AM +0000, Yury Murashka wrote:
> > > With a nested PCIe topology with multiple layers of hotplug, a link
> > > can go down near the bottom of the topology shortly before a link
> > > above it goes down. In that case, pcie_wait_for_link_status() can
> > > wait for the full timeout while every read of the link status register
> > > fails because the device has disappeared.
> > >
> > > Return immediately when reading the link status fails so event processing
> > > can continue.
> > [...]
> > > +++ b/drivers/pci/pci.c
> > > @@ -4580,7 +4581,8 @@ static int pcie_wait_for_link_status(struct pci_dev *pdev,
> > > end_jiffies = jiffies + msecs_to_jiffies(PCIE_LINK_RETRAIN_TIMEOUT_MS);
> > > do {
> > > - pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
> > > + if (pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta))
> > > + return -ENODEV;
> > > if ((lnksta & lnksta_mask) == lnksta_match)
> > > return 0;
> > > msleep(1);
> >
> > It might be clearer if you check for pci_dev_is_disconnected() directly
> > instead of relying on a PCIBIOS_DEVICE_NOT_FOUND return value which is
> > generated as a side effect of the device being gone.
>
> what to you think about this check:
>
> if ((pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta) ||
> PCI_POSSIBLE_ERROR(lnksta)) && pci_dev_is_disconnected(pdev))
> return -ENODEV;

It's repetitive because pcie_capability_read_word() already checks
internally for pci_dev_is_disconnected():

pcie_capability_read_word()
pci_read_config_word()
pci_dev_is_disconnected()

I just thought that since you specifically want to bail out in the
hot-removal case, it might be clearer to check pci_dev_is_disconnected()
in pcie_wait_for_link_status() before performing the config space read.

But I don't feel strongly either way and checking the return value of
pcie_capability_read_word() is a viable approach as well.

Thanks,

Lukas