From: Jeroen Roovers <jer@xs4all.nl>
To: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
Cc: akpm@linux-foundation.org, bhe@redhat.com, pmladek@suse.com,
kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-hyperv@vger.kernel.org, netdev@vger.kernel.org,
x86@kernel.org, kernel-dev@igalia.com, kernel@gpiccoli.net,
halves@canonical.com, fabiomirmar@gmail.com,
alejandro.j.jimenez@oracle.com,
andriy.shevchenko@linux.intel.com, arnd@arndb.de, bp@alien8.de,
corbet@lwn.net, d.hatayama@jp.fujitsu.com,
dave.hansen@linux.intel.com, dyoung@redhat.com,
feng.tang@intel.com, gregkh@linuxfoundation.org,
mikelley@microsoft.com, hidehiro.kawai.ez@hitachi.com,
jgross@suse.com, john.ogness@linutronix.de,
keescook@chromium.org, luto@kernel.org, mhiramat@kernel.org,
mingo@redhat.com, paulmck@kernel.org, peterz@infradead.org,
rostedt@goodmis.org, senozhatsky@chromium.org,
stern@rowland.harvard.edu, tglx@linutronix.de, vgoyal@redhat.com,
vkuznets@redhat.com, will@kernel.org,
linux-parisc@vger.kernel.org,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
Helge Deller <deller@gmx.de>
Subject: Re: [PATCH v2 07/13] parisc: Replace regular spinlock with spin_trylock on panic path
Date: Wed, 20 Jul 2022 03:43:00 +0200 [thread overview]
Message-ID: <20220720034300.6d2905b8@wim.jer> (raw)
In-Reply-To: <20220719195325.402745-8-gpiccoli@igalia.com>
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
next prev parent reply other threads:[~2022-07-20 1:44 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
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 01/13] ARM: Disable FIQs (but not IRQs) on CPUs shutdown paths Guilherme G. Piccoli
2022-08-07 15:35 ` Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 02/13] notifier: Add panic notifiers info and purge trailing whitespaces Guilherme G. Piccoli
2022-08-03 9:21 ` Baoquan He
2022-07-19 19:53 ` [PATCH v2 03/13] firmware: google: Test spinlock on panic path to avoid lockups Guilherme G. Piccoli
2022-08-07 15:38 ` Guilherme G. Piccoli
2022-08-08 5:07 ` Evan Green
2022-08-08 15:14 ` Guilherme G. Piccoli
2022-08-08 15:26 ` Greg Kroah-Hartman
2022-08-08 15:37 ` Guilherme G. Piccoli
2022-08-10 12:54 ` Greg Kroah-Hartman
2022-07-19 19:53 ` [PATCH v2 04/13] soc: bcm: brcmstb: Document panic notifier action and remove useless header Guilherme G. Piccoli
2022-07-20 23:00 ` Florian Fainelli
2022-07-21 13:17 ` Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 05/13] alpha: Clean-up the panic notifier code Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 06/13] um: Improve panic notifiers consistency and ordering Guilherme G. Piccoli
2022-08-07 15:40 ` Guilherme G. Piccoli
2022-08-09 18:09 ` Johannes Berg
2022-08-09 19:03 ` Guilherme G. Piccoli
2022-08-09 19:08 ` Johannes Berg
2022-08-09 19:45 ` 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 [this message]
2022-07-21 13:19 ` Guilherme G. Piccoli
2022-07-21 13:45 ` Helge Deller
2022-07-21 14:00 ` Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 08/13] tracing: Improve panic/die notifiers Guilherme G. Piccoli
2022-08-03 9:36 ` Baoquan He
2022-08-03 9:52 ` Baoquan He
2022-08-03 11:44 ` Guilherme G. Piccoli
2022-08-07 15:46 ` Guilherme G. Piccoli
2022-08-16 14:14 ` Steven Rostedt
2022-08-16 14:57 ` Alan Stern
2022-08-16 15:52 ` Steven Rostedt
2022-08-16 20:12 ` Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 09/13] notifier: Show function names on notifier routines if DEBUG_NOTIFIERS is set Guilherme G. Piccoli
2022-07-19 20:33 ` Arjan van de Ven
2022-07-19 20:44 ` Guilherme G. Piccoli
2022-07-19 20:48 ` Arjan van de Ven
2022-07-19 21:00 ` Guilherme G. Piccoli
2022-07-19 22:04 ` Arjan van de Ven
2022-07-21 13:20 ` Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 10/13] EDAC/altera: Skip the panic notifier if kdump is loaded Guilherme G. Piccoli
2022-08-07 15:48 ` Guilherme G. Piccoli
2022-08-16 18:44 ` Dinh Nguyen
2022-08-16 20:16 ` Guilherme G. Piccoli
2022-08-17 17:31 ` Borislav Petkov
2022-08-17 18:45 ` Guilherme G. Piccoli
2022-08-17 19:34 ` Borislav Petkov
2022-08-17 20:28 ` Guilherme G. Piccoli
2022-08-17 21:02 ` Borislav Petkov
2022-08-17 21:39 ` Guilherme G. Piccoli
2022-08-17 21:46 ` Borislav Petkov
2022-08-17 21:56 ` Guilherme G. Piccoli
2022-08-17 22:00 ` Borislav Petkov
2022-08-17 22:09 ` Guilherme G. Piccoli
2022-08-17 22:19 ` Borislav Petkov
2022-08-17 22:49 ` Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 11/13] video/hyperv_fb: Avoid taking busy spinlock on panic path Guilherme G. Piccoli
2022-07-25 18:09 ` Michael Kelley (LINUX)
2022-07-25 22:05 ` Guilherme G. Piccoli
2022-07-19 19:53 ` [PATCH v2 12/13] drivers/hv/vmbus, video/hyperv_fb: Untangle and refactor Hyper-V panic notifiers Guilherme G. Piccoli
2022-07-25 18:55 ` Michael Kelley (LINUX)
2022-07-19 19:53 ` [PATCH v2 13/13] panic: Fixes the panic_print NMI backtrace setting Guilherme G. Piccoli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220720034300.6d2905b8@wim.jer \
--to=jer@xs4all.nl \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=alejandro.j.jimenez@oracle.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=d.hatayama@jp.fujitsu.com \
--cc=dave.hansen@linux.intel.com \
--cc=deller@gmx.de \
--cc=dyoung@redhat.com \
--cc=fabiomirmar@gmail.com \
--cc=feng.tang@intel.com \
--cc=gpiccoli@igalia.com \
--cc=gregkh@linuxfoundation.org \
--cc=halves@canonical.com \
--cc=hidehiro.kawai.ez@hitachi.com \
--cc=jgross@suse.com \
--cc=john.ogness@linutronix.de \
--cc=keescook@chromium.org \
--cc=kernel-dev@igalia.com \
--cc=kernel@gpiccoli.net \
--cc=kexec@lists.infradead.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mikelley@microsoft.com \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=stern@rowland.harvard.edu \
--cc=tglx@linutronix.de \
--cc=vgoyal@redhat.com \
--cc=vkuznets@redhat.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).