PCI: Restore the device allowlist for lifting the 2.5GT/s speed clamp
PATCH 1/1 PCI: Restore the device allowlist for lifting the 2.5GT/s speed clamp
72780f796468 ("PCI: Always lift 2.5GT/s restriction in PCIe failed link retraining") removed the Vendor:Device allowlist and the link status check gating the removal of a 2.5GT/s speed restriction, so the restriction is now lifted on any downstream port that supports a faster link and whose Target Link Speed reads 2.5GT/s. The commit message says this is done "in a hope it is safe to do so".
On a Fujitsu XH320 V2 it is not. Root port 00:1c.3 is a 5GT/s capable C600/X79 PCH port, and firmware brought its link up at 2.5GT/s with Target Link Speed clamped to match. Behind it is an XGI Z11/Z11M VGA adapter (07:00.0) whose own Link Capabilities advertise 2.5GT/s only. Lifting the restriction makes the port retrain at 5GT/s, which does not complete against an endpoint that only advertises 2.5GT/s, and the endpoint is dropped:
pci 0000:00:1c.3: removing 2.5GT/s downstream link speed restriction
...
(no 0000:07:00.0 line follows; 18ca:0027 is absent and there is one PCI
device fewer than with the restriction left in place)
The existing failure path never runs. pcie_retrain_link(dev, false) samples DLLLA right after setting Retrain Link, while DLLLA still holds its pre-retrain value of 1, so it reports success immediately. I measured the window on this machine by issuing the same register writes from user space:
DLLLA reads 1 at t=0 and drops at t=24.9ms. Hence "retraining failed" is never printed, Target Link Speed stays at 5GT/s, and the endpoint stays off the bus.
Rolling back afterwards does not recover the device, so that is not an alternative. Writing Target Link Speed back to 2.5GT/s in the same millisecond DLLLA drops -- the best timing any post-failure workaround can achieve -- does bring the link and the endpoint back (18ca:0027 enumerates, Target Link Speed 2.5GT/s), but the device has been reset: PCI Command reads 0, CRTC Mode Control loses bit 7, and the display stops scanning. That is a dead local console, and no software brings it back: unbinding and rebinding vgacon, restoring Command to 0x0007, none of it helps. Only the firmware mode set after a reboot does.
So for this class of device the restriction must not be lifted at all. Whether the lift can succeed depends on the device behind the port, and when this quirk runs -- from pci_setup_device(), before the bus behind the port has been scanned -- that device is not enumerated yet. That is why the allowlist was there in the first place.
Restore it. Moving the restriction removal to a point after the subordinate bus has been enumerated, and consulting the downstream devices' Link Capabilities there, would keep the hot-plug case working; I am willing to do that as a follow-up, but it is a larger change, and this regression takes machines that only have a local console off the air, so it should not wait for it.
---
Tested on the affected machine (Fujitsu XH320 V2, C600/X79 PCH, XGI Z11/Z11M VGA), v7.3.4 with this patch on top, using the Ubuntu mainline 7.3.4 .config with only DEBUG_INFO turned off:
v7.3.4, unpatched: 78 PCI devices, 18ca:0027 absent, Target Link Speed
left at 5GT/s, local console dead
v7.3.4 + this patch: 79 PCI devices, 18ca:0027 present, Target Link Speed
2.5GT/s, "removing 2.5GT/s..." no longer printed, simpledrm binds fb0 and the console works
6.8.0-31: 79 PCI devices, 18ca:0027 present, same as above
The same numbers come out of the unpatched kernel when the single offending register write is issued by hand from user space on 6.8.0-31, i.e. the difference above is attributable to this one hunk.
drivers/pci/quirks.c | 20 +++++++++++++------- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/pci/quirks.c +15 -5
@@ -80,10 +80,15 @@* Restrict the speed to 2.5GT/s then with the Target Link Speed field, * request a retrain and check the result. * -* If this turns out successful, or where a 2.5GT/s speed restriction has -* been previously arranged by the firmware and the port reports its link -* already being up, lift the restriction, in a hope it is safe to do so, -* letting the devices negotiate a higher speed. +* If this turns out successful and the device is one where lifting the +* restriction is known to be safe, then lift it and let the devices +* negotiate a higher speed. +* +* Do not lift the restriction on a link that firmware has already brought +* up at 2.5GT/s merely because the port itself could go faster: a retrain +* at a speed the device behind the port does not support takes that device +* off the bus, and it does not come back. For a display device this means +* a blank local console with no software-recoverable state. * * Otherwise revert the speed to the original setting and request a retrain * again to remove any residual state, ignoring the result as it's supposed
@@ -94,6 +99,10 @@*/ int pcie_failed_link_retrain (struct pci_dev *dev) { +static const struct pci_device_id ids[] = { + {PCI_VDEVICE (ASMEDIA ,0x2824 ) },/* ASMedia ASM2824 */ + {} + };u16 lnksta, lnkctl2, oldlnkctl2;enum pci_bus_speed speed_cap;int ret = -ENOTTY ;
@@ -120,7 +129,8 @@ }pcie_capability_read_word (dev,PCI_EXP_LNKCTL2 , &lnkctl2); -if ((lnkctl2 &PCI_EXP_LNKCTL2_TLS ) ==PCI_EXP_LNKCTL2_TLS_2_5GT ) { +if ((lnkctl2 &PCI_EXP_LNKCTL2_TLS ) ==PCI_EXP_LNKCTL2_TLS_2_5GT && +pci_match_id (ids, dev)) {pci_info (dev,"removing 2.5GT/s downstream link speed restriction\n" ); ret =pcie_set_target_speed (dev, speed_cap, false);if (ret)
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 14 lines
72780f796468("PCI: Always lift 2.5GT/s restriction in PCIe failed link retraining") removed the Vendor:Device allowlist and the link status check gating the removal of a 2.5GT/s speed restriction, so the restriction is now lifted on any downstream port that supports a faster link and whose Target Link Speed reads 2.5GT/s. The commit message says this is done "in a hope it is safe to do so".On a Fujitsu XH320 V2 it is not. Root port 00:1c.3 is a 5GT/s capable C600/X79 PCH port, and firmware brought its link up at 2.5GT/s with Target Link Speed clamped to match. Behind it is an XGI Z11/Z11M VGA adapter (07:00.0) whose own Link Capabilities advertise 2.5GT/s only. Lifting the restriction makes the port retrain at 5GT/s, which does not complete against an endpoint that only advertises 2.5GT/s, and the endpoint is dropped:
Quoted 7 lines
pci 0000:00:1c.3: removing 2.5GT/s downstream link speed restriction
[ ... ]Fixes 72780f796468 ("PCI: Always lift 2.5GT/s restriction in PCIe failed link retraining")Cc [email protected] # v6.5+Reported-by Chen Haohui <[email protected]>Signed-off-by Chen Haohui <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1