From nobody Sun Feb 8 09:10:31 2026 Received: from CWXP265CU009.outbound.protection.outlook.com (mail-ukwestazon11021078.outbound.protection.outlook.com [52.101.100.78]) (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 1AAB723A9AD for ; Thu, 15 Jan 2026 02:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.100.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768444359; cv=fail; b=SBPcP/Or9oXFD2LkInqakFjzwsLKWx5zEMvPrGv2XHX+lYvM0j1DJ+YnRYNr9IyvxM4kmB5ziu6uRok7NB1VHSu2nFF1CqPuP2qJy8ATru1tIkLGKgZF+fCfJMXT/vggOYJ/h5MaNJPN33q1ZgcIx4FKH8m/f80I3cL/le1kC1I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768444359; c=relaxed/simple; bh=xI8WKpdGzH6XS/8Jbbd1Xas1OglsSBxiHtGWqG3lm3k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=mwR1IticUfyRcx28uAODYWKtjWzGO3xyROpt/E20WQ11AInlsZMMPeKsclaAOwlVze7itwZCe578oqMvPdFgt2PNbd4S4tCxR2FLZznLlFyiigHyXa6/FRMN+eYMjO6ImOB2rQOdEFTuxosXVXRlFhGMHkOnCLGYCfMxvAknLuo= 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.100.78 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=ANi0Xy7zCRxdJZAMrc6Gk2wyj7GPvCyQvSTsqYQ2LWeMOGjaeO5b1GB1+pGWLjbA3Ute3CvjSrOii06nuLinnbZqx8fWZALk0zI8VV4/K8gkrnJ5bxTkSJP6D4GjeqxUJY+eitWCIGg4BOrvMyiXh8za6r4yRWwrtDs3rEGc81t/qlicwTcpBSG96/tdGzXstIbCBUzDdbEl8xuqUSLiuHJWPR83LKx3OnrIELg5yD4DnoQ0CelPZE2haWTQIyZB+lRHbHLy9zbH2YIasajE0SbZi/9fKaD2opTnkuHv3VF5ieDFq4DVNct0BWJ803A8VSsL2wAg7fxazw9/CW3xUA== 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=8PnztWUhBSxeLGjIKSilQtzyNs5rA3MkPF/V5j0M4mE=; b=eil+GEogcFvyalTB54V/sSjfoR6IjeaSaRiPSeq9IQnd1wwVCx/sWPGy0zaOMS+e8zvPhAjoBQlJtQGifPwbPjt6aPSZwI9T2L2a1DEcVSjGpbC5Dd+hVHXaumDYDVkF/PNGDABslFpdQG++wb0hV+mIEIYoRlzFFd8dfTQu62+HD8sH3n4vKURn80KsIJw3sN4KwvpgOJOJ6CfR8MGxy9kA8ndBOGUqV+A3D0B13WJot4HBrTyXm168Ysq9VmWZTlDYU5oOqEFHGxNL314gH1bx6byVCyfHfpksQwFydaA6tEl6NjOD7w1pq5srQNftJtl4fkwuwc3Wz7TY3QoXmw== 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 CWLP123MB3396.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:6c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.6; Thu, 15 Jan 2026 02:32:37 +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.9520.003; Thu, 15 Jan 2026 02:32:37 +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: sean@ashe.io, linux-kernel@vger.kernel.org Subject: [v6 PATCH 1/2] hung_task: Convert detection count to atomic_long_t Date: Wed, 14 Jan 2026 21:32:28 -0500 Message-ID: <20260115023229.3028462-2-atomlin@atomlin.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260115023229.3028462-1-atomlin@atomlin.com> References: <20260115023229.3028462-1-atomlin@atomlin.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN0PR04CA0152.namprd04.prod.outlook.com (2603:10b6:408:eb::7) 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_|CWLP123MB3396:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e58a5a2-f1d8-4f74-4e2a-08de53de58a7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pKX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r2Ia968bivWbayBj?= =?us-ascii?Q?G7QvvzbS4QOFV7FALYTu6FQMSkbO5JGYebBIkkMJ/JUIXS9Tjqlu7sqnbZRf?= =?us-ascii?Q?FDrvv74e3E2A/9JmQcsLPN+jfqhlGl+XeVM7QvH2RLH6L2ciBAO7E1S+z1Rb?= =?us-ascii?Q?0IwgT5dBrzQItUkUJs2gz6zi4k6ZaMZWxftsrpC694t3tzK9ueStICldwTjO?= =?us-ascii?Q?QAzibtIdrU30g2J4uTnGnaz0d/GuQ/NWX80VlZeYiS4D6h9zC5wGyZNaJ2TX?= =?us-ascii?Q?cHWsaBoo4BMUvB6e+rYAtjPhiS8luh1ySnzXurhD9RvbtvQG0+KeF7uzldcz?= =?us-ascii?Q?YEZdPvc/pL+oXmzVP3HWovB5i0qRcB3cTc4At1f9qgUKU0melDHcesnWrDhR?= =?us-ascii?Q?dHfrE+cJPjjXM5zCx/OOrySv67ItCNvi8QT1Y4mk/iJMA8n36llJOv64WNyZ?= =?us-ascii?Q?IAgoq3xCuRMDQotlPCZCQQLBjyMqo6oulyK7HaZSHHnZ3/n8gcI6Cjuye3A5?= =?us-ascii?Q?RB+lSTQ1rzZTaS4GS/mubtd2DVEKtmQD5q5A5Vg91Ta16Xl5k047KFmgxl+J?= =?us-ascii?Q?KzewQ+O1BJ5dRi7r+Fj7T4ZpNlpJ89bOA/nsP5IHldBkq9W9UAeLuVpF39kA?= =?us-ascii?Q?pqkVfDAwNPfsX+zaYgY2Lnos/RzgWZRQ8bcgaDBBDn804WnWPeuKpDJzHOvs?= =?us-ascii?Q?TxxxFaHnEU/FXdp1BKE=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)(366016)(1800799024)(376014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exch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KT6/31BzsJgq?= =?us-ascii?Q?f8CnQ7IZ0Q=3D=3D?= X-OriginatorOrg: atomlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e58a5a2-f1d8-4f74-4e2a-08de53de58a7 X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB3523.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 02:32:37.0243 (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: MrnShv4CF2lr/JAf1nTEQJ3GYA9P6dHFbEU3H8SwUCjodaolFo6dCMjkuNw8Ov8pkJZvqjbQI3AqDecjcHABtg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP123MB3396 Content-Type: text/plain; charset="utf-8" To facilitate the future introduction of a runtime reset mechanism for the hung task detector, it is necessary to manage sysctl_hung_task_detect_count via atomic operations. This ensures that concurrent modifications - specifically between the khungtaskd kernel thread and potential future user-space writers - are handled safely without the requirement for heavyweight locking. Consequently, this patch converts the variable from unsigned long to atomic_long_t. Accordingly, the increment logic within check_hung_task() is updated to utilise atomic_long_inc_return_relaxed(). Furthermore, a custom proc_handler, proc_dohung_task_detect_count(), is introduced to bridge the interface between the atomic variable and the standard sysctl infrastructure. Note that as the sysctl entry retains its read-only permission (0444) within the scope of this commit, the handler implementation is currently restricted to read operations via a proxy variable. The logic requisite for handling user-space writes is reserved for a subsequent patch which will formally enable the reset capability. Signed-off-by: Aaron Tomlin --- kernel/hung_task.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/kernel/hung_task.c b/kernel/hung_task.c index d2254c91450b..b5ad7a755eb5 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ static int __read_mostly sysctl_hung_task_check_count =3D= PID_MAX_LIMIT; /* * Total number of tasks detected as hung since boot: */ -static unsigned long __read_mostly sysctl_hung_task_detect_count; +static atomic_long_t sysctl_hung_task_detect_count =3D ATOMIC_LONG_INIT(0); =20 /* * Limit number of tasks checked in a batch. @@ -224,9 +225,9 @@ static inline void debug_show_blocker(struct task_struc= t *task, unsigned long ti #endif =20 static void check_hung_task(struct task_struct *t, unsigned long timeout, - unsigned long prev_detect_count) + unsigned long prev_detect_count) { - unsigned long total_hung_task; + unsigned long total_hung_task, cur_detect_count; =20 if (!task_is_hung(t, timeout)) return; @@ -235,9 +236,9 @@ static void check_hung_task(struct task_struct *t, unsi= gned long timeout, * This counter tracks the total number of tasks detected as hung * since boot. */ - sysctl_hung_task_detect_count++; + cur_detect_count =3D atomic_long_inc_return_relaxed(&sysctl_hung_task_det= ect_count); + total_hung_task =3D cur_detect_count - prev_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= ) { @@ -305,10 +306,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; struct task_struct *g, *t; - unsigned long prev_detect_count =3D sysctl_hung_task_detect_count; + unsigned long prev_detect_count; int need_warning =3D sysctl_hung_task_warnings; unsigned long si_mask =3D hung_task_si_mask; =20 + prev_detect_count =3D atomic_long_read(&sysctl_hung_task_detect_count); /* * If the system crashed already then all bets are off, * do not report extra hung tasks: @@ -333,7 +335,8 @@ static void check_hung_uninterruptible_tasks(unsigned l= ong timeout) unlock: rcu_read_unlock(); =20 - if (!(sysctl_hung_task_detect_count - prev_detect_count)) + if (!(atomic_long_read(&sysctl_hung_task_detect_count) - + prev_detect_count)) return; =20 if (need_warning || hung_task_call_panic) { @@ -358,6 +361,31 @@ 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. + * Returns 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; + + detect_count =3D atomic_long_read(&sysctl_hung_task_detect_count); + proxy_table =3D *table; + proxy_table.data =3D &detect_count; + + return proc_doulongvec_minmax(&proxy_table, dir, buffer, lenp, ppos); +} + /* * Process updating of timeout sysctl */ @@ -438,10 +466,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, + .proc_handler =3D proc_dohung_task_detect_count, }, { .procname =3D "hung_task_sys_info", --=20 2.51.0