Skip to content

Commit 829632d

Browse files
guilhermepiccolihdeller
authored andcommitted
parisc: Replace regular spinlock with spin_trylock on panic path
The panic notifiers' callbacks execute in an atomic context, with interrupts/preemption disabled, and all CPUs not running the panic function are off, so it's very dangerous to wait on a regular spinlock, there's a risk of deadlock. Refactor the panic notifier of parisc/power driver to make use of spin_trylock - for that, we've added a second version of the soft-power function. Also, some comments were reorganized and trailing white spaces, useless header inclusion and blank lines were removed. Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Cc: Jeroen Roovers <jer@xs4all.nl> Acked-by: Helge Deller <deller@gmx.de> # parisc Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com> Signed-off-by: Helge Deller <deller@gmx.de>
1 parent e0838a9 commit 829632d

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

arch/parisc/include/asm/pdc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ int pdc_do_firm_test_reset(unsigned long ftc_bitmap);
8080
int pdc_do_reset(void);
8181
int pdc_soft_power_info(unsigned long *power_reg);
8282
int pdc_soft_power_button(int sw_control);
83+
int pdc_soft_power_button_panic(int sw_control);
8384
void pdc_io_reset(void);
8485
void pdc_io_reset_devices(void);
8586
int pdc_iodc_getc(void);

arch/parisc/kernel/firmware.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,15 +1232,18 @@ int __init pdc_soft_power_info(unsigned long *power_reg)
12321232
}
12331233

12341234
/*
1235-
* pdc_soft_power_button - Control the soft power button behaviour
1236-
* @sw_control: 0 for hardware control, 1 for software control
1235+
* pdc_soft_power_button{_panic} - Control the soft power button behaviour
1236+
* @sw_control: 0 for hardware control, 1 for software control
12371237
*
12381238
*
12391239
* This PDC function places the soft power button under software or
12401240
* hardware control.
1241-
* Under software control the OS may control to when to allow to shut
1242-
* down the system. Under hardware control pressing the power button
1241+
* Under software control the OS may control to when to allow to shut
1242+
* down the system. Under hardware control pressing the power button
12431243
* powers off the system immediately.
1244+
*
1245+
* The _panic version relies on spin_trylock to prevent deadlock
1246+
* on panic path.
12441247
*/
12451248
int pdc_soft_power_button(int sw_control)
12461249
{
@@ -1254,6 +1257,22 @@ int pdc_soft_power_button(int sw_control)
12541257
return retval;
12551258
}
12561259

1260+
int pdc_soft_power_button_panic(int sw_control)
1261+
{
1262+
int retval;
1263+
unsigned long flags;
1264+
1265+
if (!spin_trylock_irqsave(&pdc_lock, flags)) {
1266+
pr_emerg("Couldn't enable soft power button\n");
1267+
return -EBUSY; /* ignored by the panic notifier */
1268+
}
1269+
1270+
retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
1271+
spin_unlock_irqrestore(&pdc_lock, flags);
1272+
1273+
return retval;
1274+
}
1275+
12571276
/*
12581277
* pdc_io_reset - Hack to avoid overlapping range registers of Bridges devices.
12591278
* Primarily a problem on T600 (which parisc-linux doesn't support) but

drivers/parisc/power.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <linux/module.h>
3838
#include <linux/init.h>
3939
#include <linux/kernel.h>
40-
#include <linux/notifier.h>
4140
#include <linux/panic_notifier.h>
4241
#include <linux/reboot.h>
4342
#include <linux/sched/signal.h>
@@ -175,16 +174,21 @@ static void powerfail_interrupt(int code, void *x)
175174

176175

177176

178-
/* parisc_panic_event() is called by the panic handler.
179-
* As soon as a panic occurs, our tasklets above will not be
180-
* executed any longer. This function then re-enables the
181-
* soft-power switch and allows the user to switch off the system
177+
/*
178+
* parisc_panic_event() is called by the panic handler.
179+
*
180+
* As soon as a panic occurs, our tasklets above will not
181+
* be executed any longer. This function then re-enables
182+
* the soft-power switch and allows the user to switch off
183+
* the system. We rely in pdc_soft_power_button_panic()
184+
* since this version spin_trylocks (instead of regular
185+
* spinlock), preventing deadlocks on panic path.
182186
*/
183187
static int parisc_panic_event(struct notifier_block *this,
184188
unsigned long event, void *ptr)
185189
{
186190
/* re-enable the soft-power switch */
187-
pdc_soft_power_button(0);
191+
pdc_soft_power_button_panic(0);
188192
return NOTIFY_DONE;
189193
}
190194

0 commit comments

Comments
 (0)