powerpc/eeh: fix recursive pci_lock_rescan_remove locking in EEH event handling
Subsystems (2)
PATCH 1/1 powerpc/eeh: fix recursive pci_lock_rescan_remove locking in EEH event handling
The recent commit 1010b4c012b0 ("powerpc/eeh: Make EEH driver device hotplug safe") restructured the EEH driver to improve synchronization with the PCI hotplug layer.
However, it inadvertently moved pci_lock_rescan_remove() outside its intended scope in eeh_handle_normal_event(), leading to broken PCI error reporting and improper EEH event triggering. Specifically, eeh_handle_normal_event() acquired pci_lock_rescan_remove() before calling eeh_pe_bus_get(), but eeh_pe_bus_get() itself attempts to acquire the same lock internally, causing nested locking and disrupting normal EEH event handling paths.
This patch adds a boolean parameter do_lock to _eeh_pe_bus_get(), with two public wrappers:
eeh_pe_bus_get() with locking enabled. eeh_pe_bus_get_nolock() that skips locking.
Callers that already hold pci_lock_rescan_remove() now use eeh_pe_bus_get_nolock() to avoid recursive lock acquisition.
Additionally, pci_lock_rescan_remove() calls are restored to the correct position—after eeh_pe_bus_get() and immediately before iterating affected PEs and devices. This ensures EEH-triggered PCI removes occur under proper bus rescan locking without recursive lock contention.
This resolves lockdep warnings such as:
<snip>
[ 84.964298] [ T928] ============================================
[ 84.964304] [ T928] WARNING: possible recursive locking detected
[ 84.964311] [ T928] 6.18.0-rc3 #51 Not tainted
[ 84.964315] [ T928] --------------------------------------------
[ 84.964320] [ T928] eehd/928 is trying to acquire lock:
[ 84.964324] [ T928] c000000003b29d58 (pci_rescan_remove_lock){+.+.}-{3:3}, at: pci_lock_rescan_remove+0x28/0x40
[ 84.964342] [ T928]
but task is already holding lock:
[ 84.964347] [ T928] c000000003b29d58 (pci_rescan_remove_lock){+.+.}-{3:3}, at: pci_lock_rescan_remove+0x28/0x40
[ 84.964357] [ T928]
other info that might help us debug this:
[ 84.964363] [ T928] Possible unsafe locking scenario:[ 84.964367] [ T928] CPU0
[ 84.964370] [ T928] ----
[ 84.964373] [ T928] lock(pci_rescan_remove_lock);
[ 84.964378] [ T928] lock(pci_rescan_remove_lock);
[ 84.964383] [ T928]
*** DEADLOCK ***[ 84.964388] [ T928] May be due to missing lock nesting notation
[ 84.964393] [ T928] 1 lock held by eehd/928:
[ 84.964397] [ T928] #0: c000000003b29d58 (pci_rescan_remove_lock){+.+.}-{3:3}, at: pci_lock_rescan_remove+0x28/0x40
[ 84.964408] [ T928]
stack backtrace:
[ 84.964414] [ T928] CPU: 2 UID: 0 PID: 928 Comm: eehd Not tainted 6.18.0-rc3 #51 VOLUNTARY
[ 84.964417] [ T928] Hardware name: IBM,9080-HEX POWER10 (architected) 0x800200 0xf000006 of:IBM,FW1060.00 (NH1060_022) hv:phyp pSeries
[ 84.964419] [ T928] Call Trace:
[ 84.964420] [ T928] [c0000011a7157990] [c000000001705de4] dump_stack_lvl+0xc8/0x130 (unreliable)
[ 84.964424] [ T928] [c0000011a71579d0] [c0000000002f66e0] print_deadlock_bug+0x430/0x440
[ 84.964428] [ T928] [c0000011a7157a70] [c0000000002fd0c0] __lock_acquire+0x1530/0x2d80
[ 84.964431] [ T928] [c0000011a7157ba0] [c0000000002fea54] lock_acquire+0x144/0x410
[ 84.964433] [ T928] [c0000011a7157cb0] [c0000011a7157cb0] __mutex_lock+0xf4/0x1050
[ 84.964436] [ T928] [c0000011a7157e00] [c000000000de21d8] pci_lock_rescan_remove+0x28/0x40
[ 84.964439] [ T928] [c0000011a7157e20] [c00000000004ed98] eeh_pe_bus_get+0x48/0xc0
[ 84.964442] [ T928] [c0000011a7157e50] [c000000000050434] eeh_handle_normal_event+0x64/0xa60
[ 84.964446] [ T928] [c0000011a7157f30] [c000000000051de8] eeh_event_handler+0xf8/0x190
[ 84.964450] [ T928] [c0000011a7157f90] [c0000000002747ac] kthread+0x16c/0x180
[ 84.964453] [ T928] [c0000011a7157fe0] [c00000000000ded8] start_kernel_thread+0x14/0x18</snip>
--- arch/powerpc/include/asm/eeh.h | 1 + arch/powerpc/kernel/eeh_driver.c | 39 +++++++++++++++++++--- arch/powerpc/kernel/eeh_pe.c | 56 +++++++++++++++++++++++++++++--- 3 files changed, 87 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/eeh.h +1 -0
@@ -289,6 +289,7 @@ void eeh_pe_dev_traverse(struct eeh_pe *root,void eeh_pe_restore_bars (struct eeh_pe *pe);const char *eeh_pe_loc_get (struct eeh_pe *pe);struct pci_bus *eeh_pe_bus_get (struct eeh_pe *pe); +struct pci_bus *eeh_pe_bus_get_nolock (struct eeh_pe *pe);void eeh_show_enabled (void );int __init eeh_init (struct eeh_ops *ops);
arch/powerpc/kernel/eeh_driver.c +34 -5
@@ -812,6 +812,35 @@ static void eeh_clear_slot_attention(struct pci_dev *pdev) ops->set_attention_status (slot->hotplug,0 ); } +static const char *eeh_pe_get_loc (struct eeh_pe *pe) +{ +struct pci_bus *bus =eeh_pe_bus_get_nolock (pe); +struct device_node *dn; +const char *location =NULL ; + +while (bus) { + dn =pci_bus_to_OF_node (bus); +if (!dn) { + bus = bus->parent; +continue ; + } + +if (pci_is_root_bus (bus)) + location =of_get_property (dn,"ibm,io-base-loc-code" , +NULL ); +else + location =of_get_property (dn,"ibm,slot-location-code" , +NULL ); + +if (location) +return location; + + bus = bus->parent; + } + +return "N/A" ; +} +/** * eeh_handle_normal_event - Handle EEH events on a specific PE * @pe: EEH PE - which should not be used after we return, as it may
@@ -846,7 +875,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)pci_lock_rescan_remove (); - bus =eeh_pe_bus_get (pe); + bus =eeh_pe_bus_get_nolock (pe);if (!bus) {pr_err ("%s: Cannot find PCI bus for PHB#%x-PE#%x\n" , __func__, pe->phb->global_number, pe->addr);
@@ -886,14 +915,14 @@ void eeh_handle_normal_event(struct eeh_pe *pe)/* Log the event */ if (pe->type &EEH_PE_PHB ) {pr_err ("EEH: Recovering PHB#%x, location: %s\n" , - pe->phb->global_number,eeh_pe_loc_get (pe)); + pe->phb->global_number,eeh_pe_get_loc (pe)); }else {struct eeh_pe *phb_pe =eeh_phb_pe_get (pe->phb);pr_err ("EEH: Recovering PHB#%x-PE#%x\n" , pe->phb->global_number, pe->addr);pr_err ("EEH: PE location: %s, PHB location: %s\n" , -eeh_pe_loc_get (pe),eeh_pe_loc_get (phb_pe)); +eeh_pe_get_loc (pe),eeh_pe_get_loc (phb_pe)); }#ifdef CONFIG_STACKTRACE
@@ -1098,7 +1127,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)eeh_pe_state_clear (pe,EEH_PE_PRI_BUS , true);eeh_pe_dev_mode_mark (pe,EEH_DEV_REMOVED ); - bus =eeh_pe_bus_get (pe); + bus =eeh_pe_bus_get_nolock (pe);if (bus)pci_hp_remove_devices (bus);else
@@ -1222,7 +1251,7 @@ void eeh_handle_special_event(void) (phb_pe->state & EEH_PE_RECOVERING))continue ; - bus =eeh_pe_bus_get (phb_pe); + bus =eeh_pe_bus_get_nolock (phb_pe);if (!bus) { pr_err("%s: Cannot find PCI bus for " "PHB#%x-PE#%x\n",
arch/powerpc/kernel/eeh_pe.c +52 -4
78 lines not on this page · raw message
Signature · 1 line
2.51.0
Mahesh J Salgaonkar
maintainerQuoted 25 lines · Narayana Murty N
The recent commit
1010b4c012b0("powerpc/eeh: Make EEH driver device hotplug safe") restructured the EEH driver to improve synchronization with the PCI hotplug layer.However, it inadvertently moved
pci_lock_rescan_remove()outside its intended scope ineeh_handle_normal_event(), leading to broken PCI error reporting and improper EEH event triggering. Specifically,eeh_handle_normal_event()acquiredpci_lock_rescan_remove()before callingeeh_pe_bus_get(), buteeh_pe_bus_get()itself attempts to acquire the same lock internally, causing nested locking and disrupting normal EEH event handling paths.This patch adds a boolean parameter
do_lockto_eeh_pe_bus_get(), with two public wrappers:
eeh_pe_bus_get()with locking enabled.eeh_pe_bus_get_nolock()that skips locking.Callers that already hold
pci_lock_rescan_remove()now useeeh_pe_bus_get_nolock()to avoid recursive lock acquisition.Additionally,
pci_lock_rescan_remove()calls are restored to the correct position—aftereeh_pe_bus_get()and immediately before iterating affected PEs and devices. This ensures EEH-triggered PCI removes occur under proper bus rescan locking without recursive lock contention.
[...]
arch/powerpc/kernel/eeh_driver.c static void eeh_clear_slot_attention(struct pci_dev *pdev) · line 816
Quoted 10 lines
arch/powerpc/kernel/eeh_driver.c +2
-0@@ -812,6 +812,35 @@ static void eeh_clear_slot_attention(struct pci_dev *pdev) ops->set_attention_status (slot->hotplug,0 ); } +static const char *eeh_pe_get_loc (struct eeh_pe *pe) +{
So it is duplicate of eeh_pe_loc_get() with nolock variant. Instead, can we split original function eeh_pe_loc_get() ? Move the while (bus) loop into another function with name eeh_bus_loc_get(bus) which will be nolock variant and use that here ?
Quoted 45 lines
arch/powerpc/kernel/eeh_driver.c +29
-2+struct pci_bus *bus =eeh_pe_bus_get_nolock (pe); +struct device_node *dn; +const char *location =NULL ; + +while (bus) { + dn =pci_bus_to_OF_node (bus); +if (!dn) { + bus = bus->parent; +continue ; + } + +if (pci_is_root_bus (bus)) + location =of_get_property (dn,"ibm,io-base-loc-code" , +NULL ); +else + location =of_get_property (dn,"ibm,slot-location-code" , +NULL ); + +if (location) +return location; + + bus = bus->parent; + } + +return "N/A" ; +} +/** * eeh_handle_normal_event - Handle EEH events on a specific PE * @pe: EEH PE - which should not be used after we return, as it may @@ -846,7 +875,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)pci_lock_rescan_remove (); - bus =eeh_pe_bus_get (pe); + bus =eeh_pe_bus_get_nolock (pe);if (!bus) {pr_err ("%s: Cannot find PCI bus for PHB#%x-PE#%x\n" , __func__, pe->phb->global_number, pe->addr);@@ -886,14 +915,14 @@ void eeh_handle_normal_event(struct eeh_pe *pe)/* Log the event */ if (pe->type &EEH_PE_PHB ) {pr_err ("EEH: Recovering PHB#%x, location: %s\n" , - pe->phb->global_number,eeh_pe_loc_get (pe)); + pe->phb->global_number,eeh_pe_get_loc (pe));
arch/powerpc/kernel/eeh_driver.c void eeh_handle_normal_event(struct eeh_pe *pe) · line 927
Quoted 10 lines
arch/powerpc/kernel/eeh_driver.c +1
-1}else {struct eeh_pe *phb_pe =eeh_phb_pe_get (pe->phb);pr_err ("EEH: Recovering PHB#%x-PE#%x\n" , pe->phb->global_number, pe->addr);pr_err ("EEH: PE location: %s, PHB location: %s\n" , -eeh_pe_loc_get (pe),eeh_pe_loc_get (phb_pe)); +eeh_pe_get_loc (pe),eeh_pe_get_loc (phb_pe)); }
Thanks,
-Mahesh.
Quoted 35 lines · Mahesh J Salgaonkar
Quoted 25 lines · Narayana Murty N
The recent commit
1010b4c012b0("powerpc/eeh: Make EEH driver device hotplug safe") restructured the EEH driver to improve synchronization with the PCI hotplug layer.However, it inadvertently moved
pci_lock_rescan_remove()outside its intended scope ineeh_handle_normal_event(), leading to broken PCI error reporting and improper EEH event triggering. Specifically,eeh_handle_normal_event()acquiredpci_lock_rescan_remove()before callingeeh_pe_bus_get(), buteeh_pe_bus_get()itself attempts to acquire the same lock internally, causing nested locking and disrupting normal EEH event handling paths.This patch adds a boolean parameter
do_lockto_eeh_pe_bus_get(), with two public wrappers:
eeh_pe_bus_get()with locking enabled.eeh_pe_bus_get_nolock()that skips locking.Callers that already hold
pci_lock_rescan_remove()now useeeh_pe_bus_get_nolock()to avoid recursive lock acquisition.Additionally,
pci_lock_rescan_remove()calls are restored to the correct position—aftereeh_pe_bus_get()and immediately before iterating affected PEs and devices. This ensures EEH-triggered PCI removes occur under proper bus rescan locking without recursive lock contention.[...]
Quoted 8 lines
arch/powerpc/kernel/eeh_driver.c +0
-0@@ -812,6 +812,35 @@ static void eeh_clear_slot_attention(struct pci_dev *pdev) ops->set_attention_status (slot->hotplug,0 ); }
Quoted 6 lines
arch/powerpc/kernel/eeh_driver.c static void eeh_clear_slot_attention(struct pci_dev *pdev) · line 816
Quoted 2 lines
arch/powerpc/kernel/eeh_driver.c +2
-0+static const char *eeh_pe_get_loc (struct eeh_pe *pe) +{So it is duplicate of
eeh_pe_loc_get()with nolock variant. Instead, can we split original functioneeh_pe_loc_get()? Move the while (bus) loop into another function with nameeeh_bus_loc_get(bus)which will be nolock variant and use that here ?
Thanks Mahesh, your suggestion will be taken care in the next version of patch.
https://lore.kernel.org/all/[email protected]/
Quoted 48 lines
Quoted 48 lines
arch/powerpc/kernel/eeh_driver.c +29
-2+struct pci_bus *bus =eeh_pe_bus_get_nolock (pe); +struct device_node *dn; +const char *location =NULL ; + +while (bus) { + dn =pci_bus_to_OF_node (bus); +if (!dn) { + bus = bus->parent; +continue ; + } + +if (pci_is_root_bus (bus)) + location =of_get_property (dn,"ibm,io-base-loc-code" , +NULL ); +else + location =of_get_property (dn,"ibm,slot-location-code" , +NULL ); + +if (location) +return location; + + bus = bus->parent; + } + +return "N/A" ; +} +/** * eeh_handle_normal_event - Handle EEH events on a specific PE * @pe: EEH PE - which should not be used after we return, as it may @@ -846,7 +875,7 @@ void eeh_handle_normal_event(struct eeh_pe *pe)pci_lock_rescan_remove (); - bus =eeh_pe_bus_get (pe); + bus =eeh_pe_bus_get_nolock (pe);if (!bus) {pr_err ("%s: Cannot find PCI bus for PHB#%x-PE#%x\n" , __func__, pe->phb->global_number, pe->addr);@@ -886,14 +915,14 @@ void eeh_handle_normal_event(struct eeh_pe *pe)/* Log the event */ if (pe->type &EEH_PE_PHB ) {pr_err ("EEH: Recovering PHB#%x, location: %s\n" , - pe->phb->global_number,eeh_pe_loc_get (pe)); + pe->phb->global_number,eeh_pe_get_loc (pe)); }else {struct eeh_pe *phb_pe =eeh_phb_pe_get (pe->phb);
Quoted 9 lines
arch/powerpc/kernel/eeh_driver.c void eeh_handle_normal_event(struct eeh_pe *pe) · line 927
Quoted 7 lines
arch/powerpc/kernel/eeh_driver.c +1
-1pr_err ("EEH: Recovering PHB#%x-PE#%x\n" , pe->phb->global_number, pe->addr);pr_err ("EEH: PE location: %s, PHB location: %s\n" , -eeh_pe_loc_get (pe),eeh_pe_loc_get (phb_pe)); +eeh_pe_get_loc (pe),eeh_pe_get_loc (phb_pe)); }Thanks,
-Mahesh.
Regards,
-Narayana Murty.