Skip to content

Commit 3e08143

Browse files
guilhermepiccoligregkh
authored andcommitted
firmware: google: Test spinlock on panic path to avoid lockups
Currently the gsmi driver registers a panic notifier as well as reboot and die notifiers. The callbacks registered are called in atomic and very limited context - for instance, panic disables preemption and local IRQs, also all secondary CPUs (not executing the panic path) are shutdown. With that said, taking a spinlock in this scenario is a dangerous invitation for lockup scenarios. So, fix that by checking if the spinlock is free to acquire in the panic notifier callback - if not, bail-out and avoid a potential hang. Fixes: 74c5b31 ("driver: Google EFI SMI") Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: David Gow <davidgow@google.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Julius Werner <jwerner@chromium.org> Cc: Petr Mladek <pmladek@suse.com> Reviewed-by: Evan Green <evgreen@chromium.org> Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com> Link: https://lore.kernel.org/r/20220909200755.189679-1-gpiccoli@igalia.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a5ccec1 commit 3e08143

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/firmware/google/gsmi.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,15 @@ static struct notifier_block gsmi_die_notifier = {
681681
static int gsmi_panic_callback(struct notifier_block *nb,
682682
unsigned long reason, void *arg)
683683
{
684+
685+
/*
686+
* Panic callbacks are executed with all other CPUs stopped,
687+
* so we must not attempt to spin waiting for gsmi_dev.lock
688+
* to be released.
689+
*/
690+
if (spin_is_locked(&gsmi_dev.lock))
691+
return NOTIFY_DONE;
692+
684693
gsmi_shutdown_reason(GSMI_SHUTDOWN_PANIC);
685694
return NOTIFY_DONE;
686695
}

0 commit comments

Comments
 (0)