FAILED: patch "[PATCH] PCI: Unify delay handling for reset and resume" failed to apply to 5.15-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x ac91e6980563ed53afadd925fa6585ffd2bc4a2c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
ac91e6980563 ("PCI: Unify delay handling for reset and resume")8ef0217227b4 ("PCI/PM: Observe reset delay irrespective of bridge_d3")730643d33e2d ("PCI/PM: Resume subordinate bus in bus type callbacks")18a94192e20d ("PCI/PM: Define pci_restore_standard_config() only for CONFIG_PM_SLEEP") 0c5c62ddf88c ("Merge tag 'pci-v5.16-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ac91e6980563ed53afadd925fa6585ffd2bc4a2c Mon Sep 17 00:00:00 2001
From: Lukas Wunner <[email protected]>
Date: Sun, 15 Jan 2023 09:20:32 +0100
Subject: [PATCH] PCI: Unify delay handling for reset and resume
Sheng Bi reports that pci_bridge_secondary_bus_reset() may fail to wait for devices on the secondary bus to become accessible after reset:
Although it does call pci_dev_wait(), it erroneously passes the bridge's pci_dev rather than that of a child. The bridge of course is always accessible while its secondary bus is reset, so pci_dev_wait() returns immediately.
Sheng Bi proposes introducing a new pci_bridge_secondary_bus_wait() function which is called from pci_bridge_secondary_bus_reset():
https://lore.kernel.org/linux-pci/[email protected]/
However we already have pci_bridge_wait_for_secondary_bus() which does almost exactly what we need. So far it's only called on resume from D3cold (which implies a Fundamental Reset per PCIe r6.0 sec 5.8). Re-using it for Secondary Bus Resets is a leaner and more rational approach than introducing a new function.
That only requires a few minor tweaks:
- Amend pci_bridge_wait_for_secondary_bus() to await accessibility of the first device on the secondary bus by calling pci_dev_wait() after performing the prescribed delays. pci_dev_wait() needs two parameters, a reset reason and a timeout, which callers must now pass to pci_bridge_wait_for_secondary_bus(). The timeout is 1 sec for resume (PCIe r6.0 sec 6.6.1) and 60 sec for reset (commit 821cdad5c46c ("PCI:
Wait up to 60 seconds for device to become ready after FLR")). Introduce a PCI_RESET_WAIT macro for the 1 sec timeout.
- Amend pci_bridge_wait_for_secondary_bus() to return 0 on success or -ENOTTY on error for consumption by pci_bridge_secondary_bus_reset().
- Drop an unnecessary 1 sec delay from pci_reset_secondary_bus() which is now performed by pci_bridge_wait_for_secondary_bus(). A static delay this long is only necessary for Conventional PCI, so modern PCIe systems benefit from shorter reset times as a side effect.
drivers/pci/pci-driver.c +1 -1
@@ -572,7 +572,7 @@ static void pci_pm_default_resume_early(struct pci_dev *pci_dev)static void pci_pm_bridge_power_up_actions (struct pci_dev *pci_dev) { -pci_bridge_wait_for_secondary_bus (pci_dev); +pci_bridge_wait_for_secondary_bus (pci_dev,"resume" ,PCI_RESET_WAIT );/* * When powering on a bridge from D3cold, the whole hierarchy may be * powered on into D0uninitialized state, resume them to give them a
drivers/pci/pci.c +24 -30
137 lines not on this page · raw message
drivers/pci/pci.h +9 -1
@@ -64,6 +64,13 @@ struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,#define PCI_PM_D3HOT_WAIT 10/* msec */ #define PCI_PM_D3COLD_WAIT 100/* msec */ +/* +* Following exit from Conventional Reset, devices must be ready within 1 sec +* (PCIe r6.0 sec 6.6.1). A D3cold to D0 transition implies a Conventional +* Reset (PCIe r6.0 sec 5.8). +*/ +#define PCI_RESET_WAIT 1000/* msec */ +void pci_update_current_state (struct pci_dev *dev,pci_power_t state);void pci_refresh_power_state (struct pci_dev *dev);int pci_power_up (struct pci_dev *dev);
@@ -86,8 +93,9 @@ void pci_msi_init(struct pci_dev *dev);void pci_msix_init (struct pci_dev *dev);bool pci_bridge_d3_possible (struct pci_dev *dev);void pci_bridge_d3_update (struct pci_dev *dev); -void pci_bridge_wait_for_secondary_bus (struct pci_dev *dev);void pci_bridge_reconfigure_ltr (struct pci_dev *dev); +int pci_bridge_wait_for_secondary_bus (struct pci_dev *dev,char *reset_type, +int timeout);static inline void pci_wakeup_event (struct pci_dev *dev) {
PATCH 1/2 PCI: Unify delay handling for reset and resume
commit ac91e6980563ed53afadd925fa6585ffd2bc4a2c upstream.
Sheng Bi reports that pci_bridge_secondary_bus_reset() may fail to wait for devices on the secondary bus to become accessible after reset:
Although it does call pci_dev_wait(), it erroneously passes the bridge's pci_dev rather than that of a child. The bridge of course is always accessible while its secondary bus is reset, so pci_dev_wait() returns immediately.
Sheng Bi proposes introducing a new pci_bridge_secondary_bus_wait() function which is called from pci_bridge_secondary_bus_reset():
https://lore.kernel.org/linux-pci/[email protected]/
However we already have pci_bridge_wait_for_secondary_bus() which does almost exactly what we need. So far it's only called on resume from D3cold (which implies a Fundamental Reset per PCIe r6.0 sec 5.8). Re-using it for Secondary Bus Resets is a leaner and more rational approach than introducing a new function.
That only requires a few minor tweaks:
- Amend pci_bridge_wait_for_secondary_bus() to await accessibility of the first device on the secondary bus by calling pci_dev_wait() after performing the prescribed delays. pci_dev_wait() needs two parameters, a reset reason and a timeout, which callers must now pass to pci_bridge_wait_for_secondary_bus(). The timeout is 1 sec for resume (PCIe r6.0 sec 6.6.1) and 60 sec for reset (commit 821cdad5c46c ("PCI:
Wait up to 60 seconds for device to become ready after FLR")). Introduce a PCI_RESET_WAIT macro for the 1 sec timeout.
- Amend pci_bridge_wait_for_secondary_bus() to return 0 on success or -ENOTTY on error for consumption by pci_bridge_secondary_bus_reset().
- Drop an unnecessary 1 sec delay from pci_reset_secondary_bus() which is now performed by pci_bridge_wait_for_secondary_bus(). A static delay this long is only necessary for Conventional PCI, so modern PCIe systems benefit from shorter reset times as a side effect.
--- drivers/pci/pci-driver.c | 4 +-- drivers/pci/pci.c | 54 ++++++++++++++++++---------------------- drivers/pci/pci.h | 10 +++++++- 3 files changed, 35 insertions(+), 33 deletions(-)
drivers/pci/pci-driver.c +2 -2
@@ -925,7 +925,7 @@ static int pci_pm_resume_noirq(struct device *dev)pcie_pme_root_status_cleanup (pci_dev);if (!skip_bus_pm && prev_state == PCI_D3cold) -pci_bridge_wait_for_secondary_bus (pci_dev); +pci_bridge_wait_for_secondary_bus (pci_dev,"resume" ,PCI_RESET_WAIT );if (pci_has_legacy_pm_support (pci_dev))return 0 ;
@@ -1312,7 +1312,7 @@ static int pci_pm_runtime_resume(struct device *dev)pci_pm_default_resume (pci_dev);if (prev_state == PCI_D3cold) -pci_bridge_wait_for_secondary_bus (pci_dev); +pci_bridge_wait_for_secondary_bus (pci_dev,"resume" ,PCI_RESET_WAIT );if (pm && pm->runtime_resume) error = pm->runtime_resume (dev);
drivers/pci/pci.c +24 -30
137 lines not on this page · raw message
drivers/pci/pci.h +9 -1
@@ -63,6 +63,13 @@ struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,#define PCI_PM_D3HOT_WAIT 10/* msec */ #define PCI_PM_D3COLD_WAIT 100/* msec */ +/* +* Following exit from Conventional Reset, devices must be ready within 1 sec +* (PCIe r6.0 sec 6.6.1). A D3cold to D0 transition implies a Conventional +* Reset (PCIe r6.0 sec 5.8). +*/ +#define PCI_RESET_WAIT 1000/* msec */ +/** * struct pci_platform_pm_ops - Firmware PM callbacks *
@@ -124,7 +131,8 @@ void pci_msi_init(struct pci_dev *dev);void pci_msix_init (struct pci_dev *dev);bool pci_bridge_d3_possible (struct pci_dev *dev);void pci_bridge_d3_update (struct pci_dev *dev); -void pci_bridge_wait_for_secondary_bus (struct pci_dev *dev); +int pci_bridge_wait_for_secondary_bus (struct pci_dev *dev,char *reset_type, +int timeout);static inline void pci_wakeup_event (struct pci_dev *dev) {
Signature · 1 line
2.39.2
PATCH 2/2 PCI/DPC: Await readiness of secondary bus after reset
In reply to [email protected]commit 53b54ad074de1896f8b021615f65b27f557ce874 upstream.
pci_bridge_wait_for_secondary_bus() is called after a Secondary Bus Reset, but not after a DPC-induced Hot Reset.
As a result, the delays prescribed by PCIe r6.0 sec 6.6.1 are not observed and devices on the secondary bus may be accessed before they're ready.
One affected device is Intel's Ponte Vecchio HPC GPU. It comprises a PCIe switch whose upstream port is not immediately ready after reset. Because its config space is restored too early, it remains in D0uninitialized, its subordinate devices remain inaccessible and DPC recovery fails with messages such as:
i915 0000:8c:00.0: can't change power state from D3cold to D0 (config space inaccessible) intel_vsec 0000:8e:00.1: can't change power state from D3cold to D0 (config space inaccessible) pcieport 0000:89:02.0: AER: device recovery failed
Fix it.
--- drivers/pci/pci.c | 3 --- drivers/pci/pci.h | 6 ++++++ drivers/pci/pcie/dpc.c | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-)
drivers/pci/pci.c +0 -3
@@ -163,9 +163,6 @@ static int __init pcie_port_pm_setup(char *str) }__setup ("pcie_port_pm=" , pcie_port_pm_setup); -/* Time to wait after a reset for device to become responsive */ -#define PCIE_RESET_READY_POLL_MS 60000 -/** * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children * @bus: pointer to PCI bus structure to search
drivers/pci/pci.h +6 -0
@@ -69,6 +69,12 @@ struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,* Reset (PCIe r6.0 sec 5.8). */ #define PCI_RESET_WAIT 1000/* msec */ +/* +* Devices may extend the 1 sec period through Request Retry Status completions +* (PCIe r6.0 sec 2.3.1). The spec does not provide an upper limit, but 60 sec +* ought to be enough for any device to become responsive. +*/ +#define PCIE_RESET_READY_POLL_MS 60000/* msec */ /** * struct pci_platform_pm_ops - Firmware PM callbacks
drivers/pci/pcie/dpc.c +2 -2
@@ -170,8 +170,8 @@ pci_ers_result_t dpc_reset_link(struct pci_dev *pdev)pci_write_config_word (pdev, cap +PCI_EXP_DPC_STATUS ,PCI_EXP_DPC_STATUS_TRIGGER ); -if (!pcie_wait_for_link (pdev, true)) { -pci_info (pdev,"Data Link Layer Link Active not set in 1000 msec\n" ); +if (pci_bridge_wait_for_secondary_bus (pdev,"DPC" , +PCIE_RESET_READY_POLL_MS )) {clear_bit (PCI_DPC_RECOVERED , &pdev->priv_flags); ret =PCI_ERS_RESULT_DISCONNECT ; }else {
Signature · 1 line
2.39.2