From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010051.outbound.protection.outlook.com [52.101.201.51]) (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 DE70E35B653 for ; Mon, 27 Apr 2026 06:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.51 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777272075; cv=fail; b=oyzdTKxVuqJ4YYEFq7eqZH3x9Ia7upwYi3Z7vLfIdJDoQAvl3i5DeCb4Qd7PqEErPBgslDrrXi9+kC/bYhFCRbOLuHCBqmdWp5aULaZ3IU9i7FUkKO192K6j2k59rFB3gPRJjGj8haisOUL2+nqNvqlNGFgvdy3HjZj67WGCUhA= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777272075; c=relaxed/simple; bh=dcX47Nl/hYcYXe6jElF0XslrBVa9kC9YC7RmxPbxg0g=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=nog/mvpFKi1I6OOkOhDONs8k/v5JB4g0DbI71ptDxyccUNofgZqukbm6YrGNF35byOoKV8IA4Cvrqa70SKNgDvcyXFOzmix/EkbfM0gLNmvvhiiowHxmz39ZtuphioaBCs6shaFrei2C42HIEXaBv+TOCbpU4vh1MTDkkpuDlwo= 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=KtPkQOYX; arc=fail smtp.client-ip=52.101.201.51 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="KtPkQOYX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=M82UboCdgBxv936rUu2akC7qfSvwX1DrZesv+lcphY8+eZGapRFWuDDwHtvac1F8eLsbfRVVSjMr5dgfmJbF3JeDoVFLzzChr9B6kiXAHfDRqetpTh6CcFOlFvAFRPorygXgGb56oXuPWaaSKqYsH/QMS9Wysa3okTAdOHrDRs+VpUsXZHV5Q3V2h39vueDNajs4nSRTVnPy9ziudTckrijL175JYO+piBJmna2O6SHQuHTBEpdv79BIIs5GH6owgdbJzFM44lBbcNnDKNH2Q/LZgYpLia8CNyhxxrhZg2RceTfqE0V5yhcD4oyog3gJeMgAUZIxqX9pDKnRLsdwMQ== 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=fI5s/1bDFejZvRs8vNY7RTaWVDqkZBkXjNrQemfdPF8=; b=PVrYE03q6rPopaIbhY0pHnoM5BkDotTBiCpcIRl4ysmud2nxmASHJ/UQ3Z6rAcfCcBMgChaxiqJ9LbYFzkso5/As1B5wiiR30Q3fQeofJuYAugQ0b5eZRaKoo2+ozG+P5dlihrTMprdDoPbPmgqpiOO7KBzBjtqZIcitpGJuHchQIuJ5QW8ck/JsjnboHPNhqEp4ThKo9ziBeL95Z7frZAOC+fEtjXJMo0YpgzClAuOR73c/w4+hi87LlRxH81028G0cVLZmXLd7wVhotcBsGjewqbm9MrwVhsIzFazv+P7GDMXK3UTsrwfDgsiPXQj76fJQSytwcqsyaWZjWGKUPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=huawei.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=fI5s/1bDFejZvRs8vNY7RTaWVDqkZBkXjNrQemfdPF8=; b=KtPkQOYXinLgmTSwJuCkJ3H/oEUbJlQ7KYTFzSXOsth5+Z2A790zGPOGEgAe31paB2FRYcOD3U3i/nagcuTdTmy3PrbhkWi2g1/O237/vAbdFp1ku6o35XcTljBm68bFZEgHlmoP3V64uLygPY24OXZt9+aCWIw/1aNjawMN2lo= Received: from BYAPR04CA0021.namprd04.prod.outlook.com (2603:10b6:a03:40::34) by MN2PR12MB4256.namprd12.prod.outlook.com (2603:10b6:208:1d2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9818.20; Mon, 27 Apr 2026 06:41:09 +0000 Received: from SJ1PEPF00001CEA.namprd03.prod.outlook.com (2603:10b6:a03:40:cafe::d0) by BYAPR04CA0021.outlook.office365.com (2603:10b6:a03:40::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.26 via Frontend Transport; Mon, 27 Apr 2026 06:41:09 +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 SJ1PEPF00001CEA.mail.protection.outlook.com (10.167.242.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.18 via Frontend Transport; Mon, 27 Apr 2026 06:41:07 +0000 Received: from Satlexmb09.amd.com (10.181.42.218) 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; Mon, 27 Apr 2026 01:41:07 -0500 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb09.amd.com (10.181.42.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Sun, 26 Apr 2026 23:41:07 -0700 Received: from [10.136.41.76] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Mon, 27 Apr 2026 01:41:03 -0500 Message-ID: <88d837dd-0267-4cf1-91b4-a2878e722674@amd.com> Date: Mon, 27 Apr 2026 12:11:02 +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] sched/fair: Clear rel_deadline when initializing forked entities To: Zicheng Qu , , , , , , , , , , CC: , References: <20260424071113.1199600-1-quzicheng@huawei.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20260424071113.1199600-1-quzicheng@huawei.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CEA:EE_|MN2PR12MB4256:EE_ X-MS-Office365-Filtering-Correlation-Id: 874475bd-3429-4957-7dd2-08dea427f693 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|82310400026|376014|7416014|1800799024|56012099003|22082099003|921020|18002099003; X-Microsoft-Antispam-Message-Info: 8gI3kOMSA/I+egn2FzTvjbjjywRDJp+EjSVKDX9K57pMxjWn35CxrCu0CJgVzkl3DM9PWHBRuTEVAK1c4hqFCKRQfT/KiRd7cO2L36GAPSznQgxVonz596qIsaeYcCcgb+hVRBUFeF5ozfpPza+LstEtH7HjgyRrtUXgBke1L9u7bsSVY0+9CFgGz6UIwB74IXqklE0uPCPCGJjzy0kgFKW+fM5JyJhNEvKY4oI9mk5wAKIJUJnAhw1gk+QEhmbPSJuiIFb6dF1uYDRd03FG8CWX8hBReXcNfUwJiGDgyafFifcX4pIl3EK/6k0KwFren2blQMNknDQjvi6DtZHgVF+ANzJ/1ruR7VuaTFLYU96Ntnl5PLGG7xI+nclMCrPbb4pJP4dTm1knp3FPqjGdV4ExThkIgU6JnZbYiv88b1BWnVe+iwK5BmPHB1DR4gZBob5tgKGGeb1vzf6T4fXgBlq4rw5IGCSyvLLTZm+E4j6qF9yMGu1o/3jn43cgcKgCtKbjR2UpiF+wpn/YyswqOZtsBXf6o7GsIMgIwuV3lKF+VICOFKtT7cbkFgIEJjvCX+v/2pNzQ29Sm7aX/OpZK08zHSSMHRKTbavG2Jk3IJW/zrjVW9bqNTm2lF4QNxv7ZTVrBclh8I1zOTcTlIe/GuCgb6Mqg24BrgTqon3QvhfQU1siRXlNw78PLPfjXsRYp1qZ8E3y8Ky3SmmX6uub0lFsKlbDKmE50T02L0iVj008/AvovVd1rfhnmRJ/A68T2U/DjDF1tHOdxMQOHom4gxQoYSTSzR7dtVjOTpS4mcaf238OvVSaaTAOBZyEQG2X 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)(36860700016)(82310400026)(376014)(7416014)(1800799024)(56012099003)(22082099003)(921020)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: km3liG5Wj+kEh8YNGQVSlfkQkYXgG2OmS19C9Qs+gViMh5HObzmJ8WW8fZqApsoP9tId4k8Ve/EjoVXB7K5OeDe0CBJe68BSajT3DbUBChorc4eZfz1GB8NxCFiqKVl5kgWgclUjj+LPGUuLaxQnHsVD+l4QwY3o49eS11J3tXGq1wVgH55N53uWWbSQqn4wCfphMBBLe5sR7h5zqGqPfME2qy8rRlif0r+K0nnxfNtzuxZyQnshyC1F1YBNi8cm/QTBsBV9ofAaixkpmmiTP8rL3dLOnHYe7oBwzft3mFSa2C3BIb3uZD14dm0dOM4kU/PPYsKIZT8VTtzOaSeEMMwN28m05UzCKNg0tQKz5yACBEiuPJTSzuny0GjdkLwzc749ariMwsADOaX1/pMPnjKF2m6cAXIOmYtgzE7SEgPDceP/vXALivtUYzSQmMnq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2026 06:41:07.9684 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 874475bd-3429-4957-7dd2-08dea427f693 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: SJ1PEPF00001CEA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4256 Hello Zicheng, On 4/24/2026 12:41 PM, Zicheng Qu wrote: > A yield-triggered crash can happen when a newly forked sched_entity > enters the fair class with se->rel_deadline unexpectedly set. > > The failing sequence is: > > 1. A task is forked while se->rel_deadline is still set. I think a bit more information on how this is happens would be nice: "rel_deadline" is meant to be an internal indicator to during reweight and migration but a reweight of parent from a remote CPU can race with a fork() where the child inherits the "rel_deadline" during copy_process() since fork() does not grab the pi_lock of parent. On a side note, should we grab the pi_lock when inheriting the sched attributes of the parent? I don't think it is strictly necessary since we reconstruct the state but it does seem racy to my eyes against a setscheduler on parent unless I'm missing something. > 2. __sched_fork() initializes vruntime, vlag and other sched_entity > state, but does not clear rel_deadline. > 3. On the first enqueue, enqueue_entity() calls place_entity(). > 4. Because se->rel_deadline is set, place_entity() treats se->deadline > as a relative deadline and converts it to an absolute deadline by > adding the current vruntime. > 5. However, the forked entity's deadline is not a valid inherited > relative deadline for this new scheduling instance, so the conversion > produces an abnormally large deadline. > 6. If the task later calls sched_yield(), yield_task_fair() advances > se->vruntime to se->deadline. > 7. The inflated vruntime is then used by the following enqueue path, > where the vruntime-derived key can overflow when multiplied by the > entity weight. > 8. This corrupts cfs_rq->sum_w_vruntime, breaks EEVDF eligibility > calculation, and can eventually make all entities appear ineligible. > pick_next_entity() may then return NULL unexpectedly, leading to a > later NULL dereference. > > A captured trace shows the effect clearly. Before yield, the entity's > vruntime was around: > > 9834017729983308 > > After yield_task_fair() executed: > > se->vruntime = se->deadline > > the vruntime jumped to: > > 19668035460670230 > > and the deadline was later advanced further to: > > 19668035463470230 > > This shows that the deadline had already become abnormally large before > yield_task_fair() copied it into vruntime. Although I can hit this very easily, I haven't yet been able to crash a system from this, or see the vruntime drift apart when stressing - in my case, the deadline seems to pretty tame for most part but that is probably because I don't have the weights right and it is a probability game. Either ways, the fix does make sense to me. > > rel_deadline is only meaningful when se->deadline really carries a > relative deadline that still needs to be placed against vruntime. A > freshly forked sched_entity should not inherit or retain this state. > Clear se->rel_deadline in __sched_fork(), together with the other > sched_entity runtime state, so that the first enqueue does not interpret > the new entity's deadline as a stale relative deadline. > > Fixes: 82e9d0456e06 ("sched/fair: Avoid re-setting virtual deadline on 'migrations'") > Analyzed-by: Hui Tang > Analyzed-by: Zhang Qiao > Signed-off-by: Zicheng Qu Feel free to include: Reviewed-by: K Prateek Nayak > --- > kernel/sched/core.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index da20fb6ea25a..b8871449d3c6 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -4458,6 +4458,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.rel_deadline = 0; > INIT_LIST_HEAD(&p->se.group_node); > > /* A delayed task cannot be in clone(). */ -- Thanks and Regards, Prateek