Re: [RESEND PATCH v4 04/15] fs/resctrl: Introduce kernel mode (kmode) data structures
From: Babu Moger
Date: Wed Jul 08 2026 - 16:56:49 EST
On 7/7/26 16:50, Babu Moger wrote:
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;
Sashiko reported:
https://sashiko.dev/#/patchset/cover.1783461016.git.babu.moger%40amd.com?part=4
--- Patch [4]: [RESEND PATCH v4 04/15] fs/resctrl: Introduce kernel mode (kmode) data structures ---
commit 1114f46dcb9c990326351e5e6fea6cb114024be3
Author: Babu Moger <babu.moger@xxxxxxx>
fs/resctrl: Introduce kernel mode (kmode) data structures
This commit introduces the resctrl_kernel_mode enum to define policies for
allocating and monitoring contexts for kernel-mode traffic. It enables the
kernel to either inherit contexts from the user task or use globally assigned
allocations.
> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
> index 73ff522448a02..c7abed51cd5f0 100644
> --- a/include/linux/resctrl.h
> +++ b/include/linux/resctrl.h
[ ... ]
> +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,
> +};
This isn't a bug, but does this risk polluting the global kernel namespace?
The enumerators INHERIT_CTRL_AND_MON, GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU,
and GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU are defined in a globally included
kernel header without a subsystem-specific prefix.
Should these be prefixed with something like RESCTRL_ (similar to
RESCTRL_KMODE_LAST) to prevent potential name collisions with other kernel
code?
Yes, agreed. These names need another look. They are quite long, and we should try to shorten them without losing their meaning or context.
I'm looking for suggestions as well.
Can this be something like:
enum sysfs
KMODE_INHERIT_CTRL_MON "inherit_ctrl_mon"
KMODE_ASSIGN_CTRL_INHERIT_MON "assign_ctrl_inherit_mon"
KMODE_ASSIGN_CTRL_MON "assign_ctrl_mon"
CPU scope is already handled by kmode_cpus.
Thanks
Babu