• Breno Leitao's avatar
    x86/nmi: Fix the inverse "in NMI handler" check · d54e56f3
    Breno Leitao authored
    Commit 344da544 ("x86/nmi: Print reasons why backtrace NMIs are
    ignored") creates a super nice framework to diagnose NMIs.
    
    Every time nmi_exc() is called, it increments a per_cpu counter
    (nsp->idt_nmi_seq). At its exit, it also increments the same counter.  By
    reading this counter it can be seen how many times that function was called
    (dividing by 2), and, if the function is still being executed, by checking
    the idt_nmi_seq's least significant bit.
    
    On the check side (nmi_backtrace_stall_check()), that variable is queried
    to check if the NMI is still being executed, but, there is a mistake in the
    bitwise operation. That code wants to check if the least significant bit of
    the idt_nmi_seq is set or not, but does the opposite, and checks for all
    the other bits, which will always be true after the first exc_nmi()
    executed successfully.
    
    This appends the misleading string to the dump "(CPU currently in NMI
    handler function)"
    
    Fix it by checking the least significant bit, and if it is set, append the
    string.
    
    Fixes: 344da544 ("x86/nmi: Print reasons why backtrace NMIs are ignored")
    Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Reviewed-by: default avatarPaul E. McKenney <paulmck@kernel.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240207165237.1048837-1-leitao@debian.org
    d54e56f3
nmi.c 18.8 KB