From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.193.138 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796065196; b=vA5IWZTTnWIRwRGQ+gCcC7D/d4+zhTropObQreDoF+fhfajaX88+O8DxgsLM+C0KEg2f +airrrLCGBzbDfCwSAc2Y3VxuelqGLPxbA3o7e9GALiCveNGhzLltnP5CtjoM0GqKJQYv PXBnvIltAoqPqcBJdn+PSHY63raRq2bUFZPuNnkCDHjPIsS3n3X9iITYyNRheSkuR6jHp cQnlCzuCiD+SD+2Dpo9X+FPdTeGr82nEKOtGiocTO5iga83RfoZS3q6cjZZGrZeX3dnTO xdECpoWjpS9rY+WtvqPlsCe67iIm/VaUgupbPvt/xAQV1lDdSkhE47G/7zNs3lS7dDA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796065196; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:From:Content-Language:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: 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-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=6Ax7pQWN9BXMfTzVR2Z71SMWbaTgtjUwLRxmxv1wXqk=; b=o/z6HRlGQmanHbpHn0glMuIXuKhhfutw01FhI2aiOLtPUkDosFOVytykZ83EFCz0MhmJ ropRIcRPG7JKFX1qWy1ceHLmqb6jFlFHLGQ1dCPKK/KJPbRTDchOf5/jLDWLAz40bHdjK TM3n9WvaG7aowIaggTq9y4ChX9YQZmJk66xCzg+k7LNmnMGJo/xnaMueArx43zTEhZC2h PJXXht16VZ8Jw8weVzSCvsup67X4Dg1q74yuXv4IMZkDWGKvlOknzY7RPweJqTZabZE5h wkElPhfUBJY8QpSz5UgIW92cRZSMot/91UydGlAQnehwfpCk9QnGwBNNDp+zNXqNN+Q== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=selector1 header.b="J/IQj1O5"; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.193.138 Received: from YT6PR01CU002.outbound.protection.outlook.com (mail-canadacentralazon11022138.outbound.protection.outlook.com [40.107.193.138]) (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 975CB606A325; Mon, 30 Nov 2026 18:59:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 975CB606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=selector1 header.b=J/IQj1O5 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oS1hLMcPDjm4+bf0wIoRHir2AC4liGUDB2kizVBLhUtjAS1h/ezB3Xdv6rxh0QWjpKy6ErQFa3XD75RBNFj2vQG39AnThGRGJBWJeMFl19/c8O6QhN1baOYxHWVID1RgM4azAY9Gli34p1fX/YqPKmtH1RpYCgNQCBSeFMbb1uzFonv2V5VGYVgoXzXKrs/t4NwQ4CAErFqCkpIHnZtjm58f1dqhsTzx862DrsXuMeMlGM/qp6rZj2DJjjJkh53u8ympjGFGp1mE7Fl1rU/w2/Xuu1BAZDMtwKFxGdoLK1bH2U+OGwp/ZNkt/Jt7LqTNWnCbujUcxEMgnX3w8r2Xyg== 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=6Ax7pQWN9BXMfTzVR2Z71SMWbaTgtjUwLRxmxv1wXqk=; b=hoCaKYRMw5QIwiuhY7zeihJ4dPKIhHQf672QKqQJgHc4SZI1av3NBjDft1Kc4DDbw+8CkNCl3Y1WjcXtPjfkZZYY+YgKNS6bAOgHnJkhC9Bwo92MGJUOc8nP3p6jD8Qy5bpfgeBK1pKG49XalVKZJ66Ui0cAkTxnpf28MTODZPEajG5jgtfnx7S0CRz7IcoGumlpZW64lLqSS4nEhg2CteYqxGCvlx4m2TOLBg/z2dGTS/TgdkDT6R142ZHINmmnHwMF9xh01LRQcgZ/7ihtC5VVifudvSvI/7ivYAdya8uNSpgH/0h7BTnfL/axPg6tnbgtHzq3SYHdhJC6a24K0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=efficios.com; dmarc=pass action=none header.from=efficios.com; dkim=pass header.d=efficios.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6Ax7pQWN9BXMfTzVR2Z71SMWbaTgtjUwLRxmxv1wXqk=; b=J/IQj1O51RVWNDgywEbQMnm7Yh4y9WECy8JO+OOF1PTNQd+AUVm9DGQYiL88659c2ulI7A35mBFSe9AHRGrqlB6X+D9UKKizhJVgoztJiIMcnIFJCF4B6ZksGanxiUxdxAyBJXupSlUp2fcnJZnwgDEIVuSTlxEzrsV3LsX9GrbDAzPpd1LGjWNTCFdR+gt+wjUyREfejZuftOz2Gh3uHOm9q0vAibN4hOQDqQ7nSPVC6fSrkivvQqAig5/hmkAv4okB95LhZqIMfdw+hDLs62VDry3jB31RV58EF05YwRMe1IkLd6VOXDyqwQt962xdxlYBu9tXORdun8pY8elBuA== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=efficios.com; Received: from YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:1d0::10) by YQBPR0101MB5423.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:46::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Mon, 30 Nov 2026 18:59:50 +0000 Received: from YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM ([fe80::6b9e:a901:67c5:7ddc]) by YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM ([fe80::6b9e:a901:67c5:7ddc%6]) with mapi id 15.21.0662.012; Mon, 30 Nov 2026 18:59:50 +0000 Message-ID: Date: Mon, 30 Nov 2026 13:59:49 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity To: Thomas Gleixner , Karl Mehltretter Cc: peterz@infradead.org, linux-kernel@vger.kernel.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, paulmck@kernel.org, boqun@kernel.org, shuah@kernel.org, kees@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, oleg@redhat.com, bestswngs@gmail.com, xmei5@asu.edu, xujiakai24@mails.ucas.ac.cn, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, Dominik Maier References: <87bj79s11m.ffs@fw13> <20261128192202.93895-1-kmehltretter@gmail.com> <875wxgshou.ffs@fw13> <8733sjs408.ffs@fw13> <87ecc2qs9i.ffs@fw13> From: Mathieu Desnoyers Content-Language: en-US In-Reply-To: <87ecc2qs9i.ffs@fw13> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: YT4PR01CA0370.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:fd::27) To YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:1d0::10) 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 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: YT6PR01MB491026:EE_|YQBPR0101MB5423:EE_ X-MS-Office365-Filtering-Correlation-Id: f4517405-9863-4118-a0bb-08df4f141c71 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016|23010399003|5023799004|4143699003|261009223027099003|18002099003|22082099003|10067099003|56012099006|261028144727099003|261026140227099003|261026121527099003|261102123227099003|261021121427099003|261021123027099003|261022105027099003; X-Microsoft-Antispam-Message-Info: bCtlDuV8np0cNgJAaYT5My35oSlzpyTIu2ixfaWq1rpeGAt3GsFnURPlB22JuZZ5+AViblgWmCLg/S7MseTDF8kyr6Wtz1XeYzDgXxvGua1db4UeaMAqyKgdRRqUkhVMa/7Y9INNIzMoX+n+ApfGPMLcU3phF844XzSzorZ+mcnahjSYjzJyJwEmAaQcFFgD9r9uV0dHYLMq752H6yzvilJxwcABUU4knB1+a1WEvQjfM0WTuFAK/4CBB+cd6zk7WMUkdmOXizHuJ091vs+T5vI5/kaabbo4U4+bGu/hLPiamP75NSkV2M8Quot1yb4QjOB+7sOIjjbuHQ9JuvUyEI583QywgSpm6cInMvoQvySk53/lfaZ+i7HRjzAgWS/wqfEMEtfJ+Q+6gW0f1G0PGJBMeQ4ctH6sZDBjJFN9l+R0JIr705mdC36j2RP7EFIdT5gP7MTNDJkBDYi4LlNnAiDq1Ob+vcokp1AC1F4PiuX917EK6rDQXnwOSirwBMK5ih4p2jGvt2nmFn8paB+zMPAMOXPvra1I8qgEu6SbchxwUchG/lmwdMwv6LcH9m9ORH5ESCT0w4K91iltDVi6zxmujxLiDkTxnFid6p9Ccao= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016)(23010399003)(5023799004)(4143699003)(261009223027099003)(18002099003)(22082099003)(10067099003)(56012099006)(261028144727099003)(261026140227099003)(261026121527099003)(261102123227099003)(261021121427099003)(261021123027099003)(261022105027099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VDlEOVlwSGhCQTFHVjF2MFlpNmQwK3NEb3RrWGE3QWlLZUdBeGJyNThKQ0Uw?= =?utf-8?B?enJ1Sk8xbDUrTVRlZDI0OXJGc3haTnZvbG9pc0pNVGoxRGVTNHdhMHhac0s2?= =?utf-8?B?QU9GVGw2UW12VE1zMFZLYkJ5RmRXNWthL0NyVFdHeGY2SG5VNGdEZWo2dW9L?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WlYxdUpGanBtNENp?= =?utf-8?B?T0hacDZNVTFSMVg5SVlkZlUvNzRoY1pPMDdVRlFkcjlpQkgxb3Vkd3czYUl0?= =?utf-8?B?a3BPcEhpOHVrS0liNFlSekNJdEVlSHBabWFMemJqaEl0Qml0Rm84ZWEyR29r?= =?utf-8?B?UkM1VS8wL1BYZGlXMTh5Q0pkOG4wY1ZmcThqRzVUanovL1VOQjM3N3hWVHJq?= =?utf-8?B?NXhjY21NVEhjdkhxL1NGNVFrNEI3dmFwMEMxc21EenJzUXZDWHBlMURHaXJv?= =?utf-8?B?S2l3ZWZGdDA3aHFFMVM0SSt0dnAxaTAzcWp6TUJXZnVkM094SWE5OXJyYVpw?= =?utf-8?B?SUJ6Y3BST1RwVzJjWjIyQmxQZkR0M1FUU0JiRjRHaTAzMkYzWFhDZGczUTdz?= =?utf-8?Q?9F/Ocl3/ZacqUZwc=3D?= X-OriginatorOrg: efficios.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4517405-9863-4118-a0bb-08df4f141c71 X-MS-Exchange-CrossTenant-AuthSource: YT6PR01MB491026.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 18:59:50.5919 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4f278736-4ab6-415c-957e-1f55336bd31e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wp/Cwi+RYf9WbvaGGLkfh3BwJxgKWYPnfZSG9PIl/4RzaVCE6HkaKvwDHuethT0Hd8iQBAV7RMzVN2HMKj8QIyFZNg8ckMuURXs1K9MOabk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: YQBPR0101MB5423 On 2026-11-30 09:59, Thomas Gleixner wrote: > That makes the whole thing even simpler. Updated patch below. Thanks Thomas, and thanks Karl for the ptrace and vfork cases. I applied this patch and your affinity patch [1] on tip sched/urgent (006991aa8997), with the selftests of the series on top. I split the affinity patch as you asked: 1) mm_init_cid() clears the allowed CPUs of the mm, and exec_mmap() no longer calls it. A task that joins the mm adds its allowed CPUs. 2) sched_mm_cid_fork() and sched_mm_cid_exit() take pi_lock around mm_cid::lock. mm_update_cpus_allowed() gets the task instead of the mm, and does nothing when the task is not active. I left out the hunk on sched_mm_cid_cleanup_execve(), as your updated patch no longer adds that function. Your two patches replace the fixes 01 and 03 to 06 of the series, so I would drop them. This includes patch 06 from Weiming Shi: an affinity update now touches p->mm only while the task is an active user of it. Could you credit Weiming in the affinity patch, with a Reported-by: or a link to his patch [2]? I ran the selftests with lockdep, on x86 guests with 2 to 64 CPUs. I ran them with both parts of the split, and with the first part alone. The results are the same. Here are the cases of Karl's list: - execve_test case 1 (07/17) and case 3 (17/17) pass on all guests. So does exec_affinity_test case 2 (12/17). - execve_test case 2 (08/17) fails on 2 and 3 CPUs. Karl saw it on 2. I agree that it tests a detail of my implementation. The case needs per CPU mode to last down to one thread, which happens only with 2 or 3 possible CPUs. That thread then fails execve(). With your patch, it no longer leaves the CID management of the mm. So on CPU 1 it reads the CID of CPU 1, as it would without the execve(). That is a valid CID. I will drop this case. All the other cases pass. Two small things: - In the affinity patch, the !CONFIG_SCHED_MM_CID stub of mm_update_cpus_allowed() has no body: "{ }" is missing. I added it in my split. - In this patch, the new comment in the last user branch of sched_mm_cid_exit() says that sched_mm_cid_after_execve() handles a stale transit. That function has no such code in this version. It does not need it: with the hooks in exec_mmap(), a task never rejoins the old mm. So the last sentence of the comment can go. I also checked your two patches with the Spin model I mentioned in the cover letter. It runs up to 3 tasks on 2 or 3 CPUs, with up to 6 possible CPUs. No run found a violation of these: - The CIDs stay unique and below the number of possible CPUs. - mm_get_cid() never waits. - No affinity change is lost. - The affinity update never reads a freed mm. Without your patches, the model finds the known bugs, the 0x80000000 CID among them. The model found one new case with your affinity patch. It needs 4 possible CPUs or more. The mm starts in per CPU mode, and pcpu_thrs was computed for the allowed CPUs of its threads. Then: - A new child gets more allowed CPUs before sched_post_fork(). Another task can do this with sched_setaffinity() on the new pid. With CLONE_INTO_CGROUP, cpuset_fork() does it with the CPUs of the target cpuset. - mm_update_cpus_allowed() skips the child, which is not active yet. - sched_mm_cid_add_user() adds the child's CPUs to the mm. It drops the return value of __mm_update_cpus_allowed(), so pcpu_thrs is not recomputed. pcpu_thrs keeps the value of the smaller mask. So the mm stays in per CPU mode when its user count drops below the threshold of the new mask. Only an affinity change which adds a CPU to the mm recomputes pcpu_thrs later. For example, a process left with 2 threads allowed on 6 CPUs would use CIDs up to 5 instead of 0 and 1. The CIDs stay unique and in bounds. This change on top of your affinity patch passes in the model. The selftests give the same results with it: --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11007,8 +11007,12 @@ static bool sched_mm_cid_add_user(struct task_struct *t, struct mm_struct *mm) /* * Update allowed CPUs to take any affinity change, which happened * before sched_mm_cid_fork() acquired the locks, into account. + * Adjust the threshold to a wider set, as mm_update_cpus_allowed() + * does. */ - __mm_update_cpus_allowed(mm, &t->cpus_mask); + if (__mm_update_cpus_allowed(mm, &t->cpus_mask) && + cid_on_cpu(mm->mm_cid.mode)) + mm->mm_cid.pcpu_thrs = mm_cid_calc_pcpu_thrs(&mm->mm_cid); t->mm_cid.active = 1; hlist_add_head(&t->mm_cid.node, &mm->mm_cid.user_list); How do you want to route your patches? You can take them yourself. Or I can carry them in the next version of this series, if you give me your Signed-off-by for them. The selftests would come on top. Thanks, Mathieu [1] https://lore.kernel.org/all/87v75fqnsi.ffs@fw13/ [2] https://lore.kernel.org/all/20261110183809.3308868-1-bestswngs@gmail.com/ -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com