[PATCH v2 08/16] x86/resctrl: Add per-CPU and per-task kernel mode state

Babu Moger
2026-03-12T20:38:37Z

Add per-CPU state and per-task state for resctrl kernel mode.

Signed-off-by: Babu Moger <babu.moger@amd.com>
---
v2: Minor name change from plza to kmode.
Tony suggested using global variables to store the kernel mode
CLOSID and RMID. However, the kernel mode CLOSID and RMID are
coming from rdtgroup structure with the new interface. Accessing
them requires holding the associated lock, which would make the
context switch path unnecessarily expensive.
https://lore.kernel.org/lkml/aXuxVSbk1GR2ttzF@agluck-desk3/
---
arch/x86/include/asm/resctrl.h | 14 +++++++++++++-
include/linux/sched.h | 2 ++
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h
index 4b4291006e78..e0a992abaeb4 100644
--- a/arch/x86/include/asm/resctrl.h
+++ b/arch/x86/include/asm/resctrl.h
@@ -21,9 +21,13 @@
/**
* struct resctrl_pqr_state - State cache for the PQR MSR
* @cur_rmid: The cached Resource Monitoring ID
- * @cur_closid: The cached Class Of Service ID
+ * @cur_closid: The cached Class Of Service ID
* @default_rmid: The user assigned Resource Monitoring ID
* @default_closid: The user assigned cached Class Of Service ID
+ * @cur_kmode: Currently active kernel mode (PLZA) bits for this CPU
+ * @default_kmode: Default kernel mode bits for this CPU (e.g. from resctrl mount)
+ * @kmode_rmid: RMID used when executing in kernel mode (PLZA)
+ * @kmode_closid: CLOSID used when executing in kernel mode (PLZA)
*
* The upper 32 bits of MSR_IA32_PQR_ASSOC contain closid and the
* lower 10 bits rmid. The update to MSR_IA32_PQR_ASSOC always
@@ -32,12 +36,20 @@
*
* The cache also helps to avoid pointless updates if the value does
* not change.
+ *
+ * Kernel mode (e.g. PLZA) state: cur_kmode/default_kmode hold the active
+ * and default mode bits; kmode_rmid and kmode_closid are the association
+ * used when the thread is in privilege level zero.
*/
struct resctrl_pqr_state {
u32 cur_rmid;
u32 cur_closid;
u32 default_rmid;
u32 default_closid;
+ u32 cur_kmode;
+ u32 default_kmode;
+ u32 kmode_rmid;
+ u32 kmode_closid;
};

DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state);
diff --git a/include/linux/sched.h b/include/linux/sched.h
index a7b4a980eb2f..2ec0530399be 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1328,6 +1328,8 @@ struct task_struct {
#ifdef CONFIG_X86_CPU_RESCTRL
u32 closid;
u32 rmid;
+ /* Resctrl kernel mode (e.g. PLZA) bits for this task */
+ u32 kmode;
#endif
#ifdef CONFIG_FUTEX
struct robust_list_head __user *robust_list;
--
2.43.0