Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI/PM: Reject invalid PMCSR when checking PME status
@ 2026-12-01  7:25 xianhutan
  2026-12-01  7:32 ` sashiko-bot
  0 siblings, 1 reply; 2+ 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] 2+ 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
  0 siblings, 0 replies; 2+ 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] 2+ messages in thread

end of thread, other threads:[~2026-12-01  7:32 UTC | newest]

Thread overview: 2+ 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

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