Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH v7] PCI/PM: Skip resuming to D0 if device is disconnected
@ 2025-09-09  3:19 Mario Limonciello (AMD)
  2025-09-17 22:03 ` Bjorn Helgaas
  2025-09-18 22:08 ` Bjorn Helgaas
  0 siblings, 2 replies; 4+ messages in thread
From: Mario Limonciello (AMD) @ 2025-09-09  3:19 UTC (permalink / raw)
  To: mario.limonciello, bhelgaas
  Cc: Lukas Wunner, Ilpo Järvinen, Rafael J . Wysocki, linux-pci

From: Mario Limonciello <mario.limonciello@amd.com>

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@wunner.de>
Reviewed-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v7] PCI/PM: Skip resuming to D0 if device is disconnected
  2025-09-09  3:19 [PATCH v7] PCI/PM: Skip resuming to D0 if device is disconnected Mario Limonciello (AMD)
@ 2025-09-17 22:03 ` Bjorn Helgaas
  2025-09-18 22:08 ` Bjorn Helgaas
  1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2025-09-17 22:03 UTC (permalink / raw)
  To: Mario Limonciello (AMD)
  Cc: mario.limonciello, bhelgaas, Lukas Wunner, Ilpo Järvinen,
	Rafael J . Wysocki, linux-pci

On Mon, Sep 08, 2025 at 10:19:15PM -0500, Mario Limonciello (AMD) wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> 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@wunner.de>
> Reviewed-by: Lukas Wunner <lukas@wunner.de>
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Acked-by: Rafael J. Wysocki <rafael@kernel.org>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>

Applied to pci/pm for v6.18, thanks, Mario!

> ---
> 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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v7] PCI/PM: Skip resuming to D0 if device is disconnected
  2025-09-09  3:19 [PATCH v7] PCI/PM: Skip resuming to D0 if device is disconnected Mario Limonciello (AMD)
  2025-09-17 22:03 ` Bjorn Helgaas
@ 2025-09-18 22:08 ` Bjorn Helgaas
  2025-09-19  1:29   ` Mario Limonciello
  1 sibling, 1 reply; 4+ messages in thread
From: Bjorn Helgaas @ 2025-09-18 22:08 UTC (permalink / raw)
  To: Mario Limonciello (AMD)
  Cc: mario.limonciello, bhelgaas, Lukas Wunner, Ilpo Järvinen,
	Rafael J . Wysocki, linux-pci

On Mon, Sep 08, 2025 at 10:19:15PM -0500, Mario Limonciello (AMD) wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> 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.

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.

> Suggested-by: Lukas Wunner <lukas@wunner.de>
> Reviewed-by: Lukas Wunner <lukas@wunner.de>
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Acked-by: Rafael J. Wysocki <rafael@kernel.org>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> 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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v7] PCI/PM: Skip resuming to D0 if device is disconnected
  2025-09-18 22:08 ` Bjorn Helgaas
@ 2025-09-19  1:29   ` Mario Limonciello
  0 siblings, 0 replies; 4+ messages in thread
From: Mario Limonciello @ 2025-09-19  1:29 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: mario.limonciello, bhelgaas, Lukas Wunner, Ilpo Järvinen,
	Rafael J . Wysocki, linux-pci



On 9/18/25 5:08 PM, Bjorn Helgaas wrote:
> On Mon, Sep 08, 2025 at 10:19:15PM -0500, Mario Limonciello (AMD) wrote:
>> From: Mario Limonciello <mario.limonciello@amd.com>
>>
>> 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.
> 
> 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.
> 

Yes spot on.  The dock needs to be TBT3 or USB4 and the host has to 
offer PCIe tunneling for it to occur.

>> Suggested-by: Lukas Wunner <lukas@wunner.de>
>> Reviewed-by: Lukas Wunner <lukas@wunner.de>
>> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
>> Acked-by: Rafael J. Wysocki <rafael@kernel.org>
>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>> ---
>> 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
>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-19  1:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-09  3:19 [PATCH v7] PCI/PM: Skip resuming to D0 if device is disconnected Mario Limonciello (AMD)
2025-09-17 22:03 ` Bjorn Helgaas
2025-09-18 22:08 ` Bjorn Helgaas
2025-09-19  1:29   ` Mario Limonciello

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox