From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 2DE0835E54E for ; Wed, 17 Dec 2025 13:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765977675; cv=none; b=qg/0KiNTPm05XnRmyWz74A4nbErizgsMr7M4z4/wOccbGRifQlt/JYK6rU+0hsD4BoawT+yoz+9xW84j+l4WBwxzkiP3ojWLSVErIweZYVp5il34DD2l5o/z2/ADeUwog+FvLUUpc5oEXz6hncvTTInsM0sf0rHvdYLvWLXw7XY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765977675; c=relaxed/simple; bh=jPSEje1617QVP0f9i+NwoPbwFro5hx5iR3qjW+1Ttl4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GF/j2E+HJyrThLgBPFGbPAco4ZRsBZB4DUt4cdtNTbHDFKtKMlNBA3yJLbpIYjBJkWe45UWBt/AKyOW+bGtiOPLuvXb8dDO13LT7s28Y/VODVg1arSo7tCfh/v7eP5JJDpvO6B2eqAuBoC25ZJvzdqDmtWeDANNC//EaWU3TSC8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=q6vyi0bm; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="q6vyi0bm" Message-ID: <23d396d9-c055-4385-8a0f-c16fd24bedba@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765977671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qyUf0gDFdpM4MLSIhyUmzrFQKhOTBLL4le2+X09+pO0=; b=q6vyi0bmN/WR1bE0mCWEcXs0NGeV0mltNlDgrufnTuTaITy8HpzzQDl35iKUvttozHJmZL 5TOSmzDNofkCdEM7fHw3xKXY90PeJg84CSedVxMZdxXxoTjGj9UjrOBzeZVn6KG/jcRN9+ RQ9AQUKUrL0s2E39Prjo/W88JAMzmiw= Date: Wed, 17 Dec 2025 21:21:01 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v3 2/2] hung_task: Enable runtime reset of hung_task_detect_count To: Petr Mladek Cc: akpm@linux-foundation.org, mhiramat@kernel.org, gregkh@linuxfoundation.org, sean@ashe.io, Joel Granados , linux-kernel@vger.kernel.org, Aaron Tomlin References: <20251216030036.1822217-1-atomlin@atomlin.com> <20251216030036.1822217-3-atomlin@atomlin.com> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2025/12/17 20:48, Petr Mladek wrote: > Adding Joel into Cc. He is improving the sysctl API... > > On Mon 2025-12-15 22:00:36, Aaron Tomlin wrote: >> Introduce support for writing to /proc/sys/kernel/hung_task_detect_count. >> >> Writing any value to this file atomically resets the counter of detected >> hung tasks to zero. This grants system administrators the ability to clear >> the cumulative diagnostic history after resolving an incident, simplifying >> monitoring without requiring a system restart. >> >> --- a/Documentation/admin-guide/sysctl/kernel.rst >> +++ b/Documentation/admin-guide/sysctl/kernel.rst >> @@ -418,7 +418,7 @@ hung_task_detect_count >> ====================== >> >> Indicates the total number of tasks that have been detected as hung since >> -the system boot. >> +the system boot. The counter can be reset to zero when written to. >> >> This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled. >> >> diff --git a/kernel/hung_task.c b/kernel/hung_task.c >> index 5902573200c0..01ce46a107b0 100644 >> --- a/kernel/hung_task.c >> +++ b/kernel/hung_task.c >> @@ -375,6 +375,31 @@ static long hung_timeout_jiffies(unsigned long last_checked, >> } >> >> #ifdef CONFIG_SYSCTL >> + >> +/** >> + * proc_dohung_task_detect_count - proc handler for hung_task_detect_count >> + * @table: Pointer to the struct ctl_table definition for this proc entry >> + * @write: Flag indicating the operation >> + * @buffer: User space buffer for data transfer >> + * @lenp: Pointer to the length of the data being transferred >> + * @ppos: Pointer to the current file offset >> + * >> + * This handler is used for reading the current hung task detection count >> + * and for resetting it to zero when a write operation is performed. >> + * Returns 0 on success or a negative error code on failure. >> + */ >> +static int proc_dohung_task_detect_count(const struct ctl_table *table, int write, >> + void *buffer, size_t *lenp, loff_t *ppos) >> +{ >> + if (!write) >> + return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); > > There have been some changes in the sysctl API recently, see > https://lore.kernel.org/lkml/20251016-jag-sysctl_conv-v2-0-a2f16529acc4@kernel.org/ > > They are backward compatible, so the above code works. But it would be > nice to make it up-to-date, namely: > > + Replace "write" with "dir" > + Use SYSCTL_USER_TO_KERN(dir) instead of (!write) > > >> + WRITE_ONCE(sysctl_hung_task_detect_count, 0); > > I might be too conservative. But it looks weird to allow clearing the > value by any write. It would be better to return -EINVAL for non-zero > values. This would require using a copy of struct ctl_table and read > the value into a temporary variable. That's okay, I think. See vmstat_refresh() for a similar pattern - it accepts any write value to trigger the refresh operation without validating the specific value ;)