From nobody Mon Feb 9 00:55:17 2026 Received: from LO2P265CU024.outbound.protection.outlook.com (mail-uksouthazon11021113.outbound.protection.outlook.com [52.101.95.113]) (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 9D20231BC9E for ; Sun, 25 Jan 2026 13:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.95.113 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769349548; cv=fail; b=cAELDXWsTmZGPg15n9U2h8OIMplEAxgH+cuxA/FGtvviRQnJCZbqYILeU8rdZuqCD9pIOQ9RXivigJdOGWQSG7xYDbbNR2bjxyi3oN7D8fnlMIjJ1JZqAwXPj1vI4eYLYiJ8/yk3+BoVxSZHU/b08BukLgyRROFJzf/PY6s8Zww= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769349548; c=relaxed/simple; bh=KVN8SC4lzkIkpjdzB3QIk4tuB0xsvsOUrNRqjP46rO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=fBK3ZHT6iCZ9/6GrLgRNWzowpkKnqboT/MXb3NLH8ABgP0+j/x/v+Xo9Tn+4c7arfBIu3vSBRv1JDC1/iJU3Ge9it1EAWAiZ9kSljNaKJBsu/qotc3mZF6Q1LB/CfsfbTKhW5Kmud5mleuQzEt60/Mt6WlF8+QKqaS3Qc9yEajE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomlin.com; spf=pass smtp.mailfrom=atomlin.com; arc=fail smtp.client-ip=52.101.95.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=atomlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=atomlin.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pSuFLnB4UMBiQBarUeOb+mFM+LgHgsbElPf0L9zaFLXm0W2qInKxICBy6E6z+11Zy1V6uLizHhiB5wXXErOD8sf+H1xNClvts/p2Q7JWq8ZO/FTvpRzSgk3VHehQjH3ICpCU3vRJV8zhuGMky+09ukouPcbDLiFvE4b1678f7MXUKNTdB1qVC8LMZi0ur6BtnEvIfUmD98EiphrcenYKuzrbJZZsER542i+ERAfjUMh5hN5UvGikRCEEzZTHxCXzB7yZwY0DfhE1NnV4S0zfXtavVcXb9CZdK2n2dDZGw3J8Xhg9ichgEmWZlSKHESfyA4Tm5WkR8SqljonLQc2NZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LYCSl9dTuxD2bbhfBUCEiFJBi+WNF6Co2d+akOC8/7c=; b=s2v/NYoWJ975llX7ucdRZ+DaZFg2TWOBWYHWRW8lcSgnxoKo9qKNMxvGB18DwhWwXuIVElQ0nr2yhWdmezkFavNtRVsuBsX4yLY7cKJiRnIefne0pQHA69jcSijFIWhi+qBHiUdUv2CNSbu8+vJHNhSQryHm7wUOLT+SebZcb9Ecc7sR7E5jR6aMFwq9BVHS1WJ70hQ2bfLGAxaVCJvm8v7lh2/1K88mmgiq7+Bs6OxqqEKERiBnPsAq32hl0+/d4QLPAbfRW+I7TxingExlffDy0S4o++Hr1LYwHCRhgOqwlhZdiOf3+Tu8YQ0Dz3Kr1qf6NYWiaCPRaeMMa9KI1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=atomlin.com; dmarc=pass action=none header.from=atomlin.com; dkim=pass header.d=atomlin.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=atomlin.com; Received: from CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:70::10) by LOYP123MB3104.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:e2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.9; Sun, 25 Jan 2026 13:59:03 +0000 Received: from CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM ([fe80::de8e:2e4f:6c6:f3bf]) by CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM ([fe80::de8e:2e4f:6c6:f3bf%5]) with mapi id 15.20.9542.010; Sun, 25 Jan 2026 13:59:03 +0000 From: Aaron Tomlin To: akpm@linux-foundation.org, lance.yang@linux.dev, mhiramat@kernel.org, gregkh@linuxfoundation.org, pmladek@suse.com, joel.granados@kernel.org Cc: neelx@suse.com, sean@ashe.io, mproche@gmail.com, chjohnst@gmail.com, nick.lange@gmail.com, linux-kernel@vger.kernel.org Subject: [v7 PATCH 2/2] hung_task: Enable runtime reset of hung_task_detect_count Date: Sun, 25 Jan 2026 08:58:48 -0500 Message-ID: <20260125135848.3356585-3-atomlin@atomlin.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260125135848.3356585-1-atomlin@atomlin.com> References: <20260125135848.3356585-1-atomlin@atomlin.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9PR03CA0202.namprd03.prod.outlook.com (2603:10b6:408:f9::27) To CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:70::10) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CWLP123MB3523:EE_|LOYP123MB3104:EE_ X-MS-Office365-Filtering-Correlation-Id: 365a5de8-4cb9-40c9-638b-08de5c19e5d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?bWW2tr8KUwYHi0nHZzOy3xdVquAga+1N0nSd5bCRpn+jrp4T2h3JfsF6jmVX?= =?us-ascii?Q?F7l2BbtmRfRUvNNygGza2ULebE828YguxUuHO3A/CjaiR5u55jJrkHxYp6fj?= =?us-ascii?Q?E8IrOgfFseh+H2voR3W+1X7wVtk3goiF/TmFzYAnA7zFo7hXuYO3cZgvbw4T?= =?us-ascii?Q?2i9TwbJ5TeSoNYzrzbe+B1j53hRcGoEMagdreBVNiyzYlJ1KJij5ykKXuZDA?= =?us-ascii?Q?VnAwlPo3s3RHOKFeEmr6nEcCV4v29UNx3A3HgalVA80W7dVR/VSbkhlX4jR/?= =?us-ascii?Q?B9+wZl1njPrEU7oQAdTWMO8f23sjAV3784UwC+4n2bLNNJegUgWQAh0uUxNm?= =?us-ascii?Q?wrp6hUA0pXE1Vla+ErsP2qvNa2jFk18zms9vDB7sYv/FRmor3zAW5DbZELyl?= =?us-ascii?Q?2habo9yn3FR0NbgjWWXPfkfUV8yw3YoqQJDv04G4GZIJi+aZZzZTstrbgfu4?= =?us-ascii?Q?MhkmazYnqojxIQWjK0TWWWx0pXcTVVShZMe6uIBwjA+Enode8/xawhJ+iNEA?= =?us-ascii?Q?O28zNHbYXZCoCkY7IfBgsM8UrClxuJs++dDwju19noGD3zURN3qrTLEegA3M?= =?us-ascii?Q?EcdrJbACllXgIteZCnBMRTDthibWsd04eos5OpExUGDRrNs1zSTeaXroYkxY?= =?us-ascii?Q?TikRoaJCfy+eWWyGV/yFEasZjGh9n1isCaxhrrH51rr1CMbhB9gB2Xc3OzY/?= =?us-ascii?Q?PztKCw7Ua8YNCxPi4Ng1L81AruqpO9fxVrmqKmYDAf66tYKzy+okMC5US1VS?= =?us-ascii?Q?nfHBoigfoJWEQWPt0IdNo+t7LC5ECnV/i9OGO8AJL+VWFp8Izg1aeVpBCstU?= =?us-ascii?Q?uAOXoUYgwPqomC+1/8GmGlfhGbAlbU2icwfTb/dUne7NXx1Nn4tH3Tk7Tz26?= =?us-ascii?Q?fJhFd2whGDNPBFiyoJ1B8nuZerNQJf9pGZ+KOzSJHxN4sXnj7b1JW/hmCMTB?= =?us-ascii?Q?7nn9kaNf7kuhn6J3u3zfhos8/OBw0HokaZJU5etBzjr/Ge19d8EBQhXyqSRI?= =?us-ascii?Q?L995uBBUFAVJT19TuW6/9Dd6kvJUmfUom4MjkmzkVXTiRs1jHtRvRjSH/AQL?= =?us-ascii?Q?YnQNjyuGztyfoMulhxHPf9DzY8CbIZhFYGxhSMNp0JnmGHHrRkYjaIjTP25E?= =?us-ascii?Q?rcggrEcDVp+rNEAP5XUznvf2cobNlebYyzWwnRqD8CwJTjkfrzqc8s2yPLQ9?= =?us-ascii?Q?E3P4ObnvbDu7QbSL4njwgkj6pW6Q9IadqOkqAVAs5tsl2flrSDskDTEJzglc?= =?us-ascii?Q?Uql7hpHoXO0gbAE/l/VjwpoRRQOOYUg8d77BCgMO2DR0qdjkp++1lW44q7vP?= =?us-ascii?Q?5wsxnr6AmDgeLr8Hc5RgeE333/XhCWPwwiq5Nv4AiYmJobFT6qupDZnB/RCZ?= =?us-ascii?Q?ey7Sl9Vhb2hnp9Bs+wZGZKG88SnX4SZZZNnumdn91fUkvXgP5FnZdHnuRRMa?= =?us-ascii?Q?E2/w0A6lMg7eRp86ffzbyVDNZ1ox/kSF4KPOgqxFxnQGaRmdt9jKwA+9Uxn5?= =?us-ascii?Q?gFjTPXAgLoIRv3A1iwDxUDBgQzjn6n2CAW29NJsfJPiYTNsgEDZrEx8fK6Lp?= =?us-ascii?Q?PfEQU28GWhLPL9vveic=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?7nFj5uTAXgKZzdE0W2+UrzSx1xOXDCnjcyO5Zwc/73cRJ0YxBu3XniJggIvp?= =?us-ascii?Q?iUsdg0jp3FDteKOx/ZKgWzAymJMINXkwdMCBNp7pr9w6SfQXnW78NMuzZZgQ?= =?us-ascii?Q?f8wUvYb1CekGfuOda+lARAAYVAWNNrlu4Yt1pdEA1mA1S07CTAU7UsHd0Hql?= =?us-ascii?Q?LwMUu43C0h81vWJvGuOrwq7GvlpD4DclcTe+QnxwigBBxnGgQT0eZDFzupMm?= =?us-ascii?Q?PvtoPq2ramNWZKQFxq+bs0KWqSPHwpInbRdUJgZ8E2igAwlxUeeq7HNWMDOi?= =?us-ascii?Q?fjcfOfjPNWuWtNgkayFzATLAbEX4bivMz/yTSpDTVszcS8zgBRqO7z2qRQHg?= =?us-ascii?Q?5NphSxFXvIrJlJPu6KOl3T5xAM1aaVrN1JRmrnPat8On36HvOQwBuvoL62FB?= =?us-ascii?Q?dR0Lq3dhkvrsy+7IzKFYWsC9pKig7WuidJSMAKCnwLQhfppTi5SASiBo9JYe?= =?us-ascii?Q?R+6wkaZhXA4GLHXjN/mLjWEh3Hp3eVvyT7y89Npumyd1EZ+Cy6nlKiUqj0ZA?= =?us-ascii?Q?JMFcVXdmKt4BAAe8QShJJAU5pYEdGSKaMXDaHeuEIK0Y7Bl/LjXz6lNvQ6HE?= =?us-ascii?Q?8Jp3IXdmLvJvNVHMwhQiPNJpuzUXL6IOV9NEwmJLtlMsG1a2adeIbyWArzLl?= =?us-ascii?Q?0Dcogf9Wn11IDELEsXsgVtfQguVASddLRWWik3oXPoWJloSN8IbyLmZuS5El?= =?us-ascii?Q?pYzPSDKS2pRy12VprRqilXvRllXczqvKMXISjiOnIv8dkIDVh0R2nupskxvP?= =?us-ascii?Q?fPYTLeDTBf3swPgYujvEAW/WPp/0Wc+53JwVxbIl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QAJC0wVKh2IUh22qQyIf+0IEX55ieX35bws0GCT/iBmu+O10?= =?us-ascii?Q?NlpXp4j6ZQ=3D=3D?= X-OriginatorOrg: atomlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: 365a5de8-4cb9-40c9-638b-08de5c19e5d9 X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2026 13:59:03.5051 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e6a32402-7d7b-4830-9a2b-76945bbbcb57 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tc6KjSQ12CYjjjhmmSCtKuWfQFZSbaJ2izSzFjBH7QobQiZOM8+fJKa0NkDLRrqMWAEKM9/mdGfpR47NwXzMPw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LOYP123MB3104 Content-Type: text/plain; charset="utf-8" Currently, the hung_task_detect_count sysctl provides a cumulative count of hung tasks since boot. In long-running, high-availability environments, this counter may lose its utility if it cannot be reset once an incident has been resolved. Furthermore, the previous implementation relied upon implicit ordering, which could not strictly guarantee that diagnostic metadata published by one CPU was visible to the panic logic on another. This patch introduces the capability to reset the detection count by writing "0" to the hung_task_detect_count sysctl. The proc_handler logic has been updated to validate this input and atomically reset the counter. The synchronisation of sysctl_hung_task_detect_count relies upon a transactional model to ensure the integrity of the detection counter against concurrent resets from userspace. The application of atomic_long_read_acquire() and atomic_long_cmpxchg_release() is correct and provides the following guarantees: 1. Prevention of Load-Store Reordering via Acquire Semantics By utilising atomic_long_read_acquire() to snapshot the counter before initiating the task traversal, we establish a strict memory barrier. This prevents the compiler or hardware from reordering the initial load to a point later in the scan. Without this "acquire" barrier, a delayed load could potentially read a "0" value resulting from a userspace reset that occurred mid-scan. This would lead to the subsequent cmpxchg succeeding erroneously, thereby overwriting the user's reset with stale increment data. 2. Atomicity of the "Commit" Phase via Release Semantics The atomic_long_cmpxchg_release() serves as the transaction's commit point. The "release" barrier ensures that all diagnostic recordings and task-state observations made during the scan are globally visible before the counter is incremented. 3. Race Condition Resolution This pairing effectively detects any "out-of-band" reset of the counter. If sysctl_hung_task_detect_count is modified via the procfs interface during the scan, the final cmpxchg will detect the discrepancy between the current value and the "acquire" snapshot. Consequently, the update will fail, ensuring that a reset command from the administrator is prioritised over a scan that may have been invalidated by that very reset. Signed-off-by: Aaron Tomlin Reviewed-by: Masami Hiramatsu (Google) Reviewed-by: Petr Mladek --- Documentation/admin-guide/sysctl/kernel.rst | 3 +- kernel/hung_task.c | 58 ++++++++++++++++++--- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index 239da22c4e28..68da4235225a 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -418,7 +418,8 @@ hung_task_detect_count =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Indicates the total number of tasks that have been detected as hung since -the system boot. +the system boot or since the counter was reset. The counter is zeroed when +a value of 0 is written. =20 This file shows up if ``CONFIG_DETECT_HUNG_TASK`` is enabled. =20 diff --git a/kernel/hung_task.c b/kernel/hung_task.c index df10830ed9ef..350093de0535 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -306,7 +306,11 @@ static void check_hung_uninterruptible_tasks(unsigned = long timeout) int need_warning =3D sysctl_hung_task_warnings; unsigned long si_mask =3D hung_task_si_mask; =20 - total_count =3D atomic_long_read(&sysctl_hung_task_detect_count); + /* + * The counter might get reset. Remember the initial value. + * Acquire prevents reordering task checks before this point. + */ + total_count =3D atomic_long_read_acquire(&sysctl_hung_task_detect_count); /* * If the system crashed already then all bets are off, * do not report extra hung tasks: @@ -337,10 +341,11 @@ static void check_hung_uninterruptible_tasks(unsigned= long timeout) return; =20 /* - * This counter tracks the total number of tasks detected as hung - * since boot. + * Do not count this round when the global counter has been reset + * during this check. Release ensures we see all hang details + * recorded during the scan. */ - atomic_long_cmpxchg_relaxed(&sysctl_hung_task_detect_count, + atomic_long_cmpxchg_release(&sysctl_hung_task_detect_count, total_count, total_count + this_round_count); =20 @@ -366,6 +371,46 @@ static long hung_timeout_jiffies(unsigned long last_ch= ecked, } =20 #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 + * @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 + * + * This handler is used for reading the current hung task detection count + * and for resetting it to zero when a write operation is performed using a + * zero value only. + * Return: 0 on success, or a negative error code on failure. + */ +static int proc_dohung_task_detect_count(const struct ctl_table *table, in= t dir, + void *buffer, size_t *lenp, loff_t *ppos) +{ + unsigned long detect_count; + struct ctl_table proxy_table; + int err; + + proxy_table =3D *table; + proxy_table.data =3D &detect_count; + + if (SYSCTL_KERN_TO_USER(dir)) + detect_count =3D atomic_long_read(&sysctl_hung_task_detect_count); + + err =3D proc_doulongvec_minmax(&proxy_table, dir, buffer, lenp, ppos); + if (err < 0) + return err; + + if (SYSCTL_USER_TO_KERN(dir)) { + if (detect_count) + return -EINVAL; + atomic_long_set(&sysctl_hung_task_detect_count, 0); + } + + return 0; +} + /* * Process updating of timeout sysctl */ @@ -446,10 +491,9 @@ static const struct ctl_table hung_task_sysctls[] =3D { }, { .procname =3D "hung_task_detect_count", - .data =3D &sysctl_hung_task_detect_count, .maxlen =3D sizeof(unsigned long), - .mode =3D 0444, - .proc_handler =3D proc_doulongvec_minmax, + .mode =3D 0644, + .proc_handler =3D proc_dohung_task_detect_count, }, { .procname =3D "hung_task_sys_info", --=20 2.51.0