From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2087.outbound.protection.outlook.com [40.107.100.87]) (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 D8C9E139D for ; Fri, 1 Aug 2025 05:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.87 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754024958; cv=fail; b=pIt6nDhMM0vOWFuKsr7qd4110HrbAgwxdLIAXBqnZoInxqc5b0Ren8Sg3ZarW9RkVIxf8PTy4mNZ0UX7RyE4fKiB/L/9/XnKxmayOHOjXZVM2WwzxAlYZvw4qwUtOybdH2ES0bVVNMj8cNn1gg+rbX5F1NE0CfXn7R42Cxuiys0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754024958; c=relaxed/simple; bh=u3P97TcYkQ93jS+zBa4u3QLWGxD+qRGsfZN5SKjr1BU=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=YazO6WtOzNYpQbLRy3gTuQFZXWx4PmPHL22r/5OmiZNEXaAt3m6jZQFWMFbw2vEzRVvjIz6anp7WC/7nL98xnGiKt0Pjcq3BOHiMRRojhblO5O0eIkJP44owT/Wf/Ipor1iZO8DZppZDoGJfRpMt1avxVcZ4lrFdcGEJyeOqNpM= 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=vXHXpKiH; arc=fail smtp.client-ip=40.107.100.87 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="vXHXpKiH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EBxccflnhmS4wGasUHuvpi5ATYz6/g46wk6dVT4J3M2j1CpQ8ZxQObQR7zcOks5ETgO2AO0Ou1mCXQDJep8tG7So3lLJu3YMDSh2jupQKNot7Ibf/QhEEsFXYqWftGDgQgWnd9sr3I10zuPxBw0lnZCrja3Q2UBuBYUI66/wkU7fHNX44w8GzYDMbW5LoWBlooQMkqhRzsbgm0Q+9dKe61eatwx2PawaRcqDgw1W5NS8VMw6CA+oXBTkETJGrjz0hb2ewUnumcQAjgUjg5AvzbIgBBFmKm9f3AqZ+jUx8sF+7Lel70a9FivLQim0sECLzTSj32BcshJz43Zjq2Olnw== 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=ZfOG9CO6tg9eagrNjexTXl9P9mtjz1VL9zCsNGFYpus=; b=BTo00/3SK0t8ATdgckI0JcVZhfxg6rHB3kdIzAO+8aS0mfOKekGMtkldQDVBdCAbFw5sCX1G7Z+ToAIw4J/JFXCJV9R81E5zqHIb7BkZPdjQomrIcb5K33bcsNat/nlU2ItPMNxnoNwjLBMnAQ5UU9PyOL5F65oM6FIyJH5uQsSwL92Tg3BbNhCxgfzJWXrQaMi7crgjk2xD8Xriiefy+W3484s53dvcZ2+Nj4OTOXCY19pNzkD+kdCdAhdRgB47nu+FwdX7BAs+boDCFUrevobeh6cxIvcfC8pVuwniRKPaePk3xCgco4w19xGvXRtZTQqKXVHmZfr2P4qMfACICQ== 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=ZfOG9CO6tg9eagrNjexTXl9P9mtjz1VL9zCsNGFYpus=; b=vXHXpKiHn81WaVLnv1tFM8+drFtNQZkPI9bkoX6yIu2+nBrL0iXcevJPWZkrpSvEf+WXvwAW+hYMeM6s/x0W0+ZuX9oAByXnBxXjWPOiRrgGcKVi1fTk3LoRZ5CU5B6fo6QDfcSPruOuT+EeM5CC/VVKvYQ3Mg7K0Nxu57q+/4M= Received: from BL0PR01CA0006.prod.exchangelabs.com (2603:10b6:208:71::19) by IA1PR12MB7758.namprd12.prod.outlook.com (2603:10b6:208:421::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8989.12; Fri, 1 Aug 2025 05:09:14 +0000 Received: from BN2PEPF000055DA.namprd21.prod.outlook.com (2603:10b6:208:71:cafe::3b) by BL0PR01CA0006.outlook.office365.com (2603:10b6:208:71::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8989.14 via Frontend Transport; Fri, 1 Aug 2025 05:07:53 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN2PEPF000055DA.mail.protection.outlook.com (10.167.245.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.9009.0 via Frontend Transport; Fri, 1 Aug 2025 05:09:14 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Fri, 1 Aug 2025 00:09:13 -0500 Received: from [10.85.43.78] (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Fri, 1 Aug 2025 00:09:09 -0500 Message-ID: <2812bdc6-8d7e-48a3-8f5b-a26cd5d18c32@amd.com> Date: Fri, 1 Aug 2025 10:39:08 +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: [RFC][PATCH] locking: Fix __clear_task_blocked_on() warning from __ww_mutex_wound() path To: John Stultz , LKML CC: , Maarten Lankhorst , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Suleiman Souhlal , , , , , , References: <68894443.a00a0220.26d0e1.0015.GAE@google.com> <20250731201337.274382-1-jstultz@google.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20250731201337.274382-1-jstultz@google.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: BN2PEPF000055DA:EE_|IA1PR12MB7758:EE_ X-MS-Office365-Filtering-Correlation-Id: ffc5381a-4006-4d4c-c494-08ddd0b98ee7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|82310400026|1800799024|376014|36860700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WVdDcVBnS1lmUHJweWF5WWZxVHNWcWpRNDFQWEVCQ0tuaDNu?= =?utf-8?B?MGV0L1VWSGdlWlZCK0M3TzJjTzJkaXd1ZHRaeGlPakZmS2xhQjZkK2sxbTg3?= =?utf-8?B?QXhHUVo4UFgvdFYyL0RMSFMyZGs3Nm1BZlZKZHZTdEJxUFVaRlVPSkNrOC92?= =?utf-8?B?MUdYbWp4RGg4NHkydnpiWWRlRnc5eVZWYkZlQXNERXRtUDQ2NStkNlc3KzZG?= =?utf-8?B?ZW9ZV3k5eEZ0Zy9naDBESjJ6UTFlM3B2ci8rTm5jQW5DL1RwQ2IzSFUxQjlt?= =?utf-8?Q?vlo55M?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(82310400026)(1800799024)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2025 05:09:14.1131 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ffc5381a-4006-4d4c-c494-08ddd0b98ee7 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF000055DA.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7758 Hello John, On 8/1/2025 1:43 AM, John Stultz wrote: [..snip..] > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 40d2fa90df425..a9a78f51f7f57 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -2166,15 +2166,16 @@ static inline void set_task_blocked_on(struct task_struct *p, struct mutex *m) > > static inline void __clear_task_blocked_on(struct task_struct *p, struct mutex *m) > { > - WARN_ON_ONCE(!m); > - /* Currently we serialize blocked_on under the mutex::wait_lock */ > - lockdep_assert_held_once(&m->wait_lock); > - /* > - * There may be cases where we re-clear already cleared > - * blocked_on relationships, but make sure we are not > - * clearing the relationship with a different lock. > - */ > - WARN_ON_ONCE(m && p->blocked_on && p->blocked_on != m); > + if (m) { > + /* Currently we serialize blocked_on under the mutex::wait_lock */ > + lockdep_assert_held_once(&m->wait_lock); > + /* > + * There may be cases where we re-clear already cleared > + * blocked_on relationships, but make sure we are not > + * clearing the relationship with a different lock. > + */ > + WARN_ON_ONCE(m && p->blocked_on && p->blocked_on != m); Small concern since we don't hold the "owner->blocked_on->wait_lock" here when arriving from __ww_mutex_wound() as Hillf pointed out, can we run into a situation like: CPU0 CPU1 (Owner of Mutex A, (Trying to acquire Mutex A) trying to acquire Mutex B) ========================== =========================== __mutex_lock_common(B) ... /* B->wait_lock held */ set_task_blocked_on(ownerA, B) if (__mutex_trylock(B)) /* Returns true */ __mutex_lock_common(A) goto acquired; /* Goes to below point */ ... /* A->wait_lock held */ __clear_task_blocked_on(ownerA, B); __ww_mutex_wound(ownerA) WARN_ON_ONCE(m /* Mutex B*/ ... && ownerA->blocked_on /* Mutex B */ __clear_task_blocked_on(ownerA, NULL) ... ownerA->blocked_on = NULL; && ownerA->blocked_on /* NULL */ != m /* Mutex B */); !!! SPLAT !!! At the very least I think we should make a local copy of "p->blocked_on" to see a consistent view throughout __clear_task_blocked_on() - task either sees it is blocked on the mutex and clear "p->blocked_on", or it sees it is blocked on nothing and still clears "p->blocked_on". (Tested lightly with syzbot's C reproducer) diff --git a/include/linux/sched.h b/include/linux/sched.h index 02c340450469..f35d93cca64f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2165,6 +2165,8 @@ static inline void set_task_blocked_on(struct task_struct *p, struct mutex *m) static inline void __clear_task_blocked_on(struct task_struct *p, struct mutex *m) { if (m) { + struct mutex *blocked_on = p->blocked_on; + /* Currently we serialize blocked_on under the mutex::wait_lock */ lockdep_assert_held_once(&m->wait_lock); /* @@ -2172,7 +2174,7 @@ static inline void __clear_task_blocked_on(struct task_struct *p, struct mutex * * blocked_on relationships, but make sure we are not * clearing the relationship with a different lock. */ - WARN_ON_ONCE(m && p->blocked_on && p->blocked_on != m); + WARN_ON_ONCE(m && blocked_on && blocked_on != m); } p->blocked_on = NULL; } --- End result is the same, only that we avoid an unnecessary splat in this very unlikely case and save ourselves some head scratching later :) Thoughts? > + } > p->blocked_on = NULL; > } > > diff --git a/kernel/locking/ww_mutex.h b/kernel/locking/ww_mutex.h > index 086fd5487ca77..ef8ef3c28592c 100644 > --- a/kernel/locking/ww_mutex.h > +++ b/kernel/locking/ww_mutex.h > @@ -342,8 +342,12 @@ static bool __ww_mutex_wound(struct MUTEX *lock, > * When waking up the task to wound, be sure to clear the > * blocked_on pointer. Otherwise we can see circular > * blocked_on relationships that can't resolve. > + * > + * NOTE: We pass NULL here instead of lock, because we > + * are waking the lock owner, who may be currently blocked > + * on a different lock. > */ > - __clear_task_blocked_on(owner, lock); > + __clear_task_blocked_on(owner, NULL); > wake_q_add(wake_q, owner); > } > return true; -- Thanks and Regards, Prateek