From nobody Sat Feb 7 18:15:30 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 From nobody Sat Feb 7 18:15:30 2026 Received: from LO2P265CU024.outbound.protection.outlook.com (mail-uksouthazon11021085.outbound.protection.outlook.com [52.101.95.85]) (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 4925D23A9AD for ; Thu, 15 Jan 2026 02:32:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.95.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768444365; cv=fail; b=YjhT/YKWT8X6xz01D9m3mzMQE/PbPAqBcEo6raIABeqPjvFOJ9ZsY6mr7C13a0b9wX377fnO3k+8gkJ3sgymBWE13WHiNZ0iDnn1Hgr28VDngIhgyx3kJrEohwMOaTpAlgn9B/7RUYiWdXOB04Ei4w/XhTN/sq6tWgZ09c5fAHA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768444365; c=relaxed/simple; bh=SEAObGDNQorKXzBelDeoAxsCbrddtMYBZXKeiH6EsMU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=PlIhTP10t9kEu3TIXti8ifA+a8U8mtYMxSEfUVVkRlKdEipnBIZ5ZaOgb52vWQqHazm6DQy1ZQ8et+tcwZMrKuT71u/kG8YJnT/6H55p+A8mn435H3mvR+KfWSNZtWbJ/ViHUPJzhnq++TiyctaQrnNquP6W4Ku99jU+Kug0wjY= 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.85 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=mjQt28cTFLMhwSXPMrxqHofxW1v1t/vQJ42YzLSohkuqMnjY92N2Bz2Y4RBZEw+/2FvPqI2Q7+U0amDliedc4rZvx9Q4ri0VY1CbllG7WGRpUbq/RSk0uN6P+HD0Eq5DH5VOTzWh4mOvARGVQpKfBrKD+uZbV7Cu8ol35Xh63hysstdIrcrPfmIdbnRjKdulp+CM2ZzHHmXUwNMV91whlMnec+9VBuHkMAprfFPf1/FTpvsJr2OMmxMJDma48qnANSOFKu5MiDA21QG/NW9KEGc3TCl+9y74hqUnNzjyQnI39R2us2oByiSJhJCKognfrIn3scA4tAZNQKLeMGkbLg== 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=9rbiRMDGdBm+UgqPQpvo51hioDBvcSRO3jmKFVninVQ=; b=tFRk8okYUQweQtSd1ufjt5gtZQyfIi8RgVdZjXVHFQcZ9vDUKoaxMJ0ar92gBiWtOtLKflavqiCG0sp9WxbEkKnGxVyEVyuuXFaAw3PDi6WaPTS0CVCLqbhRwN6l0P61AFrFuWg/+71B3cDwkg9lJfAzlNw4nsPZalXwlwFqREH5ofqg0BKFfMEN3faTgDyDds8lu3lgvaGsVjjuhDv2XlUHAmysDBajjrxx9O+59ychSDyynIXAzVsVgTnG5Pd2bmKpEVqOH/G95L3bsuxuvtRM9Hc090JpWOMMqs/gGBEQuiuOVqbkx8EFkNX90BHQ+ksCBxztFvcTrSvohumUlQ== 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:41 +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:41 +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 2/2] hung_task: Enable runtime reset of hung_task_detect_count Date: Wed, 14 Jan 2026 21:32:29 -0500 Message-ID: <20260115023229.3028462-3-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: BN9PR03CA0355.namprd03.prod.outlook.com (2603:10b6:408:f6::30) 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: 451431ca-f4b7-498f-ba4d-08de53de5b12 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?+qaNrml6G34A7cc21WSINdBfrKctNxwTd72hYyCUdYVx9W/gGZOhVyK7dm1n?= =?us-ascii?Q?lZveWuDZSkPb8uHQJ9NzhPTwmiy0w5YkfRdhqYZ42bqdWPOtr6jxPfOvgDVz?= =?us-ascii?Q?a4Q6TrfnIfma5DDXh1FZT3Do/5xwUxKQQAjLjgS6AL9s+s2q+OnvNJkxD8Ih?= =?us-ascii?Q?lzt+3h+pocT4aPzx1kgc4p94SisOwxidHQHZgUxCB4Vt4O6LVS2dwOVn28nV?= =?us-ascii?Q?DI+4EXPgfiI16YDFTIVB1XEOllG9Yja7q1IPPJwoord177D22IysMMyybWek?= =?us-ascii?Q?5VErkRh1ybVFX8hAsgWvA4Zq4sy3tfp8jHoTe1Ul26NG2YOhsbgG0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Nex4cMcUO99UhyqNEsd/hsTnhUKXdq2No?= =?us-ascii?Q?q7RLxXlooHJ4KgLU96pDWGOJoq3siQcFVZJ56ojTZ3zW54ELpFTwJKKKRdEN?= =?us-ascii?Q?Tsrb1hNy/ZhebhOEWNTni4WP4FROoFE5wF7C12O4eqIaL5srisE+OJ6qgxOu?= =?us-ascii?Q?FsBkhu1XyuerEknHdBEDiSFtkTMPoJQRM8RYKDREbAjs5ZvqEAFLz/3uKCZT?= =?us-ascii?Q?QHFrtems7wbfJUzc0mM/DQwT3t6mq7pNrYKJW36bZSK+3oVZFIkiOQdXLry3?= =?us-ascii?Q?9cx052Vxif5jyLHMBidDbfq+s6nzcqIqiWjWe6CYy74l2HtxVCbiPBQ+rMHr?= =?us-ascii?Q?YTDuKIM3Rput5QXRumY=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-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?posSBgrIbfLB2tqhVkEu6iVCGDyyXEKM3RC9gRJ6L7dpZKHMhjWks2/Z9xeC?= =?us-ascii?Q?DefZZHR6aBzThdbiRhu9ElpZuunLh2/ayf0cwP/YEOMGNaNXnn3Kon9XaSjV?= =?us-ascii?Q?JHPNIssxtespvpDVKYmyoOzQ73+Pfg+ymkh43OBxfLPMEp5Gq7LccaT0YH2T?= =?us-ascii?Q?6RzKAnWE6UAgLreQRs/MqJHLJ85uepMXCTlTPGbIkauh0azSBMu78a1MGixC?= =?us-ascii?Q?3MFqTvzA5Aw0uXjqzhxg2CP7F33cLXCOSi48ptC6DHtSF6YnMUp1omUEtpZi?= =?us-ascii?Q?Ig9s1Ib94ju3sHNqyfAnFflmQVLXZOf3E5kipoS1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g00T44kIdVkp2IGEJdPGLCkVLJYqRzDYsm0tBqrDyO2FUUL0LxT?= =?us-ascii?Q?FFgziVQrtA9RIR9rjYv/ED+ZH4ws/k5rbPgMgyWJwv9IIjJ4K69wEBzzhpfY?= =?us-ascii?Q?ovVE7JmXHihecy2AhCHcdNCyxuBq04B3DF0ePBgqGz/EoUBloWexqAn1MDuU?= =?us-ascii?Q?js/oLnMISy/0l2TK1vfekbnYVI8ilcoiSXYEGXLSPrU7kf8PGO3TxT/oo9NV?= =?us-ascii?Q?F6trw4fRNUqDfD378zAaRV14pXu8mw2dr8hhPH6Hgs/mB6vkaFc/67W1LyjE?= =?us-ascii?Q?ojGWXaAihMWY/V6JlwFD7kbGZtat05l2DgmJJECqqlfO56G1KB5UmTmkwbI4?= =?us-ascii?Q?WswFk67oFR4kB6oZmma8SZvn/GzC6kVHxcy2x0JEJDVhaqoF1qkeGLhwF1ds?= =?us-ascii?Q?ds2vmrsXyHUybW7Oo2DHpjbKS7Ah/+flB1LtzxhmBT3w4bH9EglXLv5Aq5mu?= =?us-ascii?Q?UISwwpKpPZlBuWoDe1x2a0u3raCHF6GY7gWvWqbwVgfk+S0lznyuKbmiomWB?= =?us-ascii?Q?CMyo/vEZfg=3D=3D?= X-OriginatorOrg: atomlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: 451431ca-f4b7-498f-ba4d-08de53de5b12 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:41.1299 (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: 5KnExLR75Go2oWEngQDGE1XtCOXoiq5P7F2J+EuAeDHFVe6i+IYrVCTMFt27aq5LkYyaDlliG7tC/5/PzQNjXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP123MB3396 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 --- Documentation/admin-guide/sysctl/kernel.rst | 3 +- kernel/hung_task.c | 109 +++++++++++++------- 2 files changed, 75 insertions(+), 37 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 b5ad7a755eb5..2eb9c861bdcc 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -224,24 +224,43 @@ static inline void debug_show_blocker(struct task_str= uct *task, unsigned long ti } #endif =20 -static void check_hung_task(struct task_struct *t, unsigned long timeout, - unsigned long prev_detect_count) +/** + * hung_task_diagnostics - Print structured diagnostic info for a hung tas= k. + * @t: Pointer to the detected hung task. + * + * This function consolidates the printing of core diagnostic information + * for a task found to be blocked. + */ +static inline void hung_task_diagnostics(struct task_struct *t) { - unsigned long total_hung_task, cur_detect_count; - - if (!task_is_hung(t, timeout)) - return; - - /* - * This counter tracks the total number of tasks detected as hung - * since boot. - */ - 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; + unsigned long blocked_secs =3D (jiffies - t->last_switch_time) / HZ; + + pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n", + t->comm, t->pid, blocked_secs); + pr_err(" %s %s %.*s\n", + print_tainted(), init_utsname()->release, + (int)strcspn(init_utsname()->version, " "), + init_utsname()->version); + if (t->flags & PF_POSTCOREDUMP) + pr_err(" Blocked by coredump.\n"); + pr_err("\"echo 0 > /proc/sys/kernel/hung_task_timeout_secs\" disables thi= s message.\n"); +} =20 +/** + * hung_task_info - Print diagnostic details for a hung task + * @t: Pointer to the detected hung task. + * @timeout: Timeout threshold for detecting hung tasks + * @this_round_count: Count of hung tasks detected in the current iteration + * + * Print structured information about the specified hung task, if warnings + * are enabled or if the panic batch threshold is exceeded. + */ +static void hung_task_info(struct task_struct *t, unsigned long timeout, + unsigned long this_round_count) +{ trace_sched_process_hang(t); =20 - if (sysctl_hung_task_panic && total_hung_task >=3D sysctl_hung_task_panic= ) { + if (sysctl_hung_task_panic && this_round_count >=3D sysctl_hung_task_pani= c) { console_verbose(); hung_task_call_panic =3D true; } @@ -251,18 +270,7 @@ static void check_hung_task(struct task_struct *t, uns= igned long timeout, * complain: */ if (sysctl_hung_task_warnings || hung_task_call_panic) { - if (sysctl_hung_task_warnings > 0) - sysctl_hung_task_warnings--; - pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n", - t->comm, t->pid, (jiffies - t->last_switch_time) / HZ); - pr_err(" %s %s %.*s\n", - print_tainted(), init_utsname()->release, - (int)strcspn(init_utsname()->version, " "), - init_utsname()->version); - if (t->flags & PF_POSTCOREDUMP) - pr_err(" Blocked by coredump.\n"); - pr_err("\"echo 0 > /proc/sys/kernel/hung_task_timeout_secs\"" - " disables this message.\n"); + hung_task_diagnostics(t); sched_show_task(t); debug_show_blocker(t, timeout); =20 @@ -306,11 +314,14 @@ 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; + unsigned long total_count, this_round_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); + /* 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: @@ -318,7 +329,7 @@ static void check_hung_uninterruptible_tasks(unsigned l= ong timeout) if (test_taint(TAINT_DIE) || did_panic) return; =20 - + this_round_count =3D 0; rcu_read_lock(); for_each_process_thread(g, t) { =20 @@ -330,15 +341,26 @@ static void check_hung_uninterruptible_tasks(unsigned= long timeout) last_break =3D jiffies; } =20 - check_hung_task(t, timeout, prev_detect_count); + if (task_is_hung(t, timeout)) { + this_round_count++; + hung_task_info(t, timeout, this_round_count); + } } unlock: rcu_read_unlock(); =20 - if (!(atomic_long_read(&sysctl_hung_task_detect_count) - - prev_detect_count)) + if (!this_round_count) return; =20 + /* + * 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_release(&sysctl_hung_task_detect_count, + total_count, total_count + + this_round_count); + if (need_warning || hung_task_call_panic) { si_mask |=3D SYS_INFO_LOCKS; =20 @@ -370,20 +392,35 @@ static long hung_timeout_jiffies(unsigned long last_c= hecked, * @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. + * 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. 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; + int err; =20 - detect_count =3D atomic_long_read(&sysctl_hung_task_detect_count); proxy_table =3D *table; proxy_table.data =3D &detect_count; =20 - return proc_doulongvec_minmax(&proxy_table, dir, buffer, lenp, ppos); + 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; } =20 /* --=20 2.51.0