hung_task: Panic when there are more than N hung tasks at the same time
Subsystems (9)
PATCH v4 1/1 hung_task: Panic when there are more than N hung tasks at the same time
From: Li RongQing <[email protected]>
Currently, when 'hung_task_panic' is enabled, the kernel panics immediately upon detecting the first hung task. However, some hung tasks are transient and allow system recovery, while persistent hangs should trigger a panic when accumulating beyond a threshold.
Extend the 'hung_task_panic' sysctl to accept a threshold value specifying the number of hung tasks that must be detected before triggering a kernel panic. This provides finer control for environments where transient hangs may occur but persistent hangs should be fatal.
The sysctl now accepts:
- 0: don't panic (maintains original behavior)
- 1: panic on first hung task (maintains original behavior)
- N > 1: panic after N hung tasks are detected in a single scan
This maintains backward compatibility while providing flexibility for different hang scenarios.
---
diff with v3: comments modification, suggested by Lance, Masami, Randy and Petr diff with v2: do not add a new sysctl, extend hung_task_panic, suggested by Kees Cook
Documentation/admin-guide/kernel-parameters.txt | 20 +++++++++++++------- Documentation/admin-guide/sysctl/kernel.rst | 9 +++++---- arch/arm/configs/aspeed_g5_defconfig | 2 +- kernel/configs/debug.config | 2 +- kernel/hung_task.c | 15 ++++++++++----- lib/Kconfig.debug | 9 +++++---- tools/testing/selftests/wireguard/qemu/kernel.config | 2 +- 7 files changed, 36 insertions(+), 23 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +13 -7
@@ -1992,14 +1992,20 @@ the added memory block itself do not be affected. hung_task_panic= - [KNL] Should the hung task detector generate panics. - Format: 0 | 1 + [KNL] Number of hung tasks to trigger kernel panic. + Format: <int> + + When set to a non-zero value, a kernel panic will be triggered if + the number of detected hung tasks reaches this value. + + 0: don't panic + 1: panic immediately on first hung task + N: panic after N hung tasks are detected in a single scan - A value of 1 instructs the kernel to panic when a - hung task is detected. The default value is controlled - by the CONFIG_BOOTPARAM_HUNG_TASK_PANIC build-time - option. The value selected by this boot parameter can - be changed later by the kernel.hung_task_panic sysctl. + The default value is controlled by the + CONFIG_BOOTPARAM_HUNG_TASK_PANIC build-time option. The value + selected by this boot parameter can be changed later by the + kernel.hung_task_panic sysctl. hvc_iucv= [S390] Number of z/VM IUCV hypervisor console (HVC) terminal devices. Valid values: 0..8
Documentation/admin-guide/sysctl/kernel.rst +5 -4
@@ -397,13 +397,14 @@ a hung task is detected. hung_task_panic =============== -Controls the kernel's behavior when a hung task is detected. +When set to a non-zero value, a kernel panic will be triggered if the +number of hung tasks found during a single scan reaches this value. This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled. -= ================================================= += ======================================================= 0 Continue operation. This is the default behavior. -1 Panic immediately. -= ================================================= +N Panic when N hung tasks are found during a single scan. += ======================================================= hung_task_check_count
arch/arm/configs/aspeed_g5_defconfig +1 -1
@@ -308,7 +308,7 @@ CONFIG_PANIC_ON_OOPS=y CONFIG_PANIC_TIMEOUT=-1 CONFIG_SOFTLOCKUP_DETECTOR=y CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y -CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=1 CONFIG_WQ_WATCHDOG=y # CONFIG_SCHED_DEBUG is not set CONFIG_FUNCTION_TRACER=y
kernel/configs/debug.config +1 -1
@@ -83,7 +83,7 @@ CONFIG_SLUB_DEBUG_ON=y # # Debug Oops, Lockups and Hangs # -# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=0 # CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set CONFIG_DEBUG_ATOMIC_SLEEP=y CONFIG_DETECT_HUNG_TASK=y
kernel/hung_task.c +10 -5
@@ -81,7 +81,7 @@ static unsigned int __read_mostly sysctl_hung_task_all_cpu_backtrace;* hung task is detected: */ static unsigned int __read_mostly sysctl_hung_task_panic = -IS_ENABLED (CONFIG_BOOTPARAM_HUNG_TASK_PANIC ); +CONFIG_BOOTPARAM_HUNG_TASK_PANIC ;static int hung_task_panic (struct notifier_block *this,unsigned long event,void *ptr)
@@ -218,8 +218,11 @@ static inline void debug_show_blocker(struct task_struct *task, unsigned long ti }#endif -static void check_hung_task (struct task_struct *t,unsigned long timeout) +static void check_hung_task (struct task_struct *t,unsigned long timeout, +unsigned long prev_detect_count) { +unsigned long total_hung_task; +if (!task_is_hung (t, timeout))return ;
@@ -229,9 +232,10 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)*/ sysctl_hung_task_detect_count++; + total_hung_task = sysctl_hung_task_detect_count - prev_detect_count;trace_sched_process_hang (t); -if (sysctl_hung_task_panic) { +if (sysctl_hung_task_panic && total_hung_task >= sysctl_hung_task_panic) {console_verbose (); hung_task_show_lock = true; hung_task_call_panic = true;
@@ -300,6 +304,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)int max_count = sysctl_hung_task_check_count;unsigned long last_break = jiffies;struct task_struct *g, *t; +unsigned long prev_detect_count = sysctl_hung_task_detect_count;/* * If the system crashed already then all bets are off,
@@ -320,7 +325,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) last_break = jiffies; } -check_hung_task (t, timeout); +check_hung_task (t, timeout, prev_detect_count); } unlock:rcu_read_unlock ();
@@ -389,7 +394,7 @@ static const struct ctl_table hung_task_sysctls[] = { .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, + .extra2 = SYSCTL_INT_MAX, }, { .procname = "hung_task_check_count",
lib/Kconfig.debug +5 -4
@@ -1258,12 +1258,13 @@ config DEFAULT_HUNG_TASK_TIMEOUT Keeping the default should be fine in most cases. config BOOTPARAM_HUNG_TASK_PANIC - bool "Panic (Reboot) On Hung Tasks" + int "Number of hung tasks to trigger kernel panic" depends on DETECT_HUNG_TASK + default 0 help - Say Y here to enable the kernel to panic on "hung tasks", - which are bugs that cause the kernel to leave a task stuck - in uninterruptible "D" state. + When set to a non-zero value, a kernel panic will be triggered + if the number of hung tasks found during a single scan reaches + this value. The panic can be used in combination with panic_timeout, to cause the system to reboot automatically after a
tools/testing/selftests/wireguard/qemu/kernel.config +1 -1
@@ -81,7 +81,7 @@ CONFIG_WQ_WATCHDOG=y CONFIG_DETECT_HUNG_TASK=y CONFIG_BOOTPARAM_HARDLOCKUP_PANIC=y CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y -CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=1 CONFIG_PANIC_TIMEOUT=-1 CONFIG_STACKTRACE=y CONFIG_EARLY_PRINTK=y
Signature · 1 line
2.9.4
LGTM. It works as expected, thanks!
Quoted 1 line · lirongqing
From: Li RongQing <[email protected]>
For the commit message, I'd suggest the following for better clarity:
``` The hung_task_panic sysctl is currently a blunt instrument: it's all or nothing. Panicking on a single hung task can be an overreaction to a transient glitch. A more reliable indicator of a systemic problem is when multiple tasks hang simultaneously. Extend hung_task_panic to accept an integer threshold, allowing the kernel to panic only when N hung tasks are detected in a single scan. This provides finer control to distinguish between isolated incidents and system-wide failures. The accepted values are: - 0: Don't panic (unchanged) - 1: Panic on the first hung task (unchanged) - N > 1: Panic after N hung tasks are detected in a single scan The original behavior is preserved for values 0 and 1, maintaining full backward compatibility. ```
If you agree, likely no need to resend - Andrew could pick it up directly when applying :)
Quoted 45 lines
Currently, when '
hung_task_panic' is enabled, the kernel panics immediately upon detecting the first hung task. However, some hung tasks are transient and allow system recovery, while persistent hangs should trigger a panic when accumulating beyond a threshold.Extend the '
hung_task_panic' sysctl to accept a threshold value specifying the number of hung tasks that must be detected before triggering a kernel panic. This provides finer control for environments where transient hangs may occur but persistent hangs should be fatal.The sysctl now accepts:
- 0: don't panic (maintains original behavior)
- 1: panic on first hung task (maintains original behavior)
- N > 1: panic after N hung tasks are detected in a single scanThis maintains backward compatibility while providing flexibility for different hang scenarios.
Signed-off-by Li RongQing <[email protected]>Cc Andrew Jeffery <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Arnd Bergmann <[email protected]>Cc David Hildenbrand <[email protected]>Cc Florian Wesphal <[email protected]>Cc Jakub Kacinski <[email protected]>Cc Jason A. Donenfeld <[email protected]>Cc Joel Granados <[email protected]>Cc Joel Stanley <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Kees Cook <[email protected]>Cc Lance Yang <[email protected]>Cc Liam Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Masami Hiramatsu (Google)" <[email protected]>Cc "Paul E . McKenney" <[email protected]>Cc Pawan Gupta <[email protected]>Cc Petr Mladek <[email protected]>Cc Phil Auld <[email protected]>Cc Randy Dunlap <[email protected]>Cc Russell King <[email protected]>Cc Shuah Khan <[email protected]>Cc Simon Horman <[email protected]>Cc Stanislav Fomichev <[email protected]>Cc Steven Rostedt <[email protected]>
Quoted 1 line
---
So:
Cheers,
Lance
Quoted 29 lines
LGTM. It works as expected, thanks!
Quoted 1 line · lirongqing
From: Li RongQing <[email protected]>
For the commit message, I'd suggest the following for better clarity:
``` The hung_task_panic sysctl is currently a blunt instrument: it's all or nothing. Panicking on a single hung task can be an overreaction to a transient glitch. A more reliable indicator of a systemic problem is when multiple tasks hang simultaneously. Extend hung_task_panic to accept an integer threshold, allowing the kernel to panic only when N hung tasks are detected in a single scan. This provides finer control to distinguish between isolated incidents and system-wide failures. The accepted values are: - 0: Don't panic (unchanged) - 1: Panic on the first hung task (unchanged) - N > 1: Panic after N hung tasks are detected in a single scan The original behavior is preserved for values 0 and 1, maintaining full backward compatibility. ```
Quoted 3 lines
If you agree, likely no need to resend - Andrew could pick it up directly when applying :)
This is better;
Andrew, could you pick it up directly
Thanks
-Li
Quoted 55 lines
Quoted 10 lines
Currently, when '
hung_task_panic' is enabled, the kernel panics immediately upon detecting the first hung task. However, some hung tasks are transient and allow system recovery, while persistent hangs should trigger a panic when accumulating beyond a threshold.Extend the '
hung_task_panic' sysctl to accept a threshold value specifying the number of hung tasks that must be detected before triggering a kernel panic. This provides finer control for environments where transient hangs may occur but persistent hangsshould be fatal.
Quoted 35 lines
The sysctl now accepts:
- 0: don't panic (maintains original behavior)
- 1: panic on first hung task (maintains original behavior)
- N > 1: panic after N hung tasks are detected in a single scanThis maintains backward compatibility while providing flexibility for different hang scenarios.
Signed-off-by Li RongQing <[email protected]>Cc Andrew Jeffery <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Arnd Bergmann <[email protected]>Cc David Hildenbrand <[email protected]>Cc Florian Wesphal <[email protected]>Cc Jakub Kacinski <[email protected]>Cc Jason A. Donenfeld <[email protected]>Cc Joel Granados <[email protected]>Cc Joel Stanley <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Kees Cook <[email protected]>Cc Lance Yang <[email protected]>Cc Liam Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Masami Hiramatsu (Google)" <[email protected]>Cc "Paul E . McKenney" <[email protected]>Cc Pawan Gupta <[email protected]>Cc Petr Mladek <[email protected]>Cc Phil Auld <[email protected]>Cc Randy Dunlap <[email protected]>Cc Russell King <[email protected]>Cc Shuah Khan <[email protected]>Cc Simon Horman <[email protected]>Cc Stanislav Fomichev <[email protected]>Cc Steven Rostedt <[email protected]>Quoted 1 line
---
So:
Reviewed-by Lance Yang <[email protected]>Tested-by Lance Yang <[email protected]>Cheers,
Lance
Andrew Morton
maintainerQuoted 7 lines · On Thu, 16 Oct 2025 05:57:34 +0000 "Li,Rongqing" <[email protected]> wrote:
Quoted 3 lines
If you agree, likely no need to resend - Andrew could pick it up directly when applying :)
This is better;
Andrew, could you pick it up directly
No problems, thanks.
Quoted 12 lines · On Wed, 15 Oct 2025 14:36:15 +0800 lirongqing <[email protected]> wrote:
From: Li RongQing <[email protected]>
Currently, when '
hung_task_panic' is enabled, the kernel panics immediately upon detecting the first hung task. However, some hung tasks are transient and allow system recovery, while persistent hangs should trigger a panic when accumulating beyond a threshold.Extend the '
hung_task_panic' sysctl to accept a threshold value specifying the number of hung tasks that must be detected before triggering a kernel panic. This provides finer control for environments where transient hangs may occur but persistent hangs should be fatal.
Quoted 7 lines
The sysctl now accepts:
- 0: don't panic (maintains original behavior)
- 1: panic on first hung task (maintains original behavior)
- N > 1: panic after N hung tasks are detected in a single scanThis maintains backward compatibility while providing flexibility for different hang scenarios.
Looks good to me.
Thank you,
Quoted 223 lines
Signed-off-by Li RongQing <[email protected]>Cc Andrew Jeffery <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Arnd Bergmann <[email protected]>Cc David Hildenbrand <[email protected]>Cc Florian Wesphal <[email protected]>Cc Jakub Kacinski <[email protected]>Cc Jason A. Donenfeld <[email protected]>Cc Joel Granados <[email protected]>Cc Joel Stanley <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Kees Cook <[email protected]>Cc Lance Yang <[email protected]>Cc Liam Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Masami Hiramatsu (Google)" <[email protected]>Cc "Paul E . McKenney" <[email protected]>Cc Pawan Gupta <[email protected]>Cc Petr Mladek <[email protected]>Cc Phil Auld <[email protected]>Cc Randy Dunlap <[email protected]>Cc Russell King <[email protected]>Cc Shuah Khan <[email protected]>Cc Simon Horman <[email protected]>Cc Stanislav Fomichev <[email protected]>Cc Steven Rostedt <[email protected]>---
diff with v3: comments modification, suggested by Lance, Masami, Randy and Petr diff with v2: do not add a new sysctl, extendhung_task_panic, suggested by Kees CookDocumentation/admin-guide/kernel-parameters.txt | 20 +++++++++++++------- Documentation/admin-guide/sysctl/kernel.rst | 9 +++++---- arch/arm/configs/aspeed_g5_defconfig | 2 +- kernel/configs/debug.config | 2 +- kernel/hung_task.c | 15 ++++++++++----- lib/Kconfig.debug | 9 +++++---- tools/testing/selftests/wireguard/qemu/kernel.config | 2 +- 7 files changed, 36 insertions(+), 23 deletions(-)Documentation/admin-guide/kernel-parameters.txt +13
-7@@ -1992,14 +1992,20 @@ the added memory block itself do not be affected. hung_task_panic= - [KNL] Should the hung task detector generate panics. - Format: 0 | 1 + [KNL] Number of hung tasks to trigger kernel panic. + Format: <int> + + When set to a non-zero value, a kernel panic will be triggered if + the number of detected hung tasks reaches this value. + + 0: don't panic + 1: panic immediately on first hung task + N: panic after N hung tasks are detected in a single scan - A value of 1 instructs the kernel to panic when a - hung task is detected. The default value is controlled - by the CONFIG_BOOTPARAM_HUNG_TASK_PANIC build-time - option. The value selected by this boot parameter can - be changed later by the kernel.hung_task_panic sysctl. + The default value is controlled by the + CONFIG_BOOTPARAM_HUNG_TASK_PANIC build-time option. The value + selected by this boot parameter can be changed later by the + kernel.hung_task_panic sysctl. hvc_iucv= [S390] Number of z/VM IUCV hypervisor console (HVC) terminal devices. Valid values: 0..8Documentation/admin-guide/sysctl/kernel.rst +5
-4@@ -397,13 +397,14 @@ a hung task is detected. hung_task_panic =============== -Controls the kernel's behavior when a hung task is detected. +When set to a non-zero value, a kernel panic will be triggered if the +number of hung tasks found during a single scan reaches this value. This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled. -= ================================================= += ======================================================= 0 Continue operation. This is the default behavior. -1 Panic immediately. -= ================================================= +N Panic when N hung tasks are found during a single scan. += ======================================================= hung_task_check_countarch/arm/configs/aspeed_g5_defconfig +1
-1@@ -308,7 +308,7 @@ CONFIG_PANIC_ON_OOPS=y CONFIG_PANIC_TIMEOUT=-1 CONFIG_SOFTLOCKUP_DETECTOR=y CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y -CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=1 CONFIG_WQ_WATCHDOG=y # CONFIG_SCHED_DEBUG is not set CONFIG_FUNCTION_TRACER=ykernel/configs/debug.config +1
-1@@ -83,7 +83,7 @@ CONFIG_SLUB_DEBUG_ON=y # # Debug Oops, Lockups and Hangs # -# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=0 # CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set CONFIG_DEBUG_ATOMIC_SLEEP=y CONFIG_DETECT_HUNG_TASK=ykernel/hung_task.c +10
-5@@ -81,7 +81,7 @@ static unsigned int __read_mostly sysctl_hung_task_all_cpu_backtrace;* hung task is detected: */ static unsigned int __read_mostly sysctl_hung_task_panic = -IS_ENABLED (CONFIG_BOOTPARAM_HUNG_TASK_PANIC ); +CONFIG_BOOTPARAM_HUNG_TASK_PANIC ;static int hung_task_panic (struct notifier_block *this,unsigned long event,void *ptr)@@ -218,8 +218,11 @@ static inline void debug_show_blocker(struct task_struct *task, unsigned long ti }#endif -static void check_hung_task (struct task_struct *t,unsigned long timeout) +static void check_hung_task (struct task_struct *t,unsigned long timeout, +unsigned long prev_detect_count) { +unsigned long total_hung_task; +if (!task_is_hung (t, timeout))return ;@@ -229,9 +232,10 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)*/ sysctl_hung_task_detect_count++; + total_hung_task = sysctl_hung_task_detect_count - prev_detect_count;trace_sched_process_hang (t); -if (sysctl_hung_task_panic) { +if (sysctl_hung_task_panic && total_hung_task >= sysctl_hung_task_panic) {console_verbose (); hung_task_show_lock = true; hung_task_call_panic = true;@@ -300,6 +304,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)int max_count = sysctl_hung_task_check_count;unsigned long last_break = jiffies;struct task_struct *g, *t; +unsigned long prev_detect_count = sysctl_hung_task_detect_count;/* * If the system crashed already then all bets are off, @@ -320,7 +325,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) last_break = jiffies; } -check_hung_task (t, timeout); +check_hung_task (t, timeout, prev_detect_count); } unlock:rcu_read_unlock ();@@ -389,7 +394,7 @@ static const struct ctl_table hung_task_sysctls[] = { .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, + .extra2 = SYSCTL_INT_MAX, }, { .procname = "hung_task_check_count",lib/Kconfig.debug +5
-4@@ -1258,12 +1258,13 @@ config DEFAULT_HUNG_TASK_TIMEOUT Keeping the default should be fine in most cases. config BOOTPARAM_HUNG_TASK_PANIC - bool "Panic (Reboot) On Hung Tasks" + int "Number of hung tasks to trigger kernel panic" depends on DETECT_HUNG_TASK + default 0 help - Say Y here to enable the kernel to panic on "hung tasks", - which are bugs that cause the kernel to leave a task stuck - in uninterruptible "D" state. + When set to a non-zero value, a kernel panic will be triggered + if the number of hung tasks found during a single scan reaches + this value. The panic can be used in combination with panic_timeout, to cause the system to reboot automatically after atools/testing/selftests/wireguard/qemu/kernel.config +1
-1@@ -81,7 +81,7 @@ CONFIG_WQ_WATCHDOG=y CONFIG_DETECT_HUNG_TASK=y CONFIG_BOOTPARAM_HARDLOCKUP_PANIC=y CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y -CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=1 CONFIG_PANIC_TIMEOUT=-1 CONFIG_STACKTRACE=y CONFIG_EARLY_PRINTK=ySignature · 1 line
2.9.4
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Dear RongQing,
Thank you for the patch. One minor comment regarding the Kconfig description.
Am 15.10.25 um 08:36 schrieb lirongqing:
Quoted 114 lines
From: Li RongQing <[email protected]>
Currently, when '
hung_task_panic' is enabled, the kernel panics immediately upon detecting the first hung task. However, some hung tasks are transient and allow system recovery, while persistent hangs should trigger a panic when accumulating beyond a threshold.Extend the '
hung_task_panic' sysctl to accept a threshold value specifying the number of hung tasks that must be detected before triggering a kernel panic. This provides finer control for environments where transient hangs may occur but persistent hangs should be fatal.The sysctl now accepts:
- 0: don't panic (maintains original behavior)
- 1: panic on first hung task (maintains original behavior)
- N > 1: panic after N hung tasks are detected in a single scanThis maintains backward compatibility while providing flexibility for different hang scenarios.
Signed-off-by Li RongQing <[email protected]>Cc Andrew Jeffery <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Arnd Bergmann <[email protected]>Cc David Hildenbrand <[email protected]>Cc Florian Wesphal <[email protected]>Cc Jakub Kacinski <[email protected]>Cc Jason A. Donenfeld <[email protected]>Cc Joel Granados <[email protected]>Cc Joel Stanley <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Kees Cook <[email protected]>Cc Lance Yang <[email protected]>Cc Liam Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Masami Hiramatsu (Google)" <[email protected]>Cc "Paul E . McKenney" <[email protected]>Cc Pawan Gupta <[email protected]>Cc Petr Mladek <[email protected]>Cc Phil Auld <[email protected]>Cc Randy Dunlap <[email protected]>Cc Russell King <[email protected]>Cc Shuah Khan <[email protected]>Cc Simon Horman <[email protected]>Cc Stanislav Fomichev <[email protected]>Cc Steven Rostedt <[email protected]>---
diff with v3: comments modification, suggested by Lance, Masami, Randy and Petr diff with v2: do not add a new sysctl, extendhung_task_panic, suggested by Kees CookDocumentation/admin-guide/kernel-parameters.txt | 20 +++++++++++++------- Documentation/admin-guide/sysctl/kernel.rst | 9 +++++---- arch/arm/configs/aspeed_g5_defconfig | 2 +- kernel/configs/debug.config | 2 +- kernel/hung_task.c | 15 ++++++++++----- lib/Kconfig.debug | 9 +++++---- tools/testing/selftests/wireguard/qemu/kernel.config | 2 +- 7 files changed, 36 insertions(+), 23 deletions(-)Documentation/admin-guide/kernel-parameters.txt +13
-7@@ -1992,14 +1992,20 @@ the added memory block itself do not be affected. hung_task_panic= - [KNL] Should the hung task detector generate panics. - Format: 0 | 1 + [KNL] Number of hung tasks to trigger kernel panic. + Format: <int> + + When set to a non-zero value, a kernel panic will be triggered if + the number of detected hung tasks reaches this value. + + 0: don't panic + 1: panic immediately on first hung task + N: panic after N hung tasks are detected in a single scan - A value of 1 instructs the kernel to panic when a - hung task is detected. The default value is controlled - by the CONFIG_BOOTPARAM_HUNG_TASK_PANIC build-time - option. The value selected by this boot parameter can - be changed later by the kernel.hung_task_panic sysctl. + The default value is controlled by the + CONFIG_BOOTPARAM_HUNG_TASK_PANIC build-time option. The value + selected by this boot parameter can be changed later by the + kernel.hung_task_panic sysctl. hvc_iucv= [S390] Number of z/VM IUCV hypervisor console (HVC) terminal devices. Valid values: 0..8Documentation/admin-guide/sysctl/kernel.rst +5
-4@@ -397,13 +397,14 @@ a hung task is detected. hung_task_panic =============== -Controls the kernel's behavior when a hung task is detected. +When set to a non-zero value, a kernel panic will be triggered if the +number of hung tasks found during a single scan reaches this value. This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled. -= ================================================= += ======================================================= 0 Continue operation. This is the default behavior. -1 Panic immediately. -= ================================================= +N Panic when N hung tasks are found during a single scan. += ======================================================= hung_task_check_count
[…]
Quoted 12 lines
lib/Kconfig.debug +2
-1@@ -1258,12 +1258,13 @@ config DEFAULT_HUNG_TASK_TIMEOUT Keeping the default should be fine in most cases. config BOOTPARAM_HUNG_TASK_PANIC - bool "Panic (Reboot) On Hung Tasks" + int "Number of hung tasks to trigger kernel panic" depends on DETECT_HUNG_TASK + default 0
lib/Kconfig.debug config DEFAULT_HUNG_TASK_TIMEOUT · line 1270
Quoted 10 lines
lib/Kconfig.debug +3
-3help - Say Y here to enable the kernel to panic on "hung tasks", - which are bugs that cause the kernel to leave a task stuck - in uninterruptible "D" state. + When set to a non-zero value, a kernel panic will be triggered + if the number of hung tasks found during a single scan reaches + this value. The panic can be used in combination with panic_timeout, to cause the system to reboot automatically after a
Why not leave the sentence about the uninterruptible "D" state in there?
Also, it sounds like, some are actually using this in production. Maybe it should be moved out of Kconfig.debug too?
Kind regards,
Paul
Quoted 150 lines
Am 15.10.25 um 08:36 schrieb lirongqing:
Quoted 11 lines
From: Li RongQing <[email protected]>
Currently, when '
hung_task_panic' is enabled, the kernel panics immediately upon detecting the first hung task. However, some hung tasks are transient and allow system recovery, while persistent hangs should trigger a panic when accumulating beyond a threshold.Extend the '
hung_task_panic' sysctl to accept a threshold value specifying the number of hung tasks that must be detected before triggering a kernel panic. This provides finer control for environments where transient hangs may occur but persistent hangsshould be fatal.
Quoted 35 lines
The sysctl now accepts:
- 0: don't panic (maintains original behavior)
- 1: panic on first hung task (maintains original behavior)
- N > 1: panic after N hung tasks are detected in a single scanThis maintains backward compatibility while providing flexibility for different hang scenarios.
Signed-off-by Li RongQing <[email protected]>Cc Andrew Jeffery <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Arnd Bergmann <[email protected]>Cc David Hildenbrand <[email protected]>Cc Florian Wesphal <[email protected]>Cc Jakub Kacinski <[email protected]>Cc Jason A. Donenfeld <[email protected]>Cc Joel Granados <[email protected]>Cc Joel Stanley <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Kees Cook <[email protected]>Cc Lance Yang <[email protected]>Cc Liam Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Masami Hiramatsu (Google)" <[email protected]>Cc "Paul E . McKenney" <[email protected]>Cc Pawan Gupta <[email protected]>Cc Petr Mladek <[email protected]>Cc Phil Auld <[email protected]>Cc Randy Dunlap <[email protected]>Cc Russell King <[email protected]>Cc Shuah Khan <[email protected]>Cc Simon Horman <[email protected]>Cc Stanislav Fomichev <[email protected]>Cc Steven Rostedt <[email protected]>Quoted 6 lines
---
diff with v3: comments modification, suggested by Lance, Masami, Randy and Petr diff with v2: do not add a new sysctl, extendhung_task_panic, suggested by Kees CookDocumentation/admin-guide/kernel-parameters.txt | 20+++++++++++++-------
Quoted 4 lines
Documentation/admin-guide/sysctl/kernel.rst | 9 +++++---- arch/arm/configs/aspeed_g5_defconfig | 2 +- kernel/configs/debug.config | 2 +- kernel/hung_task.c | 15++++++++++-----
Quoted 1 line
lib/Kconfig.debug | 9+++++----
Quoted 9 lines
tools/testing/selftests/wireguard/qemu/kernel.config | 2 +- 7 files changed, 36 insertions(+), 23 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0Documentation/admin-guide/kernel-parameters.txt line 1998
Quoted 9 lines
Documentation/admin-guide/kernel-parameters.txt +4
-2@@ -1992,14 +1992,20 @@ the added memory block itself do not be affected. hung_task_panic= - [KNL] Should the hung task detector generate panics. - Format: 0 | 1 + [KNL] Number of hung tasks to trigger kernel panic. + Format: <int> + + When set to a non-zero value, a kernel panic will be triggeredif
Documentation/admin-guide/kernel-parameters.txt
Quoted 13 lines
Documentation/admin-guide/kernel-parameters.txt +7
-5+ the number of detected hung tasks reaches this value. + + 0: don't panic + 1: panic immediately on first hung task + N: panic after N hung tasks are detected in a single scan - A value of 1 instructs the kernel to panic when a - hung task is detected. The default value is controlled - by the CONFIG_BOOTPARAM_HUNG_TASK_PANIC build-time - option. The value selected by this boot parameter can - be changed later by the kernel.hung_task_panic sysctl. + The default value is controlled by the + CONFIG_BOOTPARAM_HUNG_TASK_PANIC build-time option.The value
Documentation/admin-guide/kernel-parameters.txt
Quoted 4 lines
Documentation/admin-guide/kernel-parameters.txt +2
-0+ selected by this boot parameter can be changed later by the + kernel.hung_task_panic sysctl. hvc_iucv= [S390] Number of z/VM IUCV hypervisor console(HVC)
Quoted 25 lines
Documentation/admin-guide/kernel-parameters.txt +0
-0terminal devices. Valid values: 0..8 diff --git
a/Documentation/admin-guide/sysctl/kernel.rstb/Documentation/admin-guide/sysctl/kernel.rst
index f3ee807..0065a55 100644Documentation/admin-guide/sysctl/kernel.rst +5
-4@@ -397,13 +397,14 @@ a hung task is detected. hung_task_panic =============== -Controls the kernel's behavior when a hung task is detected. +When set to a non-zero value, a kernel panic will be triggered if the +number of hung tasks found during a single scan reaches this value. This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled. -= ================================================= += ======================================================= 0 Continue operation. This is the default behavior. -1 Panic immediately. -= ================================================= +N Panic when N hung tasks are found during a single scan. += ======================================================= hung_task_check_count[…]
Quoted 20 lines
lib/Kconfig.debug index renamed from lib/Kconfig.debug +0
-03034e294..3976c90 100644
lib/Kconfig.debug +5
-4@@ -1258,12 +1258,13 @@ config DEFAULT_HUNG_TASK_TIMEOUT Keeping the default should be fine in most cases. config BOOTPARAM_HUNG_TASK_PANIC - bool "Panic (Reboot) On Hung Tasks" + int "Number of hung tasks to trigger kernel panic" depends on DETECT_HUNG_TASK + default 0 help - Say Y here to enable the kernel to panic on "hung tasks", - which are bugs that cause the kernel to leave a task stuck - in uninterruptible "D" state. + When set to a non-zero value, a kernel panic will be triggered + if the number of hung tasks found during a single scan reaches + this value.
Quoted 4 lines
lib/Kconfig.debug config DEFAULT_HUNG_TASK_TIMEOUT · line 1270
Quoted 2 lines
lib/Kconfig.debug +0
-0The panic can be used in combination with panic_timeout, to cause the system to reboot automatically after aWhy not leave the sentence about the uninterruptible "D" state in there?
This seem to say a kernel bug to cause hung task, but it maybe hardware failure(or virtio backend bug); so I do not keep it
Quoted 3 lines
Also, it sounds like, some are actually using this in production. Maybe it should be moved out of
Kconfig.debugtoo?
I think hung task panic is a useful feature, it should move out of Kconfig.debug
Thanks
-Li
Quoted 4 lines
Kind regards,
Paul
Quoted 46 lines · lirongqing
From: Li RongQing <[email protected]>
Currently, when '
hung_task_panic' is enabled, the kernel panics immediately upon detecting the first hung task. However, some hung tasks are transient and allow system recovery, while persistent hangs should trigger a panic when accumulating beyond a threshold.Extend the '
hung_task_panic' sysctl to accept a threshold value specifying the number of hung tasks that must be detected before triggering a kernel panic. This provides finer control for environments where transient hangs may occur but persistent hangs should be fatal.The sysctl now accepts:
- 0: don't panic (maintains original behavior)
- 1: panic on first hung task (maintains original behavior)
- N > 1: panic after N hung tasks are detected in a single scanThis maintains backward compatibility while providing flexibility for different hang scenarios.
Signed-off-by Li RongQing <[email protected]>Cc Andrew Jeffery <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Arnd Bergmann <[email protected]>Cc David Hildenbrand <[email protected]>Cc Florian Wesphal <[email protected]>Cc Jakub Kacinski <[email protected]>Cc Jason A. Donenfeld <[email protected]>Cc Joel Granados <[email protected]>Cc Joel Stanley <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Kees Cook <[email protected]>Cc Lance Yang <[email protected]>Cc Liam Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc "Masami Hiramatsu (Google)" <[email protected]>Cc "Paul E . McKenney" <[email protected]>Cc Pawan Gupta <[email protected]>Cc Petr Mladek <[email protected]>Cc Phil Auld <[email protected]>Cc Randy Dunlap <[email protected]>Cc Russell King <[email protected]>Cc Shuah Khan <[email protected]>Cc Simon Horman <[email protected]>Cc Stanislav Fomichev <[email protected]>Cc Steven Rostedt <[email protected]>
Quoted 7 lines
---
diff with v3: comments modification, suggested by Lance, Masami, Randy and Petr diff with v2: do not add a new sysctl, extendhung_task_panic, suggested by Kees CookDocumentation/admin-guide/kernel-parameters.txt | 20 +++++++++++++------- Documentation/admin-guide/sysctl/kernel.rst | 9 +++++---- arch/arm/configs/aspeed_g5_defconfig | 2 +-
For the aspeed_g5_defconfig change: