Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/4] PCI/ASPM: keep software state and hardware in sync
@ 2026-11-30  1:43 Yaxiong Tian
  2026-11-30  1:45 ` [PATCH v2 1/4] PCI/ASPM: Only update ASPM and CLKREQ bits in the saved LNKCTL Yaxiong Tian
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Yaxiong Tian @ 2026-11-30  1:43 UTC (permalink / raw)
  To: bhelgaas, mani, krishna.chundru, ilpo.jarvinen, lukas,
	sathyanarayanan.kuppuswamy, david.e.box, vidyas
  Cc: linux-pci, Yaxiong Tian

Four places where the ASPM core ends up recording one state while the
hardware is in another.  The first three are about the same invariant:
link->aspm_enabled and the saved LNKCTL must match what is programmed in
the device.  The fourth is a NULL dereference on a link that cannot be
managed at all.

1/4 Only update ASPM and CLKREQ bits in the saved LNKCTL

    pci_update_aspm_saved_state() rebuilt the whole saved LNKCTL from a
    value read back from hardware.  When that read failed, or returned
    PCI_ERROR_RESPONSE, the snapshot became zeroes or all ones, and
    pci_restore_pcie_state() wrote that back: ASPMC and CCC were lost in
    the first case, ASPMC was forced to L0s+L1 in the second.

2/4 Update saved LNKCTL for every function of the link

    pcie_config_aspm_link() programs LNKCTL on every function of the
    downstream component, but refreshed only function 0's snapshot.  A
    driver calling pci_restore_state() from slot_reset() put the other
    functions back to a stale ASPMC value, leaving the functions of one
    link disagreeing.

3/4 Disable ASPM left on by firmware after a HEADER quirk

    A HEADER quirk that clears the cached L0s/L1 support makes
    pcie_aspm_cap_init() return before reading LNKCTL.  Firmware may have
    enabled ASPM on that link, and because link->aspm_enabled stays zero,
    every later request finds the link "already disabled" and leaves the
    hardware alone.  Mark the states disabled and configure the link
    right away, as the blacklist path does.  Doing it here also
    closes the same window on the blacklist path, which only cleared
    LNKCTL.ASPMC from a later pcie_config_aspm_path() that is skipped
    under POLICY_POWERSAVE and POLICY_POWER_SUPERSAVE.

4/4 Skip links whose downstream bus has no function 0

    alloc_pcie_link_state() stores pci_function_0() without checking the
    result, and pcie_aspm_cap_init() dereferences it.  Reachable only
    when function 0 is missing, which needs a hypervisor that passes
    through individual functions (s390, loongarch, Jailhouse).
    Pre-existing; split out so the fix can be reviewed on its own.

The first two were found by inspection while porting the L0s/L1 caching
series; the third is a regression from 30579eebba6a, which is in v6.18;
the fourth predates all of them.  The third and the fourth were exercised
in a QEMU guest, as described in their commit messages; none of them has
been reproduced on hardware.

Yaxiong Tian (4):
  PCI/ASPM: Only update ASPM and CLKREQ bits in the saved LNKCTL
  PCI/ASPM: Update saved LNKCTL for every function of the link
  PCI/ASPM: Disable ASPM left on by firmware after a HEADER quirk
  PCI/ASPM: Skip links whose downstream bus has no function 0

 drivers/pci/pcie/aspm.c | 71 +++++++++++++++++++++++++++++++----------
 1 file changed, 54 insertions(+), 17 deletions(-)


---
Changes in v2:
- 1/4, 2/4: unchanged.
- 3/4: configure the link right away instead of waiting for a later
  pcie_config_aspm_path(), which is skipped under POLICY_POWERSAVE and
  POLICY_POWER_SUPERSAVE, and handle the blacklist path the same way;
  mark only L0s and L1 as enabled so that the L1 PM Substate bits do not
  end up in link->aspm_enabled when either end is not in D0; add
  Cc: stable.
- 4/4: new: skip links whose downstream bus has no function 0.
- 3/4, 4/4: note how they were exercised in a QEMU guest.
-- 
2.43.0


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

end of thread, other threads:[~2026-11-30  1:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  1:43 [PATCH v2 0/4] PCI/ASPM: keep software state and hardware in sync Yaxiong Tian
2026-11-30  1:45 ` [PATCH v2 1/4] PCI/ASPM: Only update ASPM and CLKREQ bits in the saved LNKCTL Yaxiong Tian
2026-11-30  1:45 ` [PATCH v2 2/4] PCI/ASPM: Update saved LNKCTL for every function of the link Yaxiong Tian
2026-11-30  1:45 ` [PATCH v2 3/4] PCI/ASPM: Disable ASPM left on by firmware after a HEADER quirk Yaxiong Tian
2026-11-30  1:45 ` [PATCH v2 4/4] PCI/ASPM: Skip links whose downstream bus has no function 0 Yaxiong Tian
2026-11-30  1:54 ` [PATCH v2 0/4] PCI/ASPM: keep software state and hardware in sync sashiko-bot

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