From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796411735; b=oQsTTF8jWJIFB71iuPyBn+oePgxBrTG7DDG8R3q2P+Oej9oveg/v4AgSYXersI8ucAFm QKwSufwNHoBevQhj4pL5stCX3/ihMBdAZH5SuPMYDudo/KLdqa3I9+vMkjqznX2LYP55W VgJj5MSyl3YHXt5hSJw0emuthz2p4wG3GHQypaSZr3NzddIXoU1amJ5659vEvZHAlpL5V AqvdrdluxsvkFjxtkoHdR1Y4nW3sdg8NcKSwot6YJdScJvXqVFH/0NSKFYLJbiNvdcxB1 nxi4ABo6yW2Qll/R0hfv2JJu4KrtcI2AKhFze4FeA5o+Lxnz6U04TLZOl9geGvLkc8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796411735; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=tsn/s1AL0q8n+PBK+IlKZP34RGNi3sBnoK8GZLH1w88=; b=vEQjgpaUWNT7kUoss1Fm9Dpp12eQNQQOfRca+vnHbC3bt1jNzEO8RXSBkjh98JMOkrxs vNnFtI5bIXNBrKCqZU95Rb0nDlJI+gHqv71DVBT7ckCHyUEXNfkWwP6fSCtyGnwRtWZcr alxRtfm0xc1lkAW18Ol3VUp39LTpSXDsM2/WZXim2pPaFQ18CVxqQiDnsikyNOIaLqzpP hCk6N72KYbU5SQIwxP08mznSWkJTIto7N/9+Mq4/U1268xjZ+XG5kVNB7WOXAYKEtCBAN xWtJSL4G4mJDC8kPsSsw55El+vC1Ni+d7C5OnwnbxjRyLRBdzbBAU6AUEPykYkYVseg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=kSq4gMuv; arc=none smtp.remote-ip=192.198.163.17 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D6DB606A32C for ; Fri, 4 Dec 2026 19:15:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6D6DB606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com 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=kSq4gMuv DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796411735; x=1827947735; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=tsn/s1AL0q8n+PBK+IlKZP34RGNi3sBnoK8GZLH1w88=; b=kSq4gMuvOFXsV2WLjlcjWVmDdrF0QqAr/u8mFWgHBJPLkFkoJzmDHzon 66QBVZfCL2k5RSFcWRq2xCM97DMXV3yDc2mtFi+a7W11fw2z8j4ueHIUk YUG3ZoR8pTvn6P+0k6mmujtN2jNS+zUSUzPsN8WZbVaKoqMPWN7iQSx13 OEQvKBqY4LDXDeSSUKSDOFQFzqBj9+bJnZTyljEf7jeHVBoBu1gMe9rRT Waw2dw0ESJigYf1J1IAyIEh/BM3mT8xMYP+qK1F93lzc/GzTAIAdC5qcv K2YIWOKQOPA812KXv1xS3xRLYrho5JR5/nvJWCpoQxg32GOsfT9V4YlWN g==; X-CSE-ConnectionGUID: dDYPOAe3Q2GXdpElTf8M2g== X-CSE-MsgGUID: hKTkO/0IQaGfbpqtIgqPQQ== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5410854" X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="5410854" 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-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 Content-Transfer-Encoding: 8bit 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