From: Reinette Chatre <reinette.chatre@intel.com>
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, bp@alien8.de,
tglx@linutronix.de, dave.hansen@linux.intel.com,
tony.luck@intel.com, ben.horgan@arm.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: [RFC PATCH 0/3] fork,arm,x86,fs/resctrl: Fix stale resource group assignment on fork
Date: Fri, 20 Nov 2026 10:39:29 -0800 [thread overview]
Message-ID: <cover.1795197419.git.reinette.chatre@intel.com> (raw)
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 3 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 1 depicts the race.
resctrl has no fork() hook today. Patch 1 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 custom used to address an issue with this shape.
1 Add resctrl_copy_process() and assign a task's CLOSID and RMID
with tasklist_lock held
2 Record the new tasklist_lock requirement with lockdep
3 Reproducer, not for inclusion
Why is this an RFC?
===================
- resctrl_copy_process() runs on every fork(), so
resctrl_arch_copy_closid_rmid() is a static inline on x86 but is
out-of-line for MPAM. The note below patch 1 describes what was
attempted to make it inline for MPAM and asks the MPAM maintainers
what shape it should take there.
- Patch 1 touches kernel/fork.c. It adds a single call inside the
existing write_lock_irq(&tasklist_lock) region of copy_process(),
immediately after klp_copy_process() on which it is modelled.
How was this tested?
====================
The issue can be reproduced using Jedrzej's script found in patch #3. On
my test system the issue is encountered on a single run. With these fixes
the reproducer did not encounter the issue in 100 runs.
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-rc3.
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 (2):
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 | 6 +
arch/x86/include/asm/resctrl.h | 11 ++
drivers/resctrl/mpam_resctrl.c | 8 ++
fs/resctrl/rdtgroup.c | 21 +++
include/linux/arm_mpam.h | 1 +
include/linux/resctrl.h | 28 ++++
kernel/fork.c | 3 +
.../selftests/resctrl/stray_tasks_repro.sh | 122 ++++++++++++++++++
8 files changed, 200 insertions(+)
create mode 100755 tools/testing/selftests/resctrl/stray_tasks_repro.sh
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.56.0
next reply other threads:[~2026-11-20 18:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 18:39 Reinette Chatre [this message]
2026-11-20 18:39 ` [RFC PATCH 1/3] fork,arm,x86,fs/resctrl: Fix stale resource group assignment vs copy_process() Reinette Chatre
2026-11-20 18:39 ` [RFC PATCH 2/3] arm,x86/resctrl: Assert tasklist_lock is held when setting CLOSID and RMID Reinette Chatre
2026-11-20 18:39 ` [RFC PATCH 3/3] NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer Reinette Chatre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1795197419.git.reinette.chatre@intel.com \
--to=reinette.chatre@intel.com \
--cc=Dave.Martin@arm.com \
--cc=babu.moger@amd.com \
--cc=ben.horgan@arm.com \
--cc=bp@alien8.de \
--cc=bsegall@google.com \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=fenghuay@nvidia.com \
--cc=fustini@kernel.org \
--cc=james.morse@arm.com \
--cc=jedrzej.wasiukiewicz@intel.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=patches@lists.linux.dev \
--cc=peternewman@google.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=vbabka@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=x86@kernel.org \
--cc=yu.c.chen@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®