Re: [PATCH 3/3] hpwdt: Use nmi_panic() when kernel panics in NMI handler

From: Guenter Roeck
Date: Mon Feb 29 2016 - 21:55:36 EST


On 02/29/2016 05:50 PM, Hidehiro Kawai wrote:
commit 58c5661f2144 ("panic, x86: Allow CPUs to save registers even
if looping in NMI context") introduced nmi_panic() which prevents
concurrent/recursive execution of panic(). It also saves registers
for the crash dump on x86.

hpwdt driver can call panic() from NMI handler, so replace it with
nmi_panic().

Signed-off-by: Hidehiro Kawai <hidehiro.kawai.ez@xxxxxxxxxxx>
Cc: Thomas Mingarelli <thomas.mingarelli@xxxxxxx>
Cc: Wim Van Sebroeck <wim@xxxxxxxxx>
Cc: Guenter Roeck <linux@xxxxxxxxxxxx>
Cc: linux-watchdog@xxxxxxxxxxxxxxx
---
drivers/watchdog/hpwdt.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c
index 92443c3..fd0486f 100644
--- a/drivers/watchdog/hpwdt.c
+++ b/drivers/watchdog/hpwdt.c
@@ -496,11 +496,12 @@ static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs)

if (!is_icru && !is_uefi) {
if (cmn_regs.u1.ral == 0) {
- panic("An NMI occurred, "
+ nmi_panic(regs, "An NMI occurred, "
"but unable to determine source.\n");

This message should really be in a single line.
Sure, strictly speaking that should be done in a separate patch,
but since you touch the line you might as well fix it.

+ goto handled;

The goto is unnecessary. Just return NMI_HANDLED.

}
}
- panic("An NMI occurred. Depending on your system the reason "
+ nmi_panic(regs, "An NMI occurred. Depending on your system the reason "
"for the NMI is logged in any one of the following "
"resources:\n"
"1. Integrated Management Log (IML)\n"
@@ -508,6 +509,13 @@ static int hpwdt_pretimeout(unsigned int ulReason, struct pt_regs *regs)
"3. OA Forward Progress Log\n"
"4. iLO Event Log");

+handled:
+ /*
+ * Returning from nmi_panic() means this CPU was processing panic()
+ * before NMI. Return NMI_HANDLED and go back to panic routines.
+ */

I don't think this comment adds much if any value.

+ return NMI_HANDLED;
+
out:

Any goto to this label does no longer serve a useful purpose (if it ever served one),
and should be replaced with "return NMI_DONE;"

return NMI_DONE;
}