From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013026.outbound.protection.outlook.com [40.93.196.26]) (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 C125F3314B7 for ; Fri, 31 Jul 2026 12:16:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.26 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785500220; cv=fail; b=QROU8wTzFCHhUphh0kK1p4V/r4EY3ujXuBGVQOr381mX/VE8gV8PKVQXrHpnIEmsXeIkauyM6xofdQZ5aPIkn1QmwzzZO3n7h4qIo4yqFktoRId5hP2pQ6IWpBaPUTsoPhUBJ4ZdT/4UoRiOc6J9wCQ6c9IPtuethgHcxwhmOII= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785500220; c=relaxed/simple; bh=WdtIDTuFMzkzX3FUGInNksihLKp8FQjIXiNnJABECWE=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=LcYRraz1HrU/QRJ1QNjdoEoeHi7xgfu2koY06yQ7UfQ+OzI5O2iMTNtjAbIFvDxZQ8OOlG4+XAV4W30sXsMpgNrhdvzE2dejBcckQGABYISBuUMOs3oUM4QOufADLf3uzRY7kf6RXjcFQ8uT1uqrYqWROPzt9xX9wkCSzESC+K0= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=b02ytSfJ; arc=fail smtp.client-ip=40.93.196.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="b02ytSfJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wKK35+la3aKz0dbEnNpzbDGwANGh7kjvKojJnAIYX+6X1cCmey7LZnnY1WIvoZxzgmt7EZVS7zDch+XbhNJR+p1meNrwG56EY8q1LoO1lB2XHVBXyiMWsgdKUlT3Aak6qqu716Efk0+yjDu2cExPm2JyDiNjubR1so4ZyunSBXlp16nvTvBnQOojLy534PPgARkAy7K/dH/OhLiZM2JEHsan+BDHWt7AJh3s0vuUOKAYUlGjHkjLP88H/DFk3TBEl9/mGI8LNbQMlrIPbkNyAPHGL8l9TG2Q87M76xi92RrMg7VkVcfn3T8ST0Oo0mG+JRfawrkwzY5S054cGg9K5Q== 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=lyd6q6m2dWmSF80tSXxkkOH9yg+EVVC0wBCvF7eIT7c=; b=HmtJ8rbALnKYaAdFi1RT/GrmxOP+RemrdTK6H1pVdt+ZzMBGKpCqpbHmrcqAmInj/q8BDcPC5uvkv4xhw5xpS89NXCu/2elFGZLCGJfwgREdQrZDwtErbJobdv1XfzrFF/rkbWPNfUSTCsNsmcCjzRWHHMtH2WLnCl1V6VERJ6zvONSfxGfhdoYzXwZ1xJpF0/IZrCgx2BvuYTHrfpov/IaPhEKgUYAoT6ONfzlngwDZ0Q/kNNNcgTR91RVU6efIItAmcARdpJayhSAuTwK52feMXhdEm5A1PL3BW4CbT5uUv5Q187B2EDEZQhINqVA1fxOiN7vPMC0NBj/pkgey8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lyd6q6m2dWmSF80tSXxkkOH9yg+EVVC0wBCvF7eIT7c=; b=b02ytSfJQ1fOz1lFyHe9NUH4I/oZIOSuvlZzlL8nuidlP46KVH0MNuyvVrCLmlXdhJjTjWiUiAVGIeLbT3jNFj/VhGbbF/ceBABsmHgq82zijMziBsbsDzR8dbhY8ldYWSOocd2ka8k0SCBCnoRyA8WQ6vptHqrYBijAumQANn7q6ObImjJIvjMDcoLS4stT+ZB3vsSz5eLVOwvcgpAeeUmyFhjCq2Bwb22i1XHSiDo1WJ8xfJR4C+tzpp6SBi1Itpdkw/NZLirFuAW1L8TXQgextNQKX9StqVNo4ap3kr33uR3OzkgUnD11FjjGBGiOLe6W7Us2omkpbxl9eVkC6A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4827.namprd12.prod.outlook.com (2603:10b6:5:1d6::14) by IA0PR12MB8301.namprd12.prod.outlook.com (2603:10b6:208:40b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.16; Fri, 31 Jul 2026 12:16:53 +0000 Received: from DM6PR12MB4827.namprd12.prod.outlook.com ([fe80::6261:3040:864b:159c]) by DM6PR12MB4827.namprd12.prod.outlook.com ([fe80::6261:3040:864b:159c%5]) with mapi id 15.21.0270.015; Fri, 31 Jul 2026 12:16:53 +0000 Date: Fri, 31 Jul 2026 14:16:43 +0200 From: Andrea Righi To: K Prateek Nayak Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Tejun Heo , Patrick Bellasi , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] sched: Reject policy changes with SCHED_FLAG_KEEP_PARAMS Message-ID: References: <20260730135858.2460751-1-arighi@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: MI0P293CA0013.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:44::18) To DM6PR12MB4827.namprd12.prod.outlook.com (2603:10b6:5:1d6::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB4827:EE_|IA0PR12MB8301:EE_ X-MS-Office365-Filtering-Correlation-Id: ce1f1ffb-881b-49c2-f311-08deeefd9b31 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|23010399003|366016|4143699003|5023799004|11063799006|56012099006|10067099003|22082099003|18002099003|3023799007; X-Microsoft-Antispam-Message-Info: JyqNcoCR2QXhBuRumgTVTN9paF6SbhlvkpYwDo8vHa3Y1VIwyYWZEZ6y432GnnSLEX3D2Cf0UngEjsl7UI2NQXOyGT/T1ncrm541k5TdfYD/xH+kM09vbLxhakomhiLhkS0fIvx61M2Ma+C8M9RBHz8RFbrKrDdL1jOwt/xhVXfUFKXIQa8hXXoaP/ptcxfGj14G4GZRJJzF1y5txG3pSCKpWYM/m8UGdcJ8TfPh5rRsvHPlQHJxRAQfD+eiZ8bC3S9SSEwMSptY3dE/wkOvZl8eemhlVhgn+SGtTjPdwq+yocSfOSuMtfTc6YowjQZYKbvBpnow5pqXylZ+ployiHrc5yaYKzNUcjZN4rlwa8DQ7xC13ejZmPk6jH8xiAaqcUZhc0laapxdw+mt8nuGD57IDTV7EDT+REQhcg2SGoy7u6Mnu4PPv47BeqMqw/oZvh08kd2QIVPfmrKYLN+zX1f4jBXSRQ+1/6gBOJMFreGw/JN5V5ygHEHINJLXuvX9ove6cL1vtqz9x5KTdAGVPiywUCk3Xzrabyyo8YyJ7AAr8LAvvjOaIbBaGeI/zeNmP7YXN9NfNuxLVIWdIw246Wx7U7spHiR9o69LxY9ViCWZpiMw7+4ljv211x0OxXbOJTDe8rsLlrcIpCWdACgMigCNjcaVIBf2zeCFBhmzajc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4827.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(23010399003)(366016)(4143699003)(5023799004)(11063799006)(56012099006)(10067099003)(22082099003)(18002099003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?S3J9c1CMUk6oCZcuAAxU/xOjzW+hFc2VajtnAouk1dKlWzNbhbzzsGjzxYfx?= =?us-ascii?Q?5ZYqx6z4OxliMGXvnm4he5fj0Z6S2+zp5ZXpKKiLQSLTUqYZEHI1zcX+Km7V?= =?us-ascii?Q?TzPTOhH4/O46a48xEU93eHLp4HrijCe+tiRwK1CLK5zV1DkHnnpBI1oll4aR?= =?us-ascii?Q?PMHW+dXA1NkIuQmKRCZHjRYDzoHnnmFRHt5jiI+WTz2FrMPu1f47Q2CEXNfd?= =?us-ascii?Q?oXRaUJeA0E7Gpc6f3YN4ehOqLGkNTJCycBXdtW4eBl5HvmeMJzFI6fD9mxjB?= =?us-ascii?Q?PxZGV6REAETroJBUeVeJJMFHN27VgB4WBoLDRYWUYJVVoSxlOP5KOGB2+SjU?= =?us-ascii?Q?dWkHG/DB2Oh0YqS7/I/po6fhbEg/3w6r3Q1kenXagJY31tACzz0Cjyc5jCb9?= =?us-ascii?Q?+Vi7ZhxY4wrNXhhCAqjxdxSjr7XllDNUr/BjQ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vP5IPQFd1QJIvC7duLq+zj0+KKasGJf0BjpweWPZxr1pm93hJiuCRQqm?= =?us-ascii?Q?C8QNV620LufOa3ERkz4A0vtGMobEcc+n2D9s3omDOxTHXB0ggLAs2Xw1tZL0?= =?us-ascii?Q?VSwLBfkLVHmFbpfnn/b+8sDNggmu8fCqNzSDU1gmHML5I8nNpNdsjtBRmKYl?= =?us-ascii?Q?fjCWiSXXJRHrG2CEBE0ITdSCHkgTrR7+wZtxytoQtfMHgV1LFTcXgKsrYyUy?= =?us-ascii?Q?tRGSdmUWnxX9kkPY9ceNTSqU/l2vpwYjnfz0JuysEfnReLFgP/07n9JlGZU2?= =?us-ascii?Q?BjylStaku/QGwcTYSbkbTrk+o0M9m4ELFb8kvIQrtMn2R9iWoW1yMbb8MH03?= =?us-ascii?Q?B9M773J1PF4nDyiUSwWaamMeJvze0Ki3U7AaZEy+oSp7jQHQ9x8/22AnGQgJ?= =?us-ascii?Q?YLUXH3jk9Q=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce1f1ffb-881b-49c2-f311-08deeefd9b31 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4827.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2026 12:16:53.3693 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AvYSFoyfjxuIU3UqFbXwzlLFnEZwsT/3l1LwXtTt7ZzGvXTURbx8smXIUKWbGc7QfkYKnyg9lO0FP0d9Lk0HhA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8301 On Fri, Jul 31, 2026 at 10:51:39AM +0530, K Prateek Nayak wrote: > Hello Andrea, > > On 7/30/2026 7:28 PM, Andrea Righi wrote: > > diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c > > index b215b0ead9a60..8fb8474d0a0ec 100644 > > --- a/kernel/sched/syscalls.c > > +++ b/kernel/sched/syscalls.c > > @@ -645,12 +645,19 @@ int __sched_setscheduler(struct task_struct *p, > > goto recheck; > > } > > > > + /* KEEP_PARAMS only makes sense if the scheduling policy is unchanged */ > > + if ((attr->sched_flags & SCHED_FLAG_KEEP_PARAMS) && policy != p->policy) { > > + retval = -EINVAL; > > + goto unlock; > > + } > > + > > /* > > * If setscheduling to SCHED_DEADLINE (or changing the parameters > > * of a SCHED_DEADLINE task) we need to check if enough bandwidth > > * is available. > > */ > > - if ((dl_policy(policy) || dl_task(p)) && sched_dl_overflow(p, policy, attr)) { > > + if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS) && > > + (dl_policy(policy) || dl_task(p)) && sched_dl_overflow(p, policy, attr)) { > > retval = -EBUSY; > > goto unlock; > > } > > On an unrelated side note, similar concern exists for p->reset_on_fork and > that it can be changed by a parallel sched_setscheduler() that finished > before and the one that is lagging can continue with a stale copy. > > reset_on_fork is computed outside the rq_lock for KEEP_POLICY case and > p->reset_on_fork will be set to that if nothing else changes (same policy, > same attributes, no uclamp changes) in the early unlock case. This looks like another race in the KEEP_POLICY path: p->sched_reset_on_fork is sampled before taking the rq lock, while the locked recheck only detects changes to p->policy, so a concurrent same-policy update can be overwritten by the stale snapshot. We should probably address this in a separate fix. > > Peter, is that a concern? > > > @@ -675,7 +682,7 @@ int __sched_setscheduler(struct task_struct *p, > > prev_class = p->sched_class; > > next_class = __setscheduler_class(policy, newprio); > > > > - if (prev_class != next_class) > > + if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS) && prev_class != next_class) > > queue_flags |= DEQUEUE_CLASS; > > Can this happen if we've already ensured policy is unchanged under > rq_lock for KEEP_PARAMS? The > > newprio = __normal_prio(policy, ...); > > above would have fixed it under the rq_lock right based on policy > right? For the traditional DL/RT/fair mapping, yes: with the policy unchanged and after accounting for PI in newprio, the resulting class should match p->sched_class. However, __setscheduler_class() also depends on task_should_scx(policy). During sched_ext enable/disable, the global state consulted by task_should_scx() is updated before all tasks have been migrated. Therefore, __setscheduler_class() can temporarily return ext_sched_class while p->sched_class is still fair_sched_class, or vice versa, even though policy == p->policy. Since KEEP_PARAMS deliberately skips the p->sched_class = next_class assignment, it must also suppress DEQUEUE_CLASS. Otherwise, class-transition callbacks could run while p->sched_class remains unchanged. > > > > > scoped_guard (sched_change, p, queue_flags) { > > -- > Thanks and Regards, > Prateek > Thanks, -Andrea