* [PATCH] PCI/PM: Reject invalid PMCSR when checking PME status
@ 2026-12-01 7:25 xianhutan
2026-12-01 7:32 ` sashiko-bot
2026-12-01 10:20 ` Lukas Wunner
0 siblings, 2 replies; 6+ 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 related [flat|nested] 6+ 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 7:32 ` sashiko-bot
2026-12-01 10:20 ` Lukas Wunner
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-01 7:32 UTC (permalink / raw)
To: xianhutan, linux-pci
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] PCI: unchecked config reads in pci_enable_acs() [1]
--
commit 8c12dc3e4ecd98aae67c8154c4081c2845c8cd6c
Author: Xianhu Tan <xianhutan@asrmicro.com>
PCI/PM: Reject invalid PMCSR when checking PME status
This commit checks the return value of pci_read_config_word() and rejects
an all-ones PMCSR value in pci_check_pme_status() to avoid reporting
spurious PME events and writing back to inaccessible devices.
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index de0d2fa15be10..36e6099af9a88 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -2485,6 +2485,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;
>
> @@ -2492,7 +2493,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;
[Severity: Critical]
This problem wasn't introduced by this patch, but can unchecked config
reads in pci_enable_acs() and the Intel ACS quirks [1] corrupt
PCI_ACS_CTRL or arbitrary MMIO space when a config read fails and populates
~0?
In pci_enable_acs(), caps.ctrl is read without checking for a failed read
or 0xffff before modifying and writing it back:
drivers/pci/pci.c:pci_enable_acs() {
...
pci_read_config_word(dev, pos + PCI_ACS_CTRL, &caps.ctrl);
caps.fw_ctrl = caps.ctrl;
...
pci_write_config_word(dev, pos + PCI_ACS_CTRL, caps.ctrl);
}
Similarly, pci_quirk_enable_intel_lpc_acs() reads INTEL_LPC_RCBA_REG into
rcba without checking for ~0; an all-ones value passes the
INTEL_LPC_RCBA_ENABLE test, causing the quirk to ioremap() 0xffffc000 and
call writel() on it.
[1] https://sashiko.dev/#/bug/linux-184296e9-829b-490a-84f9-32f74e109f5e
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201072501.2340605-1-xianhutan@asrmicro.com?part=1
^ permalink raw reply [flat|nested] 6+ 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 7:32 ` sashiko-bot
@ 2026-12-01 10:20 ` Lukas Wunner
2026-12-02 6:08 ` Xianhu Tan
2026-12-02 6:29 ` [PATCH v2] " xianhutan
1 sibling, 2 replies; 6+ 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] 6+ messages in thread
* Re: [PATCH] PCI/PM: Reject invalid PMCSR when checking PME status
2026-12-01 10:20 ` Lukas Wunner
@ 2026-12-02 6:08 ` Xianhu Tan
2026-12-02 6:29 ` [PATCH v2] " xianhutan
1 sibling, 0 replies; 6+ messages in thread
From: Xianhu Tan @ 2026-12-02 6:08 UTC (permalink / raw)
To: linux-pci
Hi Lukas,
On Tue, Dec 01, 2026 at 11:20:07 +0100, Lukas Wunner wrote:
> 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.
Agreed on both points. The PCI core already sets PCI_ERROR_RESPONSE
on failed config reads, so checking the return value of
pci_read_config_word() is redundant. v2 will use PCI_POSSIBLE_ERROR()
and drop the rc check.
Thanks for the review!
Best regards,
Xianhu Tan
^ permalink raw reply [flat|nested] 6+ 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:08 ` Xianhu Tan
@ 2026-12-02 6:29 ` xianhutan
2026-12-02 6:34 ` sashiko-bot
1 sibling, 1 reply; 6+ 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 related [flat|nested] 6+ 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-02 6:34 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-02 6:34 UTC (permalink / raw)
To: xianhutan, linux-pci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] PCI/PM: missing Fixes: trailer on pci_check_pme_status() bug fix
--
commit dcca1782a229a418387489996a407e0fb1b337cf
Author: Xianhu Tan <xianhutan@asrmicro.com>
> PCI/PM: Reject invalid PMCSR when checking PME status
>
> 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>
[Severity: Low]
This fixes a bug in pci_check_pme_status() present since the function
was introduced. Should this include:
Fixes: 58ff463396ad ("PCI PM: Add function for checking PME status of devices")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202062959.3519241-1-xianhutan@asrmicro.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-02 6:34 UTC | newest]
Thread overview: 6+ 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 7:32 ` sashiko-bot
2026-12-01 10:20 ` Lukas Wunner
2026-12-02 6:08 ` Xianhu Tan
2026-12-02 6:29 ` [PATCH v2] " xianhutan
2026-12-02 6:34 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox