PCI/PM: Keep hotplug ports that can't wake from D3hot out of D3
Subsystems (2)
v2 cover PCI/PM: Keep hotplug ports that can't wake from D3hot out of D3
d4c79b63d82d ("PCI: Allow D3 for native hotplug-capable Root Ports on non-x86 platforms") lets native pciehp ports runtime suspend to D3hot on non-x86. The PCIe switch ports on AWS instances advertise PME from D3hot but do not send it, so hotplug events such as an ENI attach are lost on Graviton. x86 keeps the old logic, so the problem does not show up there.
Patches 1-2 handle existing switch devices, which advertise PME:
patch 1 makes pci_bridge_d3_possible() honor PCI_DEV_FLAGS_NO_D3, and patch 2 sets that flag on the Amazon switch ports.
Patch 3 handles switch devices that advertise no PME from D3hot: such hotplug ports are kept out of D3.
Changes in v2:
- Patch 1: check a copy of NO_D3 taken in pci_pm_init(), so pci_bridge_d3_possible() does not change when a FINAL fixup sets the flag after portdrv has probed.
- Patch 2: reuse quirk_no_ata_d3(), renamed to quirk_no_d3().
v1: https://lore.kernel.org/all/[email protected]/
Aviv Bakal (3):
PCI/PM: Honor PCI_DEV_FLAGS_NO_D3 in pci_bridge_d3_possible()
PCI: Avoid runtime D3 on Amazon PCIe switch ports PCI/PM: Keep hotplug ports out of D3 if they can't signal PME from
D3hot
drivers/pci/pci.c | 22 +++++++++++++++++++++- drivers/pci/quirks.c | 20 ++++++++++++++------ include/linux/pci.h | 1 + 3 files changed, 36 insertions(+), 7 deletions(-)
base-commit: 23c62304dde29abe92013d85910d03a77dada35d
Signature · 1 line
2.50.1
PATCH v2 1/3 PCI/PM: Honor PCI_DEV_FLAGS_NO_D3 in pci_bridge_d3_possible()
pci_set_power_state() does not put a device with PCI_DEV_FLAGS_NO_D3 into D3, but pci_bridge_d3_possible() ignores the flag. pcie_portdrv_probe() therefore enables runtime PM on such a port, and on runtime suspend pciehp masks the hotplug interrupt while the port stays in D0.
Return false from pci_bridge_d3_possible() when the flag is set. pci_bridge_d3_possible() must return the same value for the lifetime of the device, and FINAL fixups may set the flag after portdrv has probed, so record the flag in pci_pm_init() and check that copy.
--- drivers/pci/pci.c | 10 ++++++++++ include/linux/pci.h | 1 + 2 files changed, 11 insertions(+)
drivers/pci/pci.c +10 -0
@@ -3055,6 +3055,10 @@ bool pci_bridge_d3_possible(struct pci_dev *bridge)if (pci_bridge_d3_disable)return false; +/* The port is known not to work correctly in D3 */ +if (bridge->no_d3) +return false; +/* * Hotplug ports handled by platform firmware may not be put * into D3 by the OS, e.g. ACPI slots ...
@@ -3227,6 +3231,12 @@ void pci_pm_init(struct pci_dev *dev) dev->pm_cap =0 ; dev->pme_support =0 ; +/* +* pci_bridge_d3_possible() must not change after this point, so +* ignore NO_D3 set by later fixups. +*/ + dev->no_d3 = !!(dev->dev_flags &PCI_DEV_FLAGS_NO_D3 ); +/* find PCI PM capability in list */ pm =pci_find_capability (dev,PCI_CAP_ID_PM );if (!pm)
include/linux/pci.h +1 -0
@@ -420,6 +420,7 @@ struct pci_dev { unsigned int no_d1d2:1; /* D1 and D2 are forbidden */ unsigned int no_d3cold:1; /* D3cold is forbidden */ unsigned int bridge_d3:1; /* Allow D3 for bridge */ + unsigned int no_d3:1; /* NO_D3 set before PM init */ unsigned int d3cold_allowed:1; /* D3cold is allowed by user */ unsigned int mmio_always_on:1; /* Disallow turning off io/memdecoding during BAR sizing */
Signature · 1 line
2.50.1
[email protected]
AI reviewRe: [PATCH v2 1/3] PCI/PM: Honor PCI_DEV_FLAGS_NO_D3 in pci_bridge_d3_possible()
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
pci_set_power_state()does not put a device withPCI_DEV_FLAGS_NO_D3into D3, butpci_bridge_d3_possible()ignores the flag.pcie_portdrv_probe()therefore enables runtime PM on such a port, and on runtime suspend pciehp masks the hotplug interrupt while the port stays in D0.Return false from
pci_bridge_d3_possible()when the flag is set.pci_bridge_d3_possible()must return the same value for the lifetime of the device, and FINAL fixups may set the flag after portdrv has probed, so record the flag inpci_pm_init()and check that copy.
Quoted 5 lines
Fixes d4c79b63d82d ("PCI: Allow D3 for native hotplug-capable Root Ports on non-x86 platforms")Cc [email protected] # 7.3.xCo-developed-by Zeev Zilberman <[email protected]>Signed-off-by Zeev Zilberman <[email protected]>Signed-off-by Aviv Bakal <[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
Re: [PATCH v2 1/3] PCI/PM: Honor PCI_DEV_FLAGS_NO_D3 in pci_bridge_d3_possible()
In reply to Aviv BakalQuoted 37 lines · Aviv Bakal
pci_set_power_state()does not put a device withPCI_DEV_FLAGS_NO_D3into D3, butpci_bridge_d3_possible()ignores the flag.pcie_portdrv_probe()therefore enables runtime PM on such a port, and on runtime suspend pciehp masks the hotplug interrupt while the port stays in D0.Return false from
pci_bridge_d3_possible()when the flag is set.pci_bridge_d3_possible()must return the same value for the lifetime of the device, and FINAL fixups may set the flag after portdrv has probed, so record the flag inpci_pm_init()and check that copy.Fixes d4c79b63d82d ("PCI: Allow D3 for native hotplug-capable Root Ports on non-x86 platforms")Cc [email protected] # 7.3.xCo-developed-by Zeev Zilberman <[email protected]>Signed-off-by Zeev Zilberman <[email protected]>Signed-off-by Aviv Bakal <[email protected]>--- drivers/pci/pci.c | 10 ++++++++++ include/linux/pci.h | 1 + 2 files changed, 11 insertions(+)drivers/pci/pci.c +4
-0@@ -3055,6 +3055,10 @@ bool pci_bridge_d3_possible(struct pci_dev *bridge)if (pci_bridge_d3_disable)return false; +/* The port is known not to work correctly in D3 */ +if (bridge->no_d3) +return false; +/* * Hotplug ports handled by platform firmware may not be put * into D3 by the OS, e.g. ACPI slots ...
drivers/pci/pci.c void pci_pm_init(struct pci_dev *dev) · line 3238
Quoted 8 lines
drivers/pci/pci.c +5
-0@@ -3227,6 +3231,12 @@ void pci_pm_init(struct pci_dev *dev) dev->pm_cap =0 ; dev->pme_support =0 ; +/* +* pci_bridge_d3_possible() must not change after this point, so +* ignore NO_D3 set by later fixups. +*/ + dev->no_d3 = !!(dev->dev_flags &PCI_DEV_FLAGS_NO_D3 );
This ignores quirk_plx_pex_no_d3(). It is the only other quirk that sets NO_D3 on a PCIe port, and it is a FINAL fixup. So pci_bridge_d3_possible() still returns true for those PLX downstream ports, and portdrv still enables runtime PM on them.
Quoted 16 lines
drivers/pci/pci.c +1
-0+/* find PCI PM capability in list */ pm =pci_find_capability (dev,PCI_CAP_ID_PM );if (!pm)include/linux/pci.h +1
-0@@ -420,6 +420,7 @@ struct pci_dev { unsigned int no_d1d2:1; /* D1 and D2 are forbidden */ unsigned int no_d3cold:1; /* D3cold is forbidden */ unsigned int bridge_d3:1; /* Allow D3 for bridge */ + unsigned int no_d3:1; /* NO_D3 set before PM init */ unsigned int d3cold_allowed:1; /* D3cold is allowed by user */ unsigned int mmio_always_on:1; /* Disallow turning off io/memdecoding during BAR sizing */
Signature · 2 lines
Sathyanarayanan Kuppuswamy Linux Kernel Developer
PATCH v2 2/3 PCI: Avoid runtime D3 on Amazon PCIe switch ports
In reply to Aviv BakalThe PCIe switch ports on AWS instances (vendor 0x1d0f) advertise PME from D3hot but do not send it. Since commit d4c79b63d82d ("PCI: Allow D3 for native hotplug-capable Root Ports on non-x86 platforms") these ports runtime suspend to D3hot on non-x86 platforms, and hotplug events such as an ENI attach are lost.
Mark them PCI_DEV_FLAGS_NO_D3, reusing quirk_no_ata_d3() renamed to quirk_no_d3().
--- drivers/pci/quirks.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/pci/quirks.c +14 -6
@@ -1458,23 +1458,31 @@ static void quirk_ide_samemode(struct pci_dev *pdev) }DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_INTEL ,PCI_DEVICE_ID_INTEL_82801CA_10 , quirk_ide_samemode); -/* Some ATA devices break if put into D3 */ -static void quirk_no_ata_d3 (struct pci_dev *pdev) +/* Some devices break if put into D3 */ +static void quirk_no_d3 (struct pci_dev *pdev) { pdev->dev_flags |=PCI_DEV_FLAGS_NO_D3 ; }/* Quirk the legacy ATA devices only. The AHCI ones are ok */ DECLARE_PCI_FIXUP_CLASS_EARLY (PCI_VENDOR_ID_SERVERWORKS ,PCI_ANY_ID , -PCI_CLASS_STORAGE_IDE ,8 , quirk_no_ata_d3); +PCI_CLASS_STORAGE_IDE ,8 , quirk_no_d3);DECLARE_PCI_FIXUP_CLASS_EARLY (PCI_VENDOR_ID_ATI ,PCI_ANY_ID , -PCI_CLASS_STORAGE_IDE ,8 , quirk_no_ata_d3); +PCI_CLASS_STORAGE_IDE ,8 , quirk_no_d3);/* ALi loses some register settings that we cannot then restore */ DECLARE_PCI_FIXUP_CLASS_EARLY (PCI_VENDOR_ID_AL ,PCI_ANY_ID , -PCI_CLASS_STORAGE_IDE ,8 , quirk_no_ata_d3); +PCI_CLASS_STORAGE_IDE ,8 , quirk_no_d3);/* VIA comes back fine but we need to keep it alive or ACPI GTM failures occur when mode detecting */ DECLARE_PCI_FIXUP_CLASS_EARLY (PCI_VENDOR_ID_VIA ,PCI_ANY_ID , -PCI_CLASS_STORAGE_IDE ,8 , quirk_no_ata_d3); +PCI_CLASS_STORAGE_IDE ,8 , quirk_no_d3); + +/* +* Amazon 1d0f PCIe switch ports (e.g. 1d0f:cec2) on AWS instances +* advertise PME# from D3hot but never assert it, so hotplug events on +* a port in D3 are lost. +*/ +DECLARE_PCI_FIXUP_CLASS_EARLY (PCI_VENDOR_ID_AMAZON ,PCI_ANY_ID , +PCI_CLASS_BRIDGE_PCI ,8 , quirk_no_d3);/* * This was originally an Alpha-specific thing, but it really fits here.
Signature · 1 line
2.50.1
[email protected]
AI reviewRe: [PATCH v2 2/3] PCI: Avoid runtime D3 on Amazon PCIe switch ports
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
The PCIe switch ports on AWS instances (vendor
0x1d0f) advertise PME from D3hot but do not send it. Since commitd4c79b63d82d("PCI: Allow D3 for native hotplug-capable Root Ports on non-x86 platforms") these ports runtime suspend to D3hot on non-x86 platforms, and hotplug events such as an ENI attach are lost.
Quoted 8 lines
Mark them
PCI_DEV_FLAGS_NO_D3, reusingquirk_no_ata_d3()renamed toquirk_no_d3().Fixes d4c79b63d82d ("PCI: Allow D3 for native hotplug-capable Root Ports on non-x86 platforms")Cc [email protected] # 7.3.xCo-developed-by Zeev Zilberman <[email protected]>Signed-off-by Zeev Zilberman <[email protected]>Signed-off-by Aviv Bakal <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v2 3/3 PCI/PM: Keep hotplug ports out of D3 if they can't signal PME from D3hot
In reply to Aviv BakalOn runtime suspend pciehp masks the hotplug interrupt and relies on PME to resume the port on a slot event. pci_bridge_d3_possible() does not check whether the port can signal PME from D3hot, so a port that cannot is not resumed by slot events.
Return false from pci_bridge_d3_possible() for such native hotplug ports. pci_pm_init() computes bridge_d3 before it reads PME_Support, so move that assignment after dev->pme_support is set.
--- drivers/pci/pci.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/pci/pci.c +11 -1
@@ -3081,6 +3081,14 @@ bool pci_bridge_d3_possible(struct pci_dev *bridge)if (platform_pci_bridge_d3 (bridge))return true; +/* +* pciehp masks the hotplug interrupt on runtime suspend and +* relies on PME to resume the port on a slot event. A port +* that cannot signal PME from D3hot is not resumed. +*/ +if (bridge->is_pciehp && !pci_pme_capable (bridge, PCI_D3hot)) +return false; +/* * Hotplug ports handled natively by the OS on x86 platforms * were not validated by vendors for runtime D3 at least until
@@ -3253,7 +3261,6 @@ void pci_pm_init(struct pci_dev *dev) dev->pm_cap = pm; dev->d3hot_delay =PCI_PM_D3HOT_WAIT ; dev->d3cold_delay =PCI_PM_D3COLD_WAIT ; - dev->bridge_d3 =pci_bridge_d3_possible (dev); dev->d3cold_allowed = true; dev->d1_support = false;
@@ -3289,6 +3296,9 @@ void pci_pm_init(struct pci_dev *dev)pci_pme_active (dev, false); } +/* pci_bridge_d3_possible() looks at pme_support */ + dev->bridge_d3 =pci_bridge_d3_possible (dev); + poweron:pci_update_current_state (dev,PCI_UNKNOWN );if (dev->current_state ==PCI_D0 ) {
Signature · 1 line
2.50.1
[email protected]
AI reviewRe: [PATCH v2 3/3] PCI/PM: Keep hotplug ports out of D3 if they can't signal PME from D3hot
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] PCI/PM: missing Fixes trailer for commit d4c79b63d82d in commit message --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] PCI/PM: missing Fixes trailer for commit d4c79b63d82d in commit message
--
commit 70281f514dfa84e338f2e7558fdf02d6a96db4d6
Author: Aviv Bakal <[email protected]>
Quoted 7 lines
PCI/PM: Keep hotplug ports out of D3 if they can't signal PME from D3hot
On runtime suspend pciehp masks the hotplug interrupt and relies on PME to resume the port on a slot event.
pci_bridge_d3_possible()does not check whether the port can signal PME from D3hot, so a port that cannot is not resumed by slot events.
Quoted 7 lines
Return false from
pci_bridge_d3_possible()for such native hotplug ports.pci_pm_init()computesbridge_d3before it readsPME_Support, so move that assignment afterdev->pme_supportis set.Co-developed-by Zeev Zilberman <[email protected]>Signed-off-by Zeev Zilberman <[email protected]>Signed-off-by Aviv Bakal <[email protected]>
[Severity: Low]
This fixes a regression on non-x86 native hotplug ports that cannot signal PME from D3hot, which were allowed into D3 by commit d4c79b63d82d ("PCI: Allow D3 for native hotplug-capable Root Ports on non-x86 platforms"). Should this include:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Hi Aviv,
I independently hit this on AWS m7g.metal and reported it in a separate thread before finding this series. I applied this series (all three patches) on top of a 7.3.5-based kernel where the failure reproduced deterministically, and it fixes it.
Best,
Bjoern