2020-10-07 11:35:50

by Ethan Zhao

[permalink] [raw]
Subject: [PATCH v8 5/6] PCI/ERR: only return true when dev io state is really changed

When uncorrectable error happens, AER driver and DPC driver interrupt
handlers likely call

pcie_do_recovery()
->pci_walk_bus()
->report_frozen_detected()

with pci_channel_io_frozen the same time.
If pci_dev_set_io_state() return true even if the original state is
pci_channel_io_frozen, that will cause AER or DPC handler re-enter
the error detecting and recovery procedure one after another.
The result is the recovery flow mixed between AER and DPC.
So change the pci_dev_set_io_state() function to only return true
when dev->error_state is really changed.

Signed-off-by: Ethan Zhao <[email protected]>
---
Changnes:
v2: revise description and code according to suggestion from Andy.
v3: change code to simpler.
v4: no change.
v5: no change.
v6: no change.
v7: changed based on Bjorn's code and truth table.
v8: according to Bjorn's suggestion, rebase on another simplification
patch.

drivers/pci/pci.h | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index bceb3f108744..a11e0f9d9bdf 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -371,17 +371,14 @@ static inline bool pci_dev_set_io_state(struct pci_dev *dev,
* perm_failure | perm_failure* perm_failure* perm_failure
*/

- /* Can always put a device in perm_failure state */
- if (new == pci_channel_io_perm_failure) {
- dev->error_state = pci_channel_io_perm_failure;
- return true;
- }
-
- /* If already in perm_failure, can't set to normal or frozen */
+ /* If already in perm_failure, can't change it's state */
if (dev->error_state == pci_channel_io_perm_failure)
return false;
+ /* not change at all */
+ else if (dev->error_state == new)
+ return false;

- /* Can always change normal to frozen or vice versa */
+ /* Can always change from normal/frozen to other different state */
dev->error_state = new;
return true;
}
--
2.18.4