From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012039.outbound.protection.outlook.com [40.93.195.39]) (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 B82AC441049 for ; Tue, 28 Apr 2026 14:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.39 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777385592; cv=fail; b=CsMCAAEP1XW+ZpsGwOKqa9JkRtI44LZfqikNGOP2GpRctLJf6RRRknwwAnXR20YpZmj3TajBZ7GR0LY5NWcMs/OtHht5RpKCuyB3bEscy2Oz4jBn+H6s1evENInvbTgGNvfRwTkpHUnYNSyCDDkIrYKMXUFoUas7/kFeWaNYBe0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777385592; c=relaxed/simple; bh=1HXBXyqR1m2kF6ekukEZ9yQLV0Rqn6OIpgJ1e7iNzSE=; h=Message-ID:Date:MIME-Version:Subject:From:To:CC:References: In-Reply-To:Content-Type; b=ayggw4/Do4blDe3kBzaa8/In24cY4iZ0QNDk+d+HNJn1CZyDvdYnQNTjKp411RJmbk/isLIL5blhJ5/WkDoOIu+lVjV4kHNrhSFgNW30paNQ0hu7EgSbbI1nGP393jw1QSxltRZBSrtmqGzfTrbd0bzLKxrCuciLv49j61krAuA= 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=H9+gBDKj; arc=fail smtp.client-ip=40.93.195.39 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="H9+gBDKj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bQi6sgyFd4fG778ZMw8aSDmgnut1qJoWh2Jtf+4pcdhPgk65vVJfxSGJvSrX3HcIMSLZ3hZM9gweY+lEono/j/nd9VwCIbCM9FIIVHW3U4iq4paxMEwYT/K75qDhJENEPIpnd59vMbUoXuFCnjjBAtdLdV5Hl8JLBBSYidXUG4nm/ENqpw2EfbkLyVR0KTKKlI4Znhks5JANyJqPiga3JkNXTkESVdzTUT87E0nwB5cm5QNKhxFQveD6dpEaUJKYp7O3l9rpawTbZkgsJ7cQ6IM/u/m/rgs0BXgUS+DQlqi2i1aBfiTJTnGXIdu6AYS0/zScXfcpZ5MYoYyoOX7Mow== 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=uHitHURbYctpASuzazVtZOil0ZSRICfxsLboRbzGkIQ=; b=sJvsGYZAUlUl54Ra82MlRGkkoAfFCUi5wrZCRcUqz1cEfjto962saBGlE9w92FjtRwr4BqcFQFyLMUUZIlVifskpNjg0WwQWjEIbdq9BxA2/Gh2QOTQugoK5aVlj00ocXyK/b+6MoRHBza9FxYimaz5fnX3tXY7NeTIcb6qiqCH2WxtvW8I0MBINcdcZwy7ylKFZuRFNwUsGefQrUgFuxhKCSNqm6wLUN/XRbR5ket5cqC2Tcke1GmyIhhur8e7hKYLYgEAC5gckYyZwHBiC2iLLqVbnsbZiVmIePvQ/Z3fT5ESllVF6CDmhwt3DuVFmGlTHYVvteKzuozev/FTkGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org 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=uHitHURbYctpASuzazVtZOil0ZSRICfxsLboRbzGkIQ=; b=H9+gBDKjSOB00Mqj8PSALae62BDQK6QrtBVgoe8b7Uz/N/09sSgkRZQi6lPfaLHi5iRpQLds+EZPuEGS9tdf9hkmJi5TdbLbyiAMDnXhz1SSL3Ogf39Omq47IcayWoBlyccrAtS3KMgC+3JDTRs8MQTnsUYxXxhsW8ADxTmSA50= Received: from CY8PR12CA0012.namprd12.prod.outlook.com (2603:10b6:930:4e::10) by IA0PR12MB8895.namprd12.prod.outlook.com (2603:10b6:208:491::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.15; Tue, 28 Apr 2026 14:13:05 +0000 Received: from CH2PEPF00000099.namprd02.prod.outlook.com (2603:10b6:930:4e:cafe::f5) by CY8PR12CA0012.outlook.office365.com (2603:10b6:930:4e::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.28 via Frontend Transport; Tue, 28 Apr 2026 14:13:04 +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=satlexmb08.amd.com; pr=C Received: from satlexmb08.amd.com (165.204.84.17) by CH2PEPF00000099.mail.protection.outlook.com (10.167.244.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.18 via Frontend Transport; Tue, 28 Apr 2026 14:13:03 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.17; Tue, 28 Apr 2026 09:13:00 -0500 Received: from satlexmb07.amd.com (10.181.42.216) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 28 Apr 2026 09:13:00 -0500 Received: from [172.31.184.125] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Tue, 28 Apr 2026 09:12:53 -0500 Message-ID: <9b77c6a5-05f1-45ba-ba09-f3ed1b580a8b@amd.com> Date: Tue, 28 Apr 2026 19:42:52 +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 1/2] sched: proxy-exec: Close race causing workqueue work being delayed From: K Prateek Nayak To: Peter Zijlstra , John Stultz CC: LKML , Vineeth Pillai , Sonam Sanju , "Sean Christopherson" , Kunwu Chan , "Tejun Heo" , Joel Fernandes , Qais Yousef , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , Thomas Gleixner , Daniel Lezcano , "Suleiman Souhlal" , kuyo chang , hupu , References: <20260427183848.698551-1-jstultz@google.com> <20260427183848.698551-2-jstultz@google.com> <20260428094353.GB1026330@noisy.programming.kicks-ass.net> <20260428111833.GL3102924@noisy.programming.kicks-ass.net> <9cf9b433-cba5-4a8e-8dbf-6410239cffb6@amd.com> Content-Language: en-US In-Reply-To: <9cf9b433-cba5-4a8e-8dbf-6410239cffb6@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Received-SPF: None (SATLEXMB04.amd.com: kprateek.nayak@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000099:EE_|IA0PR12MB8895:EE_ X-MS-Office365-Filtering-Correlation-Id: 2af010b9-1121-4f1d-7b56-08dea5304304 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|36860700016|82310400026|1800799024|22082099003|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: 3QTQ8HBaxOPm9aQ9U+zfK3R81QiFWDKiUrWWHYycWsF6ywH3I3YuQOOpqEDhwm0p6yboEDevISAH2B2VISbtk94duKT48Fe51wcuilp5QHh9RNzpC5Bn+x5GHhb9qE3efU8I2ncP23h0unACA0IGWktKIPrp7bHX6VKxwHlSk35mbvRF5VxcSeco9XXt/cMITcvBHPJtMuyyURVnAVDuSKkV1gKtSYrWlDjR7wEl8eBks8kphcbNSZ2wO1Qiwz//UBAxGHfOXEg4syPLGIKQza3fOPEkn07Ro2UmRWP04ktwEzcq02znuf9YHJeFcXdZ3RGxSIXQ1uLoE1d1olcVCIoxrceEq8cjjQjRFnD+OrOt/ABiGmn6Zg3BZMeVh13023ceIyRdB6QE7JMCY9c1+ZuNVLczYthS2dSoWmsvZQ9RqusKgCqqDjwaoxGon3Om4Feq/mfEjqQDymhSP+ZpaALXfWCboWtdxZlk3hReFIaUcVtmPmmMmdOZaH8y4n25xq5w9PGpQ29hb3gPQdaoP187b/2YLo126ld8tuGUG9TM807gsOoTC8+oyn0U6YrSfnPB88tmr+S9uiOz0/2wDXkeKTTvYpWk9jUfr0DB9jL52Byk/bgX6IxHbpP7riYKux1qrwcnhJJBd3GuN1Qu1lcwnb4JBN/fXLwlB4MkuMwylS3vXkiztG1Ueyki0l/IRoMB9j27be9iyNg9SlsON0aso+RNV+L6HzOUVD7rqKu0FBMVQ0jsWmyRgTKCQjBLx4Ey6E0Tsq9pM3CDJJbzXw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(36860700016)(82310400026)(1800799024)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OXOioF9FDHz/SlZh7b1eCA4ymrnbMu5nBikG2vT0S2sqE5m7YN4gogyDaeBpOGl1SLUkWuceA3cSwU3h1XFU/y0S8TS+kQm19CTZ7Trvak02dLpNwdj0uzgIXEI1iRCoCizOu9vGaIO3u+Rsqnb/r5h5BYmehA/sWitngedpGwMr0nm04c0iT54/GbPHiV2UJaO9sw7EsC9x5RqLwDFuLJcEBjlrVGbZipUrvYsmiFHClu4pv27u/W9GeT1S4DlxorFIU/d58Bify8thGM+qZSINIcoTxbGwyR7OS2w7qZow8MOrzWIaejnK0oZUQTb4phZo/PEnmVjCxkR16nbxhG/JbeEBobu/cxVrQqQdy7Quh2bMWjNY9JEpgBuLEdoE7G970N8Yp0ftc2emShkX5cinRY0FulHHiHPNperprlvitFlkaOLRUvv7ObYBOJbe X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2026 14:13:03.4023 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2af010b9-1121-4f1d-7b56-08dea5304304 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=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000099.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8895 On 4/28/2026 6:45 PM, K Prateek Nayak wrote: > I was trying something like below but I'm somewhere missing a > clear_task_blocked_on() for PROXY_WAKING before going back into > mutex_lock_common(): And I seem to have been missing: diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 8142fba59ad94..a8679b759398c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7046,6 +7046,9 @@ static void __sched notrace __schedule(int sched_mode) switch_count = &prev->nvcsw; } + if (!prev_state && task_is_blocked(prev)) + clear_task_blocked_on(prev, NULL); + pick_again: assert_balance_callbacks_empty(rq); next = pick_next_task(rq, rq->donor, &rf); --- With that, it survives test-ww_mutex and a sched-messaging run without any splats. > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 8ec3b6d7d718b..6ea74aecc5fbd 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -586,6 +586,7 @@ struct sched_entity { > unsigned char sched_delayed; > unsigned char rel_deadline; > unsigned char custom_slice; > + unsigned char sched_proxy; > /* hole */ > > u64 exec_start; > @@ -2222,6 +2223,7 @@ static inline void __clear_task_blocked_on(struct task_struct *p, struct mutex * > * clearing the relationship with a different lock. > */ > WARN_ON_ONCE(m && p->blocked_on && p->blocked_on != m && p->blocked_on != PROXY_WAKING); > + WRITE_ONCE(p->se.sched_proxy, 0); > p->blocked_on = NULL; > } > > @@ -2250,6 +2252,8 @@ static inline void __set_task_blocked_on_waking(struct task_struct *p, struct mu > * the relationship with a different lock. > */ > WARN_ON_ONCE(m && p->blocked_on != m && p->blocked_on != PROXY_WAKING); > + /* Force the task down proxy_force_return() path. */ > + WRITE_ONCE(p->se.sched_proxy, 1); > p->blocked_on = PROXY_WAKING; > } > > diff --git a/init/init_task.c b/init/init_task.c > index b5f48ebdc2b6e..8e8fc680fcd21 100644 > --- a/init/init_task.c > +++ b/init/init_task.c > @@ -118,6 +118,7 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = { > }, > .se = { > .group_node = LIST_HEAD_INIT(init_task.se.group_node), > + .sched_proxy = 0, > }, > .rt = { > .run_list = LIST_HEAD_INIT(init_task.rt.run_list), > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 49cd5d2171613..8142fba59ad94 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -4395,6 +4395,7 @@ static void __sched_fork(u64 clone_flags, struct task_struct *p) > p->se.nr_migrations = 0; > p->se.vruntime = 0; > p->se.vlag = 0; > + p->se.sched_proxy = 0; > INIT_LIST_HEAD(&p->se.group_node); > > /* A delayed task cannot be in clone(). */ > @@ -6535,8 +6536,13 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p, > * blocked on a mutex, and we want to keep it on the runqueue > * to be selectable for proxy-execution. > */ > - if (!should_block) > + if (!should_block) { > + guard(raw_spinlock)(&p->blocked_lock); > + /* Stable against race */ > + if (task_is_blocked(p)) > + WRITE_ONCE(p->se.sched_proxy, 1); > return false; > + } > > p->sched_contributes_to_load = > (task_state & TASK_UNINTERRUPTIBLE) && > @@ -6765,11 +6771,15 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) > bool curr_in_chain = false; > int this_cpu = cpu_of(rq); > struct task_struct *p; > - struct mutex *mutex; > int owner_cpu; > > /* Follow blocked_on chain. */ > - for (p = donor; (mutex = p->blocked_on); p = owner) { > + for (p = donor; READ_ONCE(p->se.sched_proxy); p = owner) { > + struct mutex *mutex = p->blocked_on; > + > + if (!mutex) > + return NULL; > + > /* if its PROXY_WAKING, do return migration or run if current */ > if (mutex == PROXY_WAKING) { > if (task_current(rq, p)) { > @@ -6787,7 +6797,7 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) > guard(raw_spinlock)(&p->blocked_lock); > > /* Check again that p is blocked with blocked_lock held */ > - if (mutex != __get_task_blocked_on(p)) { > + if (!p->se.sched_proxy || mutex != __get_task_blocked_on(p)) { > /* > * Something changed in the blocked_on chain and > * we don't know if only at this level. So, let's > @@ -7044,7 +7054,7 @@ static void __sched notrace __schedule(int sched_mode) > struct task_struct *prev_donor = rq->donor; > > rq_set_donor(rq, next); > - if (unlikely(next->blocked_on)) { > + if (unlikely(READ_ONCE(next->se.sched_proxy))) { > next = find_proxy_task(rq, next, &rf); > if (!next) { > zap_balance_callbacks(rq); > --- > >> next = find_proxy_task(rq, next, &rf); >> if (!next) { >> zap_balance_callbacks(rq); > -- Thanks and Regards, Prateek