* [PATCH] PCI/PM: Reject invalid PMCSR when checking PME status
@ 2026-12-01 7:25 xianhutan
2026-12-01 10:20 ` Lukas Wunner
0 siblings, 1 reply; 4+ messages in thread
From: xianhutan @ 2026-12-01 7:25 UTC (permalink / raw)
To: linux-pci; +Cc: bhelgaas, linux-kernel
From: Xianhu Tan <xianhutan@asrmicro.com>
pci_check_pme_status() reads PMCSR and tests PME_STATUS without
checking whether the configuration read succeeded or returned
a valid value.
When the device or its upstream bridge is inaccessible, the
configuration read may fail or return all ones. Since bit 15
of 0xffff is set, the PCI core incorrectly interprets the
PME_STATUS bit as asserted and reports a spurious PME event,
triggering a runtime resume of an already suspended device.
The issue occurs in pci_pme_list_scan(), which scans the PME
device list and calls pci_check_pme_status() for each entry.
On the affected platform, a device that has just entered
D3hot with the PCIe link in L1 may return 0xffff when PMCSR
is read, causing the PME scan to incorrectly trigger a
runtime resume.
Check the return value of pci_read_config_word() and reject
an all-ones PMCSR before checking PME_STATUS.
This also prevents writing PMCSR back to an inaccessible
device.
Tested on:
- ARM32 platform with PCIe endpoint.
Test cases:
- PMCSR read returns 0xffff: no false PME event is reported.
- Normal PME status handling remains unchanged.
Signed-off-by: Xianhu Tan <xianhutan@asrmicro.com>
---
drivers/pci/pci.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8..d1f8ff856 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -2323,6 +2323,7 @@ void pcie_clear_root_pme_status(struct pci_dev *dev)
bool pci_check_pme_status(struct pci_dev *dev)
{
int pmcsr_pos;
+ int rc;
u16 pmcsr;
bool ret = false;
@@ -2330,7 +2331,10 @@ bool pci_check_pme_status(struct pci_dev *dev)
return false;
pmcsr_pos = dev->pm_cap + PCI_PM_CTRL;
- pci_read_config_word(dev, pmcsr_pos, &pmcsr);
+ rc = pci_read_config_word(dev, pmcsr_pos, &pmcsr);
+ if (rc != PCIBIOS_SUCCESSFUL || pmcsr == 0xffff)
+ return false;
+
if (!(pmcsr & PCI_PM_CTRL_PME_STATUS))
return false;
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI/PM: Reject invalid PMCSR when checking PME status
2026-12-01 7:25 [PATCH] PCI/PM: Reject invalid PMCSR when checking PME status xianhutan
@ 2026-12-01 10:20 ` Lukas Wunner
2026-12-02 6:29 ` [PATCH v2] " xianhutan
0 siblings, 1 reply; 4+ messages in thread
From: Lukas Wunner @ 2026-12-01 10:20 UTC (permalink / raw)
To: xianhutan; +Cc: linux-pci, bhelgaas, linux-kernel
On Tue, Dec 01, 2026 at 03:25:01PM +0800, xianhutan@asrmicro.com wrote:
> +++ b/drivers/pci/pci.c
> @@ -2323,6 +2323,7 @@ void pcie_clear_root_pme_status(struct pci_dev *dev)
> bool pci_check_pme_status(struct pci_dev *dev)
> {
> int pmcsr_pos;
> + int rc;
> u16 pmcsr;
> bool ret = false;
>
> @@ -2330,7 +2331,10 @@ bool pci_check_pme_status(struct pci_dev *dev)
> return false;
>
> pmcsr_pos = dev->pm_cap + PCI_PM_CTRL;
> - pci_read_config_word(dev, pmcsr_pos, &pmcsr);
> + rc = pci_read_config_word(dev, pmcsr_pos, &pmcsr);
> + if (rc != PCIBIOS_SUCCESSFUL || pmcsr == 0xffff)
> + return false;
> +
You can just use PCI_POSSIBLE_ERROR() instead of checking for 0xffff.
I'm not sure whether checking the return value is necessary or useful,
usually checking for PCI_POSSIBLE_ERROR() is sufficient.
Thanks,
Lukas
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] PCI/PM: Reject invalid PMCSR when checking PME status
2026-12-01 10:20 ` Lukas Wunner
@ 2026-12-02 6:29 ` xianhutan
2026-12-06 0:04 ` Bjorn Helgaas
0 siblings, 1 reply; 4+ messages in thread
From: xianhutan @ 2026-12-02 6:29 UTC (permalink / raw)
To: linux-pci; +Cc: bhelgaas, lukas, linux-kernel
From: Xianhu Tan <xianhutan@asrmicro.com>
pci_check_pme_status() reads the PMCSR and checks the PME_STATUS
bit without validating the value read from the device.
If the device or its upstream bridge is inaccessible, a
configuration read may return all ones. Since bit 15 of 0xffff
is set, the PCI core incorrectly interprets the value as an
asserted PME_STATUS bit and reports a spurious PME event.
This can cause an unnecessary runtime resume of a suspended
device.
The issue occurs in pci_pme_list_scan(), which scans devices
on the PME list and calls pci_check_pme_status() to check
their PME status.
On the affected platform, reading the PMCSR after the device
enters D3hot with the PCIe link in L1 returns 0xffff, causing
the PME scan to trigger a false PME event.
Use PCI_POSSIBLE_ERROR() to reject an invalid PMCSR value
before checking PME_STATUS.
This also prevents writing the invalid PMCSR value back to
the device when clearing the PME status.
Tested on:
- ARM32 platform with PCIe endpoint.
Test cases:
- PMCSR read returns 0xffff: no false PME event is reported.
- Normal PME status handling remains unchanged.
Signed-off-by: Xianhu Tan <xianhutan@asrmicro.com>
---
v2: Use PCI_POSSIBLE_ERROR() instead of open-coding the 0xffff check,
and drop the return value check of pci_read_config_word(), since the
PCI core already sets PCI_ERROR_RESPONSE on failed config reads.
(Lukas Wunner)
drivers/pci/pci.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..29ef31411dc8 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -2331,6 +2331,9 @@ bool pci_check_pme_status(struct pci_dev *dev)
pmcsr_pos = dev->pm_cap + PCI_PM_CTRL;
pci_read_config_word(dev, pmcsr_pos, &pmcsr);
+ if (PCI_POSSIBLE_ERROR(pmcsr))
+ return false;
+
if (!(pmcsr & PCI_PM_CTRL_PME_STATUS))
return false;
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] PCI/PM: Reject invalid PMCSR when checking PME status
2026-12-02 6:29 ` [PATCH v2] " xianhutan
@ 2026-12-06 0:04 ` Bjorn Helgaas
0 siblings, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2026-12-06 0:04 UTC (permalink / raw)
To: xianhutan; +Cc: linux-pci, bhelgaas, lukas, linux-kernel, Rafael J. Wysocki
[+cc Rafael, author of 58ff463396ad ("PCI PM: Add function for
checking PME status of devices"), which sashiko suggested as Fixes:]
On Wed, Dec 02, 2026 at 02:29:59PM +0800, xianhutan@asrmicro.com wrote:
> From: Xianhu Tan <xianhutan@asrmicro.com>
>
> pci_check_pme_status() reads the PMCSR and checks the PME_STATUS
> bit without validating the value read from the device.
>
> If the device or its upstream bridge is inaccessible, a
> configuration read may return all ones. Since bit 15 of 0xffff
> is set, the PCI core incorrectly interprets the value as an
> asserted PME_STATUS bit and reports a spurious PME event.
>
> This can cause an unnecessary runtime resume of a suspended
> device.
>
> The issue occurs in pci_pme_list_scan(), which scans devices
> on the PME list and calls pci_check_pme_status() to check
> their PME status.
>
> On the affected platform, reading the PMCSR after the device
> enters D3hot with the PCIe link in L1 returns 0xffff, causing
> the PME scan to trigger a false PME event.
What is the affected platform and why is it relevant? And why is L1
relevant? I thought L1 should be a hardware concern, not something
software needs to worry about.
Reading config space, including PMCSR, while in D3hot is supposed to
work, isn't it?
I do agree that we shouldn't interpret a 0xffff value from PMCSR as
having PME_STATUS set, because 0xffff is not a valid value for that
register, so the patch itself seems fine to me.
I guess I'm only probing for whether there's something special about
some platform. If not, maybe we can trim down the commit log a bit.
> Use PCI_POSSIBLE_ERROR() to reject an invalid PMCSR value
> before checking PME_STATUS.
>
> This also prevents writing the invalid PMCSR value back to
> the device when clearing the PME status.
>
> Tested on:
> - ARM32 platform with PCIe endpoint.
>
> Test cases:
> - PMCSR read returns 0xffff: no false PME event is reported.
> - Normal PME status handling remains unchanged.
>
> Signed-off-by: Xianhu Tan <xianhutan@asrmicro.com>
> ---
> v2: Use PCI_POSSIBLE_ERROR() instead of open-coding the 0xffff check,
> and drop the return value check of pci_read_config_word(), since the
> PCI core already sets PCI_ERROR_RESPONSE on failed config reads.
> (Lukas Wunner)
>
> drivers/pci/pci.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 7c6f2aba8144..29ef31411dc8 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -2331,6 +2331,9 @@ bool pci_check_pme_status(struct pci_dev *dev)
>
> pmcsr_pos = dev->pm_cap + PCI_PM_CTRL;
> pci_read_config_word(dev, pmcsr_pos, &pmcsr);
> + if (PCI_POSSIBLE_ERROR(pmcsr))
> + return false;
> +
> if (!(pmcsr & PCI_PM_CTRL_PME_STATUS))
> return false;
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-06 0:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 7:25 [PATCH] PCI/PM: Reject invalid PMCSR when checking PME status xianhutan
2026-12-01 10:20 ` Lukas Wunner
2026-12-02 6:29 ` [PATCH v2] " xianhutan
2026-12-06 0:04 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®