EEH refactoring 1
Subsystems (2)
cover EEH refactoring 1
Hello everyone,
Here is a set of some small, mostly idempotent, changes to improve maintainability in some of the EEH code, primarily in eeh_driver.c.
I've kept them all small to aid review but perhaps they should be squashed down before being applied.
Cheers,
Sam.
Sam Bobroff (9):
powerpc/eeh: Remove eeh_handle_event()
powerpc/eeh: Manage EEH_PE_RECOVERING inside eeh_handle_normal_event() powerpc/eeh: Fix misleading comment in __eeh_addr_cache_get_device() powerpc/eeh: Remove misleading test in eeh_handle_normal_event() powerpc/eeh: Rename frozen_bus to bus in eeh_handle_normal_event() powerpc/eeh: Clarify arguments to eeh_reset_device() powerpc/eeh: Remove always-true tests in eeh_reset_device() powerpc/eeh: Factor out common code eeh_reset_device() powerpc/eeh: Add eeh_state_active() helper
arch/powerpc/include/asm/eeh.h | 6 ++ arch/powerpc/include/asm/eeh_event.h | 3 +- arch/powerpc/kernel/eeh.c | 19 ++-- arch/powerpc/kernel/eeh_cache.c | 3 +- arch/powerpc/kernel/eeh_driver.c | 143 +++++++++++---------------- arch/powerpc/kernel/eeh_event.c | 6 +- arch/powerpc/platforms/powernv/eeh-powernv.c | 9 +- 7 files changed, 75 insertions(+), 114 deletions(-)
Signature · 1 line
2.16.1.74.g9b0b1f47b
PATCH 1/9 powerpc/eeh: Remove eeh_handle_event()
The function eeh_handle_event(pe) does nothing other than switching between calling eeh_handle_normal_event(pe) and eeh_handle_special_event(). However it is only called in two places, one where pe can't be NULL and the other where it must be NULL (see eeh_event_handler()) so it does nothing but obscure the flow of control.
So, remove it.
--- arch/powerpc/include/asm/eeh_event.h | 3 ++- arch/powerpc/kernel/eeh_driver.c | 42 +++++++++++++----------------------- arch/powerpc/kernel/eeh_event.c | 4 ++-- 3 files changed, 19 insertions(+), 30 deletions(-)
arch/powerpc/include/asm/eeh_event.h +2 -1
@@ -34,7 +34,8 @@ struct eeh_event {int eeh_event_init (void );int eeh_send_failure_event (struct eeh_pe *pe);void eeh_remove_event (struct eeh_pe *pe,bool force); -void eeh_handle_event (struct eeh_pe *pe); +bool eeh_handle_normal_event (struct eeh_pe *pe); +void eeh_handle_special_event (void );#endif /* __KERNEL__ */ #endif /* ASM_POWERPC_EEH_EVENT_H */
arch/powerpc/kernel/eeh_driver.c +15 -27
59 lines not on this page · raw message
arch/powerpc/kernel/eeh_event.c +2 -2
@@ -81,10 +81,10 @@ static int eeh_event_handler(void * dummy)pr_info ("EEH: Detected PCI bus error on " "PHB#%x-PE#%x\n" , pe->phb->global_number, pe->addr); -eeh_handle_event (pe); +eeh_handle_normal_event (pe);eeh_pe_state_clear (pe,EEH_PE_RECOVERING ); }else { -eeh_handle_event (NULL ); +eeh_handle_special_event (); }kfree (event);
Signature · 1 line
2.16.1.74.g9b0b1f47b
PATCH 2/9 powerpc/eeh: Manage EEH_PE_RECOVERING inside eeh_handle_normal_event()
In reply to Sam BobroffCurrently the EEH_PE_RECOVERING flag for a PE is managed by both the caller and callee of eeh_handle_normal_event() (among other places not considered here). This is complicated by the fact that the PE may or may not have been invalidated by the call.
So move the callee's handling into eeh_handle_normal_event(), which clarifies it and allows the return type to be changed to void (because it no longer needs to indicate at the PE has been invalidated).
This should not change behaviour except in eeh_event_handler() where it was previously possible to cause eeh_pe_state_clear() to be called on an invalid PE, which is now avoided.
--- arch/powerpc/include/asm/eeh_event.h | 2 +- arch/powerpc/kernel/eeh_driver.c | 29 +++++++++++------------------ arch/powerpc/kernel/eeh_event.c | 2 -- 3 files changed, 12 insertions(+), 21 deletions(-)
arch/powerpc/include/asm/eeh_event.h +1 -1
@@ -34,7 +34,7 @@ struct eeh_event {int eeh_event_init (void );int eeh_send_failure_event (struct eeh_pe *pe);void eeh_remove_event (struct eeh_pe *pe,bool force); -bool eeh_handle_normal_event (struct eeh_pe *pe); +void eeh_handle_normal_event (struct eeh_pe *pe);void eeh_handle_special_event (void );#endif /* __KERNEL__ */
arch/powerpc/kernel/eeh_driver.c +11 -18
@@ -733,7 +733,8 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,/** * eeh_handle_normal_event - Handle EEH events on a specific PE -* @pe: EEH PE +* @pe: EEH PE - which should not be used after we return, as it may +* have been invalidated. * * Attempts to recover the given PE. If recovery fails or the PE has failed * too many times, remove the PE.
@@ -750,10 +751,8 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,* & devices under this slot, and then finally restarting the device * drivers (which cause a second set of hotplug events to go out to * userspace). -* -* Returns true if @pe should no longer be used, else false. */ -bool eeh_handle_normal_event (struct eeh_pe *pe) +void eeh_handle_normal_event (struct eeh_pe *pe) {struct pci_bus *frozen_bus;struct eeh_dev *edev, *tmp;
@@ -765,9 +764,11 @@ bool eeh_handle_normal_event(struct eeh_pe *pe)if (!frozen_bus) {pr_err ("%s: Cannot find PCI bus for PHB#%x-PE#%x\n" , __func__, pe->phb->global_number, pe->addr); -return false; +return ; } +eeh_pe_state_mark (pe,EEH_PE_RECOVERING ); +eeh_pe_update_time_stamp (pe); pe->freeze_count++;if (pe->freeze_count > eeh_max_freezes) {
@@ -904,7 +905,7 @@ bool eeh_handle_normal_event(struct eeh_pe *pe)pr_info ("EEH: Notify device driver to resume\n" );eeh_pe_dev_traverse (pe, eeh_report_resume,NULL ); -return false; + goto final; hard_fail:/*
@@ -940,12 +941,12 @@ bool eeh_handle_normal_event(struct eeh_pe *pe)pci_lock_rescan_remove ();pci_hp_remove_devices (frozen_bus);pci_unlock_rescan_remove (); -/* The passed PE should no longer be used */ -return true; +return ; } } -return false; +final: +eeh_pe_state_clear (pe,EEH_PE_RECOVERING ); }/**
@@ -1018,15 +1019,7 @@ void eeh_handle_special_event(void)*/ if (rc ==EEH_NEXT_ERR_FROZEN_PE || rc ==EEH_NEXT_ERR_FENCED_PHB ) { -/* -* eeh_handle_normal_event() can make the PE stale if it -* determines that the PE cannot possibly be recovered. -* Don't modify the PE state if that's the case. -*/ -if (eeh_handle_normal_event (pe)) -continue ; - -eeh_pe_state_clear (pe,EEH_PE_RECOVERING ); +eeh_handle_normal_event (pe); }else {pci_lock_rescan_remove ();list_for_each_entry (hose, &hose_list, list_node) {
arch/powerpc/kernel/eeh_event.c +0 -2
@@ -73,7 +73,6 @@ static int eeh_event_handler(void * dummy)/* We might have event without binding PE */ pe = event->pe;if (pe) { -eeh_pe_state_mark (pe,EEH_PE_RECOVERING );if (pe->type &EEH_PE_PHB )pr_info ("EEH: Detected error on PHB#%x\n" , pe->phb->global_number);
@@ -82,7 +81,6 @@ static int eeh_event_handler(void * dummy)"PHB#%x-PE#%x\n" , pe->phb->global_number, pe->addr);eeh_handle_normal_event (pe); -eeh_pe_state_clear (pe,EEH_PE_RECOVERING ); }else {eeh_handle_special_event (); }
Signature · 1 line
2.16.1.74.g9b0b1f47b
PATCH 3/9 powerpc/eeh: Fix misleading comment in __eeh_addr_cache_get_device()
In reply to Sam BobroffCommit "0ba178888b05 powerpc/eeh: Remove reference to PCI device" removed a call to pci_dev_get() from __eeh_addr_cache_get_device() but did not update the comment to match.
--- arch/powerpc/kernel/eeh_cache.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/kernel/eeh_cache.c +1 -2
@@ -84,8 +84,7 @@ static inline struct eeh_dev *__eeh_addr_cache_get_device(unsigned long addr)* @addr: mmio (PIO) phys address or i/o port number * * Given an mmio phys address, or a port number, find a pci device -* that implements this address. Be sure to pci_dev_put the device -* when finished. I/O port numbers are assumed to be offset +* that implements this address. I/O port numbers are assumed to be offset * from zero (that is, they do *not* have pci_io_addr added in). * It is safe to call this function within an interrupt. */
Signature · 1 line
2.16.1.74.g9b0b1f47b
PATCH 4/9 powerpc/eeh: Remove misleading test in eeh_handle_normal_event()
In reply to Sam BobroffRemove a test that checks if "frozen_bus" is NULL, because it cannot have changed since it was tested at the start of the function and so must be true here.
--- arch/powerpc/kernel/eeh_driver.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
arch/powerpc/kernel/eeh_driver.c +11 -13
@@ -930,20 +930,18 @@ void eeh_handle_normal_event(struct eeh_pe *pe)* all removed devices correctly to avoid access * the their PCI config any more. */ -if (frozen_bus) { -if (pe->type &EEH_PE_VF ) { -eeh_pe_dev_traverse (pe, eeh_rmv_device,NULL ); -eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); - }else { -eeh_pe_state_clear (pe,EEH_PE_PRI_BUS ); -eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); +if (pe->type &EEH_PE_VF ) { +eeh_pe_dev_traverse (pe, eeh_rmv_device,NULL ); +eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); + }else { +eeh_pe_state_clear (pe,EEH_PE_PRI_BUS ); +eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); -pci_lock_rescan_remove (); -pci_hp_remove_devices (frozen_bus); -pci_unlock_rescan_remove (); -/* The passed PE should no longer be used */ -return ; - } +pci_lock_rescan_remove (); +pci_hp_remove_devices (frozen_bus); +pci_unlock_rescan_remove (); +/* The passed PE should no longer be used */ +return ; } final:eeh_pe_state_clear (pe,EEH_PE_RECOVERING );
Signature · 1 line
2.16.1.74.g9b0b1f47b
PATCH 5/9 powerpc/eeh: Rename frozen_bus to bus in eeh_handle_normal_event()
In reply to Sam BobroffThe name "frozen_bus" is misleading: it's not necessarily frozen, it's just the PE's PCI bus.
--- arch/powerpc/kernel/eeh_driver.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/kernel/eeh_driver.c +5 -5
@@ -754,14 +754,14 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,*/ void eeh_handle_normal_event (struct eeh_pe *pe) { -struct pci_bus *frozen_bus; +struct pci_bus *bus;struct eeh_dev *edev, *tmp;int rc =0 ;enum pci_ers_result result =PCI_ERS_RESULT_NONE ;struct eeh_rmv_data rmv_data = {LIST_HEAD_INIT (rmv_data.edev_list),0 }; - frozen_bus =eeh_pe_bus_get (pe); -if (!frozen_bus) { + bus =eeh_pe_bus_get (pe); +if (!bus) {pr_err ("%s: Cannot find PCI bus for PHB#%x-PE#%x\n" , __func__, pe->phb->global_number, pe->addr);return ;
@@ -820,7 +820,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)*/ if (result ==PCI_ERS_RESULT_NONE ) {pr_info ("EEH: Reset with hotplug activity\n" ); - rc =eeh_reset_device (pe, frozen_bus,NULL ); + rc =eeh_reset_device (pe, bus,NULL );if (rc) {pr_warn ("%s: Unable to reset, err=%d\n" , __func__, rc);
@@ -938,7 +938,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED );pci_lock_rescan_remove (); -pci_hp_remove_devices (frozen_bus); +pci_hp_remove_devices (bus);pci_unlock_rescan_remove ();/* The passed PE should no longer be used */ return ;
Signature · 1 line
2.16.1.74.g9b0b1f47b
PATCH 6/9 powerpc/eeh: Clarify arguments to eeh_reset_device()
In reply to Sam BobroffIt is currently difficult to understand the behaviour of eeh_reset_device() due to the way it's parameters are used. In particular, when 'bus' is NULL, it's value is still necessary so the same value is looked up again locally under a different name ('frozen_bus') but behaviour is changed.
To clarify this, add a new parameter 'eeh_aware_driver', and have the caller set it when it would have passed NULL for 'bus' and always pass a value for 'bus'. Then change any test that was on 'bus' to one on '!eeh_aware_driver' and replace uses of 'frozen_bus' with 'bus'.
Also update the function's comment.
This should not change behaviour.
--- arch/powerpc/kernel/eeh_driver.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
arch/powerpc/kernel/eeh_driver.c +12 -10
@@ -619,17 +619,19 @@ int eeh_pe_reset_and_recover(struct eeh_pe *pe)/** * eeh_reset_device - Perform actual reset of a pci slot +* @eeh_aware_driver: Does the device's driver provide EEH support? * @pe: EEH PE * @bus: PCI bus corresponding to the isolcated slot +* @rmv_data: Optional, list to record removed devices * * This routine must be called to do reset on the indicated PE. * During the reset, udev might be invoked because those affected * PCI devices will be removed and then added. */ -static int eeh_reset_device (struct eeh_pe *pe,struct pci_bus *bus, -struct eeh_rmv_data *rmv_data) +static int eeh_reset_device (bool eeh_aware_driver, +struct eeh_pe *pe,struct pci_bus *bus, +struct eeh_rmv_data *rmv_data) { -struct pci_bus *frozen_bus =eeh_pe_bus_get (pe);time64_t tstamp;int cnt, rc;struct eeh_dev *edev;
@@ -645,7 +647,7 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,* into pci_hp_add_devices(). */ eeh_pe_state_mark (pe,EEH_PE_KEEP ); -if (bus) { +if (!eeh_aware_driver) {if (pe->type &EEH_PE_VF ) {eeh_pe_dev_traverse (pe, eeh_rmv_device,NULL ); }else {
@@ -653,7 +655,7 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,pci_hp_remove_devices (bus);pci_unlock_rescan_remove (); } - }else if (frozen_bus) { + }else if (bus) {eeh_pe_dev_traverse (pe, eeh_rmv_device, rmv_data); }
@@ -689,7 +691,7 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,* the device up before the scripts have taken it down, * potentially weird things happen. */ -if (bus) { +if (!eeh_aware_driver) {pr_info ("EEH: Sleep 5s ahead of complete hotplug\n" );ssleep (5 );
@@ -706,7 +708,7 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,eeh_pe_state_clear (pe,EEH_PE_PRI_BUS );pci_hp_add_devices (bus); } - }else if (frozen_bus && rmv_data->removed) { + }else if (bus && rmv_data->removed) {pr_info ("EEH: Sleep 5s ahead of partial hotplug\n" );ssleep (5 );
@@ -715,7 +717,7 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,if (pe->type &EEH_PE_VF )eeh_add_virt_device (edev,NULL );else -pci_hp_add_devices (frozen_bus); +pci_hp_add_devices (bus); }eeh_pe_state_clear (pe,EEH_PE_KEEP );
@@ -820,7 +822,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)*/ if (result ==PCI_ERS_RESULT_NONE ) {pr_info ("EEH: Reset with hotplug activity\n" ); - rc =eeh_reset_device (pe, bus,NULL ); + rc =eeh_reset_device (false, pe, bus,NULL );if (rc) {pr_warn ("%s: Unable to reset, err=%d\n" , __func__, rc);
@@ -872,7 +874,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)/* If any device called out for a reset, then reset the slot */ if (result ==PCI_ERS_RESULT_NEED_RESET ) {pr_info ("EEH: Reset without hotplug activity\n" ); - rc =eeh_reset_device (pe,NULL , &rmv_data); + rc =eeh_reset_device (true, pe, bus, &rmv_data);if (rc) {pr_warn ("%s: Cannot reset, err=%d\n" , __func__, rc);
Signature · 1 line
2.16.1.74.g9b0b1f47b
PATCH 7/9 powerpc/eeh: Remove always-true tests in eeh_reset_device()
In reply to Sam Bobroffeeh_reset_device() tests the value of 'bus' more than once but the only caller, eeh_handle_normal_device() does this test itself and will never pass NULL.
So, remove the dead tests.
This should not change behaviour.
--- arch/powerpc/kernel/eeh_driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kernel/eeh_driver.c +2 -2
@@ -655,7 +655,7 @@ static int eeh_reset_device(bool eeh_aware_driver,pci_hp_remove_devices (bus);pci_unlock_rescan_remove (); } - }else if (bus) { + }else {eeh_pe_dev_traverse (pe, eeh_rmv_device, rmv_data); }
@@ -708,7 +708,7 @@ static int eeh_reset_device(bool eeh_aware_driver,eeh_pe_state_clear (pe,EEH_PE_PRI_BUS );pci_hp_add_devices (bus); } - }else if (bus && rmv_data->removed) { + }else if (rmv_data->removed) {pr_info ("EEH: Sleep 5s ahead of partial hotplug\n" );ssleep (5 );
Signature · 1 line
2.16.1.74.g9b0b1f47b
PATCH 8/9 powerpc/eeh: Factor out common code eeh_reset_device()
In reply to Sam BobroffThe caller will always pass NULL for 'rmv_data' when 'eeh_aware_driver' is true, so the first two calls to eeh_pe_dev_traverse() can be combined without changing behaviour as can the two arms of the final 'if' block.
This should not change behaviour.
--- arch/powerpc/kernel/eeh_driver.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)
arch/powerpc/kernel/eeh_driver.c +12 -24
@@ -647,16 +647,12 @@ static int eeh_reset_device(bool eeh_aware_driver,* into pci_hp_add_devices(). */ eeh_pe_state_mark (pe,EEH_PE_KEEP ); -if (!eeh_aware_driver) { -if (pe->type &EEH_PE_VF ) { -eeh_pe_dev_traverse (pe, eeh_rmv_device,NULL ); - }else { -pci_lock_rescan_remove (); -pci_hp_remove_devices (bus); -pci_unlock_rescan_remove (); - } - }else { +if (eeh_aware_driver || (pe->type &EEH_PE_VF )) {eeh_pe_dev_traverse (pe, eeh_rmv_device, rmv_data); + }else { +pci_lock_rescan_remove (); +pci_hp_remove_devices (bus); +pci_unlock_rescan_remove (); }/*
@@ -691,8 +687,9 @@ static int eeh_reset_device(bool eeh_aware_driver,* the device up before the scripts have taken it down, * potentially weird things happen. */ -if (!eeh_aware_driver) { -pr_info ("EEH: Sleep 5s ahead of complete hotplug\n" ); +if (!eeh_aware_driver || rmv_data->removed) { +pr_info ("EEH: Sleep 5s ahead of %s hotplug\n" , + (eeh_aware_driver ?"partial" :"complete" ));ssleep (5 );/*
@@ -700,24 +697,15 @@ static int eeh_reset_device(bool eeh_aware_driver,* PE. We should disconnect it so the binding can be * rebuilt when adding PCI devices. */ - edev = list_first_entry(&pe->edevs, struct eeh_dev, list); -eeh_pe_traverse (pe, eeh_pe_detach_dev,NULL ); -if (pe->type &EEH_PE_VF ) { -eeh_add_virt_device (edev,NULL ); - }else { -eeh_pe_state_clear (pe,EEH_PE_PRI_BUS ); -pci_hp_add_devices (bus); - } - }else if (rmv_data->removed) { -pr_info ("EEH: Sleep 5s ahead of partial hotplug\n" ); -ssleep (5 ); - edev = list_first_entry(&pe->edevs, struct eeh_dev, list);eeh_pe_traverse (pe, eeh_pe_detach_dev,NULL );if (pe->type &EEH_PE_VF )eeh_add_virt_device (edev,NULL ); -else +else { +if (!eeh_aware_driver) +eeh_pe_state_clear (pe,EEH_PE_PRI_BUS );pci_hp_add_devices (bus); + } }eeh_pe_state_clear (pe,EEH_PE_KEEP );
Signature · 1 line
2.16.1.74.g9b0b1f47b
PATCH 9/9 powerpc/eeh: Add eeh_state_active() helper
In reply to Sam BobroffChecking for a "fully active" device state requires testing two flag bits, which is open coded in several places, so add a function to do it.
--- arch/powerpc/include/asm/eeh.h | 6 ++++++ arch/powerpc/kernel/eeh.c | 19 ++++++------------- arch/powerpc/platforms/powernv/eeh-powernv.c | 9 ++------- 3 files changed, 14 insertions(+), 20 deletions(-)
arch/powerpc/include/asm/eeh.h +6 -0
@@ -256,6 +256,12 @@ static inline void eeh_serialize_unlock(unsigned long flags)raw_spin_unlock_irqrestore (&confirm_error_lock, flags); } +static inline bool eeh_state_active (int state) +{ +return (state & (EEH_STATE_MMIO_ACTIVE |EEH_STATE_DMA_ACTIVE )) + == (EEH_STATE_MMIO_ACTIVE |EEH_STATE_DMA_ACTIVE ); +} +typedef void *(*eeh_traverse_func )(void *data,void *flag);void eeh_set_pe_aux_size (int size);int eeh_phb_pe_create (struct pci_controller *phb);
arch/powerpc/kernel/eeh.c +6 -13
@@ -394,9 +394,7 @@ static int eeh_phb_check_failure(struct eeh_pe *pe)/* Check PHB state */ ret = eeh_ops->get_state (phb_pe,NULL );if ((ret <0 ) || - (ret ==EEH_STATE_NOT_SUPPORT ) || - (ret & (EEH_STATE_MMIO_ACTIVE |EEH_STATE_DMA_ACTIVE )) == - (EEH_STATE_MMIO_ACTIVE |EEH_STATE_DMA_ACTIVE )) { + (ret ==EEH_STATE_NOT_SUPPORT ) ||eeh_state_active (ret)) { ret =0 ; goto out; }
@@ -433,7 +431,6 @@ static int eeh_phb_check_failure(struct eeh_pe *pe)int eeh_dev_check_failure (struct eeh_dev *edev) {int ret; -int active_flags = (EEH_STATE_MMIO_ACTIVE |EEH_STATE_DMA_ACTIVE );unsigned long flags;struct device_node *dn;struct pci_dev *dev;
@@ -525,8 +522,7 @@ int eeh_dev_check_failure(struct eeh_dev *edev)* state, PE is in good state. */ if ((ret <0 ) || - (ret ==EEH_STATE_NOT_SUPPORT ) || - ((ret & active_flags) == active_flags)) { + (ret ==EEH_STATE_NOT_SUPPORT ) ||eeh_state_active (ret)) { eeh_stats.false_positives++; pe->false_positives++; rc =0 ;
@@ -546,8 +542,7 @@ int eeh_dev_check_failure(struct eeh_dev *edev)/* Frozen parent PE ? */ ret = eeh_ops->get_state (parent_pe,NULL ); -if (ret >0 && - (ret & active_flags) != active_flags) +if (ret >0 && !eeh_state_active (ret)) pe = parent_pe;/* Next parent level */
@@ -888,7 +883,6 @@ static void *eeh_set_dev_freset(void *data, void *flag)*/ int eeh_pe_reset_full (struct eeh_pe *pe) { -int active_flags = (EEH_STATE_MMIO_ACTIVE |EEH_STATE_DMA_ACTIVE );int reset_state = (EEH_PE_RESET |EEH_PE_CFG_BLOCKED );int type =EEH_RESET_HOT ;unsigned int freset =0 ;
@@ -919,7 +913,7 @@ int eeh_pe_reset_full(struct eeh_pe *pe)/* Wait until the PE is in a functioning state */ state = eeh_ops->wait_state (pe,PCI_BUS_RESET_WAIT_MSEC ); -if ((state & active_flags) == active_flags) +if (eeh_state_active (state))break ;if (state <0 ) {
@@ -1352,16 +1346,15 @@ static int eeh_pe_change_owner(struct eeh_pe *pe)struct eeh_dev *edev, *tmp;struct pci_dev *pdev;struct pci_device_id *id; -int flags, ret; +int ret;/* Check PE state */ - flags = (EEH_STATE_MMIO_ACTIVE |EEH_STATE_DMA_ACTIVE ); ret = eeh_ops->get_state (pe,NULL );if (ret <0 || ret ==EEH_STATE_NOT_SUPPORT )return 0 ;/* Unfrozen PE, nothing to do */ -if ((ret & flags) == flags) +if (eeh_state_active (ret))return 0 ;/* Frozen PE, check if it needs PE level reset */
arch/powerpc/platforms/powernv/eeh-powernv.c +2 -7
@@ -1425,11 +1425,8 @@ static int pnv_eeh_get_pe(struct pci_controller *hose, dev_pe = dev_pe->parent;while (dev_pe && !(dev_pe->type &EEH_PE_PHB )) {int ret; -int active_flags = (EEH_STATE_MMIO_ACTIVE | -EEH_STATE_DMA_ACTIVE ); - ret = eeh_ops->get_state (dev_pe,NULL ); -if (ret <=0 || (ret & active_flags) == active_flags) { +if (ret <=0 ||eeh_state_active (ret)) { dev_pe = dev_pe->parent;continue ; }
@@ -1463,7 +1460,6 @@ static int pnv_eeh_next_error(struct eeh_pe **pe)struct eeh_pe *phb_pe, *parent_pe;__be64 frozen_pe_no;__be16 err_type, severity; -int active_flags = (EEH_STATE_MMIO_ACTIVE |EEH_STATE_DMA_ACTIVE );long rc;int state, ret =EEH_NEXT_ERR_NONE ;
@@ -1626,8 +1622,7 @@ static int pnv_eeh_next_error(struct eeh_pe **pe)/* Frozen parent PE ? */ state = eeh_ops->get_state (parent_pe,NULL ); -if (state >0 && - (state & active_flags) != active_flags) +if (state >0 && !eeh_state_active (state)) *pe = parent_pe;/* Next parent level */
Signature · 1 line
2.16.1.74.g9b0b1f47b
Re: [PATCH 1/9] powerpc/eeh: Remove eeh_handle_event()
In reply to Sam BobroffQuoted 10 lines · Sam Bobroff
The function
eeh_handle_event(pe)does nothing other than switching between callingeeh_handle_normal_event(pe)andeeh_handle_special_event(). However it is only called in two places, one where pe can't be NULL and the other where it must be NULL (seeeeh_event_handler()) so it does nothing but obscure the flow of control.So, remove it.
Signed-off-by Sam Bobroff <[email protected]>
Re: [PATCH 2/9] powerpc/eeh: Manage EEH_PE_RECOVERING inside eeh_handle_normal_event()
In reply to Sam BobroffQuoted 11 lines · Sam Bobroff
Currently the
EEH_PE_RECOVERINGflag for a PE is managed by both the caller and callee ofeeh_handle_normal_event()(among other places not
considered here). This is complicated by the fact that the PE may or may not have been invalidated by the call.So move the callee's handling into
eeh_handle_normal_event(), which clarifies it and allows the return type to be changed to void (because
it no longer needs to indicate at the PE has been invalidated).
Quoted 5 lines
This should not change behaviour except in
eeh_event_handler()where it was previously possible to causeeeh_pe_state_clear()to be called on an invalid PE, which is now avoided.Signed-off-by Sam Bobroff <[email protected]>
Re: [PATCH 3/9] powerpc/eeh: Fix misleading comment in __eeh_addr_cache_get_device()
In reply to Sam BobroffQuoted 6 lines · Sam Bobroff
Commit "
0ba178888b05powerpc/eeh: Remove reference to PCI device" removed a call topci_dev_get()from__eeh_addr_cache_get_device()but
did not update the comment to match.Signed-off-by Sam Bobroff <[email protected]>
Re: [PATCH 4/9] powerpc/eeh: Remove misleading test in eeh_handle_normal_event()
In reply to Sam BobroffQuoted 3 lines · Sam Bobroff
Remove a test that checks if "
frozen_bus" is NULL, because it cannot have changed since it was tested at the start of the function and so must be true here.
It could potentially be modified since it gets passed into eeh_reset_device() but it doesn't look like it does anywhere.
Quoted 2 lines
Signed-off-by Sam Bobroff <[email protected]>
Re: [PATCH 5/9] powerpc/eeh: Rename frozen_bus to bus in eeh_handle_normal_event()
In reply to Sam BobroffQuoted 5 lines · Sam Bobroff
The name "
frozen_bus" is misleading: it's not necessarily frozen, it's
just the PE's PCI bus.Signed-off-by Sam Bobroff <[email protected]>
Re: [PATCH 1/9] powerpc/eeh: Remove eeh_handle_event()
In reply to Sam BobroffHi Sam,
Quoted 6 lines
The function
eeh_handle_event(pe)does nothing other than switching between callingeeh_handle_normal_event(pe)andeeh_handle_special_event(). However it is only called in two places, one where pe can't be NULL and the other where it must be NULL (seeeeh_event_handler()) so it does nothing but obscure the flow of control.
I've verified this.
Quoted 2 lines
So, remove it.
Sounds good.
Quoted 5 lines
+ * While PHB detects address or data parity errors on particular PCI
+ * slot, the associated PE will be frozen. Besides, DMA's occurring
+ * to wild addresses (which usually happen due to bugs in device
+ * drivers or in PCI adapter firmware) can cause EEH error. #SERR,
+ * #PERR or other misc PCI-related errors also can trigger EEH errors.
Quoted 8 lines
+ *
+ * Recovery process consists of unplugging the device driver (which
+ * generated hotplug events to userspace), then issuing a PCI #RST to
+ * the device, then reconfiguring the PCI config space for all bridges
+ * & devices under this slot, and then finally restarting the device
+ * drivers (which cause a second set of hotplug events to go out to
+ * userspace).
+ *
So this is the comment from eeh_handle_event. This seems as good a place as any to put it. (At some point someone should check if it lines up well with Documentation/powerpc/eeh-pci-error-recovery.txt but it can wait.)
In conclusion:
Thanks Sam!
Regards,
Daniel
Quoted 64 lines
* Returns true if @pe should no longer be used, else false. */
arch/powerpc/kernel/eeh_driver.c +2
-27-static bool eeh_handle_normal_event (struct eeh_pe *pe) +bool eeh_handle_normal_event (struct eeh_pe *pe) {struct pci_bus *frozen_bus;struct eeh_dev *edev, *tmp;@@ -942,7 +955,7 @@ static bool eeh_handle_normal_event(struct eeh_pe *pe)* specific PE. Iterates through possible failures and handles them as * necessary. */ -static void eeh_handle_special_event (void ) +void eeh_handle_special_event (void ) {struct eeh_pe *pe, *phb_pe;struct pci_bus *bus;@@ -1049,28 +1062,3 @@ static void eeh_handle_special_event(void)break ; }while (rc !=EEH_NEXT_ERR_NONE ); } - -/** -* eeh_handle_event - Reset a PCI device after hard lockup. -* @pe: EEH PE -* -* While PHB detects address or data parity errors on particular PCI -* slot, the associated PE will be frozen. Besides, DMA's occurring -* to wild addresses (which usually happen due to bugs in device -* drivers or in PCI adapter firmware) can cause EEH error. #SERR, -* #PERR or other misc PCI-related errors also can trigger EEH errors. -* -* Recovery process consists of unplugging the device driver (which -* generated hotplug events to userspace), then issuing a PCI #RST to -* the device, then reconfiguring the PCI config space for all bridges -* & devices under this slot, and then finally restarting the device -* drivers (which cause a second set of hotplug events to go out to -* userspace). -*/ -void eeh_handle_event (struct eeh_pe *pe) -{ -if (pe) -eeh_handle_normal_event (pe); -else -eeh_handle_special_event (); -}arch/powerpc/kernel/eeh_event.c +2
-2@@ -81,10 +81,10 @@ static int eeh_event_handler(void * dummy)pr_info ("EEH: Detected PCI bus error on " "PHB#%x-PE#%x\n" , pe->phb->global_number, pe->addr); -eeh_handle_event (pe); +eeh_handle_normal_event (pe);eeh_pe_state_clear (pe,EEH_PE_RECOVERING ); }else { -eeh_handle_event (NULL ); +eeh_handle_special_event (); }kfree (event);Signature · 1 line
2.16.1.74.g9b0b1f47b
Re: [PATCH 2/9] powerpc/eeh: Manage EEH_PE_RECOVERING inside eeh_handle_normal_event()
In reply to Sam BobroffHi Sam,
Quoted 4 lines
Currently the
EEH_PE_RECOVERINGflag for a PE is managed by both the caller and callee ofeeh_handle_normal_event()(among other places not considered here). This is complicated by the fact that the PE may or may not have been invalidated by the call.
So, I applied this patch and looked at those places. They're now restricted to eeh_driver.c and eeh.c.
The only other place it's marked is eeh_driver.c::eeh_pe_reset_and_recover(), which is itself only called from eeh.c::eeh_pe_change_owner(). That is only called from 2 places, both in eeh.c - eeh_dev_open() and eeh_dev_release(). I have not yet wrapped my head around the logic of that.
I suspect the entire logic can have some more simplifications, but this is definitely a good step.
I also read through your patch and have no other comments, so:
Regards,
Daniel
Quoted 132 lines
So move the callee's handling into
eeh_handle_normal_event(), which clarifies it and allows the return type to be changed to void (because it no longer needs to indicate at the PE has been invalidated).This should not change behaviour except in
eeh_event_handler()where it was previously possible to causeeeh_pe_state_clear()to be called on an invalid PE, which is now avoided.Signed-off-by Sam Bobroff <[email protected]>--- arch/powerpc/include/asm/eeh_event.h | 2 +- arch/powerpc/kernel/eeh_driver.c | 29 +++++++++++------------------ arch/powerpc/kernel/eeh_event.c | 2 -- 3 files changed, 12 insertions(+), 21 deletions(-)arch/powerpc/include/asm/eeh_event.h +1
-1@@ -34,7 +34,7 @@ struct eeh_event {int eeh_event_init (void );int eeh_send_failure_event (struct eeh_pe *pe);void eeh_remove_event (struct eeh_pe *pe,bool force); -bool eeh_handle_normal_event (struct eeh_pe *pe); +void eeh_handle_normal_event (struct eeh_pe *pe);void eeh_handle_special_event (void );#endif /* __KERNEL__ */ arch/powerpc/kernel/eeh_driver.c +11
-18@@ -733,7 +733,8 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,/** * eeh_handle_normal_event - Handle EEH events on a specific PE -* @pe: EEH PE +* @pe: EEH PE - which should not be used after we return, as it may +* have been invalidated. * * Attempts to recover the given PE. If recovery fails or the PE has failed * too many times, remove the PE. @@ -750,10 +751,8 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,* & devices under this slot, and then finally restarting the device * drivers (which cause a second set of hotplug events to go out to * userspace). -* -* Returns true if @pe should no longer be used, else false. */ -bool eeh_handle_normal_event (struct eeh_pe *pe) +void eeh_handle_normal_event (struct eeh_pe *pe) {struct pci_bus *frozen_bus;struct eeh_dev *edev, *tmp;@@ -765,9 +764,11 @@ bool eeh_handle_normal_event(struct eeh_pe *pe)if (!frozen_bus) {pr_err ("%s: Cannot find PCI bus for PHB#%x-PE#%x\n" , __func__, pe->phb->global_number, pe->addr); -return false; +return ; } +eeh_pe_state_mark (pe,EEH_PE_RECOVERING ); +eeh_pe_update_time_stamp (pe); pe->freeze_count++;if (pe->freeze_count > eeh_max_freezes) {@@ -904,7 +905,7 @@ bool eeh_handle_normal_event(struct eeh_pe *pe)pr_info ("EEH: Notify device driver to resume\n" );eeh_pe_dev_traverse (pe, eeh_report_resume,NULL ); -return false; + goto final; hard_fail:/* @@ -940,12 +941,12 @@ bool eeh_handle_normal_event(struct eeh_pe *pe)pci_lock_rescan_remove ();pci_hp_remove_devices (frozen_bus);pci_unlock_rescan_remove (); -/* The passed PE should no longer be used */ -return true; +return ; } } -return false; +final: +eeh_pe_state_clear (pe,EEH_PE_RECOVERING ); }/** @@ -1018,15 +1019,7 @@ void eeh_handle_special_event(void)*/ if (rc ==EEH_NEXT_ERR_FROZEN_PE || rc ==EEH_NEXT_ERR_FENCED_PHB ) { -/* -* eeh_handle_normal_event() can make the PE stale if it -* determines that the PE cannot possibly be recovered. -* Don't modify the PE state if that's the case. -*/ -if (eeh_handle_normal_event (pe)) -continue ; - -eeh_pe_state_clear (pe,EEH_PE_RECOVERING ); +eeh_handle_normal_event (pe); }else {pci_lock_rescan_remove ();list_for_each_entry (hose, &hose_list, list_node) {arch/powerpc/kernel/eeh_event.c +0
-2@@ -73,7 +73,6 @@ static int eeh_event_handler(void * dummy)/* We might have event without binding PE */ pe = event->pe;if (pe) { -eeh_pe_state_mark (pe,EEH_PE_RECOVERING );if (pe->type &EEH_PE_PHB )pr_info ("EEH: Detected error on PHB#%x\n" , pe->phb->global_number);@@ -82,7 +81,6 @@ static int eeh_event_handler(void * dummy)"PHB#%x-PE#%x\n" , pe->phb->global_number, pe->addr);eeh_handle_normal_event (pe); -eeh_pe_state_clear (pe,EEH_PE_RECOVERING ); }else {eeh_handle_special_event (); }Signature · 1 line
2.16.1.74.g9b0b1f47b
Re: [PATCH 4/9] powerpc/eeh: Remove misleading test in eeh_handle_normal_event()
In reply to Sam BobroffQuoted 3 lines · Sam Bobroff
Remove a test that checks if "
frozen_bus" is NULL, because it cannot have changed since it was tested at the start of the function and so must be true here.
As far as I can tell this was added back in 2012 in 9b3c76f08122f. As far as I can tell it couldn't be NULL back then either. Weird.
LGTM, but I'm not super comfortable chnging something I don't understand so I will leave the formal review for now.
Regards,
Daniel
Quoted 44 lines
Signed-off-by Sam Bobroff <[email protected]>--- arch/powerpc/kernel/eeh_driver.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)arch/powerpc/kernel/eeh_driver.c +11
-13@@ -930,20 +930,18 @@ void eeh_handle_normal_event(struct eeh_pe *pe)* all removed devices correctly to avoid access * the their PCI config any more. */ -if (frozen_bus) { -if (pe->type &EEH_PE_VF ) { -eeh_pe_dev_traverse (pe, eeh_rmv_device,NULL ); -eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); - }else { -eeh_pe_state_clear (pe,EEH_PE_PRI_BUS ); -eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); +if (pe->type &EEH_PE_VF ) { +eeh_pe_dev_traverse (pe, eeh_rmv_device,NULL ); +eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); + }else { +eeh_pe_state_clear (pe,EEH_PE_PRI_BUS ); +eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); -pci_lock_rescan_remove (); -pci_hp_remove_devices (frozen_bus); -pci_unlock_rescan_remove (); -/* The passed PE should no longer be used */ -return ; - } +pci_lock_rescan_remove (); +pci_hp_remove_devices (frozen_bus); +pci_unlock_rescan_remove (); +/* The passed PE should no longer be used */ +return ; } final:eeh_pe_state_clear (pe,EEH_PE_RECOVERING );Signature · 1 line
2.16.1.74.g9b0b1f47b
Re: [PATCH 6/9] powerpc/eeh: Clarify arguments to eeh_reset_device()
In reply to Sam BobroffQuoted 29 lines · Sam Bobroff
It is currently difficult to understand the behaviour of
eeh_reset_device()due to the way it's parameters are used. In particular, when 'bus' is NULL, it's value is still necessary so the same value is looked up again locally under a different name ('frozen_bus') but behaviour is changed.To clarify this, add a new parameter '
eeh_aware_driver', and have the caller set it when it would have passed NULL for 'bus' and always pass
a value for 'bus'. Then change any test that was on 'bus' to one on '!eeh_aware_driver' and replace uses of 'frozen_bus' with 'bus'.Also update the function's comment.
This should not change behaviour.
Signed-off-by Sam Bobroff <[email protected]>--- arch/powerpc/kernel/eeh_driver.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)arch/powerpc/kernel/eeh_driver.c +0
-0@@ -619,17 +619,19 @@ int eeh_pe_reset_and_recover(struct eeh_pe *pe)/**
arch/powerpc/kernel/eeh_driver.c int eeh_pe_reset_and_recover(struct eeh_pe *pe) · line 630
Quoted 10 lines
arch/powerpc/kernel/eeh_driver.c +2
-0* eeh_reset_device - Perform actual reset of a pci slot +* @eeh_aware_driver: Does the device's driver provide EEH support? * @pe: EEH PE * @bus: PCI bus corresponding to the isolcated slot +* @rmv_data: Optional, list to record removed devices * * This routine must be called to do reset on the indicated PE. * During the reset, udev might be invoked because those affected * PCI devices will be removed and then added. */
Just a nitpick here, I would prefer that the PE remain the first argument of the function since that's one thing that's pretty standard across the EEH implementation. I'd also say that "driver_aware" is clearer than "aware_driver".
Re: [PATCH 7/9] powerpc/eeh: Remove always-true tests in eeh_reset_device()
In reply to Sam BobroffQuoted 10 lines · Sam Bobroff
eeh_reset_device()tests the value of 'bus' more than once but the only caller,eeh_handle_normal_device()does this test itself and will
never pass NULL.So, remove the dead tests.
This should not change behaviour.
Signed-off-by Sam Bobroff <[email protected]>
Re: [PATCH 8/9] powerpc/eeh: Factor out common code eeh_reset_device()
In reply to Sam BobroffQuoted 9 lines · Sam Bobroff
The caller will always pass NULL for '
rmv_data' when 'eeh_aware_driver' is true, so the first two calls toeeh_pe_dev_traverse()can be combined without changing behaviour as can the two arms of the final 'if' block.This should not change behaviour.
Signed-off-by Sam Bobroff <[email protected]>---
minor nitpick below
Quoted 63 lines
arch/powerpc/kernel/eeh_driver.c | 36 ++++++++++++---------------- -------- 1 file changed, 12 insertions(+), 24 deletions(-)arch/powerpc/kernel/eeh_driver.c +5
-9@@ -647,16 +647,12 @@ static int eeh_reset_device(booleeh_aware_driver, * into pci_hp_add_devices(). */ eeh_pe_state_mark (pe,EEH_PE_KEEP ); -if (!eeh_aware_driver) { -if (pe->type &EEH_PE_VF ) { -eeh_pe_dev_traverse (pe, eeh_rmv_device, NULL); - }else { -pci_lock_rescan_remove (); -pci_hp_remove_devices (bus); -pci_unlock_rescan_remove (); - } - }else { +if (eeh_aware_driver || (pe->type &EEH_PE_VF )) {eeh_pe_dev_traverse (pe, eeh_rmv_device, rmv_data); + }else { +pci_lock_rescan_remove (); +pci_hp_remove_devices (bus); +pci_unlock_rescan_remove (); }arch/powerpc/kernel/eeh_driver.c +3
-2/* @@ -691,8 +687,9 @@ static int eeh_reset_device(booleeh_aware_driver, * the device up before the scripts have taken it down, * potentially weird things happen. */ -if (!eeh_aware_driver) { -pr_info ("EEH: Sleep 5s ahead of complete hotplug\n"); +if (!eeh_aware_driver || rmv_data->removed) { +pr_info ("EEH: Sleep 5s ahead of %s hotplug\n" , + (eeh_aware_driver ?"partial" :"complete" ));arch/powerpc/kernel/eeh_driver.c +0
-9ssleep (5 );/* @@ -700,24 +697,15 @@ static int eeh_reset_device(booleeh_aware_driver, * PE. We should disconnect it so the binding can be * rebuilt when adding PCI devices. */ - edev = list_first_entry(&pe->edevs, struct eeh_dev, list); -eeh_pe_traverse (pe, eeh_pe_detach_dev,NULL ); -if (pe->type &EEH_PE_VF ) { -eeh_add_virt_device (edev,NULL ); - }else { -eeh_pe_state_clear (pe,EEH_PE_PRI_BUS ); -pci_hp_add_devices (bus); - } - }else if (rmv_data->removed) {
arch/powerpc/kernel/eeh_driver.c static int eeh_reset_device(bool · line 707
Quoted 10 lines
arch/powerpc/kernel/eeh_driver.c +1
-4-pr_info ("EEH: Sleep 5s ahead of partial hotplug\n" ); -ssleep (5 ); - edev = list_first_entry(&pe->edevs, struct eeh_dev, list);eeh_pe_traverse (pe, eeh_pe_detach_dev,NULL );if (pe->type &EEH_PE_VF )eeh_add_virt_device (edev,NULL ); -else +else {
Put brackets around the if block now that the else block isn't a one liner
Quoted 8 lines
arch/powerpc/kernel/eeh_driver.c +3
-0+if (!eeh_aware_driver) +eeh_pe_state_clear (pe,EEH_PE_PRI_BUS );pci_hp_add_devices (bus); + } }eeh_pe_state_clear (pe,EEH_PE_KEEP );
Re: [PATCH 9/9] powerpc/eeh: Add eeh_state_active() helper
In reply to Sam BobroffQuoted 5 lines · Sam Bobroff
Checking for a "fully active" device state requires testing two flag bits, which is open coded in several places, so add a function to do it.
Signed-off-by Sam Bobroff <[email protected]>
Thanks for the patches.
Re: [PATCH 9/9] powerpc/eeh: Add eeh_state_active() helper
Quoted 8 lines · Russell Currey
Quoted 5 lines · Sam Bobroff
Checking for a "fully active" device state requires testing two flag bits, which is open coded in several places, so add a function to do it.
Signed-off-by Sam Bobroff <[email protected]>Thanks for the patches.
Thanks for the review, I'll do a v2 with all the nits mentioned so far, Sam.
Quoted 1 line
Reviewed-by Russell Currey <[email protected]>