From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EADCB606A683 for ; Fri, 4 Dec 2026 19:15:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=e6G3UsOl Received: by kanga.kvack.org (Postfix) id BBD676B05B4; Fri, 4 Dec 2026 14:15:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6D836B05B5; Fri, 4 Dec 2026 14:15:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5C406B05B6; Fri, 4 Dec 2026 14:15:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 717456B05B4 for ; Fri, 4 Dec 2026 14:15:39 -0500 (EST) Received: from smtpin30.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EA70D8058D for ; Fri, 4 Dec 2026 19:15:38 +0000 (UTC) X-FDA: 85507254756.30.763D637 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by imf24.hostedemail.com (Postfix) with ESMTP id 31D3A180003 for ; Fri, 4 Dec 2026 19:15:35 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=e6G3UsOl; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of reinette.chatre@intel.com designates 192.198.163.17 as permitted sender) smtp.mailfrom=reinette.chatre@intel.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796411737; b=6TSn4NybhtAuOm2R9/LXVCHZPrhaPzwalfmIystOECEJnfwVB4PQ154OH51RUiA2WY4EX5 tWJnOEsgCmG3Q9pL/GJ+wA5kDw+bcuQCXxybSus2T6I0eXcZ+btfJxOJKvhawxEORE3I2A O5nS0j0YElO/+8xDYxTlkVKhXRufr74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796411737; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=tsn/s1AL0q8n+PBK+IlKZP34RGNi3sBnoK8GZLH1w88=; b=12p6L5JJK6913A1K3yVb01fQQ63VNZikPFKCqkgBwNUBjFCNvc9rTrYN79fpCXTAfySgSw HqCcEmIMCrkBnnv49LtiYF8mtsjx/2vfnDC65cpi5V+tWEpydT9w66H0zcb8zmo5azGmdR /7bsfTdE66BSy0TvWo9GHFSo425jZE8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=e6G3UsOl; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of reinette.chatre@intel.com designates 192.198.163.17 as permitted sender) smtp.mailfrom=reinette.chatre@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796411736; x=1827947736; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=tsn/s1AL0q8n+PBK+IlKZP34RGNi3sBnoK8GZLH1w88=; b=e6G3UsOlMDBzdhVAJRFCw+P6CpNfT78NWTHOUJ+9N2oLbzmiN6RdBomR X/ogpyxuTE/8ziQL0FaS5GsfxCZfYvA77LbGryC5fe98LlOVDlTB/CvvS MFvS0z1KbsSG6nuuFp6ZuLGmZ7ckf1bXNehffSx+OWLnq1FoW6rm0O81T C/L0uosZJ9+sYFAXJwVcYg3McyiiKLqLmORcs8yEu4qYm6CrTNY8bx21U ywBUWZ4oDaBvkli6NcVbFRMhnassxKqontBE6fz8QD2PVcQQONThntLPF LnSDkmKzM9gkX1rmFm7mcxcLvdJWalLWdwEcSZrqwdKMYBNWXjC9k9lVS A==; X-CSE-ConnectionGUID: Oqvh9b7HQvmtM8t+uOwJdw== X-CSE-MsgGUID: DThzgDy0Qu6BWoEOUmf3tQ== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5410847" X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="5410847" Received: from fmviesa012.fm.intel.com ([10.60.135.152]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 11:15:34 -0800 X-CSE-ConnectionGUID: CSr6jtQjT56rO9lulKxA3A== X-CSE-MsgGUID: eLHjUaoiQ+msdtVgIU+k2g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="15793133" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 11:15:34 -0800 From: Reinette Chatre To: kees@kernel.org, mingo@redhat.com, peterz@infradead.org, 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, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, tony.luck@intel.com, ben.horgan@arm.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com, Dave.Martin@arm.com, james.morse@arm.com, babu.moger@amd.com, fustini@kernel.org, jedrzej.wasiukiewicz@intel.com Cc: fenghuay@nvidia.com, peternewman@google.com, yu.c.chen@intel.com, x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v2 0/4] fork,arm,x86,fs/resctrl: Fix stale resource group assignment on fork Date: Fri, 4 Dec 2026 11:15:12 -0800 Message-ID: X-Mailer: git-send-email 2.56.0 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam11 X-Rspam-User: X-Stat-Signature: jziat9q6nfnnhr3d46we5aybwm3bx5ng X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: 31D3A180003 X-HE-Tag: 1796411735-537080 X-HE-Meta: U2FsdGVkX1/kCGFnSSLUgQvf+F/HQERhIrexjW9GDrHyMn7+5H0lXtxKRoMbKmw+9wPhAV0LOsJLDuSteBUYhxJSFS05DDR5ZrEgZJPacqYNH+M+EA6sG/Zjgh/wnsqX1cHNtVI0eQWVOF58MjwugjOzAwOHZBOQX+CSHdKzXo6dQbK8Y9TbJy7C7Ic7XwFYVTkPAnfWFkurdN1DA1KgdGe4uvYM+x3C2fbT/R/OQtmIEJbnrxmEzq6a2q3VqtgR/d9EPOg+dxjyuImcmyZTsTLd2jZTwJeMP/24I/7JjURPO8V/mR50WoWbGKv3ENIFXwjvNvc6b+1vjbrkrcLzmCQCsnXiOrpQEg++9gfXyTizr4N6eGMBZrc5eHUeyinHUSsGgxyPmxYvRcjrj7hBG7ep44JVvsAw/Pdlql1CJUspZHOqlPl0W9Jmn3vULjJM6aiYSu8sFFMvbaf0jBnQqqcxvELsw+86Plpd6L2hXr/xf9GbQ3XjlbN2iS+ziKyrlWK7v84TNbJIIYkBAl2C95WNawlVWJ2ADc4zUl1uyYHFq5UYwvL+xaPdYnWfyEARjcHNy588k//7fuJfD5IzAEFhFSCPtCHRQYr+vYQki5nWph7w3n6dtm9cDk4M2hx5SwBzQPRYCE3/G3aGPc3+Q+mwgW281hvEwf1flgLh59X1EVmLNIIDv/5LXRP5U+tabjqSeQqW6tLdg+DBclLguK3qb3KzAQX67ZQ4qerTjSibbZbh8Xagj1qWql6azXLxiJxitVjUJDLXu8waM9x2NvCH7RqumKJXlhQ8bWriUWtuup3ipgeMGJfZBgpEkIdYEdQ6H7fXVOTgUPMpWu7cYcFrYDOP1aO/YN0X+q5vktKtLnmlauCOZMUiYValKnBN8cyapO5KjVVBVxW79phBrMZyL5x4H+eYzoNis0pYyNUKVEe2voyjMEvGHu76fzdjzjy5cY6sm+54cUDUlTE MRhCIf5k ouoXeFNNym76Ho9e2q8IsEL7mjEIHGydHwKs/pJDor8UGL2BCYUVaN0RA6d232WnjLkmFptJIgwmhCW6SnUdjdmmgmQe5AnSQuvZh1bZO871/ey5La2Nku7RCQn3nw//QrxpgN+nD2H1+FdSuU//MVIK4+1pTqY6vaiQ+WLgtcxCjwAW6jLirUIRSq6Fd0/m288+9WWHZILcc7CavMrbjnEjpuYgZKP9BldD88I+qxPRn0eC6aOHdx9NN3patXPUFkxSt/q6se8wx5JxXPmmMG8e6PXrnOojxa7K0imnCbDfovvvVvL+iGQPMwMReEEh2VVUtkPwiUhWsvFxKJ2HW41YzDiwTJYAXzCjwPt1gxVtgHnRTIovISmQsc3lqbeEEf3oIqoryHVmOhA2nUdOEubskYKp81lXBceO2Apn0llo7B2Y= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Changes since RFC: - RFC: https://lore.kernel.org/all/cover.1795197419.git.reinette.chatre@intel.com/ - Rebase on v7.4-rc5. - Add Chenyu's Tested-by to fix patch. - Add new patch to remove unneeded include of linux/arm_mpam.h. (Ben) - Make MPAM resctrl_arch_copy_closid_rmid() a static inline. (Ben) - Add note to reproducer about the sashiko reports. Hi Everybody, Jedrzej reported that a newly created resource group can start out with tasks in it, before any task has been assigned to it. He created the reproducer in patch 4 to demonstrate this. Hitting this needs a fork() to overlap the removal of the resource group the forking task belongs to. A system that forks heavily while monitor groups are created and removed around it will eventually do both at once. Removing a resctrl resource group moves the group's tasks to another group by walking the task list, and then frees the group's CLOSID and RMID. A task created while that walk runs escapes it: fork() copies the parent's CLOSID and RMID early in copy_process(), before the new task is linked onto the task list, and the walk holds tasklist_lock for read so the new task cannot join the list until the walk has finished. The new task is thus left with the CLOSID and RMID of a resource group that no longer exists, and passes them on to every task it creates. Once the freed CLOSID and RMID are handed to a resource group created later, the strays appear in that group's tasks file, their memory accesses are counted in its monitoring data, and they are subject to its allocation policy, while the group intended for them does not control or monitor them. Series layout ============= Patch 2 depicts the race. resctrl has no fork() hook today. Patch 2 adds one, resctrl_copy_process(), called from copy_process() while tasklist_lock is held for write, which is the lock the task list walk is serialized against. Considering klp_copy_process(), this seems to match the convention used to address an issue with this shape. 1 Remove unneeded include of linux/arm_mpam.h so that linux/arm_mpam.h can include asm/mpam.h 2 Add resctrl_copy_process() and assign a task's CLOSID and RMID with tasklist_lock held 3 Record the new tasklist_lock requirement with lockdep 4 Reproducer, not for inclusion Transition from RFC to PATCH ============================ This version implements the MPAM maintainer's guidance on the shape of the MPAM implementation. There was no feedback on the kernel/fork.c change. Since it is modelled on klp_copy_process(), dropping the RFC seems reasonable, but review of that change remains very welcome. How was this tested? ==================== The issue can be reproduced using Jedrzej's script found in patch 4, which on x86 needs a system booted with "rdt=!cmt". On my test system the issue reproduces on the first run. With these fixes the reproducer did not encounter the issue in 100 runs. The MPAM changes are compile tested only. What remains? ============= On x86 the CLOSID and RMID are separate values in struct task_struct and __resctrl_sched_in() reads them without a lock, so a task can still be labelled with a mismatched pair for the duration of a move. Unlike the fork case, which is permanent and invisible to every later walk of the task list, that window is transient and the pair is corrected at the next context switch. MPAM stores the two as a single value. The series is based on v7.4-rc5. Any feedback is appreciated. Thank you. Reinette Jedrzej Wasiukiewicz (1): NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer Reinette Chatre (3): arm64: mpam: Remove unneeded include of linux/arm_mpam.h fork,arm,x86,fs/resctrl: Fix stale resource group assignment vs copy_process() arm,x86/resctrl: Assert tasklist_lock is held when setting CLOSID and RMID arch/arm64/include/asm/mpam.h | 7 +- arch/x86/include/asm/resctrl.h | 11 ++ drivers/resctrl/mpam_resctrl.c | 2 + fs/resctrl/rdtgroup.c | 21 +++ include/linux/arm_mpam.h | 8 ++ include/linux/resctrl.h | 28 ++++ kernel/fork.c | 3 + .../selftests/resctrl/stray_tasks_repro.sh | 122 ++++++++++++++++++ 8 files changed, 201 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/resctrl/stray_tasks_repro.sh base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244 -- 2.56.0