From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010055.outbound.protection.outlook.com [52.101.56.55]) (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 7CB8C340A76 for ; Tue, 21 Jul 2026 03:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.55 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784605327; cv=fail; b=Wge2LeeRkA4VHJsnq6cpWr5IYRMfZ/29kbtpuDkve7rXVivyiG6sWcDHA2FOw4jHBPVHiOZCcZBnfQ1KSeuEFb8UaoZisGvSSbqha+srO2DLvChhBGcXrcZ+q0t6ISYDaqLQKA19T6EM5EvyBik7R7Yc5m8HjBIUpWSo2YpLkW0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784605327; c=relaxed/simple; bh=sSEgawPr8mQxQwuOePNtY/x3X3CSw0PpPkXgGSfOUys=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=q9htsNNK+Mh3sNvuWHJpmvjUi2R6+KJ+DTgoln17dXmYFELPqiFemrpYR5zTkwbH8kZw0KHjAMWdrm5nsjo6UP/iLq9vHysJQxCpTiP7kTQMbaq3IzKxUCEfDTx04MqSUdQ5NSL9UDFbF9/9IZEV2cgC2NFiYrMvGvOg/bwOEic= 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=vdr5UEEO; arc=fail smtp.client-ip=52.101.56.55 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="vdr5UEEO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JVfJK874OFtrUQ39D/kfqFeTprSkRhLCX+M+sTxL36nALffgGedBOuLZkvWa5bIs4UvYY3Ez6JkBTnTcu2SGEn/enN+xQA1EckYCsDTDPZhnxWgRHnKXoVExQFU6pJ3cm3Lnsc6PqO1XiB9c7n9Q1FioVZDTPE3avtoiK2VsCkfxNI5zoCZanRou54cTCNaEd/+EswCK5ih+CaJC6HW2v0ZMJiTlUsF1aafiY2k/pIV5EuPziKdA9pjzgEuV0ty8O6reR3oliWuwRbMoXQyxTnt9qBo08t35cziBdgJ8PLcPv71EUz2ikvwziSVbSUkCJ0E5hF5mJe3PKtx1b4slGA== 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=or6Gg2IiYyFe6w0VBmoHXvcEXTG9xul4Fk4iGcjhGoA=; b=F14K6DjeGUqundaWMRi9WPLQid23yVM8OCJM76H1Ui/WXjfh40BtqtHNU0XtYeZtRZ3IvM5WHJDpNKoZjL4wqlEus///5ZIgHiJVhdqcyplofl6EY89PSXT/FMcuz/wOjRW3WQbdfuOEVgYVoZ4O4MhgBnGP2u0YtvhXCZSfZVVA3fMntz2o82Ix908+Jn2XjrZuPSAJajvkcVproNP6D0YPKL+AhhR9gcr1yBQiGTAxX6K06hHXJ3Wg6KZZgnaa1SQAKN9sJ+9XddAwHt6vJq7TXn3E1MnhSWVwFlYIZPo4s00NTxoY6/XcCHkz9/fOhrnMseBr0iTnTf/d+2yMWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=gmail.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=or6Gg2IiYyFe6w0VBmoHXvcEXTG9xul4Fk4iGcjhGoA=; b=vdr5UEEOHfWeD0FtGnzPTU+tRkDP6VFYEjCKRNnZjF21PEW9BKeqOPIuQl3tpARIwo8CP4fLQTK0GREKJoFtxtOUhtRdrPHTtaRFnM47fhjCrxVu5I4d9myH+NfJyyk1s6aG3/vc3EewiNl9Zmo8+RfVjqnMR7l6LBpIG6L8Lls= Received: from BY3PR10CA0020.namprd10.prod.outlook.com (2603:10b6:a03:255::25) by IA1PR12MB7709.namprd12.prod.outlook.com (2603:10b6:208:423::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.223.18; Tue, 21 Jul 2026 03:42:00 +0000 Received: from SJ1PEPF00002314.namprd03.prod.outlook.com (2603:10b6:a03:255:cafe::17) by BY3PR10CA0020.outlook.office365.com (2603:10b6:a03:255::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.223.18 via Frontend Transport; Tue, 21 Jul 2026 03:42:00 +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 SJ1PEPF00002314.mail.protection.outlook.com (10.167.242.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.5 via Frontend Transport; Tue, 21 Jul 2026 03:42:00 +0000 Received: from satlexmb07.amd.com (10.181.42.216) 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.41; Mon, 20 Jul 2026 22:41:59 -0500 Received: from [10.136.38.108] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.41 via Frontend Transport; Mon, 20 Jul 2026 22:41:56 -0500 Message-ID: <51450a8f-f053-45b3-a2fc-2bd0b75181b6@amd.com> Date: Tue, 21 Jul 2026 09:11:50 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4] sched/proxy_exec: Detect cycles in proxy walks To: "zhidao su (Xiaomi)" , John Stultz CC: Peter Zijlstra , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , References: <3ab1c896-7b33-4d39-85cd-3ab78f3a5bf8@amd.com> <20260717125512.865145-1-soolaugust@gmail.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20260717125512.865145-1-soolaugust@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002314:EE_|IA1PR12MB7709:EE_ X-MS-Office365-Filtering-Correlation-Id: c7449e7e-3672-4bb2-fb46-08dee6da05c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|23010399003|7416014|36860700016|82310400026|1800799024|4143699003|11063799006|56012099006|10067099003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: /QGMhwaylh2dKDh9pCefTiS+ZfQwT+AEHTynN2adDrbnu7T81eyPO+3/c3TeU3Ds3f3nfx0JExk8QSmR3VdczANFcBWkQEcePjQevnbpr//g6iwYVkKS68x+lLqS7kmdsEMZuMfHiU3aJoe45IMiwB/w4dsC4ZdHwcNXkT3MvSFAWG0hL+q/OE7m0m6EaOLvijgQpE7W76mnaGcFHTQ/hbZ9/AqywjMvca6K1r9YSke+EKiLAKvpqBCgk97qxLMM4QNph+uC1r96WroRM8O7MBWHDiqq965eUkc4P3IVqLTk6LiOIn5sJ1+kXjpzH16xpwdPO8ugjR6mVYMMe+e9WeMLDcPcR+pLLbjxKk+RIZzfO5oTAFrfQwB5PgCLgXGao4Pwvif4sWCz1T584zMuKgeg5uCbikaw2mfPJDyWNV9Zav3xe/Xgi38CrkisFXElVj5qdIhbk07stLq2nloxRFNw/v914/KYCqoGdonVHVu6aKmy6M35542PDb6ZDv14nJ87c+2dbKf5LDHErYcY8TwoqDja74DMI9w0chLaBuCsGSWJm0fWhZ3m/BZZtm62KWJgcwv4bbClVCCpt75NH758VCesLtP9T3QM4MVEHPXoarnGgjVsx8uvRsmWvAV91C8xwbYe8vCqXL+tk0Vj8Wxm2t7/QDZIHFgsOfZUb09RBDMljvknXMm1g0+FAdGS X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(23010399003)(7416014)(36860700016)(82310400026)(1800799024)(4143699003)(11063799006)(56012099006)(10067099003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sHrxigNuxOLFwW9fO0A8MUh9UL1TDFPU2KwRJ+T5WfkerLd4+hB0PrGOkhDoOQ81uxTBgn+NW7FPK5wd9XYfnCxpR1zI+0i0Yi1pr5ZXHMWHjJ0OuAibV3Di7PZYWLCFwDdzNfWN0M50zdVTsiz+EpkvyOKtZ5tD3ZyBzpCeGo6vksQHGREZq4huIpl9X/82W+SNH3Ws0J81vo2o5vy/uJaOJBPnqvEVl4g4CemZoMwjcZ7QIWAU/voCoXNEub9md9Xb+7xNCWitNPinWpFO4epguzA0Q1NQs+iFx6B3+5AzhZdVXVSHxdl/Dq36OR9aWsL0p/Kht+q3REcQQ76r+oY7UGZoRkxex61a2mLrsbF1clIjW40yc+cJLVCw5SHZcBZfUj+QZsoqb85IozCuWFJPpVcfQRMi6alWwdOvRjrBEfqF7s6Ag+BkvcICT7x6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2026 03:42:00.5903 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c7449e7e-3672-4bb2-fb46-08dee6da05c3 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: SJ1PEPF00002314.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7709 Hello Zhidao, On 7/17/2026 6:25 PM, zhidao su (Xiaomi) wrote: > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 2e7cde033a319..1a9d3decd66e0 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -2221,6 +2221,9 @@ void activate_task(struct rq *rq, struct task_struct *p, int flags) > if (task_on_rq_migrating(p)) > flags |= ENQUEUE_MIGRATED; > > +#ifdef CONFIG_SCHED_PROXY_EXEC > + p->proxy_pick_seq = 0; > +#endif nit. I think it would be better if we have a sched_proxy_enqueue_task() wrapper around this to avoid sprinkling #ifdef in otherwise what is a clean function. Also you can bail out early for !sched_proxy_exec() to avoid this write for users who disable proxy execution at runtime. > enqueue_task(rq, p, flags); > > WRITE_ONCE(p->on_rq, TASK_ON_RQ_QUEUED); > @@ -6724,6 +6727,7 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p, > } > > #ifdef CONFIG_SCHED_PROXY_EXEC > + > static inline void proxy_set_task_cpu(struct task_struct *p, int cpu) > { > unsigned int wake_cpu; > @@ -6839,14 +6843,14 @@ static void proxy_migrate_task(struct rq *rq, struct rq_flags *rf, > } > > /* > - * Find runnable lock owner to proxy for mutex blocked donor > + * Find runnable lock owner to proxy for a blocked donor > * > * Follow the blocked-on relation: > * > * ,-> task > * | | blocked-on > * | v > - * blocked_donor | mutex > + * blocked_donor | blocking primitive > * | | owner > * | v > * `-- task > @@ -6874,6 +6878,8 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) > struct task_struct *p; > int owner_cpu; > > + rq->proxy_pick_seq++; > + > /* Follow blocked_on chain. */ > for (p = donor; p->is_blocked; p = owner) { > /* if its PROXY_WAKING, do return migration or run if current */ > @@ -6905,6 +6911,14 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) > return NULL; > } > > + if (p->proxy_pick_seq == rq->proxy_pick_seq) { > + WARN_ONCE(1, "sched/pe: deadlock cycle detected, pid %d\n", You can use pr_warn_once(). > + p->pid); > + __clear_task_blocked_on(p, NULL); > + goto deactivate; > + } > + p->proxy_pick_seq = rq->proxy_pick_seq; > + Do we need to do this here too? ... > if (task_current(rq, p)) > curr_in_chain = true; > > @@ -6990,6 +7004,13 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) > */ > return proxy_resched_idle(rq); > } > + > + if (owner->proxy_pick_seq == rq->proxy_pick_seq) { > + WARN_ONCE(1, "sched/pe: deadlock cycle detected, pid %d\n", > + p->pid); > + __clear_task_blocked_on(p, NULL); > + goto deactivate; > + } ... This should be sufficient right? You can just set owner->proxy_pick_seq = rq->proxy_pick_seq; below once owner is finalized instead of setting "p->proxy_pick_seq" very early above. > /* > * OK, now we're absolutely sure @owner is on this > * rq, therefore holding @rq->lock is sufficient to Apart from those, the patch looks good. With the comments addressed, feel free to include: Reviewed-by: K Prateek Nayak -- Thanks and Regards, Prateek