PCI/PM: Skip resuming to D0 if device is disconnected
PATCH v7 1/1 PCI/PM: Skip resuming to D0 if device is disconnected
From: Mario Limonciello <[email protected]>
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.
---
v7:
* Reword commit message
* Rebase on v6.17-rc5
--- drivers/pci/pci.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/pci/pci.c +5 -0
@@ -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",
Signature · 1 line
2.43.0
Bjorn Helgaas
AppliedQuoted 14 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
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 viapci_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 intopci_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 inpci_power_up()and returning-EIO.
Quoted 5 lines
Suggested-by Lukas Wunner <[email protected]>Reviewed-by Lukas Wunner <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Signed-off-by Mario Limonciello <[email protected]>
Applied to pci/pm for v6.18, thanks, Mario!
Quoted 27 lines
---
v7:
* Reword commit message
* Rebase on v6.17-rc5--- drivers/pci/pci.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/pci/pci.c +5
-0@@ -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",Signature · 1 line
2.43.0
Quoted 7 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
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 viapci_dev_is_disconnected().
Quoted 6 lines
During device removal, the runtime PM framework may attempt to resume the device to D0 via
pm_runtime_get_sync(), which calls intopci_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 inpci_power_up()and returning-EIO.
Hi Mario,
I forgot to ask if there are any characteristic dmesg logs and user activities that we could include here to help users recognize this problem. I suppose it results in messages like this?
pci 0000:01:00.0: Unable to change power state from D3cold to D0, device inaccessible
Maybe especially when undocking? Although oddly a google search for that message and "undock" finds nothing.
Quoted 32 lines
Suggested-by Lukas Wunner <[email protected]>Reviewed-by Lukas Wunner <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Signed-off-by Mario Limonciello <[email protected]>---
v7:
* Reword commit message
* Rebase on v6.17-rc5--- drivers/pci/pci.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/pci/pci.c +5
-0@@ -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",Signature · 1 line
2.43.0
Quoted 17 lines · Bjorn Helgaas
Quoted 7 lines · Mario Limonciello (AMD)
From: Mario Limonciello <[email protected]>
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 viapci_dev_is_disconnected().Quoted 6 lines
During device removal, the runtime PM framework may attempt to resume the device to D0 via
pm_runtime_get_sync(), which calls intopci_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 inpci_power_up()and returning-EIO.Hi Mario,
Quoted 9 lines
I forgot to ask if there are any characteristic dmesg logs and user activities that we could include here to help users recognize this problem. I suppose it results in messages like this?
pci 0000:01:00.0: Unable to change power state from D3cold to D0, device inaccessible
Maybe especially when undocking? Although oddly a google search for that message and "undock" finds nothing.
Yes spot on. The dock needs to be TBT3 or USB4 and the host has to offer PCIe tunneling for it to occur.
Quoted 32 lines
Quoted 32 lines
Suggested-by Lukas Wunner <[email protected]>Reviewed-by Lukas Wunner <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>Signed-off-by Mario Limonciello <[email protected]>---
v7:
* Reword commit message
* Rebase on v6.17-rc5--- drivers/pci/pci.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/pci/pci.c +5
-0@@ -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",Signature · 1 line
2.43.0