[RESEND PATCH v4 04/15] fs/resctrl: Introduce kernel mode (kmode) data structures
From: Babu Moger
Date: Tue Jul 07 2026 - 17:51:32 EST
Kernel-mode traffic can use a different allocation and monitoring context
than the originating user task. On x86, Privilege Level Zero Association
(PLZA) enables the kernel to switch to a different CLOSID (and optionally
RMID) when entering kernel mode.
Architectures need a common way to name kernel-mode policies before resctrl
can report what is active or what the platform supports.
Introduce enum resctrl_kernel_mode:
- INHERIT_CTRL_AND_MON: Kernel work inherits allocation and monitoring
from the user task (current behavior).
- GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU: Assign allocation for kernel
work; inherit monitoring from the user task.
- GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU: Assign a dedicated allocation
and monitoring for kernel work.
Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v4: Updated the changelog to be generic as possible.
Moved the enum resctrl_kernel_mode to include/linux/resctrl.h.
Updated the code comments to be generic.
Removed resctrl_kmode_cfg from the code. This definition can be fs
specific only and architectures dont need to know.
Changed enum name to resctrl_kernel_mode from resctrl_kernel_modes.
v3: Removed resctrl_kmode definition.
Changed the kernel mode definitions to enum resctrl_kernel_modes.
Used BIT() to set/test the features.
Added details to changelog.
v2: New patch to handle PLZA interfaces with /sys/fs/resctrl/info/ directory.
https://lore.kernel.org/lkml/2ab556af-095b-422b-9396-f845c6fd0342@xxxxxxxxx/
---
include/linux/resctrl.h | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 73ff522448a0..c7abed51cd5f 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -703,6 +703,37 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable);
*/
bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r);
+/**
+ * enum resctrl_kernel_mode - Kernel-mode control and monitor association
+ * policy.
+ *
+ * @INHERIT_CTRL_AND_MON:
+ * Kernel work inherits the allocation and monitoring from the user space
+ * task. On x86 this means that kernel work shares the same CLOSID and
+ * RMID as the user space task. This matches today's resctrl behavior.
+ *
+ * @GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU:
+ * Kernel work uses a globally assigned allocation while monitoring is
+ * inherited from the user space task. On x86 this means a CLOSID is
+ * assigned for kernel work and the RMID is inherited from the user space
+ * task. Default scope is all online CPUs; a subset may be selected via
+ * the resctrl group interface. A CTRL_MON group is bound to this mode.
+ *
+ * @GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU:
+ * Kernel work uses globally assigned allocation and monitoring. On x86
+ * this means both CLOSID and RMID are assigned for kernel work. Default
+ * scope is all online CPUs; a subset may be selected via the resctrl
+ * group interface. A CTRL_MON or MON group is bound to this mode.
+ */
+enum resctrl_kernel_mode {
+ INHERIT_CTRL_AND_MON,
+ GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU,
+ GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU,
+ RESCTRL_KMODE_LAST = GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU,
+};
+
+#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1)
+
extern unsigned int resctrl_rmid_realloc_threshold;
extern unsigned int resctrl_rmid_realloc_limit;
--
2.43.0