* [PATCH v2 00/13] The panic notifiers refactor strikes back - fixes/clean-ups
@ 2022-07-19 19:53 Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path Guilherme G. Piccoli
0 siblings, 1 reply; 6+ messages in thread
From: Guilherme G. Piccoli @ 2022-07-19 19:53 UTC (permalink / raw)
To: akpm, bhe, pmladek, kexec
Cc: linux-kernel, linux-hyperv, netdev, x86, kernel-dev, kernel,
halves, fabiomirmar, alejandro.j.jimenez, andriy.shevchenko, arnd,
bp, corbet, d.hatayama, dave.hansen, dyoung, feng.tang, gregkh,
mikelley, hidehiro.kawai.ez, jgross, john.ogness, keescook, luto,
mhiramat, mingo, paulmck, peterz, rostedt, senozhatsky, stern,
tglx, vgoyal, vkuznets, will, Guilherme G. Piccoli,
bcm-kernel-feedback-list, linux-alpha, linux-arm-kernel,
linux-edac, linux-efi, linux-parisc, linux-um
Hi folks, this the second iteration of the panic notifiers refactor work,
but limited to the fixes/clean-ups in the first moment. The (full) V1 is
available at:
https://lore.kernel.org/lkml/20220427224924.592546-1-gpiccoli@igalia.com/
The idea of splitting the series is that, originally we had a bunch of fixes
followed by the notifiers refactor, but this second part (the effective
refactor) is a bit "polemic", with reviews having antagonistic goals and some
complexities - it might be hard to achieve consensus.
For the curious, here is a good summary of the conflicting views and some
strategies we might take in the refactor V2:
https://lore.kernel.org/lkml/0d084eed-4781-c815-29c7-ac62c498e216@igalia.com/
So splitting and sending only the simple fixes/clean-ups in a first moment
makes sense, this way we don't prevent them to be discussed/merged/reworked
while the more complex part is subject to scrutiny in a different (future)
email thread.
I've tried to test this series building for all affected architecture/drivers
and also through some boot/runtime tests; below the test "matrix" used:
Build tests (using cross-compilers): alpha, arm, arm64, parisc, um, x86_64.
Boot/Runtime tests: x86_64 (Hyper-V and QEMU guests).
Here is the link with the .config files used:
https://people.igalia.com/gpiccoli/panic_notifiers_configs/5.19-rc7/
(tried my best to build all the affected code).
The series is based on 5.19-rc7; I'd like to ask that, if possible, maintainers
take the patches here in their trees, since there is no need to merge the series
as whole, patches are independent from each other.
Regarding the CC strategy, I've tried to reduce a bit the list of CCed emails,
given that it was huge in the first iteration. Hopefully I didn't forget
anybody interested in the topic (my apologies if so).
As usual, reviews / comments are always welcome, thanks in advance for them!
Cheers,
Guilherme
Guilherme G. Piccoli (13):
ARM: Disable FIQs (but not IRQs) on CPUs shutdown paths
notifier: Add panic notifiers info and purge trailing whitespaces
firmware: google: Test spinlock on panic path to avoid lockups
soc: bcm: brcmstb: Document panic notifier action and remove useless header
alpha: Clean-up the panic notifier code
um: Improve panic notifiers consistency and ordering
parisc: Replace regular spinlock with spin_trylock on panic path
tracing: Improve panic/die notifiers
notifier: Show function names on notifier routines if DEBUG_NOTIFIERS is set
EDAC/altera: Skip the panic notifier if kdump is loaded
video/hyperv_fb: Avoid taking busy spinlock on panic path
drivers/hv/vmbus, video/hyperv_fb: Untangle and refactor Hyper-V panic notifiers
panic: Fixes the panic_print NMI backtrace setting
arch/alpha/kernel/setup.c | 36 ++++-----
arch/arm/kernel/machine_kexec.c | 2 +
arch/arm/kernel/smp.c | 5 +-
arch/parisc/include/asm/pdc.h | 1 +
arch/parisc/kernel/firmware.c | 27 ++++++-
arch/um/drivers/mconsole_kern.c | 7 +-
arch/um/kernel/um_arch.c | 8 +-
drivers/edac/altera_edac.c | 16 +++-
drivers/firmware/google/gsmi.c | 8 ++
drivers/hv/ring_buffer.c | 16 ++++
drivers/hv/vmbus_drv.c | 109 +++++++++++++++++-----------
drivers/parisc/power.c | 17 +++--
drivers/soc/bcm/brcmstb/pm/pm-arm.c | 16 +++-
drivers/video/fbdev/hyperv_fb.c | 16 +++-
include/linux/hyperv.h | 2 +
include/linux/notifier.h | 8 +-
kernel/notifier.c | 22 ++++--
kernel/panic.c | 47 +++++++-----
kernel/trace/trace.c | 55 +++++++-------
19 files changed, 268 insertions(+), 150 deletions(-)
--
2.37.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path
2022-07-19 19:53 [PATCH v2 00/13] The panic notifiers refactor strikes back - fixes/clean-ups Guilherme G. Piccoli
@ 2022-07-19 19:53 ` Guilherme G. Piccoli
2022-07-20 1:43 ` Jeroen Roovers
0 siblings, 1 reply; 6+ messages in thread
From: Guilherme G. Piccoli @ 2022-07-19 19:53 UTC (permalink / raw)
To: akpm, bhe, pmladek, kexec
Cc: linux-kernel, linux-hyperv, netdev, x86, kernel-dev, kernel,
halves, fabiomirmar, alejandro.j.jimenez, andriy.shevchenko, arnd,
bp, corbet, d.hatayama, dave.hansen, dyoung, feng.tang, gregkh,
mikelley, hidehiro.kawai.ez, jgross, john.ogness, keescook, luto,
mhiramat, mingo, paulmck, peterz, rostedt, senozhatsky, stern,
tglx, vgoyal, vkuznets, will, Guilherme G. Piccoli, linux-parisc,
James E.J. Bottomley, Helge Deller
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>
Acked-by: Helge Deller <deller@gmx.de> # parisc
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---
V2:
- Added Helge's ACK - thanks!
arch/parisc/include/asm/pdc.h | 1 +
arch/parisc/kernel/firmware.c | 27 +++++++++++++++++++++++----
drivers/parisc/power.c | 17 ++++++++++-------
3 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/arch/parisc/include/asm/pdc.h b/arch/parisc/include/asm/pdc.h
index b643092d4b98..7a106008e258 100644
--- a/arch/parisc/include/asm/pdc.h
+++ b/arch/parisc/include/asm/pdc.h
@@ -83,6 +83,7 @@ int pdc_do_firm_test_reset(unsigned long ftc_bitmap);
int pdc_do_reset(void);
int pdc_soft_power_info(unsigned long *power_reg);
int pdc_soft_power_button(int sw_control);
+int pdc_soft_power_button_panic(int sw_control);
void pdc_io_reset(void);
void pdc_io_reset_devices(void);
int pdc_iodc_getc(void);
diff --git a/arch/parisc/kernel/firmware.c b/arch/parisc/kernel/firmware.c
index 6a7e315bcc2e..0e2f70b592f4 100644
--- a/arch/parisc/kernel/firmware.c
+++ b/arch/parisc/kernel/firmware.c
@@ -1232,15 +1232,18 @@ int __init pdc_soft_power_info(unsigned long *power_reg)
}
/*
- * pdc_soft_power_button - Control the soft power button behaviour
- * @sw_control: 0 for hardware control, 1 for software control
+ * pdc_soft_power_button{_panic} - Control the soft power button behaviour
+ * @sw_control: 0 for hardware control, 1 for software control
*
*
* This PDC function places the soft power button under software or
* hardware control.
- * Under software control the OS may control to when to allow to shut
- * down the system. Under hardware control pressing the power button
+ * Under software control the OS may control to when to allow to shut
+ * down the system. Under hardware control pressing the power button
* powers off the system immediately.
+ *
+ * The _panic version relies in spin_trylock to prevent deadlock
+ * on panic path.
*/
int pdc_soft_power_button(int sw_control)
{
@@ -1254,6 +1257,22 @@ int pdc_soft_power_button(int sw_control)
return retval;
}
+int pdc_soft_power_button_panic(int sw_control)
+{
+ int retval;
+ unsigned long flags;
+
+ if (!spin_trylock_irqsave(&pdc_lock, flags)) {
+ pr_emerg("Couldn't enable soft power button\n");
+ return -EBUSY; /* ignored by the panic notifier */
+ }
+
+ retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
+ spin_unlock_irqrestore(&pdc_lock, flags);
+
+ return retval;
+}
+
/*
* pdc_io_reset - Hack to avoid overlapping range registers of Bridges devices.
* Primarily a problem on T600 (which parisc-linux doesn't support) but
diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c
index 456776bd8ee6..8512884de2cf 100644
--- a/drivers/parisc/power.c
+++ b/drivers/parisc/power.c
@@ -37,7 +37,6 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
-#include <linux/notifier.h>
#include <linux/panic_notifier.h>
#include <linux/reboot.h>
#include <linux/sched/signal.h>
@@ -175,16 +174,21 @@ static void powerfail_interrupt(int code, void *x)
-/* parisc_panic_event() is called by the panic handler.
- * As soon as a panic occurs, our tasklets above will not be
- * executed any longer. This function then re-enables the
- * soft-power switch and allows the user to switch off the system
+/*
+ * parisc_panic_event() is called by the panic handler.
+ *
+ * As soon as a panic occurs, our tasklets above will not
+ * be executed any longer. This function then re-enables
+ * the soft-power switch and allows the user to switch off
+ * the system. We rely in pdc_soft_power_button_panic()
+ * since this version spin_trylocks (instead of regular
+ * spinlock), preventing deadlocks on panic path.
*/
static int parisc_panic_event(struct notifier_block *this,
unsigned long event, void *ptr)
{
/* re-enable the soft-power switch */
- pdc_soft_power_button(0);
+ pdc_soft_power_button_panic(0);
return NOTIFY_DONE;
}
@@ -193,7 +197,6 @@ static struct notifier_block parisc_panic_block = {
.priority = INT_MAX,
};
-
static int __init power_init(void)
{
unsigned long ret;
--
2.37.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path
2022-07-19 19:53 ` [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path Guilherme G. Piccoli
@ 2022-07-20 1:43 ` Jeroen Roovers
2022-07-21 13:19 ` Guilherme G. Piccoli
0 siblings, 1 reply; 6+ messages in thread
From: Jeroen Roovers @ 2022-07-20 1:43 UTC (permalink / raw)
To: Guilherme G. Piccoli
Cc: akpm, bhe, pmladek, kexec, linux-kernel, linux-hyperv, netdev,
x86, kernel-dev, kernel, halves, fabiomirmar, alejandro.j.jimenez,
andriy.shevchenko, arnd, bp, corbet, d.hatayama, dave.hansen,
dyoung, feng.tang, gregkh, mikelley, hidehiro.kawai.ez, jgross,
john.ogness, keescook, luto, mhiramat, mingo, paulmck, peterz,
rostedt, senozhatsky, stern, tglx, vgoyal, vkuznets, will,
linux-parisc, James E.J. Bottomley, Helge Deller
Hi Guilherme,
On Tue, 19 Jul 2022 16:53:20 -0300
"Guilherme G. Piccoli" <gpiccoli@igalia.com> wrote:
> 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>
> Acked-by: Helge Deller <deller@gmx.de> # parisc
> Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
>
> ---
>
> V2:
> - Added Helge's ACK - thanks!
>
> arch/parisc/include/asm/pdc.h | 1 +
> arch/parisc/kernel/firmware.c | 27 +++++++++++++++++++++++----
> drivers/parisc/power.c | 17 ++++++++++-------
> 3 files changed, 34 insertions(+), 11 deletions(-)
>
> diff --git a/arch/parisc/include/asm/pdc.h
> b/arch/parisc/include/asm/pdc.h index b643092d4b98..7a106008e258
> 100644 --- a/arch/parisc/include/asm/pdc.h
> +++ b/arch/parisc/include/asm/pdc.h
> @@ -83,6 +83,7 @@ int pdc_do_firm_test_reset(unsigned long
> ftc_bitmap); int pdc_do_reset(void);
> int pdc_soft_power_info(unsigned long *power_reg);
> int pdc_soft_power_button(int sw_control);
> +int pdc_soft_power_button_panic(int sw_control);
> void pdc_io_reset(void);
> void pdc_io_reset_devices(void);
> int pdc_iodc_getc(void);
> diff --git a/arch/parisc/kernel/firmware.c
> b/arch/parisc/kernel/firmware.c index 6a7e315bcc2e..0e2f70b592f4
> 100644 --- a/arch/parisc/kernel/firmware.c
> +++ b/arch/parisc/kernel/firmware.c
> @@ -1232,15 +1232,18 @@ int __init pdc_soft_power_info(unsigned long
> *power_reg) }
>
> /*
> - * pdc_soft_power_button - Control the soft power button behaviour
> - * @sw_control: 0 for hardware control, 1 for software control
> + * pdc_soft_power_button{_panic} - Control the soft power button
> behaviour
> + * @sw_control: 0 for hardware control, 1 for software control
> *
> *
> * This PDC function places the soft power button under software or
> * hardware control.
> - * Under software control the OS may control to when to allow to
> shut
> - * down the system. Under hardware control pressing the power button
> + * Under software control the OS may control to when to allow to shut
> + * down the system. Under hardware control pressing the power button
> * powers off the system immediately.
> + *
> + * The _panic version relies in spin_trylock to prevent deadlock
> + * on panic path.
in => on
> */
> int pdc_soft_power_button(int sw_control)
> {
> @@ -1254,6 +1257,22 @@ int pdc_soft_power_button(int sw_control)
> return retval;
> }
>
> +int pdc_soft_power_button_panic(int sw_control)
> +{
> + int retval;
> + unsigned long flags;
> +
> + if (!spin_trylock_irqsave(&pdc_lock, flags)) {
> + pr_emerg("Couldn't enable soft power button\n");
> + return -EBUSY; /* ignored by the panic notifier */
> + }
> +
> + retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE,
> __pa(pdc_result), sw_control);
> + spin_unlock_irqrestore(&pdc_lock, flags);
> +
> + return retval;
> +}
> +
> /*
> * pdc_io_reset - Hack to avoid overlapping range registers of
> Bridges devices.
> * Primarily a problem on T600 (which parisc-linux doesn't support)
> but diff --git a/drivers/parisc/power.c b/drivers/parisc/power.c
> index 456776bd8ee6..8512884de2cf 100644
> --- a/drivers/parisc/power.c
> +++ b/drivers/parisc/power.c
> @@ -37,7 +37,6 @@
> #include <linux/module.h>
> #include <linux/init.h>
> #include <linux/kernel.h>
> -#include <linux/notifier.h>
> #include <linux/panic_notifier.h>
> #include <linux/reboot.h>
> #include <linux/sched/signal.h>
> @@ -175,16 +174,21 @@ static void powerfail_interrupt(int code, void
> *x)
>
>
> -/* parisc_panic_event() is called by the panic handler.
> - * As soon as a panic occurs, our tasklets above will not be
> - * executed any longer. This function then re-enables the
> - * soft-power switch and allows the user to switch off the system
> +/*
> + * parisc_panic_event() is called by the panic handler.
> + *
> + * As soon as a panic occurs, our tasklets above will not
> + * be executed any longer. This function then re-enables
> + * the soft-power switch and allows the user to switch off
> + * the system. We rely in pdc_soft_power_button_panic()
> + * since this version spin_trylocks (instead of regular
> + * spinlock), preventing deadlocks on panic path.
> */
> static int parisc_panic_event(struct notifier_block *this,
> unsigned long event, void *ptr)
> {
> /* re-enable the soft-power switch */
> - pdc_soft_power_button(0);
> + pdc_soft_power_button_panic(0);
> return NOTIFY_DONE;
> }
>
> @@ -193,7 +197,6 @@ static struct notifier_block parisc_panic_block =
> { .priority = INT_MAX,
> };
>
> -
> static int __init power_init(void)
> {
> unsigned long ret;
Kind regards,
jer
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path
2022-07-20 1:43 ` Jeroen Roovers
@ 2022-07-21 13:19 ` Guilherme G. Piccoli
2022-07-21 13:45 ` Helge Deller
0 siblings, 1 reply; 6+ messages in thread
From: Guilherme G. Piccoli @ 2022-07-21 13:19 UTC (permalink / raw)
To: Jeroen Roovers, Helge Deller
Cc: akpm, bhe, pmladek, kexec, linux-kernel, linux-hyperv, netdev,
x86, kernel-dev, kernel, halves, fabiomirmar, alejandro.j.jimenez,
andriy.shevchenko, arnd, bp, corbet, d.hatayama, dave.hansen,
dyoung, feng.tang, gregkh, mikelley, hidehiro.kawai.ez, jgross,
john.ogness, keescook, luto, mhiramat, mingo, paulmck, peterz,
rostedt, senozhatsky, stern, tglx, vgoyal, vkuznets, will,
linux-parisc, James E.J. Bottomley
On 19/07/2022 22:43, Jeroen Roovers wrote:
> Hi Guilherme,
> [...]
>> + *
>> + * The _panic version relies in spin_trylock to prevent deadlock
>> + * on panic path.
>
> in => on
>
Hi Jer, thanks for the suggestion!
Helge, do you think you could fix it when applying, if there's no other
issue in the patch?
Thanks,
Guilherme
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path
2022-07-21 13:19 ` Guilherme G. Piccoli
@ 2022-07-21 13:45 ` Helge Deller
2022-07-21 14:00 ` Guilherme G. Piccoli
0 siblings, 1 reply; 6+ messages in thread
From: Helge Deller @ 2022-07-21 13:45 UTC (permalink / raw)
To: Guilherme G. Piccoli, Jeroen Roovers
Cc: akpm, bhe, pmladek, kexec, linux-kernel, linux-hyperv, netdev,
x86, kernel-dev, kernel, halves, fabiomirmar, alejandro.j.jimenez,
andriy.shevchenko, arnd, bp, corbet, d.hatayama, dave.hansen,
dyoung, feng.tang, gregkh, mikelley, hidehiro.kawai.ez, jgross,
john.ogness, keescook, luto, mhiramat, mingo, paulmck, peterz,
rostedt, senozhatsky, stern, tglx, vgoyal, vkuznets, will,
linux-parisc, James E.J. Bottomley
On 7/21/22 15:19, Guilherme G. Piccoli wrote:
> On 19/07/2022 22:43, Jeroen Roovers wrote:
>> Hi Guilherme,
>> [...]
>>> + *
>>> + * The _panic version relies in spin_trylock to prevent deadlock
>>> + * on panic path.
>>
>> in => on
>
> Hi Jer, thanks for the suggestion!
>
> Helge, do you think you could fix it when applying, if there's no other
> issue in the patch?
> Thanks,
Guilherme, I'd really prefer that you push the whole series at once through
some generic tree.
Helge
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path
2022-07-21 13:45 ` Helge Deller
@ 2022-07-21 14:00 ` Guilherme G. Piccoli
0 siblings, 0 replies; 6+ messages in thread
From: Guilherme G. Piccoli @ 2022-07-21 14:00 UTC (permalink / raw)
To: Helge Deller, Jeroen Roovers
Cc: akpm, bhe, pmladek, kexec, linux-kernel, linux-hyperv, netdev,
x86, kernel-dev, kernel, halves, fabiomirmar, alejandro.j.jimenez,
andriy.shevchenko, arnd, bp, corbet, d.hatayama, dave.hansen,
dyoung, feng.tang, gregkh, mikelley, hidehiro.kawai.ez, jgross,
john.ogness, keescook, luto, mhiramat, mingo, paulmck, peterz,
rostedt, senozhatsky, stern, tglx, vgoyal, vkuznets, will,
linux-parisc, James E.J. Bottomley
On 21/07/2022 10:45, Helge Deller wrote:
> [...]
> Guilherme, I'd really prefer that you push the whole series at once through
> some generic tree.
>
> Helge
Hmm..OK.
Some maintainers will take patches from here and merge, but given your
preference I can talk to Andrew to see if the can pick via his tree
(along with the generic panic patches).
Cheers,
Guilherme
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-07-21 14:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-19 19:53 [PATCH v2 00/13] The panic notifiers refactor strikes back - fixes/clean-ups Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path Guilherme G. Piccoli
2022-07-20 1:43 ` Jeroen Roovers
2022-07-21 13:19 ` Guilherme G. Piccoli
2022-07-21 13:45 ` Helge Deller
2022-07-21 14:00 ` Guilherme G. Piccoli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox