From: "Luck, Tony" <tony.luck@intel.com>
To: Reinette Chatre <reinette.chatre@intel.com>
Cc: <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>, <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>, <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>
Subject: Re: [PATCH v2 0/4] fork,arm,x86,fs/resctrl: Fix stale resource group assignment on fork
Date: Fri, 4 Dec 2026 13:07:53 -0800 [thread overview]
Message-ID: <axMrqfLmLZBfIUuN@agluck-desk3> (raw)
In-Reply-To: <cover.1796411500.git.reinette.chatre@intel.com>
On Fri, Dec 04, 2026 at 11:15:12AM -0800, Reinette Chatre wrote:
> 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.
I think the patch below covers this (only atomic on 64-bit CPUs).
Builds and passes tools/testing/selftests/resctrl/resctrl_tests.
-Tony
---
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e4f6323d7855..c79ac345136d 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1364,8 +1364,13 @@ struct task_struct {
#endif /* CONFIG_PREEMPT_RT */
#endif /* CONFIG_CGROUPS */
#ifdef CONFIG_X86_CPU_RESCTRL
- u32 closid;
- u32 rmid;
+ union x86_pqosid {
+ u64 pqosid;
+ struct {
+ u32 closid;
+ u32 rmid;
+ };
+ };
#endif
struct futex_sched_data futex;
diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h
index 48bf22fb6b47..1b842c55d92f 100644
--- a/arch/x86/include/asm/resctrl.h
+++ b/arch/x86/include/asm/resctrl.h
@@ -104,23 +104,23 @@ static inline void __resctrl_sched_in(struct task_struct *tsk)
struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state);
u32 closid = READ_ONCE(state->default_closid);
u32 rmid = READ_ONCE(state->default_rmid);
+ union x86_pqosid tmp;
struct msr val;
- u32 tmp;
+
+ tmp.pqosid = READ_ONCE(tsk->pqosid);
/*
* If this task has a closid/rmid assigned, use it.
* Else use the closid/rmid assigned to this cpu.
*/
if (static_branch_likely(&rdt_alloc_enable_key)) {
- tmp = READ_ONCE(tsk->closid);
- if (tmp)
- closid = tmp;
+ if (tmp.closid)
+ closid = tmp.closid;
}
if (static_branch_likely(&rdt_mon_enable_key)) {
- tmp = READ_ONCE(tsk->rmid);
- if (tmp)
- rmid = tmp;
+ if (tmp.rmid)
+ rmid = tmp.rmid;
}
if (closid != state->cur_closid || rmid != state->cur_rmid) {
@@ -160,8 +160,7 @@ static inline void resctrl_arch_set_closid_rmid(struct task_struct *tsk,
static inline void resctrl_arch_copy_closid_rmid(struct task_struct *dst,
struct task_struct *src)
{
- WRITE_ONCE(dst->closid, READ_ONCE(src->closid));
- WRITE_ONCE(dst->rmid, READ_ONCE(src->rmid));
+ WRITE_ONCE(dst->pqosid, READ_ONCE(src->pqosid));
}
static inline bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid)
next prev parent reply other threads:[~2026-12-04 21:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 19:15 [PATCH v2 0/4] fork,arm,x86,fs/resctrl: Fix stale resource group assignment on fork Reinette Chatre
2026-12-04 19:15 ` [PATCH v2 1/4] arm64: mpam: Remove unneeded include of linux/arm_mpam.h Reinette Chatre
2026-12-04 19:15 ` [PATCH v2 2/4] fork,arm,x86,fs/resctrl: Fix stale resource group assignment vs copy_process() Reinette Chatre
2026-12-04 19:15 ` [PATCH v2 3/4] arm,x86/resctrl: Assert tasklist_lock is held when setting CLOSID and RMID Reinette Chatre
2026-12-04 19:15 ` [PATCH v2 4/4] NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer Reinette Chatre
2026-12-05 19:16 ` sashiko-bot
2026-12-04 21:07 ` Luck, Tony [this message]
2026-12-04 23:00 ` [PATCH v2 0/4] fork,arm,x86,fs/resctrl: Fix stale resource group assignment on fork 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=axMrqfLmLZBfIUuN@agluck-desk3 \
--to=tony.luck@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=reinette.chatre@intel.com \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.