[PATCH v5 09/16] fs/resctrl: Add interface to display supported and active kernel modes

From: Babu Moger

Date: Wed Aug 26 2026 - 15:36:31 EST


Resctrl kernel modes define how resource allocation and monitoring
associations are applied in kernel mode relative to user mode. Generic
resctrl maintains information about supported kernel modes, the currently
active mode, and the resource group associated with global assignment
mode, but this information is not currently visible to user space.

Add info/kernel_mode to expose kernel mode configuration through the
resctrl filesystem. The file lists all supported kernel modes, one per
line, identifies the active mode by enclosing it in square brackets, and
for assign_global_enable_per_cpu also reports ctrl=, mon=, and group=.
Document the read interface in Documentation/filesystems/resctrl.rst.

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v5: Use resctrl_kcfg.caps and resctrl_kcfg.active after the struct split
from patch 0006. Rename resctrl_kmode_bind_str() to
resctrl_kmode_state_str() and ctrl_bind/mon_bind to ctrl_state/mon_state.
Used info_kn_lock()/info_kn_unlock().
Add documentation update in resctrl.rst.

v4: Fixed the display of inherit_ctrl_and_mon policy. It is not
associated with any group.
Added "uninitialized" for the non-active group.
Rewrote the changelog.

v3: New patch to handle the changed interface file info/kernel_mode.
Changed the group name to "none" if kmode binding is not done.
Reinette suggested "uninitialized". "none" seemed more relevent.
---
Documentation/filesystems/resctrl.rst | 29 +++++++
fs/resctrl/rdtgroup.c | 115 ++++++++++++++++++++++++++
2 files changed, 144 insertions(+)

diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst
index f3e941404967..c6e8cf828e18 100644
--- a/Documentation/filesystems/resctrl.rst
+++ b/Documentation/filesystems/resctrl.rst
@@ -528,6 +528,35 @@ conveyed in the error returns from file operations. E.g.
# cat info/last_cmd_status
mask f7 has non-consecutive 1-bits

+"kernel_mode":
+ In the top level of the "info" directory, "kernel_mode" reports
+ supported and active kernel modes available on the system.
+
+ Reading the file lists one mode per line. The active mode is wrapped in
+ square brackets. inherit_user is shown without options.
+ assign_global_enable_per_cpu is shown as::
+
+ assign_global_enable_per_cpu:ctrl=<assign|inherit>;mon=<assign|inherit>;group=<ctrl>/<mon>/
+
+ - inherit_user: inherit allocation and monitoring from the user task.
+ - assign_global_enable_per_cpu: kernel mode may use separate
+ allocation and/or monitoring associations. ctrl= and mon= show
+ whether each is assigned or inherited, and group= identifies the
+ associated resource group using <CTRL_MON>/<MON>/ path syntax.
+
+ Only supported modes are listed. On an inactive
+ assign_global_enable_per_cpu line, ctrl= and mon= show platform
+ capability defaults rather than the last active assignment, and
+ group=// is shown. When the mode is active, ctrl= and mon= report
+ the current assignment state and group= identifies the associated
+ resource group.
+
+ Example::
+
+ # cat info/kernel_mode
+ [inherit_user]
+ assign_global_enable_per_cpu:ctrl=assign;mon=assign;group=//
+
Resource alloc and monitor groups
=================================

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 3bb0e3a203ac..992af586a194 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1010,6 +1010,114 @@ static int rdt_last_cmd_status_show(struct kernfs_open_file *of,
return 0;
}

+/* Sysfs lines for info/kernel_mode; indexed by enum resctrl_kernel_mode */
+static const char * const resctrl_mode_str[] = {
+ [RESCTRL_INHERIT_USER] = "inherit_user",
+ [RESCTRL_ASSIGN_GLOBAL_ENABLE_PER_CPU] = "assign_global_enable_per_cpu"
+};
+
+static_assert(ARRAY_SIZE(resctrl_mode_str) == RESCTRL_NUM_KERNEL_MODES);
+
+static const char *resctrl_kmode_state_str(enum kmode_state state)
+{
+ return state == KMODE_ASSIGN ? "assign" : "inherit";
+}
+
+static void resctrl_kmode_group_path(struct rdtgroup *rdtgrp,
+ const char **ctrl, const char **mon)
+{
+ *ctrl = "";
+ *mon = "";
+
+ if (!rdtgrp)
+ return;
+
+ if (rdtgrp->type == RDTMON_GROUP) {
+ *ctrl = rdt_kn_name(rdtgrp->mon.parent->kn);
+ *mon = rdt_kn_name(rdtgrp->kn);
+ } else {
+ *ctrl = rdt_kn_name(rdtgrp->kn);
+ }
+}
+
+/**
+ * resctrl_kernel_mode_show() - Display supported and active kernel modes
+ * @of: kernfs open file
+ * @seq: output seq_file
+ * @v: unused
+ *
+ * Lists one line per mode set in resctrl_kcfg.caps.kmode_sup. Brackets the
+ * active mode. inherit_user is shown without any options.
+ * assign_global_enable_per_cpu is shown as:
+ *
+ * assign_global_enable_per_cpu:ctrl=<assign|inherit>;mon=<assign|inherit>;\
+ * group=<ctrl>/<mon>/
+ *
+ * When assign_global_enable_per_cpu is inactive, ctrl=assign and mon=assign
+ * reflect resctrl_kcfg.caps.ctrl_en and resctrl_kcfg.caps.mon_en, and
+ * group=//. When active, assign state comes from resctrl_kcfg.active.ctrl_mode
+ * and resctrl_kcfg.active.mon_mode.
+ *
+ * Return: 0 on success, or -ENOENT on error.
+ */
+static int resctrl_kernel_mode_show(struct kernfs_open_file *of,
+ struct seq_file *seq, void *v)
+{
+ const char *ctrl_state, *mon_state;
+ enum resctrl_kernel_mode mode;
+ struct rdtgroup *rdtgrp;
+ const char *ctrl, *mon;
+ bool active;
+ int ret = 0;
+
+ if (!info_kn_lock(of->kn))
+ return -ENOENT;
+
+ for (mode = 0; mode < RESCTRL_NUM_KERNEL_MODES; mode++) {
+ if (!test_bit(mode, resctrl_kcfg.caps.kmode_sup))
+ continue;
+
+ active = (resctrl_kcfg.active.kmode_cur == mode);
+
+ if (mode == RESCTRL_INHERIT_USER) {
+ seq_printf(seq, active ? "[%s]\n" : "%s\n",
+ resctrl_mode_str[mode]);
+ continue;
+ }
+
+ if (active) {
+ ctrl_state = resctrl_kmode_state_str(resctrl_kcfg.active.ctrl_mode);
+ mon_state = resctrl_kmode_state_str(resctrl_kcfg.active.mon_mode);
+ rdtgrp = resctrl_kcfg.active.k_rdtgrp;
+ if (WARN_ON(!rdtgrp)) {
+ rdt_last_cmd_puts("Invalid kernel mode group\n");
+ ret = -ENOENT;
+ goto out_unlock;
+ }
+ resctrl_kmode_group_path(rdtgrp, &ctrl, &mon);
+ } else {
+ ctrl_state = resctrl_kcfg.caps.ctrl_en ? "assign" : "inherit";
+ mon_state = resctrl_kcfg.caps.mon_en ? "assign" : "inherit";
+ ctrl = "";
+ mon = "";
+ }
+
+ if (active) {
+ seq_printf(seq, "[%s:ctrl=%s;mon=%s;group=%s/%s/]\n",
+ resctrl_mode_str[mode], ctrl_state, mon_state,
+ ctrl, mon);
+ } else {
+ seq_printf(seq, "%s:ctrl=%s;mon=%s;group=%s/%s/\n",
+ resctrl_mode_str[mode], ctrl_state, mon_state,
+ ctrl, mon);
+ }
+ }
+
+out_unlock:
+ info_kn_unlock(of->kn);
+ return ret;
+}
+
void *rdt_kn_parent_priv(struct kernfs_node *kn)
{
/*
@@ -1995,6 +2103,13 @@ static struct rftype res_common_files[] = {
.seq_show = rdt_last_cmd_status_show,
.fflags = RFTYPE_TOP_INFO,
},
+ {
+ .name = "kernel_mode",
+ .mode = 0444,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .seq_show = resctrl_kernel_mode_show,
+ .fflags = RFTYPE_TOP_INFO,
+ },
{
.name = "mbm_assign_on_mkdir",
.mode = 0644,
--
2.43.0