* [PATCH 1/3] PCI/ASPM: Only update ASPM and CLKREQ bits in the saved LNKCTL
2026-11-27 2:11 [PATCH 0/3] PCI/ASPM: keep software state and hardware in sync Yaxiong Tian
@ 2026-11-27 2:13 ` Yaxiong Tian
2026-11-27 2:13 ` [PATCH 2/3] PCI/ASPM: Update saved LNKCTL for every function of the link Yaxiong Tian
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Yaxiong Tian @ 2026-11-27 2:13 UTC (permalink / raw)
To: bhelgaas, mani, krishna.chundru, ilpo.jarvinen, lukas,
sathyanarayanan.kuppuswamy, david.e.box, vidyas
Cc: linux-pci, Yaxiong Tian
The comment above this code says it updates the ASPM and CLKREQ bits of
LNKCTL in the snapshot, and explains that CCC cannot change after
enumeration. The code did not do that: it rebuilt the whole word from
the value read back from hardware, so every bit of cap[1] was replaced,
and the result of pcie_capability_read_word() was ignored.
An unusable read then destroys the snapshot in either of two ways. A
failed read sets the value to zero, and pci_restore_pcie_state() writes
those zeroes back: ASPMC is cleared, so ASPM is disabled, and CCC is
cleared with nothing in the kernel programming it again after
enumeration (pcie_aspm_configure_common_clock() is only called from
pcie_aspm_cap_init()), so the link stays misconfigured until the next
enumeration. A read that succeeds but returns PCI_ERROR_RESPONSE is
just as unusable, and worse: on an unreachable device the bridge
synthesizes all ones, so ASPMC would be recorded as L0s+L1 and CLKREQ_EN
as set, and the restore would force ASPM on. In both cases
link->aspm_enabled still records the old state, so
pcie_config_aspm_link() does not correct the hardware either.
Such reads are reachable: pcie_config_aspm_link() runs for every link in
the system when the ASPM policy changes, including links whose devices
are already inaccessible, for example runtime suspended in D3cold.
Keep the snapshot untouched when the read is unusable, and merge only
the ASPM and CLKREQ bits into it when the read returns a usable value.
No functional change when the read returns a usable value.
Fixes: 6d4266675279 ("PCI/ASPM: Update save_state when configuration changes")
Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
---
drivers/pci/pcie/aspm.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index b039b57f8466..f1ef3d41f089 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -331,7 +331,16 @@ static void pci_update_aspm_saved_state(struct pci_dev *dev)
if (!save_state)
return;
- pcie_capability_read_word(dev, PCI_EXP_LNKCTL, &lnkctl);
+ /*
+ * Both a failed read and a read that returns PCI_ERROR_RESPONSE
+ * leave the snapshot unusable: the first sets *val to zero, the
+ * second reports all ones from an unreachable device. Writing
+ * either back would clear ASPMC and CCC, or set ASPMC to L0s+L1
+ * and CLKREQ_EN, when pci_restore_pcie_state() runs.
+ */
+ if (pcie_capability_read_word(dev, PCI_EXP_LNKCTL, &lnkctl) ||
+ PCI_POSSIBLE_ERROR(lnkctl))
+ return;
/*
* Update ASPM and CLKREQ bits of LNKCTL in save_state. We only
@@ -339,11 +348,11 @@ static void pci_update_aspm_saved_state(struct pci_dev *dev)
* change after being captured in save_state.
*/
aspm_ctl = lnkctl & (PCI_EXP_LNKCTL_ASPMC | PCI_EXP_LNKCTL_CLKREQ_EN);
- lnkctl &= ~(PCI_EXP_LNKCTL_ASPMC | PCI_EXP_LNKCTL_CLKREQ_EN);
/* Depends on pci_save_pcie_state(): cap[1] is LNKCTL */
cap = (u16 *)&save_state->cap.data[0];
- cap[1] = lnkctl | aspm_ctl;
+ cap[1] = (cap[1] & ~(PCI_EXP_LNKCTL_ASPMC |
+ PCI_EXP_LNKCTL_CLKREQ_EN)) | aspm_ctl;
}
static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable)
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] PCI/ASPM: Update saved LNKCTL for every function of the link
2026-11-27 2:11 [PATCH 0/3] PCI/ASPM: keep software state and hardware in sync Yaxiong Tian
2026-11-27 2:13 ` [PATCH 1/3] PCI/ASPM: Only update ASPM and CLKREQ bits in the saved LNKCTL Yaxiong Tian
@ 2026-11-27 2:13 ` Yaxiong Tian
2026-11-27 2:13 ` [PATCH 3/3] PCI/ASPM: Disable ASPM left on by firmware after a HEADER quirk Yaxiong Tian
2026-11-27 2:33 ` [PATCH 0/3] PCI/ASPM: keep software state and hardware in sync sashiko-bot
3 siblings, 0 replies; 6+ messages in thread
From: Yaxiong Tian @ 2026-11-27 2:13 UTC (permalink / raw)
To: bhelgaas, mani, krishna.chundru, ilpo.jarvinen, lukas,
sathyanarayanan.kuppuswamy, david.e.box, vidyas
Cc: linux-pci, Yaxiong Tian
pcie_config_aspm_link() programs PCI_EXP_LNKCTL on every function of the
downstream component, as recommended by PCIe r7.0, sec 7.5.3.7:
list_for_each_entry(child, &linkbus->devices, bus_list)
pcie_config_aspm_dev(child, dwstream);
Only the saved state of function 0 (link->downstream) is refreshed,
though. The other functions keep whatever ASPMC value
pci_save_state() captured, so a driver that calls pci_restore_state()
from its slot_reset() hook restores the stale value on them. After
that the functions of the link disagree on ASPM Control, which is the
state sec 7.5.3.7 asks software to avoid.
Refresh the saved state of each function right after its LNKCTL has
been programmed. pci_save_aspm_l1ss_state() stays on function 0, since
the L1 PM Substates capability is only implemented there.
Found by inspection; not yet reproduced on hardware.
Fixes: 6d4266675279 ("PCI/ASPM: Update save_state when configuration changes")
Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
---
drivers/pci/pcie/aspm.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index f1ef3d41f089..6dbae7985bdc 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -1114,11 +1114,19 @@ static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state)
link->aspm_enabled = state;
- /* Update latest ASPM configuration in saved context */
+ /*
+ * Update the saved LNKCTL of every function that was programmed
+ * above; otherwise pci_restore_state() from a driver's slot_reset()
+ * would put the other functions back to the stale ASPMC value and
+ * leave the functions of the link disagreeing.
+ */
+ pci_update_aspm_saved_state(parent);
+ list_for_each_entry(child, &linkbus->devices, bus_list)
+ pci_update_aspm_saved_state(child);
+
+ /* L1 PM Substates are only implemented in function 0 */
pci_save_aspm_l1ss_state(link->downstream);
- pci_update_aspm_saved_state(link->downstream);
pci_save_aspm_l1ss_state(parent);
- pci_update_aspm_saved_state(parent);
}
static void pcie_config_aspm_path(struct pcie_link_state *link)
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/3] PCI/ASPM: Disable ASPM left on by firmware after a HEADER quirk
2026-11-27 2:11 [PATCH 0/3] PCI/ASPM: keep software state and hardware in sync Yaxiong Tian
2026-11-27 2:13 ` [PATCH 1/3] PCI/ASPM: Only update ASPM and CLKREQ bits in the saved LNKCTL Yaxiong Tian
2026-11-27 2:13 ` [PATCH 2/3] PCI/ASPM: Update saved LNKCTL for every function of the link Yaxiong Tian
@ 2026-11-27 2:13 ` Yaxiong Tian
2026-11-27 2:32 ` sashiko-bot
2026-11-27 2:33 ` [PATCH 0/3] PCI/ASPM: keep software state and hardware in sync sashiko-bot
3 siblings, 1 reply; 6+ messages in thread
From: Yaxiong Tian @ 2026-11-27 2:13 UTC (permalink / raw)
To: bhelgaas, mani, krishna.chundru, ilpo.jarvinen, lukas,
sathyanarayanan.kuppuswamy, david.e.box, vidyas
Cc: linux-pci, Yaxiong Tian
"PCI/ASPM: Convert quirks to override advertised link states" turned
the ASPM quirks into HEADER quirks that clear the cached L0s/L1 support
instead of calling pci_disable_link_state(), so that ASPM is never
enabled on the affected devices in the first place.
pcie_aspm_cap_init() returns before reading LNKCTL when the cached L0s
and L1 support of the two ends has no overlap. A HEADER quirk can empty
that cache on hardware that does implement ASPM, and firmware may well
have enabled ASPM on it already, so the link is left running with ASPM
on while the kernel believes it is off: link->aspm_enabled stays zero,
so pcie_config_aspm_link() sees the link as already being in the
requested (disabled) state and returns without touching the hardware.
No later request can correct it either, for the same reason. This
affects [1b21:1080], whose quirk was converted, and [1957:0451], whose
Root Port quirk was added by "Avoid L0s and L1 on Freescale [1957:0451]
Root Ports", under every policy including the default one.
The blacklist path already handles this situation: it marks all states
enabled and disabled, so the next pcie_config_aspm_path() runs
pcie_config_aspm_link() once and clears LNKCTL.ASPMC instead of
returning early. Do the same before returning here. For a link whose
support was removed by a quirk, this is the cleanup that the conversion
to a HEADER quirk dropped.
A link whose hardware really lacks ASPM support is not affected in
practice: it never advertises ASPM, so clearing ASPMC is harmless.
The L1 PM Substate enables are intentionally left alone, matching the
blacklist path. They cannot take effect while L1 is disabled.
Found by inspection; not yet reproduced on hardware.
Fixes: 30579eebba6a ("PCI/ASPM: Convert quirks to override advertised link states")
Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
---
drivers/pci/pcie/aspm.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 6dbae7985bdc..dc400cddf13c 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -955,12 +955,19 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
}
/*
- * If ASPM not supported, don't mess with the clocks and link,
- * bail out now.
+ * If ASPM not supported, don't compute anything else here. Mark all
+ * states enabled and disabled so that the next
+ * pcie_config_aspm_path() writes ASPMC=0 instead of returning early,
+ * the same way the blacklist case has always worked: the cached
+ * support may have been removed by a HEADER quirk while firmware left
+ * ASPM enabled on hardware that does implement it.
*/
if (!(parent->aspm_l0s_support && child->aspm_l0s_support) &&
- !(parent->aspm_l1_support && child->aspm_l1_support))
+ !(parent->aspm_l1_support && child->aspm_l1_support)) {
+ link->aspm_enabled = PCIE_LINK_STATE_ASPM_ALL;
+ link->aspm_disable = PCIE_LINK_STATE_ASPM_ALL;
return;
+ }
/* Configure common clock before checking latencies */
pcie_aspm_configure_common_clock(link);
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 3/3] PCI/ASPM: Disable ASPM left on by firmware after a HEADER quirk
2026-11-27 2:13 ` [PATCH 3/3] PCI/ASPM: Disable ASPM left on by firmware after a HEADER quirk Yaxiong Tian
@ 2026-11-27 2:32 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-27 2:32 UTC (permalink / raw)
To: Yaxiong Tian; +Cc: linux-pci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] PCI/ASPM: pcie_aspm_cap_init() leaves ASPM on and state bogus
under powersave
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] PCI/ASPM: null pointer dereference in pcie_aspm_cap_init() [1]
--
commit 9e8cf781eb78db18fccd661446c689e036882231
Author: Yaxiong Tian <tianyaxiong@kylinos.cn>
PCI/ASPM: Disable ASPM left on by firmware after a HEADER quirk
When cached L0s and L1 support have no overlap between the two ends of a
link, pcie_aspm_cap_init() marks all ASPM states enabled and disabled so
a subsequent pcie_config_aspm_path() clears LNKCTL.ASPMC.
> diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
> index 6dbae7985bdc0..dc400cddf13c6 100644
> --- a/drivers/pci/pcie/aspm.c
> +++ b/drivers/pci/pcie/aspm.c
> @@ -955,12 +955,19 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
> }
>
> /*
> - * If ASPM not supported, don't mess with the clocks and link,
> - * bail out now.
> + * If ASPM not supported, don't compute anything else here. Mark all
> + * states enabled and disabled so that the next
> + * pcie_config_aspm_path() writes ASPMC=0 instead of returning early,
> + * the same way the blacklist case has always worked: the cached
> + * support may have been removed by a HEADER quirk while firmware left
> + * ASPM enabled on hardware that does implement it.
> */
> if (!(parent->aspm_l0s_support && child->aspm_l0s_support) &&
> - !(parent->aspm_l1_support && child->aspm_l1_support))
> + !(parent->aspm_l1_support && child->aspm_l1_support)) {
[Severity: High]
This problem wasn't introduced by this patch, but can child be NULL here
[1]?
alloc_pcie_link_state() sets link->downstream via pci_function_0(), which
returns NULL when the subordinate bus has no function 0 (for example with
pci=pcie_scan_all or a non-standard topology), and pcie_aspm_cap_init()
dereferences child without checking it.
> + link->aspm_enabled = PCIE_LINK_STATE_ASPM_ALL;
> + link->aspm_disable = PCIE_LINK_STATE_ASPM_ALL;
> return;
> + }
[Severity: Medium]
Does relying on a later pcie_config_aspm_path() call leave firmware ASPM
enabled in hardware and link->aspm_enabled set to PCIE_LINK_STATE_ASPM_ALL
when aspm_policy is POLICY_POWERSAVE or POLICY_POWER_SUPERSAVE?
drivers/pci/pcie/aspm.c:pcie_aspm_init_link_state() {
...
if (aspm_policy != POLICY_POWERSAVE &&
aspm_policy != POLICY_POWER_SUPERSAVE) {
pcie_config_aspm_path(link);
pcie_set_clkpm(link, policy_to_clkpm_state(link));
}
...
}
Under those policies pcie_config_aspm_path() is skipped during enumeration
and only runs when do_pci_enable_device() calls
pcie_aspm_powersave_config_link() on a downstream device. For a quirked
[1b21:1080] PCIe-to-PCI bridge with no enabled downstream device (or an
unbound endpoint behind a [1957:0451] Root Port), LNKCTL.ASPMC is never
cleared and pci_save_state() in pci_bus_add_device() saves the
firmware-enabled ASPMC bits.
Until pcie_config_aspm_path() runs, link->aspm_enabled also remains
PCIE_LINK_STATE_ASPM_ALL on every link without L0s/L1 support, so
pcie_aspm_enabled() returns true. If acpi_pci_root_add() calls
pcie_no_aspm() after pci_acpi_scan_root(), pcie_aspm_powersave_config_link()
returns early on aspm_disabled and link->aspm_enabled stays non-zero
permanently.
[1] https://sashiko.dev/#/bug/linux-3d180a28-89c5-4a58-99c3-db524bb384ac
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127021128.147354-1-tianyaxiong@kylinos.cn?part=3
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] PCI/ASPM: keep software state and hardware in sync
2026-11-27 2:11 [PATCH 0/3] PCI/ASPM: keep software state and hardware in sync Yaxiong Tian
` (2 preceding siblings ...)
2026-11-27 2:13 ` [PATCH 3/3] PCI/ASPM: Disable ASPM left on by firmware after a HEADER quirk Yaxiong Tian
@ 2026-11-27 2:33 ` sashiko-bot
3 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-27 2:33 UTC (permalink / raw)
To: Yaxiong Tian; +Cc: linux-pci
Sashiko has finished reviewing this 3-patch series:
- Patches 1 and 2: no issues found.
- Patch 3 ("PCI/ASPM: Disable ASPM left on by firmware after a H..."): 1
potential issue (1 Medium) and 1 related pre-existing bug
A detailed review has been sent as a separate reply to patch 3.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127021128.147354-1-tianyaxiong@kylinos.cn
^ permalink raw reply [flat|nested] 6+ messages in thread