[RFC PATCH 2/3] arm,x86/resctrl: Assert tasklist_lock is held when setting CLOSID and RMID

From: Reinette Chatre

Date: Fri Nov 20 2026 - 13:39:56 EST


resctrl_arch_set_closid_rmid() assigns a task's CLOSID and RMID. All of
its callers hold tasklist_lock for read, which is what lets
resctrl_copy_process() read both values as intended.

Each architecture declares resctrl_arch_set_closid_rmid() itself, so
there is no shared declaration in which to record that requirement.
Record it in the implementations instead.

Signed-off-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
---
arch/x86/include/asm/resctrl.h | 4 ++++
drivers/resctrl/mpam_resctrl.c | 2 ++
2 files changed, 6 insertions(+)

diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h
index 199ca9af0089..48bf22fb6b47 100644
--- a/arch/x86/include/asm/resctrl.h
+++ b/arch/x86/include/asm/resctrl.h
@@ -5,9 +5,11 @@
#ifdef CONFIG_X86_CPU_RESCTRL

#include <linux/jump_label.h>
+#include <linux/lockdep.h>
#include <linux/percpu.h>
#include <linux/resctrl_types.h>
#include <linux/sched.h>
+#include <linux/sched/task.h>

#include <asm/msr.h>

@@ -149,6 +151,8 @@ static inline void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid,
static inline void resctrl_arch_set_closid_rmid(struct task_struct *tsk,
u32 closid, u32 rmid)
{
+ lockdep_assert_held(&tasklist_lock);
+
WRITE_ONCE(tsk->closid, closid);
WRITE_ONCE(tsk->rmid, rmid);
}
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 7aea58fca85b..4e6ffe273863 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -332,6 +332,8 @@ void resctrl_arch_sync_cpu_closid_rmid(void *info)

void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid)
{
+ lockdep_assert_held(&tasklist_lock);
+
WARN_ON_ONCE(closid > U16_MAX);
WARN_ON_ONCE(rmid > U8_MAX);

--
2.56.0