public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Aaron Tomlin <atomlin@atomlin.com>
To: akpm@linux-foundation.org, lance.yang@linux.dev,
	mhiramat@kernel.org, gregkh@linuxfoundation.org
Cc: sean@ashe.io, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] hung_task: Provide runtime reset interface for hung task detector
Date: Mon,  8 Dec 2025 23:12:18 -0500	[thread overview]
Message-ID: <20251209041218.1583600-3-atomlin@atomlin.com> (raw)
In-Reply-To: <20251209041218.1583600-1-atomlin@atomlin.com>

This patch introduces a new write-only sysfs file,
hung_task_detect_count_reset, directly under /sys/kernel/.
This file exposes an explicit control point for resetting the
/proc/sys/kernel/hung_task_detect_count counter.

Currently, this counter persists across the lifetime of the running system.
The new interface allows administrators to reset the count after investigating
an incident without requiring a full system reboot, making it easier to track
new hung task events after intervention.

The store handler enforces strict input validation, only accepting the value
"1" to execute the reset operation.

Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
 .../sysfs-kernel-hung_task_detect_count_reset |  8 +++++
 kernel/hung_task.c                            | 31 +++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count_reset

diff --git a/Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count_reset b/Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count_reset
new file mode 100644
index 000000000000..41dd30171c9c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-hung_task_detect_count_reset
@@ -0,0 +1,8 @@
+What:		/sys/kernel/hung_task_detect_count_reset
+Date:		Dec 2025
+KernelVersion:	6.19
+Contact:	Linux kernel mailing list <linux-kernel@vger.kernel.org>
+Description:
+        A write-only interface to reset the persistent counter of tasks
+        detected as hung since boot. Write 1 to clear the counter and
+        restart diagnostic tracking without rebooting.
diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index d5109a0994c5..035652dabf10 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -539,6 +539,37 @@ static int watchdog(void *dummy)
 	return 0;
 }
 
+#ifdef CONFIG_SYSFS
+static ssize_t hung_task_detect_count_reset_store(struct kobject *kobj,
+						  struct kobj_attribute *attr,
+						  const char *buf, size_t count)
+{
+	unsigned long val;
+	int ret;
+
+	ret = kstrtoul(buf, 0, &val);
+	if (ret)
+		return ret;
+	if (val != 1)
+		return -EINVAL;
+
+	WRITE_ONCE(sysctl_hung_task_detect_count, 0);
+
+	return count;
+}
+
+static struct kobj_attribute hung_task_detect_count_reset_attr = __ATTR_WO(hung_task_detect_count_reset);
+
+static __init int hung_task_detect_sysfs_init(void)
+{
+	sysfs_add_file_to_group(kernel_kobj,
+				&hung_task_detect_count_reset_attr.attr,
+				NULL);
+	return 0;
+}
+late_initcall(hung_task_detect_sysfs_init);
+#endif
+
 static int __init hung_task_init(void)
 {
 	atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
-- 
2.51.0


  parent reply	other threads:[~2025-12-09  4:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-09  4:12 [PATCH 0/2] hung_task: Provide runtime reset interface for hung task detector Aaron Tomlin
2025-12-09  4:12 ` [PATCH 1/2] hung_task: Consolidate hung task warning into an atomic log block Aaron Tomlin
2025-12-09  5:12   ` Lance Yang
2025-12-09  6:56     ` Greg KH
2025-12-09 22:14       ` Aaron Tomlin
2025-12-10  7:37         ` Greg KH
2025-12-10 13:08         ` Petr Mladek
2025-12-09 22:11     ` Aaron Tomlin
2025-12-09  4:12 ` Aaron Tomlin [this message]
2025-12-09  4:54   ` [PATCH 2/2] hung_task: Provide runtime reset interface for hung task detector Lance Yang
2025-12-09 22:06     ` Aaron Tomlin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251209041218.1583600-3-atomlin@atomlin.com \
    --to=atomlin@atomlin.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lance.yang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=sean@ashe.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox