From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011002.outbound.protection.outlook.com [40.93.194.2]) (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 6F8583D1716 for ; Fri, 1 May 2026 15:55:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.2 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777650948; cv=fail; b=k3XF5HR7B9/jJAfg77FnI0H6pl1v5RwlY/jyHgOATp3rDN+VIdrjdCaoelYaljyva7B63HdnVSiKbciCPrDZRzTGGB+woan+XUlcm9AZKBKvg7tokVKZpn0gUNjlXb2m7amw+40Ceor2tpdnG0S6xDiKdICvfK5LSrGBxoHSCxY= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777650948; c=relaxed/simple; bh=NOC64PyqwfezXTXwm9dTut/ePlMQA68FhhdR6vrj77A=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=Bpgb9PJlXugB2jPWNwQhJF5/riI4K7941vOAl7cGNm0ZO4RnD8XI8nmhEheULG5CPuR8zt+z7oEvfGY3btcLnBtbzUa9CiGdFnwO/G8aez6VGEXyWKsfylNQ8JFeij1NslkCiI+g6TIRW76lbiNzarnxZSSc1gq5spaj8ytjFk8= 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=HkK2e4Wv; arc=fail smtp.client-ip=40.93.194.2 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="HkK2e4Wv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fQpN91GTpB0hCMZepYse4oCrmTqZB7IQXQyQl5lqsdYHmuNUuPVQgJQr74ERmyNZq+CbHxXjG9sVwojXhvdB7FJOE/duL2OdF+ZkSEiwGqY6l1KAUpt+/nOIja+ZXPPQaJGMlXT0TrUl2MbzWj/r8tmeNocJFqHoTiIPgl2tFg6spW4oCND+PfsxfoIKdZ/ZEohYyK8bW7Ml67bywengtM5Et5RGcymRyBFE2F+mg0RZQgetTtpUNgBoO2O7cOZ1rxluyZeP77zkteCW8eBh7g6+cy1k8KYE49xRj0t/ND+VeM1pZ0/ddkJN1BHVLymCeBHyPtF+3KBPfK46gNddtA== 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=qALTbA/sD3RpIjCF7Tee5JShmu9EYy56QAAf3Pa6M84=; b=xut9fETaUj/QcRQGD1M1kQyY4S8Chl6WSXKRbda3/yX1QIBOmId+STLvcyxERISKBl/z95JThG0mqCsU3b66MbHzXDUIFwJp03sFU9TLUa5a+3dv4fAqzc1b/37mwJqJoISfwxlRZ9nBhdcxqg4HYlUlSOjlg/nthAHqzZkGurrNEdzpAI4cnit9083dvKVUYvsfOs0u6cKJXZHHMjVenrU4bHDepNtue2TLX5oO8PxZXZbqP/cZkeG92CKwN64rKDhxzU3QBSGlVFfzi+J+xs0twJq78CeU/mRXel/dkPdzN8FGFu4MIze7JIy++zqy7RP1emGJk4G6FKn+tIzD/Q== 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=qALTbA/sD3RpIjCF7Tee5JShmu9EYy56QAAf3Pa6M84=; b=HkK2e4Wv8/2o9sb8R7F6xxUYhn6XqWHw4QbE5hTGgjqv08XtCdM8LzRBtfo8ZBhA1wz3A+fl2lW61CUmLBqzzbvZfOM90G0IlDJmPFetBx+bPkqzS7vgWu7/ToUUjPdaqGedDA+1twf+/zj0cbxwVggy1Yt97f9WXTbbUtIHJqQ= Received: from BL1PR13CA0351.namprd13.prod.outlook.com (2603:10b6:208:2c6::26) by MN2PR12MB4390.namprd12.prod.outlook.com (2603:10b6:208:26e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9818.20; Fri, 1 May 2026 15:55:40 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:2c6:cafe::52) by BL1PR13CA0351.outlook.office365.com (2603:10b6:208:2c6::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9891.8 via Frontend Transport; Fri, 1 May 2026 15:55:40 +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 BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9891.9 via Frontend Transport; Fri, 1 May 2026 15:55:39 +0000 Received: from satlexmb10.amd.com (10.181.42.219) 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; Fri, 1 May 2026 10:55:39 -0500 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb10.amd.com (10.181.42.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Fri, 1 May 2026 10:55:39 -0500 Received: from [172.31.184.125] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Fri, 1 May 2026 10:55:30 -0500 Message-ID: <63c830c3-fe6d-4822-81db-9fdd1597282e@amd.com> Date: Fri, 1 May 2026 21:25:29 +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 v2 1/2] sched: proxy-exec: Close race causing workqueue work being delayed 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: <20260430215103.2978955-1-jstultz@google.com> <20260430215103.2978955-2-jstultz@google.com> <20260501132143.GC1026330@noisy.programming.kicks-ass.net> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20260501132143.GC1026330@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|MN2PR12MB4390:EE_ X-MS-Office365-Filtering-Correlation-Id: 09721f5c-b87d-4d81-70ab-08dea79a17b9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700016|22082099003|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: PUp8nO2k5YxVcjriF4vguykyLB1CfAYM7Y/+D9z/Pm2xtaMR4hxMViRN33hIS+PYkDW1CX7jQgjtRNqH4ihNhykilts2q0jhws26rtfWN9wSuoB1UWr08KhgveCMiuVIP0ojBLtXgPmTO0oRauxrL5QyRcCHywwk5fNkrPU8ZArUHZeTuzdCJxxIlTZk9xzVF5+v2yXSxfeyCyAwg+0tw2a17wqcKG/tH3BZGqTKR/6NiUscybABXc/yobanj5R3JYewp6gaHCIPe2hcAzW1/iwfCP/oQKrSLqYskQ6W8dj8wDoZupetwOGqBMlArFhzkDnGjYxkfD5iQaVbyJJPqJKEp6He+1/2k8ng7Vufi9YeBqTEkLlGZj9m6kpvdwEHJJfBaRHxlGF0bn874lxyQTrKXByyhdJocLI8rqua761mUGh8wRCZJvlXtAYXweSxEMcXgp7xs2su9tUGi7EjpKTmhgpua3L+5xR9XLZ0RNcV/yZvhLQmwbPfI4sfMI5JfpWx+WlCQ1LZFdD5Dp6FJBkFpvT+0mtrQFCDZeodSXmlpNHxeHA3n2MJbNNSBrIHyHMcy/3UbwFH+u2YT3WWqYTDB/SFccKpJiLgHufay2tlZmvqqAsZpWKmOUuJPli1mOjWozvCA8p7yjTyz9KyJlB6yMyBTDVMfkyA40f2zZVOKmkFt7RypuygEKR7G8hbdEU9DwZb8wZd6kpElZN2dLs8P6lwX2oXx6SxOvbeVmc= 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)(82310400026)(7416014)(376014)(1800799024)(36860700016)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ya/YPHZWFeAIDCm307W3RthHL2d+6IE+yUeOkbFH+1dXnSK3VRO+fH6+t7W99DE6C9mngY4wN/vw3NcNlhe/XI/o67cyIXfHC18NPqZDJIaZ2xg3Wa9nggmKUusfcy9T4Mak2MdWNKWuFD+y9YKSmWNiaPTzxOAGp7P32tJ+CeoZaZBp5Zvk0tE+8jwry+IhNIrEd+QE9RsWE9xGGuL2NvVbySieI5hPCDJAJeWWfMzWqo9cKbIf9GNUvx3lZv9ZutlUxSywVsrzWtvpwn/3JxOU3imGIA60CH/+lg3dcgqe7E9siOo0a40BXHz42xlVUsl9fS9iThVbwYnRWa7Fsf5Q1zfQrDGp72ytdb3ngKKsOvp/68bmc0dLarMMUXi1X/vjy6DgJ2BIWBtOlcWN/M//DBWDoI/I7BQT6I52RFxx8bBLHXamkaHauzL++bn8 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2026 15:55:39.7588 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 09721f5c-b87d-4d81-70ab-08dea79a17b9 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4390 Hello Peter, On 5/1/2026 6:51 PM, Peter Zijlstra wrote: > > Sorry for being late, I was unwell for a few days :/ Hope you are feeling better now. >> -#define PROXY_WAKING ((struct mutex *)(-1L)) >> +#define PROXY_BLOCKED_LATCH (1UL) >> +#define PROXY_BLOCKED_ON_MASK(x) ((struct mutex *)((unsigned long)(x) & ~PROXY_BLOCKED_LATCH)) >> +#define PROXY_WAKING ((struct mutex *)(-1L)) /* PROXY_WAKING has LATCH bit set */ > > Urgh, please no. > > You're making it needlessly complicated. There really are two separate > states, set by two different chains of logic: > > - the blocked_on link, set by the blocking primitive (mutex) > > - the is_blocked state, set by the scheduler when logically blocking > the task. > > by munging them together like that, you also inherit that blocked_lock > into contexts that really don't need it, and you're also sprinkling > more of that sched_proxy_exec() stuff around. > > If we keep them nicely separated, none of that happens, and > additionally, we might be able to get rid of the p->se.sched_delayed > (ab)use in the core code (eventually). So there are cases where we want to traverse the find_proxy_task() bits even after the task gets a wakeup to do return migration which will break if we start clearing p->is_blocked at ttwu_do_wakeup(). More on that below ... > > Does something like the below really not work? > > --- > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 368c7b4d7cb5..0bd5da8360f3 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -846,7 +846,11 @@ struct task_struct { > struct alloc_tag *alloc_tag; > #endif > > - int on_cpu; > + u8 on_cpu; > + u8 on_rq; > + u8 is_blocked; > + u8 __pad; > + > struct __call_single_node wake_entry; > unsigned int wakee_flips; > unsigned long wakee_flip_decay_ts; > @@ -861,7 +865,6 @@ struct task_struct { > */ > int recent_used_cpu; > int wake_cpu; > - int on_rq; > > int prio; > int static_prio; > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index b8871449d3c6..f679d65d98a3 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -615,6 +615,12 @@ EXPORT_SYMBOL(__trace_set_current_state); > * [ The astute reader will observe that it is possible for two tasks on one > * CPU to have ->on_cpu = 1 at the same time. ] > * > + * p->is_blocked <- { 0, 1 }: > + * > + * is set by try_to_block_task() and cleared by ttwu_do_wakeup() and tracks > + * if the task is blocked. Tradidionally this would mirror p->on_rq, however > + * due things like DELAY_DEQUEUE and PROXY_EXEC, this can diverge. > + * > * task_cpu(p): is changed by set_task_cpu(), the rules are: > * > * - Don't call set_task_cpu() on a blocked task: > @@ -3685,6 +3691,7 @@ ttwu_stat(struct task_struct *p, int cpu, int wake_flags) > */ > static inline void ttwu_do_wakeup(struct task_struct *p) > { > + p->is_blocked = 0; I don't think it is this simple at the moment because the proxy bits in __schedule() still have to handle PROXY_WAKING and once we clear it here task will no longer go through proxy_needs_return() path. Clearing of ->is_blocked has to be done at the same point where ->blocked_on is cleared although they are set separately. > WRITE_ONCE(p->__state, TASK_RUNNING); > trace_sched_wakeup(p); > } > @@ -4173,6 +4180,7 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) > * it disabling IRQs (this allows not taking ->pi_lock). > */ > WARN_ON_ONCE(p->se.sched_delayed); > + WARN_ON_ONCE(p->is_blocked); > if (!ttwu_state_match(p, state, &success)) > goto out; > > @@ -4463,6 +4471,7 @@ static void __sched_fork(u64 clone_flags, struct task_struct *p) > > /* A delayed task cannot be in clone(). */ > WARN_ON_ONCE(p->se.sched_delayed); > + WARN_ON_ONCE(p->is_blocked); > > #ifdef CONFIG_FAIR_GROUP_SCHED > p->se.cfs_rq = NULL; > @@ -6593,6 +6602,8 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p, > return false; > } If we change the set_task_blocked_on_waking() above for pending signal to clear_task_blocked_on(), this should be fine. Since prev is on_cpu, it doesn't need any return migration and going via PROXY_WAKING path isn't too helpful IMO. > > + p->is_blocked = 1; > + > /* > * We check should_block after signal_pending because we > * will want to wake the task in that case. But if > @@ -7108,7 +7119,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(next->is_blocked && next->blocked_on)) { There is a race with ttwu_runnable() that happens like: mutex_lock_common(mutex) set_task_blocked_on(p, mutex) set_current_state(state) mutex_unloc(mutex) schedule_preempt_disabled() set_task_blocked_on_waking(p) ... try_to_wake_up(p) /* State matches; p->on_rq */ ttwu_runnable(p) ttwu_do_wakeup(p); if (!preempt && prev_state) { /* * Never happens since * ->state == TASK_RUNNING. * -> is/_blocked is never set. */ } next = /* Gets prev again */ /* proxy bits are skipped since ->is_blocked is 0 */ /* * Exits out of schedule_preempt_disabled() * in mutex_lock_common(). */ __set_task_blocked_on(current, lock); !!! SPLAT: p->blocked_on /* PROXY_WAKING */ && p->blocked != lock !!! So that screams since we fail to clear the ->blocked_on state when ttwu_runnable() wins over schedule(). John didn't like touching the ->blocked_on state for (!prev_state && prev->blocked_on) so we resorted to using the lower bits of ->blocked_on. The p->se.sched_proxy like fix is the closest we'll get to if we go down the separate state in task_struct path and for most part it will mirror blocked_on which is why setting the bottom bits like MUTEX_FLAGS made some sense when we looked at it. > next = find_proxy_task(rq, next, &rf); > if (!next) { > zap_balance_callbacks(rq); -- Thanks and Regards, Prateek