]> www.infradead.org Git - users/jedix/linux-maple.git/commit
x86/nmi: Add an emergency handler in nmi_desc & use it in nmi_shootdown_cpus()
authorWaiman Long <longman@redhat.com>
Thu, 6 Feb 2025 19:18:44 +0000 (14:18 -0500)
committerIngo Molnar <mingo@kernel.org>
Tue, 25 Feb 2025 13:38:43 +0000 (14:38 +0100)
commitfe37c699ae3eed6e02ee55fbf5cb9ceb7fcfd76c
tree23b198e966cf50a86996e5ab418dfbae8f7e9d3e
parent684b12916a107157633311f07bb74307221eff92
x86/nmi: Add an emergency handler in nmi_desc & use it in nmi_shootdown_cpus()

Depending on the type of panics, it was found that the
__register_nmi_handler() function can be called in NMI context from
nmi_shootdown_cpus() leading to a lockdep splat:

  WARNING: inconsistent lock state
  inconsistent {INITIAL USE} -> {IN-NMI} usage.

   lock(&nmi_desc[0].lock);
   <Interrupt>
     lock(&nmi_desc[0].lock);

  Call Trace:
    _raw_spin_lock_irqsave
    __register_nmi_handler
    nmi_shootdown_cpus
    kdump_nmi_shootdown_cpus
    native_machine_crash_shutdown
    __crash_kexec

In this particular case, the following panic message was printed before:

  Kernel panic - not syncing: Fatal hardware error!

This message seemed to be given out from __ghes_panic() running in
NMI context.

The __register_nmi_handler() function which takes the nmi_desc lock
with irq disabled shouldn't be called from NMI context as this can
lead to deadlock.

The nmi_shootdown_cpus() function can only be invoked once. After the
first invocation, all other CPUs should be stuck in the newly added
crash_nmi_callback() and cannot respond to a second NMI.

Fix it by adding a new emergency NMI handler to the nmi_desc
structure and provide a new set_emergency_nmi_handler() helper to set
crash_nmi_callback() in any context. The new emergency handler will
preempt other handlers in the linked list. That will eliminate the need
to take any lock and serve the panic in NMI use case.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Rik van Riel <riel@surriel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20250206191844.131700-1-longman@redhat.com
arch/x86/include/asm/nmi.h
arch/x86/kernel/nmi.c
arch/x86/kernel/reboot.c