From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 642E834EF1F for ; Wed, 17 Dec 2025 12:48:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765975693; cv=none; b=VlDqoQ1ghDzKLNuMGYPg7oJphmdiC/7KPrBpPE6131tsn2vVgu18vRp8l+okDSImD9qHD0CPnRYxC+iGqEJrziU2OMuFfPTzkUnlLeNpgnrHH6FfnQHdyeQJmryb4wiypPWh3xU5Uw4g3juHgk4HqpmbKjNBbuHFnN/sH3kAErs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765975693; c=relaxed/simple; bh=JEI07Cb9ERy/EUiy4TzYnn4MEbWQGWIfSSnMWGuXZR0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q/YT0kedAoUSrNwJTE69otPwFX3bA52UfFw4G5D6QKDKjUVn9lNH7L88VRWHNalYKGm40kGPgca+jRd2NSGA9LqZzZeW0bUdauVrMDbw34jnpxx+2rfpzBbu5pqQGNv2gdaD8yViXoTzzkVYDhZcOu69DNk7ZgiC0ubmB50DLoI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=cJGiaTvl; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="cJGiaTvl" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-430f57cd471so1984777f8f.0 for ; Wed, 17 Dec 2025 04:48:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1765975690; x=1766580490; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ZAFo1sXRC/FmIx8CVopmBeAWMxNSmL8p3LNe9/dE5JU=; b=cJGiaTvlm/5A0UBG1hT50t447Ymc9u52TU3X/0Em/zCsByDPRI5sHEzBxNhTZRANw3 xvVeSpO284v73RZxnW4SI1sTsTz8x3wfilWn0jGYa8qoO3ByfMnn+AiZNhRsGCFkhPV2 /2oqnz7dI99JzU7PU6Phoaand70fIJOQEP3wovSiYHu9wDIxhyLaLfornH13zvRKO1Io AjOuu9NUhbjo+6PwEmEk0U47azwVVGdYz20UAnK6imvm31QQGpBq5/oNQ83IRpYAxsq+ GgKunXWWoJc9MXeOj7vyhQfM3Rm4dLrEyi+pGN/7JbihFNss0YsLO2Q5a3QCWYLfFnut 2OPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765975690; x=1766580490; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZAFo1sXRC/FmIx8CVopmBeAWMxNSmL8p3LNe9/dE5JU=; b=mGrz9Dhfx0OdZEtaPFY5e7DFzm7hm7VPLG8yij9pBeICb+BYy1Z+R+fQO9P2NxQUmv hAy3AgiKwnEOmoLf0CIzRrGzXbD5WxsPPHwED8c4+CSKthw0IZSDXCNDD6CLDLNU8VVH xKsPb3TIY8e69IC4hKjNIFxvDwRuMkRFo0W7fF+GbEptO3xE92nWXqwsr8MadKVIpbCM 3FQK7yTREZY0o+K2zX5T/QwHGP2Zrvw1+14DwUnQ2cIAk3TWDR44VeFh+UNyzxN3f8cb kD0uJJX1Fe1+spv5st7efGi9UopZYynL/5QE1ZbvgAxsPuTe2mD04uxGzcrsh5PvuFHu YCIg== X-Forwarded-Encrypted: i=1; AJvYcCUubqdmsRZfAmmpd01dlVuQfLBDQ3Nikxv85eA+gVDDWzHK1PPg+hCdLP1witfaLcDSMO8E2pFCgTWojU8=@vger.kernel.org X-Gm-Message-State: AOJu0YwtJqv6GKF0HhW62sAlKsVTl7SDZ104+o/h+Pagj9wRfMTQRJQZ yyotDJyFtsKHSTwLxRc3khiBQBQnonJhrTrztCej14LfNjw2X8Ne/OJy8ph3Vr57q1OlSlpvSSg p8/U/ X-Gm-Gg: AY/fxX56EUpxVOSNcJrsjfBMwzv07Ce/ji8m4FQ2VQD0BtJ8ix0aNFQztXueiyuGa4U Yl4xeKCYsK+8T48S8FjhM3gbgx7vGHAPJJ6Lh6rLAtts5pHEVIom0qxXOGQPKUctYeiI3PA+7Ni 0rtqB5o9TPSCdWSetosBRXBDjVnIs3pTMisbkyt1qmPfPyD2d+ZwwsWGz1K6+in16X8Z+H5nH5y reUN8O6oOUh2D44O5vN0gPJDXKZsVee+OqjDnmUoyQxlzzgG2CnQDvDgfwr3j5cZTItRGnT2pXH lSz4qI85dxIbh4OBlXdTM2igSqBtyypd1IwhnqYBjYAq9lpaoZqXYOpYlTjIXD3Bcri7RmhPsWQ eItcBJZJjCI8QGIiMTRdL/eS1LhlGq1rH+znJdXmYW4mPQXVvjkaM4Q5Xxo/MIc4XoxcG96lKQ+ 11T18rSzM6R5Vt6w== X-Google-Smtp-Source: AGHT+IGE5xOj9+SIb6VHfywcHBoUymXMlHMsY8kiHeCQvMRTf5ciIDw6mMkpW6IYz07M5mCmPd9AfA== X-Received: by 2002:a5d:5d0e:0:b0:430:f3ab:56a7 with SMTP id ffacd0b85a97d-430f3ab5944mr15067044f8f.49.1765975689522; Wed, 17 Dec 2025 04:48:09 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4310ada846bsm4537517f8f.9.2025.12.17.04.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 04:48:09 -0800 (PST) Date: Wed, 17 Dec 2025 13:48:07 +0100 From: Petr Mladek To: Aaron Tomlin Cc: akpm@linux-foundation.org, lance.yang@linux.dev, mhiramat@kernel.org, gregkh@linuxfoundation.org, sean@ashe.io, Joel Granados , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] hung_task: Enable runtime reset of hung_task_detect_count Message-ID: References: <20251216030036.1822217-1-atomlin@atomlin.com> <20251216030036.1822217-3-atomlin@atomlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251216030036.1822217-3-atomlin@atomlin.com> 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. > + *ppos += *lenp; > + > + return 0; > +} I have played with the code. The diff on top of this patch would look like: diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 01ce46a107b0..ebb3dfd0b148 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -379,7 +379,7 @@ static long hung_timeout_jiffies(unsigned long last_checked, /** * 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 + * @dir: 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 @@ -388,16 +388,29 @@ static long hung_timeout_jiffies(unsigned long last_checked, * 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, +static int proc_dohung_task_detect_count(const struct ctl_table *table, int dir, void *buffer, size_t *lenp, loff_t *ppos) { - if (!write) - return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); + unsigned long detect_count = READ_ONCE(sysctl_hung_task_detect_count); + struct ctl_table t; + int err; - WRITE_ONCE(sysctl_hung_task_detect_count, 0); - *ppos += *lenp; + t = *table; + t.data = &detect_count; - return 0; + err = proc_doulongvec_minmax(&t, dir, buffer, lenp, ppos); + if (err < 0) + return err; + + if (SYSCTL_USER_TO_KERN(dir)) { + /* The only valid value for clearing is zero. */ + if (detect_count) + return -EINVAL; + + WRITE_ONCE(sysctl_hung_task_detect_count, 0); + } + + return err; } /* Best Regards, Petr