From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011006.outbound.protection.outlook.com [52.101.57.6]) (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 8C1053D1CB1 for ; Tue, 28 Apr 2026 08:16:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.57.6 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777364204; cv=fail; b=CwjIDUHRHGhyttBxsQbOH8UyY64JE2xyj5cF15Azz3RsduHDtNEJao57A/gL9qusNo6SmotWxrQCdQpMdyzetO+ZU/dQQR5PeKpzeV4/2Too4/qaaPrwrS/TPCYDAPHM0Ljc5MyCqriDct8JhvQpqK/o/hFHO/SdkqG+PrwVQSE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777364204; c=relaxed/simple; bh=TxRQ8l0J0s6/e+qLRhJWdW0cu0dfZLlSM8Lqw6mpRVI=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=UXsxMcoBeQlUIhtE8Kdr2lPBX8zUq8LpVsYS1BqdCQ7YqZ0Uu4omQxaI7TPaRa7hEvkdl66lzRQyP/eTRpnyty5IWLaaROSAr0kBvxWj9ADoFXg1KFGJLH0g9/sDX6WVt9InPWtc2b5VTUAQrjn9R1h9CGGN4ddCeeh5H97nEnU= 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=G00DJK7O; arc=fail smtp.client-ip=52.101.57.6 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="G00DJK7O" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=plMD+AZWYCnh3I+BLXO787SAdUxJ1m3NyCrL+RUa3Jflpmwf98qK7RSt0bQQCMTPl1kIT3uweyABfYiZdZAyaNGyDrFOegEUqkBAvA7MT7RTgXh8BW8YEbE1YS/RrezUFLR/ys6kduicpV0Jf7fvNS1LWdG8JQzdSdnowbwrSwsxMvggje4VJAYAjEtMwFCqC64Ksg/+QMgKf96XZj0qjx3Hf+lzBjoe/Fx7nSBoPgRXUjUQoMGq4g/YGMlRkawF452gYyFgaEAwLE+G/QtrmAN/uRqZz9xtTvYIRzFCgdVHjzTg+Ne/4KXC6qLZBWki4WLt4iH4TfPYVX7B0P+qTg== 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=PxHIWNJzPTcxG91MUsTrIzTpxSFQtMZk3iaLW3kTNKM=; b=ZV8iSySzgOmovbDLtpRlxnC3Oz+8BcxJwkvU63/QMJa2A++7SMsKd0Miso5UZsu/JtlTrBL8E4V1nziOLaWIfsZy/AOCja/+qZaVWHXJuCsS2NrI7ybieAnsAbDt+/lyveUtNZ0RJpxYggrqRaB+p083t3yMgCOJZrGPwIZcfgnVgkceA8SIYTZqsgQDn2FIrLamNwwt098j7ArkAW1arAgfDFphSyMXx7cQ8BTXAylTRSbFiGjvzg6AF3XZ9eNYRHqskBa9OnXsKfc19POVvoXjajMLA21lDGIuUUzgxpopvSGJ01T0+vqNtzXE3j3O9ZmkjUoeu+LCG5k0t1KJHw== 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=PxHIWNJzPTcxG91MUsTrIzTpxSFQtMZk3iaLW3kTNKM=; b=G00DJK7O+MpMYO+oW/dDIBMD+y+2i3or/90JouzJkKWnLSdup64bQ1byEAEmxQJTHUpbwVwO4fm6lZ80aGZs6xQKQizKU/bvcnar+EBWrFu2ucwM2VtHDJMu9RWXZbSOL+1vcjWpf7E0d7ZkGN43SxDGcUukVePTocVE9M9LqlQ= Received: from SJ0PR13CA0123.namprd13.prod.outlook.com (2603:10b6:a03:2c6::8) by LV3PR12MB9353.namprd12.prod.outlook.com (2603:10b6:408:21b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.18; Tue, 28 Apr 2026 08:16:37 +0000 Received: from SJ1PEPF00002320.namprd03.prod.outlook.com (2603:10b6:a03:2c6:cafe::e9) by SJ0PR13CA0123.outlook.office365.com (2603:10b6:a03:2c6::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.26 via Frontend Transport; Tue, 28 Apr 2026 08:16:36 +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 SJ1PEPF00002320.mail.protection.outlook.com (10.167.242.86) 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 08:16:36 +0000 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Tue, 28 Apr 2026 03:16:36 -0500 Received: from [10.136.41.76] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Tue, 28 Apr 2026 03:16:29 -0500 Message-ID: Date: Tue, 28 Apr 2026 13:46:28 +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 2/2] locking: mutex: Fix proxy-exec potentially deactivating tasks marked TASK_RUNNING To: John Stultz , LKML CC: Vineeth Pillai , Sonam Sanju , Sean Christopherson , Kunwu Chan , Tejun Heo , Joel Fernandes , Qais Yousef , Ingo Molnar , Peter Zijlstra , 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-3-jstultz@google.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20260427183848.698551-3-jstultz@google.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002320:EE_|LV3PR12MB9353:EE_ X-MS-Office365-Filtering-Correlation-Id: b568c068-e113-4631-50ba-08dea4fe77a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700016|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: 9wpYxegfWb9JqcYGaNMOGJkCZ0b8Dz8wfv5KbFTHoqnjJXynvZTVjsgJerFnYV5pwnFzzv2gFwUMy9gd2YA32j+pwBNYPDK6SO8gP2U9OYm2G5bcVYlw6dU88GkQL7asSoTj3LR5eTwwnXdCRXelSdJ4e57fZT/QprPZttjNclcyiGbMo5niDlwZqLMrTzA/GqLFRW9AAjqLbMS51IqoJUqxQGLyH1Pzy/pU6BvypkA0S0QA0xwvnRBlIR8GnY8GAT+l+3MoS1W4l0NiHF/keDH+qFCzbUY+qgyFNIgPnOAm6HeUVdyr0yrVchV7UvIp0LLPMsshvdAKFhdJ7Htr911D1l7Qx3h/zh9j1hrz42ZlxJ7sV83gUAdg8e8TWrWyfvNRU+qP9jHTTbcvQ9S5/M86IbIvlVlY9ru+We8smxV9q5c+S8dsDobbtVCf1BYpOPAu8Xi+m52T2pwHeUB7Ey9+uWRQjT4EvmMicvQXNKClC65tj1f0/6nwA0pmCORvwcIZbjucYh9MtvDoN5V4CFbwG5KRqO5brEO52EI3PfqK2TTUZPmXEhHjnpZ1GXDNFUWdFD8iN0thiNs1rR96302Ywi+JMt/ClHEu49zppNpyQx7Ce5GM1stC6x2BB/FdOALiz1gmUYAtak719hM5zAZd/4PSVrF4Qn1y9sBcVhpswlObzXxal8vjprwe4L9YEHfkW+Flm48SVPVf5z0EEHvSvQ1uBCxG9q4YSoy8OfHc0U04G5d9m69uRV6z6PnI4oBwb2+PSoPmYKUMcusCRg== 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)(1800799024)(82310400026)(36860700016)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S8FxjB5vFkj/xfz6z9FQ8SMaAGiMvTg2/uPchT0H/E4cJMCnj0lGJlXXyePiqbROU6lZ1wfG/jxTjSEe/P+Znv0/XUp5dY8ieqBteA5AGADzSbMfzV0p+cfjJOfwvfXBY6kToX12u5vreeCjO0ltardJgJdh+llG6A1a0h8OuHWFt+DOeuk+t3Cw1t0AvlNKZ4kwZt/mtMd9my8uWwHno0R0JwSfOMz+ZuGaufSKhNG78v/I8MqctFEa9nRfYQ1TAalpAuFkPOFDJRsgm/dOVatOLV1p9UAly5ktlo+CcMRepFdrH18RFhGTl+2DXcrn6eWDu/9G2lEnctV/Krt45byWai3bxcSkgPUMDTVMIpEhHVnuC7jwJScX0KDPUNL917Xapoj9v9oLrFjxFq69k4hOToY7e69aQ1fMyZrc+tC7tLMdDc+5HQn2XVaI6PNJ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2026 08:16:36.7694 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b568c068-e113-4631-50ba-08dea4fe77a3 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: SJ1PEPF00002320.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9353 Hello John, On 4/28/2026 12:08 AM, John Stultz wrote: > Vineeth found came up with a test driver that could trip up > workqueue stalls. After fixing one issue this test found, > Vineeth reported the test was still failing. > > Greatly simplified, a task that tries to take a mutex already > owned by another task that is sleeping, can hit a edge case in > the mutex_lock_common() case. > > If the task fails to get the lock, calls into schedule, but gets > a spurious wakeup, it will find that it is first waiter, and > go into the mutex_optimistic_spin() logic. Though before calling > mutex_optimistic_spin(), we clear task blocked_on state, since > mutex_optimistic_spin() may call schedule() if need_resched() is > set. > > After mutex_optimistic_spin() fails, we set blocked_on again, > restart the main mutex loop, try to take the lock and call into > schedule_preempt_disabled(). > > From there, with proxy-execution, we'll see the task is > blocked_on, follow the chain, see the owner is sleeping and > dequeue the waiting task from the runqueue. > > This all sounds fine and reasonable. But what I had missed is > that in mutex_optimistic_spin(), not only do we call schedule() > but we set TASK_RUNNABLE right before doing so. > > This is ok for that invocation of schedule(). But when we come > back we re-set the blocked_on we had just cleared, but we do not > re-set the task state to TASK_INTERRUPTIBLE/UNINTERRUPTIBLE. > > This means we have a task that is blocked_on & TASK_RUNNABLE, > so when the proxy execution code dequeues the task, we are > in trouble since future wakeups will be shortcut by the > ttwu_state_match() check. > > Thus, to avoid this, after mutex_optimistic_spin(), set the task > state back when we set blocked_on. > > Many many thanks again to Vineeth for his very useful testing > driver that uncovered this long hidden bug, that I hadn't > tripped in all my testing! Very impressed with the problems he's > uncovered! > > Reported-by: Vineeth Pillai > Tested-by: Vineeth Pillai > Signed-off-by: John Stultz I think this too requires a: Fixes: be41bde4c3a8 ("sched: Add an initial sketch of the find_proxy_task() function") With that, feel free to include: Reviewed-by: K Prateek Nayak > --- > Cc: Vineeth Pillai > Cc: Sonam Sanju > Cc: Sean Christopherson > Cc: Kunwu Chan > Cc: Tejun Heo > Cc: Joel Fernandes > Cc: Qais Yousef > Cc: Ingo Molnar > Cc: Peter Zijlstra > Cc: Juri Lelli > Cc: Vincent Guittot > Cc: Dietmar Eggemann > Cc: Valentin Schneider > Cc: Steven Rostedt > Cc: Will Deacon > Cc: Waiman Long > Cc: Boqun Feng > Cc: "Paul E. McKenney" > Cc: Metin Kaya > Cc: Xuewen Yan > Cc: K Prateek Nayak > Cc: Thomas Gleixner > Cc: Daniel Lezcano > Cc: Suleiman Souhlal > Cc: kuyo chang > Cc: hupu > Cc: kernel-team@android.com > --- > kernel/locking/mutex.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c > index 09534628dc01a..a93d4c6bee1a3 100644 > --- a/kernel/locking/mutex.c > +++ b/kernel/locking/mutex.c > @@ -763,6 +763,7 @@ __mutex_lock_common(struct mutex *lock, unsigned int state, unsigned int subclas > raw_spin_lock_irqsave(&lock->wait_lock, flags); > raw_spin_lock(¤t->blocked_lock); > __set_task_blocked_on(current, lock); > + set_current_state(state); > > if (opt_acquired) > break; nit. As a micro-optimization, you can probably move the __set_task_blocked_on() and set_current_state() after this break. -- Thanks and Regards, Prateek