Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.56.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796194788; b=mBe/6XtwoyXSRyjlh4Ya5KN1u2+jbFOS8htVeGdcFIuuAbPbZgMCWv2nGXuuQayFPm7I adYo320eg8YMf4yRvJ9AjVfs8++7YkpMmqD9sWMMoZM4kyIAhv6ixWDF2uh2ckTJP5Th9 n+g/tE9glsU3TSSmDifvKxm0fT/YDEFYI5iyrVwWdGLTMOmIGvuUYTryaK+YjHOPnLSVM KlctB/QFvkxpk4nDh7lQJ+66FWToDpPSq8uOeUa7EPni+F+pq+OYnfKwYQvjWnx5V0x4A noo99zBfReCFZmvmUoUMDnLnl17jEFA5qrC4HSxKHciKgk+1sKjLAxnl+fuv8XlncMw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796194788; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:Received:Message-ID:Date:MIME-Version:User-Agent:Subject: From:To:CC:References:Content-Language:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=19MpFlw4Kbyf/Q15mSws7tFBs+sBjigSQF+bzBjMOZI=; b=bJnNrPSpnb/fct0tTsuIlCOgEdoH05/nPq3WSaH3MHhFWw9AtyYfNxG5+xbIFhETIQYP m1KXiZnb5hLfAZJ6yyFOVpK+NgyKYIf2Q/11BN74eYxZhsmA/gBVfniThuhAUxmcIl13s PtnuhWw3V7V+pjRnDIQEOeenDfP+bxsqX7znVDGq1rDC8SXHfcwj2fKFgRD98UxnlDBN/ QizuPXnrILYvEXCeo/QNh4t68zHhZb6lPrTOb+IItXrCxuttDBQJ4FK4xLxY0OszTDBAc 4RWGoOIYFv6ax8YFhEYUzNbAr+AUjjFMuHA24PjVgHgJY3EF3ZgtSDSMoC5bYkLLWng== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=jR6nruUT; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.56.18 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010018.outbound.protection.outlook.com [52.101.56.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2960606A322 for ; Wed, 2 Dec 2026 06:59:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E2960606A322 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, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=jR6nruUT ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uclywcHio4IN9Ou9laFgrkC8gPTD/yZYc7OlRD/ycET0eOd5SfhueoOSB0kLkKU6zkoEm5bRnkaR1rN8UKoS6pQ+LEOXj8Yy/v0aemI8aH+wX7N0Bg/wxPzxrDlRlRBjzlPGxAOvsCpbu3gt72+60NMpU0yBE1Q7SjVn45HQbXwjy1G/RjaOMUXIcdEJ3omXE1m/nxKhxY3D3Iiw2qLcYHFUCuahAMqmAvmCLuViBiRcAsJPKwMNwES7YCTS0DCnyOeu5vlwvHxdsXF7WRfuAqOc2H0NqsD3cUI0s/Un/jjwacWgbj/1d6QhHdxzA1Lki1iCX3eBQticY6XTXMqeDQ== 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=19MpFlw4Kbyf/Q15mSws7tFBs+sBjigSQF+bzBjMOZI=; b=phtD05qVo+3RYUPVhqL++t6HZLjjr5JzK6B9nTq4N7xtJII8pH1qDadu0WBc1LBCCJ5eMUUxHvhdJisahPcambzkxH3SwzFFfVRObe8BGuGlqlxr/hpmq90k7Vk6VPmEKXCG12/Qczo0UwKUH/B611+3VXYCfOt1g6yTBknbAyrVuAYp5O1b9bGg7U0u2OZOp3HQZCeEeQ0zzOd5mYARE0FK0+w4GsBzSNy4LxsuIy1hfoX4WWzIMlkojrUwY/cks/6H2W+lR6L8xR556HJW+pv19z+A66H2eqiPymAl6Pr5ONt3NQzCr4cIqM26oUSpyl4qtDNWMEjQuB5ctNoEXw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.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=19MpFlw4Kbyf/Q15mSws7tFBs+sBjigSQF+bzBjMOZI=; b=jR6nruUTyoYnu8YblLu+HP/ibpbQel2VEwkvMrkeTh3KUiu+xj42W8xDX8yM7+7+FIlR8BVw2FsjzGXWTAnZNRs+pW9b6fkN7O/IVpaw+3Z1tFoM/FVfAIjIkj5RA6mBTAvgmdG6kuVaNMe4po8nN9Bb7WQ3yJ1S7hW5I+2lEBs= Received: from CH0PR07CA0018.namprd07.prod.outlook.com (2603:10b6:610:32::23) by PH0PR12MB7080.namprd12.prod.outlook.com (2603:10b6:510:21d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Wed, 2 Dec 2026 06:59:39 +0000 Received: from CH01EPF000BE940.namprd02.prod.outlook.com (2603:10b6:610:32:cafe::ab) by CH0PR07CA0018.outlook.office365.com (2603:10b6:610:32::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Wed, 2 Dec 2026 06:59:39 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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 CH01EPF000BE940.mail.protection.outlook.com (10.167.244.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Wed, 2 Dec 2026 06:59: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.57; Wed, 2 Dec 2026 00:59:37 -0600 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.57; Wed, 2 Dec 2026 00:59:37 -0600 Received: from [10.136.42.27] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Wed, 2 Dec 2026 00:59:30 -0600 Message-ID: <331ab57e-5764-4200-a89d-443aff5482a5@amd.com> Date: Wed, 2 Dec 2026 12:29:29 +0530 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v34 05/14] sched/proxy: Clear blocked_donor when the donor stops donating From: K Prateek Nayak To: John Stultz , LKML CC: Mathieu Desnoyers , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Juri Lelli , Vincent Guittot , Valentin Schneider , Suleiman Souhlal , Andrea Righi , Johannes Weiner , Metin Kaya , Dietmar Eggemann , Steven Rostedt , Zimuzo Ezeozue , Waiman Long , Boqun Feng , "Paul E. McKenney" , Joel Fernandes , Qais Yousef , Xuewen Yan , kuyo chang , hupu , Zhan Xusheng , "zhidao su (Xiaomi)" , Hui Su , "Shubhang Kaushik (Ampere)" , References: <20261202035248.1210026-1-jstultz@google.com> <20261202035248.1210026-6-jstultz@google.com> <2422a051-ea4c-47ef-b5de-9523a351faf7@amd.com> Content-Language: en-US In-Reply-To: <2422a051-ea4c-47ef-b5de-9523a351faf7@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH01EPF000BE940:EE_|PH0PR12MB7080:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d968e26-d123-4439-48af-08df5041d56d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|36860700016|1800799024|23010399003|11063799006|4143699003|22082099003|18002099003|56012099006|10067099003|261022105027099003|261022075727099003|261028144727099003|261026121527099003|261026140227099003; X-Microsoft-Antispam-Message-Info: EuAT4S84n2qkE2O9ds62sDPLX+9DrunA7RPEnNqD7+h0ZlkLGcdGu/lMYwXiAWPJaONIKEve7kiPVDLZUqXiO/euDuhYbTTEByQhqwGiG77BkOOkzvCuzWJSWJXkpsI4zoQp8AmSTWJJ3oeI8Z1LthIAzl0BZ3NQ5u22bnkkFfPCa+Na0lUhBt6xtmteUZ7CAEFiOhEkc9ULz8R6vb1awVpwI9epku4//ePWf7wBXh07SmeRgzheukAvzP8/otKEVz/zrx8BZpbCdJOPD3UXt4a9ARIiATGw3fjDJSyhBQpsy57q7GWukTXIBbrglZL1lx15s10tkSFE8AzY8PuWYRNJV7VQA/jFAz4ZO1RXvZicH4MQVyP439hq9/Tn1tgHASNZRUWB/hmfdWePyTqxzb4Y8hig3L4kUf9AyWxYW1uEBIbWQvwFsKaMjcsSBTv0KmRwQz76MOuc2wyTeLgmNc4qG8d5w5uiiEhp2TnSHytVLulfZAOaZbMKw8ccxHmV7tcXYDpJONBPM1l6EtAJtv3OtUCG9K3MxtucdOoJ8HePtxomxd5I94j+yjycWFRW2/+pif6fJV6z39JKvk5BQe9HzrHdustcXykzcCwpLmxeNMZPZ2xYYM1o0cN6sMHy48uuOTBe/3ke4jKJOCHRWu1sZbOFCvX+PIbWRGMe/B0= 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)(7416014)(376014)(82310400026)(36860700016)(1800799024)(23010399003)(11063799006)(4143699003)(22082099003)(18002099003)(56012099006)(10067099003)(261022105027099003)(261022075727099003)(261028144727099003)(261026121527099003)(261026140227099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ppbjgk2+4eOXVP/WHsSxcCDOCkuBR+47tA2CXn1vdSayhmmhDd7FNHs0pzWk3PTPoYZu6O8y3EYcp7Fn6Q74w+dpb94CoxcU+yG+bh+K0joB5GuFVOy95hDiZac3BZESMdJv0nQieoaW4Xk0W0Q7rn/zlSwDmxI44Fhz28ckc6H3NMR2k46UtYraVoa2khUFojVUoszpsP+uE0gDIQ68tS6ywGfsb+aln96gGF+2BaH7HK3FGwbYtnSsStvrUK0OMza4KYJlD+Ptp7/AXZW5EcJYIWoRFNCuTt3coyguLh9dtg6iyBuTtSDih+DRKWB9ooF79TBoS2/duHnQYqs8dN7gtKQU6Gf2BppybPSRSc4lsUJsJ8U+ELiQU2eIQvuEQ6KFtgAVv+WjMKEY7iVpDDbf1ERPAhtAz3B+ZVHUt+qX0SqTARA1VEeyUdpMaBL3 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 06:59:39.3157 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1d968e26-d123-4439-48af-08df5041d56d 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: CH01EPF000BE940.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7080 Hello John, On 12/2/2026 11:40 AM, K Prateek Nayak wrote: > Hello John, Mathieu, > > On 12/2/2026 9:22 AM, John Stultz wrote: >> From: Mathieu Desnoyers >> >> find_proxy_task() sets owner->blocked_donor to the task that donates to >> the owner. __mutex_unlock_slowpath() reads current->blocked_donor to >> hand the mutex to that task. The comment of the field says that it is >> set in schedule() and only stable under preempt_disable(). So the >> pointer is valid until the owner schedules again. >> >> But the donor can stop donating while the owner keeps running. It is >> woken, or a change of its scheduling class or of its affinity takes it >> off the runqueue. The owner keeps its blocked_donor until it schedules. >> Meanwhile the donor can run on another CPU and exit. > > So we can just clear it in proxy_reset_donor() right? Only > current->blocked_donor is ever looked at and, it the proxy breaks mid > way, the only path that can be taken is via ttwu_runnable(). > > If the task is retained on the same CPU, it is safe to get the > reference since unlock is done with preempt disable - otherwise, we > check: > > donor = current->blocked_donor; > > guard(&donor->blocked_lock); > next_lock = __get_task_blocked_on(donor); > if (next_lock == lock) > next = get_task_struct(donor); > ... > > If ttwu_runnable() manages to clear the blocked_on relation first > under the blocked lock then we don't take a reference here and if > we manage to take a reference here, the task cannot exit > unexpectedly - it'll just get a spurious wakeup in the worst case. > > IMO, a simple READ_ONCE() to check it here and WRITE_ONCE() in > proxy_reset_donor() after the re-arrangement suggested on Patch3 > should do the trick based on my understanding. > > o Race: > > try_to_wake_up(donor) mutex_unlock_slowpath() > ttwu_runnable(rq, donor) /* MUTEX_HANDOFF */ > proxy_needs_return(rq, donor) donor = current->blocked_donor; > proxy_reset_donor(rq) raw_spin_lock_nested(donor->blocked_lock) > WRITE_ONCE(rq->curr->blocked_donor, NULL); next = get_task_struct(donor); > ... /* Donor wakes up runs, exits */ > > /* > * t->__state = TASK_DEAD > * t->usage != 0 so freeing is deferred wake_up_process(p) > */ !ttwu_state_match() > put_task_struct() > /* Freed via RCU */ > > > If the task runs and blocks on a different lock, wake_up_process() from > mutex_unlock_slowpath() (if it still think lock has not changed) will > just lead to a spurious wakeup. > > Is here a scenario where proxy_reset_donor() clearing is not enough? I guess that is not enough either since we need to clear ->blocked_donor for any wakeup in the chain :-( Btw, for cycle detection, at some point we had a rq->proxy_pick_seq based cycle detection [1] and that can be used to detect if we should actually issue a resched_curr() + clear curr->blocked_donor or not since the tasks in chain will have the same pick_seq as rq's pick_seq. I don't think the extra resched would be a visible problem atm but if we do hit something, we can perhaps consider that approach. [1] https://lore.kernel.org/lkml/20260717105259.747783-1-soolaugust@gmail.com/ -- Thanks and Regards, Prateek