[PATCH v7] PCI/PM: Skip resuming to D0 if device is disconnected

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Mario Limonciello <mario.limonciello@xxxxxxx>

When a PCIe device is surprise-removed (e.g., due to a dock unplug),
the PCI core unconfigures all downstream devices and sets their error
state to `pci_channel_io_perm_failure`. This marks them as disconnected
via `pci_dev_is_disconnected()`.

During device removal, the runtime PM framework may attempt to resume
the device to D0 via `pm_runtime_get_sync()`, which calls into
`pci_power_up()`. Since the device is already disconnected, this
resume attempt is unnecessary and results in a predictable error.
Avoid powering up disconnected devices by checking their status early
in `pci_power_up()` and returning -EIO.

Suggested-by: Lukas Wunner <lukas@xxxxxxxxx>
Reviewed-by: Lukas Wunner <lukas@xxxxxxxxx>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
Acked-by: Rafael J. Wysocki <rafael@xxxxxxxxxx>
Signed-off-by: Mario Limonciello <mario.limonciello@xxxxxxx>
---
v7:
 * Reword commit message
 * Rebase on v6.17-rc5
---
 drivers/pci/pci.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b0f4d98036cdd..036511f5b2625 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1374,6 +1374,11 @@ int pci_power_up(struct pci_dev *dev)
 		return -EIO;
 	}
 
+	if (pci_dev_is_disconnected(dev)) {
+		dev->current_state = PCI_D3cold;
+		return -EIO;
+	}
+
 	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
 	if (PCI_POSSIBLE_ERROR(pmcsr)) {
 		pci_err(dev, "Unable to change power state from %s to D0, device inaccessible\n",
-- 
2.43.0





[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux