From nobody Tue Dec 2 03:00:12 2025 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010026.outbound.protection.outlook.com [40.93.198.26]) (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 53E621DB125 for ; Mon, 17 Nov 2025 18:57:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.26 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405846; cv=fail; b=GhblBStDa1cZjI4w4MHAbgOO8a90ZeMaiBJ0ntiT5n+6tLMQyfbE5iRoBRpD01C41TYQP9MxignokYHWJpj+f2rLGhXDypz5dnON2VoFgkbB4Oo2OFzrK+cvmKLpG5/hYZqAQa1nXM8DavQy0txhsZQWsPiE6DXmbzz6JGeC1Qo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405846; c=relaxed/simple; bh=z5UqQdPa2USXA0HZiDzwOjvAgGN7Z0CrgsLu9eW074w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HHxJioolgRJjt0PDQE3DpaXlv/8RJzMYC8+lUlG6+Oj+pCf/g6NFvQBh9Xa7X6ogaHl1jhiacFO0CNt3c7Cw8KO8Sa9x1DPlfQzt7ZuemLFWqdy/yA2A6VqnpOjejiT2ph9kGztlwBQuCAZ3MsYxH92ezllt699+ctpSLWv2HI4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=UYkLNuD7; arc=fail smtp.client-ip=40.93.198.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="UYkLNuD7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Edy03IqCn3loPcUJ+W6xmJ/OnEOhuLBXW7jD0D4u8jH/+80K2tQ32MhzhoWwhPabMW6EXjsO7J9PYGGYk2Weu+sX5xTAevdGoimlpa66KIMo9JcYcj5EL1s4m2QZThEH4C0KDWceqW/0MkwAPqOZM4D2QgIF4FgIXMmkHxJ/MqDVd4ZT0iZTwIR3jRcHjpVTFDsod6NSpMelTs5mB+1EFTG711JO8yLv7d7p5JKWmMutZ0SvNWLGi4zeCC1GBeCNplNEeV246zI6NtGYVGQNvuvRlNNYZKXgepJPYRWDU22KtacBc1ehIW8qKwilXetfUMp+96Nq7vSV+ASI5+yZdw== 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=a5M7EKwcvyRkP0evhTUjajMvC3Xzot9qR3q4I3usR3E=; b=w8El6kT2QjM/bgBi+bZpmrSFodP85x+IxqPR+EZDe3VIJSSn357VXXZgEJVrolxd2qIs4Qk/MIYMqsN1SaqHP6iEbvWQ33d11kzhc2XNj0r38p5QB7GtJvk2/suvcbkgjxRMKDWDzrxWTEY2u6friiXKRi/GgftEwzONy1JD4tyrTff0+yHVYEF7y4Win2F2xwj7hU7hkZrGC0wc0pxrJVoa3hyvBYXtTLIzcvFMWjOkC9ykpdOPRtXZ0o12zaD0/1iV+I0sLc3rr95e2dHBXtYsplcnDXi5jYrbpHeAUdsqCg+adDhBCGd8UnEGWzCY1SbNjs9M9L8qwSys0hENqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a5M7EKwcvyRkP0evhTUjajMvC3Xzot9qR3q4I3usR3E=; b=UYkLNuD7PmVO5y4OZdZHgr+Dl0d31sfpBgF/wT6ZXMnZfVQ5ZuMUwTKqYk1AR/6R01AqjB/O150u1+S0vP2+ziE67Q1vEiz4O2douqS+iFogNFmUNo63GstorvbhXQu4X7USRew8ivTuulJfcTAAOEaM8vSrKakR9gzKhdVKgoQ= Received: from SJ0PR03CA0005.namprd03.prod.outlook.com (2603:10b6:a03:33a::10) by SJ0PR12MB6685.namprd12.prod.outlook.com (2603:10b6:a03:478::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Mon, 17 Nov 2025 18:57:19 +0000 Received: from CO1PEPF000066EC.namprd05.prod.outlook.com (2603:10b6:a03:33a:cafe::9a) by SJ0PR03CA0005.outlook.office365.com (2603:10b6:a03:33a::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9320.17 via Frontend Transport; Mon, 17 Nov 2025 18:56:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CO1PEPF000066EC.mail.protection.outlook.com (10.167.249.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9343.9 via Frontend Transport; Mon, 17 Nov 2025 18:57:19 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 17 Nov 2025 10:57:15 -0800 From: K Prateek Nayak To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , John Stultz , "Johannes Weiner" , Suren Baghdasaryan , CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak Subject: [RFC PATCH 4/5] sched/core: Block proxy task on pick when blocked_on is cleared before wakeup Date: Mon, 17 Nov 2025 18:55:49 +0000 Message-ID: <20251117185550.365156-5-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251117185550.365156-1-kprateek.nayak@amd.com> References: <20251117185550.365156-1-kprateek.nayak@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066EC:EE_|SJ0PR12MB6685:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ab64041-b556-4416-cb37-08de260b2259 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?JDaesIFWXb/8UBP9zjaRNR6TWRUZHZsfObmKMLwUSdQLFAeJ+vMuGAKR1K+i?= =?us-ascii?Q?x6LamvNhA03zzx9O1hPrTvjntKaQAXCvHN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?Q?moPbAPWJQfvgNfmeq9wJh7gsOPN5HBOMk0/lwkszWqK5E5BXej5vs9eZXUIW?= =?us-ascii?Q?zyQwiTA/jVz9BGxibxol0j6buHZiOattec52on7hTznshxiruy4/w+YqKwYc?= =?us-ascii?Q?IIa2DT53xc4JnyqKlitSIJZ16rcFgzcjNxEj3bBVQWzTx7KKG6kaWNz4NbLb?= =?us-ascii?Q?GtUEC9bnMGh/+hOQFd70PXKjUMtZ3+ES8RTPcTRPkVxZWds2zyKYZVFzPRCU?= =?us-ascii?Q?kZhmSct9uNvfQ+4Ekre0+hknA9ts2KQmBIt1Oc1fG+adkuI0wLzb3AUueOk+?= =?us-ascii?Q?rxVktsNKlYRZc18E+7Jw0PmwDgJf4iMUrhg2jujpNw+hXEwZdWcWsGn6grP2?= =?us-ascii?Q?cstc803+B8uCuZ/VLSzeX0U3OvtjnZ3nlXUckJlO6qBkkZUNhCknobDkPfSn?= =?us-ascii?Q?S6AzkLc2642y/qdXv2kpkPI3yssmctAq1BORIKcxVzukebbN+/23inVzouD0?= =?us-ascii?Q?zLmUA5mcnqHXIsWLvuC9pZ7G7flak0AWm8H9rtGDAQhRvNPSaHQaAYPAGLxa?= =?us-ascii?Q?AfCP9l6lO5J5sp61Zp6M+6UUg2q9qTuAwmd+iWt5W1jKklZOrdvdjujRlI5U?= =?us-ascii?Q?cuNsg8y0w5Kowca/oG0=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2025 18:57:19.4898 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ab64041-b556-4416-cb37-08de260b2259 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000066EC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6685 Content-Type: text/plain; charset="utf-8" Task's "blocked_on" relationship can be cleared remotely without acquiring the task's runqueue lock and can lead to a blocked donor being picked to run without having a wakeup. Although this is not a problem since the task blocks back again if it wasn't woken up in time, it cause problem from stats acccounting point, especially for PSI since psi_enqueue() tries to reset the runnable signals for a proxy task that wasn't fully block, and psi_sched_switch() assumes a blocking task is always runnable before being switched out. When investigating PSI task state corruption, the following transitions were observed with CONFIG_SCHED_PROXY_EXEC=3Dy: ... [141] ...: psi_flags_change: task=3D4358:... cpu=3D141 psi_flags=3D1= 4 clear=3D14 set=3D0 queued=3D1 delayed=3D0 blocked=3D1 psi_bug=3D0 # Task is retained on the rq for proxy. All runnable signals are # cleared for the task. ... [141] ...: psi_flags_change: task=3D4358:... cpu=3D141 psi_flags=3D0= clear=3D0 set=3D10 queued=3D1 delayed=3D0 blocked=3D0 psi_bug=3D0 # Task is picked and forced to run since task_is_blocked() returns # false. ... [141] ...: psi_dequeue: task=3D4358:... cpu=3D141 psi_flags=3D10 # Task blocks again. Flag modifications are deferred to # psi_sched_switch() since DEQUEUE_SLEEP. ... [141] ...: psi_flags_change: task=3D4358:... cpu=3D141 psi_flags=3D1= 0 clear=3D14 set=3D0 queued=3D1 delayed=3D1 blocked=3D0 psi_bug=3D(0 -> 1) # psi_sched_switch() tries to clear TSK_ONCPU and TSK_RUNNING. # TSK_RUNNING was never set since task was never woken up. # !! PSI inconsistent state waring triggered !! ... [014] ...: try_to_wake_up: wakeup: task=3D4358: psi_flags=3D0 queued= =3D0 delayed=3D0 blocked=3D0 # Task wakes up and is finally runnable. To prevent any inconsistencies from running a task that was supposed to be blocked, deactivate a potential donor task if it was picked without having the "sched_proxy" indicator cleared. A pending wakeup would queue the task back again when it turns runnable again. Fixes: be41bde4c3a8 ("sched: Add an initial sketch of the find_proxy_task()= function") Signed-off-by: K Prateek Nayak --- kernel/sched/core.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 52a744beeca9..d6265f38e93a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6679,6 +6679,7 @@ find_proxy_task(struct rq *rq, struct task_struct *do= nor, struct rq_flags *rf) bool is_proxy_task(struct task_struct *p) { return false; } static inline void set_task_proxy(struct task_struct *p) { } static inline void clear_task_proxy(p) { } +static bool __proxy_deactivate(struct rq *rq, struct task_struct *donor) {= return false; } static struct task_struct * find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags = *rf) { @@ -6839,6 +6840,25 @@ static void __sched notrace __schedule(int sched_mod= e) if (next =3D=3D rq->idle) goto keep_resched; } + if (unlikely(is_proxy_task(next))) { + /* + * It is possible for a remote CPU to clear task + * "blocked_on" without acquiring the task rq lock. + * + * This can lead to a blocked task retained for proxy to + * be forced on CPU without the task being woken up + * since task_is_blocked(next) above returns false. + * + * Since "sched_proxy" is only cleared on wakeup, + * is_proxy_task() returning true indicates that the + * task hasn't woken up yet. + * + * Block the task and wait for wakeup to queue it back + * when it is runnable again. + */ + if (__proxy_deactivate(rq, next)) + goto pick_again; + } picked: clear_tsk_need_resched(prev); clear_preempt_need_resched(); --=20 2.34.1