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

From: Yury Murashka

Date: Mon Sep 07 2026 - 08:51:06 EST


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 the device is disconnected so event processing can
continue.

Signed-off-by: Yury Murashka <yurypm@xxxxxxxxxx>
Co-authored-by: James Sewart <jamessewart@xxxxxxxxxx>
---
drivers/pci/pci.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

Changes in v2:
- Check pci_dev_is_disconnected() before reading link status instead of
checking the return value of pcie_capability_read_word().

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b2879a6be..a568d5ac1 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4565,8 +4565,9 @@ static int pci_pm_reset(struct pci_dev *dev, bool probe)
* @use_lt: Use the LT bit if TRUE, or the DLLLA bit if FALSE.
* @active: Waiting for active or inactive?
*
- * Return 0 if successful, or -ETIMEDOUT if status has not changed within
- * PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds.
+ * Return 0 if successful, -ENODEV if the device is disconnected, or
+ * -ETIMEDOUT if status has not changed within PCIE_LINK_RETRAIN_TIMEOUT_MS
+ * milliseconds.
*/
static int pcie_wait_for_link_status(struct pci_dev *pdev,
bool use_lt, bool active)
@@ -4580,6 +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 {
+ if (pci_dev_is_disconnected(pdev))
+ return -ENODEV;
pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
if ((lnksta & lnksta_mask) == lnksta_match)
return 0;
@@ -4603,8 +4605,9 @@ static int pcie_wait_for_link_status(struct pci_dev *pdev,
* according to @use_lt. It is not verified whether the use of the DLLLA
* bit is valid.
*
- * Return 0 if successful, or -ETIMEDOUT if training has not completed
- * within PCIE_LINK_RETRAIN_TIMEOUT_MS milliseconds.
+ * Return 0 if successful, -ENODEV if the device is disconnected, or
+ * -ETIMEDOUT if training has not completed within PCIE_LINK_RETRAIN_TIMEOUT_MS
+ * milliseconds.
*/
int pcie_retrain_link(struct pci_dev *pdev, bool use_lt)
{

base-commit: a500db7819c50db59e55f1b4fa1c3baa5a2616f3
--
2.51.0