[PATCH] kernel/hung_task.c: force ignore_loglevel before panic

From: Liu, Chuansheng
Date: Mon Dec 10 2018 - 00:40:10 EST



Based on patch commit 401c636a0eeb ("kernel/hung_task.c:
show all hung tasks before panic"), we could get the
call stack of hung task.

However, if the console loglevel is not high, we still
can not get the useful information in practice, and
in most cases users don't set console loglevel to
high level.

This patch is to force ignore_loglevel before system
panic, so that the real useful information can be seen
in the console, instead of being like the following,
which doesn't have hung task information.

[ 246.916600] INFO: task init:1 blocked for more than 120 seconds.
[ 246.922320] Tainted: G U W 4.19.0-quilt-2e5dc0ac-g51b6c21d76cc #1
[ 246.926790] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[ 246.932553] Kernel panic - not syncing: hung_task: blocked tasks
[ 246.938503] CPU: 2 PID: 479 Comm: khungtaskd Tainted: G U W 4.19.0-quilt-2e5dc0ac-g51b6c21d76cc #1
[ 246.990266] Call Trace:
[ 246.991707] dump_stack+0x4f/0x65
[ 246.993710] panic+0xde/0x231
[ 246.995445] watchdog+0x290/0x410
[ 246.997390] kthread+0x12c/0x150
[ 246.999301] ? reset_hung_task_detector+0x20/0x20
[ 247.004825] ? kthread_create_worker_on_cpu+0x70/0x70
[ 247.007735] ret_from_fork+0x35/0x40
[ 247.010280] reboot: panic mode set: p,w
[ 247.012619] Kernel Offset: 0x34000000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff)

Signed-off-by: Chuansheng Liu <chuansheng.liu@xxxxxxxxx>
---
include/linux/printk.h | 2 +-
kernel/hung_task.c | 7 +++++++
kernel/printk/printk.c | 2 +-
3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index cf3eccf..24748c1 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -59,8 +59,8 @@ static inline const char *printk_skip_headers(const char *buffer)
*/
#define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
#define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET
-
extern int console_printk[];
+extern bool ignore_loglevel;

#define console_loglevel (console_printk[0])
#define default_message_loglevel (console_printk[1])
diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index cb8e3e8..7d942d1 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -130,6 +130,13 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
init_utsname()->version);
pr_err("\"echo 0 > /proc/sys/kernel/hung_task_timeout_secs\""
" disables this message.\n");
+ /* When sysctl_hung_task_panic is set, we have to force
+ * ignore_loglevel to get really useful hung task
+ * information.
+ */
+ if (sysctl_hung_task_panic && !ignore_loglevel)
+ ignore_loglevel = true;
+
sched_show_task(t);
hung_task_show_lock = true;
}
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1b2a029..31a7a56 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1135,7 +1135,7 @@ void __init setup_log_buf(int early)
free, (free * 100) / __LOG_BUF_LEN);
}

-static bool __read_mostly ignore_loglevel;
+bool __read_mostly ignore_loglevel;

static int __init ignore_loglevel_setup(char *str)
{
--
2.7.4