From nobody Fri Dec 19 14:37:04 2025 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FEFC334C19 for ; Thu, 13 Nov 2025 11:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032252; cv=none; b=p9Kt5mXyHTr8DGvetthK2Dffbi40Nt3WIdA3FdH5scasrctnyOdHcQ5aVAXUoAC9UTplJIMhCBwJPxGmgRmRg7NpckBClErrto+7zR6s/jydL3KxE5bPFNM9OTlPpTdLHWp39ViKdJuWnD/QXSz641dT+I5g94WuFqImXs4+H/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032252; c=relaxed/simple; bh=ryBxZMUSjuvWDVwWvCYyR3VS/HcS2UnOR9sXhJ7u994=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mRlE47sNqluarS5tSGW2c/vhoArUEbM+/itLRj8FK6zO9yfc61iRARVYErm5Cf124QGOQ68fnd2fSW9diDLtAJCWsS8qzbunEMyaSX3RRtRolh5CUe5TTlPJhVuWr6B9DsgJfnuB5hBVM9ZH3pQsvi7ioN5Pcg4T1gcyON3FWnM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ULto8nXa; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ULto8nXa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1763032241; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Zik/3/bDWAwRJfJzgp7rCB/rFjPiQpDb7LLTM/iioGI=; b=ULto8nXa5FmpbeG1ME2LT2gUZEs4ma48KIvsh5HWdjAUZgSCKQwiNIOKhIG4kkXIhnMv4jDWnlAs8a9Kl87QNu3xdlm6FZSGtDCQ9ZjBIP0GJCYiEhgIgYdMSMEKiyCrn0h/e7cJzSx/aW9H9K3WmX1yrV+w1Z3D+FvsoqNBz2k= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WsJMVrd_1763032240 cluster:ay36) by smtp.aliyun-inc.com; Thu, 13 Nov 2025 19:10:40 +0800 From: Feng Tang To: Andrew Morton , Petr Mladek , Lance Yang , Jonathan Corbet , paulmck@kernel.org, Steven Rostedt , linux-kernel@vger.kernel.org Cc: Feng Tang Subject: [PATCH v2 1/4] docs: panic: correct some sys_ifo names in sysctl doc Date: Thu, 13 Nov 2025 19:10:36 +0800 Message-Id: <20251113111039.22701-2-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20251113111039.22701-1-feng.tang@linux.alibaba.com> References: <20251113111039.22701-1-feng.tang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some sys_info names wered forgotten to change in patch iterations, while the right names are defined in kernel/sys_info.c. Fixes: d747755917bf ("panic: add 'panic_sys_info' sysctl to take human read= able string parameter") Signed-off-by: Feng Tang Reviewed-by: Petr Mladek --- Documentation/admin-guide/sysctl/kernel.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index 0065a55bc09e..a397eeccaea7 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -911,8 +911,8 @@ to 'panic_print'. Possible values are: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D tasks print all tasks info mem print system memory info -timer print timers info -lock print locks info if CONFIG_LOCKDEP is on +timers print timers info +locks print locks info if CONFIG_LOCKDEP is on ftrace print ftrace buffer all_bt print all CPUs backtrace (if available in the arch) blocked_tasks print only tasks in uninterruptible (blocked) state --=20 2.43.5 From nobody Fri Dec 19 14:37:04 2025 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BD0F2DF71D for ; Thu, 13 Nov 2025 11:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032247; cv=none; b=RBLJsfDKFxhhpfl57tUubBOhQvRdMsfGMG3Xy0Ylu+63vvl8tTXo/zVKA0QkigtDVY4iwaH2arSbVyf/4hOBGLfcxOcF8I9SMj9Mw4B4WDdNA3BhN6FM7OY/uP/105m7d84mSAP+0cQEZ7+l6cRbtAIsvIHNhd1BNjpRhllRoFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032247; c=relaxed/simple; bh=ALYktRUmPHbBLsf4i7lMGjOniAp4TIarw1EYIGinXUo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IiWWLpryUkJ7t9DBdVwkQPyzKZjTcrWC/A2F8aJvkXIesjD4wmj+Bmz+WTA9hcCLyvb5KT/IoPZ3s113ZpJOAF8qLjo6pO6yw1kZQtQK1dRdc5L3skwSlQhrlJ6OVp+MTLjxm+NUs1XxgeqRf0vJhw+3gbwXt0VruMlHqjFxe3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=yL6ligVU; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="yL6ligVU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1763032241; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=rA9HZsy23Auw6ME2gNLW/s+kToiYN9UwDKgAvL8Hzms=; b=yL6ligVUdQZeFoDRaBTDcJjx2Tj2peQcBN7/fcUp9/xfEgO0JSrTDM8iOjjWLSws7rG8fwActX20B1SMoRquo7tMjaRd7yCd8vMN3kZ1e50yw6gvm7V3EUGzFT43Hw0gUzslAH/U2EtTM1AIt4/7HvQQu5fJxxW4jP/XGm6UcwA= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WsJMszq_1763032240 cluster:ay36) by smtp.aliyun-inc.com; Thu, 13 Nov 2025 19:10:41 +0800 From: Feng Tang To: Andrew Morton , Petr Mladek , Lance Yang , Jonathan Corbet , paulmck@kernel.org, Steven Rostedt , linux-kernel@vger.kernel.org Cc: Feng Tang Subject: [PATCH v2 2/4] hung_task: Add hung_task_sys_info sysctl to dump sys info on task-hung Date: Thu, 13 Nov 2025 19:10:37 +0800 Message-Id: <20251113111039.22701-3-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20251113111039.22701-1-feng.tang@linux.alibaba.com> References: <20251113111039.22701-1-feng.tang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When task-hung happens, developers may need different kinds of system information (call-stacks, memory info, locks, etc.) to help debugging. Add 'hung_task_sys_info' sysctl knob to take human readable string like "tasks,mem,timers,locks,ftrace,...", and when task-hung happens, all requested information will be dumped. (refer kernel/sys_info.c for more details). Meanwhile, the newly introduced sys_info() call is used to unify some existing info-dumping knobs. Suggested-by: Petr Mladek Signed-off-by: Feng Tang Reviewed-by: Lance Yang Reviewed-by: Petr Mladek --- Documentation/admin-guide/sysctl/kernel.rst | 5 ++ kernel/hung_task.c | 62 +++++++++++++-------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index a397eeccaea7..45b4408dad31 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -422,6 +422,11 @@ the system boot. =20 This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled. =20 +hung_task_sys_info +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +A comma separated list of extra system information to be dumped when +hung task is detected, for example, "tasks,mem,timers,locks,...". +Refer 'panic_sys_info' section below for more details. =20 hung_task_timeout_secs =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 5ac0e66a1361..5b3a7785d3a2 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -24,6 +24,7 @@ #include #include #include +#include =20 #include =20 @@ -59,12 +60,17 @@ static unsigned long __read_mostly sysctl_hung_task_che= ck_interval_secs; static int __read_mostly sysctl_hung_task_warnings =3D 10; =20 static int __read_mostly did_panic; -static bool hung_task_show_lock; static bool hung_task_call_panic; -static bool hung_task_show_all_bt; =20 static struct task_struct *watchdog_task; =20 +/* + * A bitmask to control what kinds of system info to be printed when + * a hung task is detected, it could be task, memory, lock etc. Refer + * include/linux/sys_info.h for detailed bit definition. + */ +static unsigned long hung_task_si_mask; + #ifdef CONFIG_SMP /* * Should we dump all CPUs backtraces in a hung task event? @@ -217,11 +223,8 @@ static inline void debug_show_blocker(struct task_stru= ct *task, unsigned long ti } #endif =20 -static void check_hung_task(struct task_struct *t, unsigned long timeout, - unsigned long prev_detect_count) +static void check_hung_task(struct task_struct *t, unsigned long timeout) { - unsigned long total_hung_task; - if (!task_is_hung(t, timeout)) return; =20 @@ -231,20 +234,13 @@ static void check_hung_task(struct task_struct *t, un= signed long timeout, */ sysctl_hung_task_detect_count++; =20 - total_hung_task =3D sysctl_hung_task_detect_count - prev_detect_count; trace_sched_process_hang(t); =20 - if (sysctl_hung_task_panic && total_hung_task >=3D sysctl_hung_task_panic= ) { - console_verbose(); - hung_task_show_lock =3D true; - hung_task_call_panic =3D true; - } - /* * Ok, the task did not get scheduled for more than 2 minutes, * complain: */ - if (sysctl_hung_task_warnings || hung_task_call_panic) { + if (sysctl_hung_task_warnings) { if (sysctl_hung_task_warnings > 0) sysctl_hung_task_warnings--; pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n", @@ -259,10 +255,7 @@ static void check_hung_task(struct task_struct *t, uns= igned long timeout, " disables this message.\n"); sched_show_task(t); debug_show_blocker(t, timeout); - hung_task_show_lock =3D true; =20 - if (sysctl_hung_task_all_cpu_backtrace) - hung_task_show_all_bt =3D true; if (!sysctl_hung_task_warnings) pr_info("Future hung task reports are suppressed, see sysctl kernel.hun= g_task_warnings\n"); } @@ -302,8 +295,11 @@ static void check_hung_uninterruptible_tasks(unsigned = long timeout) { int max_count =3D sysctl_hung_task_check_count; unsigned long last_break =3D jiffies; + unsigned long total_hung_task; struct task_struct *g, *t; unsigned long prev_detect_count =3D sysctl_hung_task_detect_count; + int need_warning =3D sysctl_hung_task_warnings; + unsigned long si_mask =3D hung_task_si_mask; =20 /* * If the system crashed already then all bets are off, @@ -312,7 +308,7 @@ static void check_hung_uninterruptible_tasks(unsigned l= ong timeout) if (test_taint(TAINT_DIE) || did_panic) return; =20 - hung_task_show_lock =3D false; + rcu_read_lock(); for_each_process_thread(g, t) { =20 @@ -324,18 +320,29 @@ static void check_hung_uninterruptible_tasks(unsigned= long timeout) last_break =3D jiffies; } =20 - check_hung_task(t, timeout, prev_detect_count); + check_hung_task(t, timeout); } unlock: rcu_read_unlock(); - if (hung_task_show_lock) - debug_show_all_locks(); =20 - if (hung_task_show_all_bt) { - hung_task_show_all_bt =3D false; - trigger_all_cpu_backtrace(); + total_hung_task =3D sysctl_hung_task_detect_count - prev_detect_count; + if (!total_hung_task) + return; + + if (sysctl_hung_task_panic && total_hung_task >=3D sysctl_hung_task_panic= ) { + console_verbose(); + hung_task_call_panic =3D true; + } + + if (need_warning || hung_task_call_panic) { + si_mask |=3D SYS_INFO_LOCKS; + + if (sysctl_hung_task_all_cpu_backtrace) + si_mask |=3D SYS_INFO_ALL_BT; } =20 + sys_info(si_mask); + if (hung_task_call_panic) panic("hung_task: blocked tasks"); } @@ -434,6 +441,13 @@ static const struct ctl_table hung_task_sysctls[] =3D { .mode =3D 0444, .proc_handler =3D proc_doulongvec_minmax, }, + { + .procname =3D "hung_task_sys_info", + .data =3D &hung_task_si_mask, + .maxlen =3D sizeof(hung_task_si_mask), + .mode =3D 0644, + .proc_handler =3D sysctl_sys_info_handler, + }, }; =20 static void __init hung_task_sysctl_init(void) --=20 2.43.5 From nobody Fri Dec 19 14:37:04 2025 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F259C33B6D7 for ; Thu, 13 Nov 2025 11:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032252; cv=none; b=EOpZP9n5QeVuFstkPxyqXW+DH8QmnsAMrkdgr8bNonK/HNOTkNh6r6LODsWZ55iQ5WZ/C/17phJ46RIElAwkfFEvrEOkzA6fhNRBrEq43yL6D8a0/b5+bToIg6R8XehgRs/UC2di/l7doGkqPCjp+TEp7FuRm6itRL2Kd9iEBEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032252; c=relaxed/simple; bh=IQ0dmN8tB9hARsGwXeLWbxM8TPEDkBTC5esb4ZDfriQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NOHlkNXV0Pldt/pKJAA15+m9xR+xIvfKHn7yCQaKxxmPoKEj0NaheUb/MOfvieixrB3Ei1R8z04WXLpfcN4BrYR9KF3cU8RSNjABdiegTrFRS+cBWIoTyEcmTTCjsurcSd6os6pHfc7yRWOQELTFHoLba6UdpZBraxjwC7J5ubU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=SG4z82Cc; arc=none smtp.client-ip=115.124.30.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="SG4z82Cc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1763032242; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=VHv94C4sdpaA5LbmH2N7hKRmkpD5b1808wwb54YTPH4=; b=SG4z82CcAkeBlZ09bXO49/CCg359O3gclZv9f60erMwvsxrw69ObnrZM/OLeUpNH0hu5pzuLXCCd6+qKyEQobA/eJYCHtQm7Sd4S3/wLi8QIr21nvwzxP1Z+PYMAQcny3VjTwhSC0H2Pj6hXYGZgmq1K0xUQdXh3X2RPRshzF2A= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WsJMt-0_1763032241 cluster:ay36) by smtp.aliyun-inc.com; Thu, 13 Nov 2025 19:10:41 +0800 From: Feng Tang To: Andrew Morton , Petr Mladek , Lance Yang , Jonathan Corbet , paulmck@kernel.org, Steven Rostedt , linux-kernel@vger.kernel.org Cc: Feng Tang Subject: [PATCH v2 3/4] watchdog: add sys_info sysctls to dump sys info on system lockup Date: Thu, 13 Nov 2025 19:10:38 +0800 Message-Id: <20251113111039.22701-4-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20251113111039.22701-1-feng.tang@linux.alibaba.com> References: <20251113111039.22701-1-feng.tang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When soft/hard lockup happens, developers may need different kinds of system information (call-stacks, memory info, locks, etc.) to help debugging. Add 'softlockup_sys_info' and 'hardlockup_sys_info' sysctl knobs to take human readable string like "tasks,mem,timers,locks,ftrace,...", and when system lockup happens, all requested information will be printed out. (refer kernel/sys_info.c for more details). Signed-off-by: Feng Tang Reviewed-by: Petr Mladek --- Documentation/admin-guide/sysctl/kernel.rst | 5 +++ kernel/watchdog.c | 44 +++++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index 45b4408dad31..176520283f1a 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -582,6 +582,11 @@ if leaking kernel pointer values to unprivileged users= is a concern. When ``kptr_restrict`` is set to 2, kernel pointers printed using %pK will be replaced with 0s regardless of privileges. =20 +softlockup_sys_info & hardlockup_sys_info +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +A comma separated list of extra system information to be dumped when +soft/hard lockup is detected, for example, "tasks,mem,timers,locks,...". +Refer 'panic_sys_info' section below for more details. =20 modprobe =3D=3D=3D=3D=3D=3D=3D=3D diff --git a/kernel/watchdog.c b/kernel/watchdog.c index 659f5844393c..bbd11562e4c4 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -25,6 +25,7 @@ #include #include #include +#include =20 #include #include @@ -65,6 +66,13 @@ int __read_mostly sysctl_hardlockup_all_cpu_backtrace; unsigned int __read_mostly hardlockup_panic =3D IS_ENABLED(CONFIG_BOOTPARAM_HARDLOCKUP_PANIC); =20 +/* + * bitmasks to control what kinds of system info to be printed when + * hard lockup is detected, it could be task, memory, lock etc. + * Refer include/linux/sys_info.h for detailed bit definition. + */ +static unsigned long hardlockup_si_mask; + #ifdef CONFIG_SYSFS =20 static unsigned int hardlockup_count; @@ -178,11 +186,15 @@ static void watchdog_hardlockup_kick(void) =20 void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs) { + int hardlockup_all_cpu_backtrace; + if (per_cpu(watchdog_hardlockup_touched, cpu)) { per_cpu(watchdog_hardlockup_touched, cpu) =3D false; return; } =20 + hardlockup_all_cpu_backtrace =3D (hardlockup_si_mask & SYS_INFO_ALL_BT) ? + 1 : sysctl_hardlockup_all_cpu_backtrace; /* * Check for a hardlockup by making sure the CPU's timer * interrupt is incrementing. The timer interrupt should have @@ -205,7 +217,7 @@ void watchdog_hardlockup_check(unsigned int cpu, struct= pt_regs *regs) * Prevent multiple hard-lockup reports if one cpu is already * engaged in dumping all cpu back traces. */ - if (sysctl_hardlockup_all_cpu_backtrace) { + if (hardlockup_all_cpu_backtrace) { if (test_and_set_bit_lock(0, &hard_lockup_nmi_warn)) return; } @@ -234,12 +246,13 @@ void watchdog_hardlockup_check(unsigned int cpu, stru= ct pt_regs *regs) trigger_single_cpu_backtrace(cpu); } =20 - if (sysctl_hardlockup_all_cpu_backtrace) { + if (hardlockup_all_cpu_backtrace) { trigger_allbutcpu_cpu_backtrace(cpu); if (!hardlockup_panic) clear_bit_unlock(0, &hard_lockup_nmi_warn); } =20 + sys_info(hardlockup_si_mask & ~SYS_INFO_ALL_BT); if (hardlockup_panic) nmi_panic(regs, "Hard LOCKUP"); =20 @@ -330,6 +343,13 @@ static void lockup_detector_update_enable(void) int __read_mostly sysctl_softlockup_all_cpu_backtrace; #endif =20 +/* + * bitmasks to control what kinds of system info to be printed when + * soft lockup is detected, it could be task, memory, lock etc. + * Refer include/linux/sys_info.h for detailed bit definition. + */ +static unsigned long softlockup_si_mask; + static struct cpumask watchdog_allowed_mask __read_mostly; =20 /* Global variables, exported for sysctl */ @@ -746,7 +766,7 @@ static enum hrtimer_restart watchdog_timer_fn(struct hr= timer *hrtimer) unsigned long touch_ts, period_ts, now; struct pt_regs *regs =3D get_irq_regs(); int duration; - int softlockup_all_cpu_backtrace =3D sysctl_softlockup_all_cpu_backtrace; + int softlockup_all_cpu_backtrace; unsigned long flags; =20 if (!watchdog_enabled) @@ -758,6 +778,9 @@ static enum hrtimer_restart watchdog_timer_fn(struct hr= timer *hrtimer) if (panic_in_progress()) return HRTIMER_NORESTART; =20 + softlockup_all_cpu_backtrace =3D (softlockup_si_mask & SYS_INFO_ALL_BT) ? + 1 : sysctl_softlockup_all_cpu_backtrace; + watchdog_hardlockup_kick(); =20 /* kick the softlockup detector */ @@ -846,6 +869,7 @@ static enum hrtimer_restart watchdog_timer_fn(struct hr= timer *hrtimer) } =20 add_taint(TAINT_SOFTLOCKUP, LOCKDEP_STILL_OK); + sys_info(softlockup_si_mask & ~SYS_INFO_ALL_BT); if (softlockup_panic) panic("softlockup: hung tasks"); } @@ -1197,6 +1221,13 @@ static const struct ctl_table watchdog_sysctls[] =3D= { .extra1 =3D SYSCTL_ZERO, .extra2 =3D SYSCTL_ONE, }, + { + .procname =3D "softlockup_sys_info", + .data =3D &softlockup_si_mask, + .maxlen =3D sizeof(softlockup_si_mask), + .mode =3D 0644, + .proc_handler =3D sysctl_sys_info_handler, + }, #ifdef CONFIG_SMP { .procname =3D "softlockup_all_cpu_backtrace", @@ -1219,6 +1250,13 @@ static const struct ctl_table watchdog_sysctls[] =3D= { .extra1 =3D SYSCTL_ZERO, .extra2 =3D SYSCTL_ONE, }, + { + .procname =3D "hardlockup_sys_info", + .data =3D &hardlockup_si_mask, + .maxlen =3D sizeof(hardlockup_si_mask), + .mode =3D 0644, + .proc_handler =3D sysctl_sys_info_handler, + }, #ifdef CONFIG_SMP { .procname =3D "hardlockup_all_cpu_backtrace", --=20 2.43.5 From nobody Fri Dec 19 14:37:04 2025 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1914233892C for ; Thu, 13 Nov 2025 11:10:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032249; cv=none; b=oqXkhd3bh3gKyKBiFeYrJt4/hr1LCn5+xwQwX+xWVvYoNY7LyGwWlB7jEpZvnMuJN+BTua5PGV29oRZF+CO8Ejnvbpsfvwp4iX7KfUEtIBQX/fzzMtvgRRQxkIQkHASn47lHrKLD2S3IUr94n6HVrl8IORZS7hkf8jgMk6Hejes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032249; c=relaxed/simple; bh=so546Z28Y0ozfRF4Kux5DxMbZgVLjZKYR340NOkaPTw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f1JevUQqddwgH5HGRq/+gNeryY/5yJr78dGD81A8S7GxhhVHwLdDP8Hbw863WC3VLPx7Q9KZ1s0UPWnrbB6jmhhCLz4SGsg9RD/+JKzr8gfTM7UBIrl6i9eRpcCgwuYQ9nqX/lCUeCP0sbVJeKLJ0z8D3pr8CEEgHoNtT481Bbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=NimiYNc1; arc=none smtp.client-ip=115.124.30.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="NimiYNc1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1763032244; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=lAttCcXeOxPRYUKvCBkOyAH/Ei+jFUOesij4DVKlHXA=; b=NimiYNc1QLAaoLG4hyzt20gP/6j7zyrTqHbYvKPaERqpkBul5wyrbc0sTRtMSS82Id42EJnFj5DUyNByOrBFqYCDKiDObsQ5/UGZhRbDPvQHO+UAe6FoTDNYJi9bUu5GPR+iTGmXv0EIB7Dcw9MaBF8MBBiqBmEmmCpBZnlWq1w= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WsJMVsJ_1763032242 cluster:ay36) by smtp.aliyun-inc.com; Thu, 13 Nov 2025 19:10:42 +0800 From: Feng Tang To: Andrew Morton , Petr Mladek , Lance Yang , Jonathan Corbet , paulmck@kernel.org, Steven Rostedt , linux-kernel@vger.kernel.org Cc: Feng Tang Subject: [PATCH v2 4/4] sys_info: add a default kernel sys_info mask Date: Thu, 13 Nov 2025 19:10:39 +0800 Message-Id: <20251113111039.22701-5-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20251113111039.22701-1-feng.tang@linux.alibaba.com> References: <20251113111039.22701-1-feng.tang@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Which serves as a global default sys_info mask. When users want the same system information for many error cases (panic, hung, lockup ...), they can chose to set this global knob only once, while not setting up each individual sys_info knobs. This just adds a 'lazy' option, and doesn't change existing kernel behavior as the mask is 0 by default. Suggested-by: Andrew Morton Signed-off-by: Feng Tang --- Documentation/admin-guide/sysctl/kernel.rst | 9 ++++++ lib/sys_info.c | 31 ++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index 176520283f1a..239da22c4e28 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -521,6 +521,15 @@ default), only processes with the CAP_SYS_ADMIN capabi= lity may create io_uring instances. =20 =20 +kernel_sys_info +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +A comma separated list of extra system information to be dumped when +soft/hard lockup is detected, for example, "tasks,mem,timers,locks,...". +Refer 'panic_sys_info' section below for more details. + +It serves as the default kernel control knob, which will take effect +when a kernel module calls sys_info() with parameter=3D=3D0. + kexec_load_disabled =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/lib/sys_info.c b/lib/sys_info.c index 323624093e54..f32a06ec9ed4 100644 --- a/lib/sys_info.c +++ b/lib/sys_info.c @@ -24,6 +24,13 @@ static const char * const si_names[] =3D { [ilog2(SYS_INFO_BLOCKED_TASKS)] =3D "blocked_tasks", }; =20 +/* + * Default kernel sys_info mask. + * If a kernel module calls sys_info() with "parameter =3D=3D 0", then + * this mask will be used. + */ +static unsigned long kernel_si_mask; + /* Expecting string like "xxx_sys_info=3Dtasks,mem,timers,locks,ftrace,...= " */ unsigned long sys_info_parse_param(char *str) { @@ -110,9 +117,26 @@ int sysctl_sys_info_handler(const struct ctl_table *ro= _table, int write, else return sys_info_read_handler(&table, buffer, lenp, ppos, ro_table->data); } + +static const struct ctl_table sys_info_sysctls[] =3D { + { + .procname =3D "kernel_sys_info", + .data =3D &kernel_si_mask, + .maxlen =3D sizeof(kernel_si_mask), + .mode =3D 0644, + .proc_handler =3D sysctl_sys_info_handler, + }, +}; + +static int __init sys_info_sysctl_init(void) +{ + register_sysctl_init("kernel", sys_info_sysctls); + return 0; +} +subsys_initcall(sys_info_sysctl_init); #endif =20 -void sys_info(unsigned long si_mask) +static void __sys_info(unsigned long si_mask) { if (si_mask & SYS_INFO_TASKS) show_state(); @@ -135,3 +159,8 @@ void sys_info(unsigned long si_mask) if (si_mask & SYS_INFO_BLOCKED_TASKS) show_state_filter(TASK_UNINTERRUPTIBLE); } + +void sys_info(unsigned long si_mask) +{ + __sys_info(si_mask ? : kernel_si_mask); +} --=20 2.43.5