Skip to content

Commit 262b1c7

Browse files
lian-bok-hagio
authored andcommitted
Fix printing incorrect panic string issue
Since the panic_on_oops is disabled, when getting a BUG hit in the code, the system continues and does not panic. However, a short time later, a hard lockup is hit and the system does panic. Even though the system panicked at hard lockup, the panic string is still the first BUG hit. For example: Without the patch: crash> sys | grep PANIC PANIC: "BUG: unable to handle kernel paging request at ffffab835d7f9d50" With the patch: crash> sys | grep PANIC PANIC: "Kernel panic - not syncing: Hard LOCKUP" Let's search for the panic string based on the severity of the panic event, and also refactor the get_panicmsg() a little bit to improve readability. Reported-by: John Pittman <[email protected]> Signed-off-by: Lianbo Jiang <[email protected]>
1 parent 55a43bc commit 262b1c7

File tree

1 file changed

+39
-63
lines changed

1 file changed

+39
-63
lines changed

task.c

Lines changed: 39 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6301,14 +6301,39 @@ get_active_task(int cpu)
63016301
return NO_TASK;
63026302
}
63036303

6304+
/*
6305+
* Arrange the panic strings based on the severity of the panic
6306+
* events.
6307+
*/
6308+
static const char* panic_msg[] = {
6309+
"SysRq : Crash",
6310+
"SysRq : Trigger a crash",
6311+
"SysRq : Netdump",
6312+
"Kernel panic: ",
6313+
"Kernel panic - ",
6314+
"Kernel BUG at",
6315+
"kernel BUG at",
6316+
"Unable to handle kernel paging request",
6317+
"Unable to handle kernel NULL pointer dereference",
6318+
"BUG: unable to handle kernel ",
6319+
"general protection fault: ",
6320+
"double fault: ",
6321+
"divide error: ",
6322+
"stack segment: ",
6323+
"[Hardware Error]: ",
6324+
"Bad mode in ",
6325+
"Oops: ",
6326+
};
6327+
6328+
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
63046329

63056330
/*
63066331
* Read the panic string.
63076332
*/
63086333
char *
63096334
get_panicmsg(char *buf)
63106335
{
6311-
int msg_found;
6336+
int msg_found, i;
63126337

63136338
BZERO(buf, BUFSIZE);
63146339
msg_found = FALSE;
@@ -6332,76 +6357,27 @@ get_panicmsg(char *buf)
63326357
* active-task flag appropriately. The message may or
63336358
* may not be used as the panic message.
63346359
*/
6335-
rewind(pc->tmpfile);
6336-
while (fgets(buf, BUFSIZE, pc->tmpfile)) {
6337-
if (strstr(buf, "SysRq : Crash") ||
6338-
strstr(buf, "SysRq : Trigger a crash")) {
6339-
pc->flags |= SYSRQ;
6340-
break;
6341-
}
6342-
}
6343-
rewind(pc->tmpfile);
6344-
while (!msg_found && fgets(buf, BUFSIZE, pc->tmpfile)) {
6345-
if (strstr(buf, "general protection fault: ") ||
6346-
strstr(buf, "double fault: ") ||
6347-
strstr(buf, "divide error: ") ||
6348-
strstr(buf, "stack segment: ")) {
6349-
msg_found = TRUE;
6350-
break;
6351-
}
6352-
}
6353-
rewind(pc->tmpfile);
6354-
while (!msg_found && fgets(buf, BUFSIZE, pc->tmpfile)) {
6355-
if (strstr(buf, "SysRq : Netdump") ||
6356-
strstr(buf, "SysRq : Crash") ||
6357-
strstr(buf, "SysRq : Trigger a crash")) {
6358-
pc->flags |= SYSRQ;
6359-
msg_found = TRUE;
6360-
break;
6361-
}
6362-
}
6363-
rewind(pc->tmpfile);
6364-
while (!msg_found && fgets(buf, BUFSIZE, pc->tmpfile)) {
6365-
if (strstr(buf, "Oops: ") ||
6366-
strstr(buf, "Kernel BUG at") ||
6367-
strstr(buf, "kernel BUG at") ||
6368-
strstr(buf, "Unable to handle kernel paging request") ||
6369-
strstr(buf, "Unable to handle kernel NULL pointer dereference") ||
6370-
strstr(buf, "BUG: unable to handle kernel "))
6371-
msg_found = TRUE;
6372-
}
6373-
rewind(pc->tmpfile);
6374-
while (!msg_found && fgets(buf, BUFSIZE, pc->tmpfile)) {
6375-
if (strstr(buf, "sysrq") &&
6376-
symbol_exists("sysrq_pressed")) {
6377-
get_symbol_data("sysrq_pressed", sizeof(int),
6378-
&msg_found);
6379-
break;
6380-
}
6381-
}
6382-
rewind(pc->tmpfile);
6383-
while (!msg_found && fgets(buf, BUFSIZE, pc->tmpfile)) {
6384-
if (strstr(buf, "Kernel panic: ") ||
6385-
strstr(buf, "Kernel panic - ")) {
6386-
msg_found = TRUE;
6387-
break;
6388-
}
6389-
}
6390-
rewind(pc->tmpfile);
6391-
while (!msg_found && fgets(buf, BUFSIZE, pc->tmpfile)) {
6392-
if (strstr(buf, "[Hardware Error]: ")) {
6393-
msg_found = TRUE;
6394-
break;
6360+
for (i = 0; i < ARRAY_SIZE(panic_msg); i++) {
6361+
rewind(pc->tmpfile);
6362+
while (fgets(buf, BUFSIZE, pc->tmpfile)) {
6363+
if (strstr(buf, panic_msg[i])) {
6364+
msg_found = TRUE;
6365+
if (strstr(buf, "SysRq :"))
6366+
pc->flags |= SYSRQ;
6367+
goto found;
6368+
}
63956369
}
63966370
}
6371+
63976372
rewind(pc->tmpfile);
63986373
while (!msg_found && fgets(buf, BUFSIZE, pc->tmpfile)) {
6399-
if (strstr(buf, "Bad mode in ")) {
6400-
msg_found = TRUE;
6374+
if (strstr(buf, "sysrq") && symbol_exists("sysrq_pressed")) {
6375+
get_symbol_data("sysrq_pressed", sizeof(int), &msg_found);
64016376
break;
64026377
}
64036378
}
64046379

6380+
found:
64056381
close_tmpfile();
64066382

64076383
if (!msg_found)

0 commit comments

Comments
 (0)