[RESEND PATCH v4 09/15] fs/resctrl: Introduce kmode_cpus/kmode_cpus_list per rdtgroup

From: Babu Moger

Date: Tue Jul 07 2026 - 17:56:19 EST


Kernel-mode resctrl policies allow kernel work to be associated with a
specific rdtgroup, optionally restricted to a subset of online CPUs.

While user space can query the active kernel-mode policy and its associated
rdtgroup through info/kernel_mode, it currently lacks visibility into the
CPU scope of that binding.

Introduce read-only kmode_cpus and kmode_cpus_list files for each rdtgroup.
These expose rdtgrp->kmode_cpu_mask in both bitmap and range-list formats,
consistent with the existing cpus and cpus_list interfaces.

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v4: Rewrote the change to be generic.

v3: New patch to add "kmode_cpus" and "kmode_cpus_list" to support
kernel_modes.
---
fs/resctrl/internal.h | 4 ++++
fs/resctrl/rdtgroup.c | 46 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+)

diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index 178126bb2da5..12db6933bc54 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -216,6 +216,8 @@ struct mongroup {
* @mon: mongroup related data
* @mode: mode of resource group
* @mba_mbps_event: input monitoring event id when mba_sc is enabled
+ * @kmode: true if this group is bound to a kernel-mode policy
+ * @kmode_cpu_mask: CPU scope for this group's kernel-mode binding
* @plr: pseudo-locked region
*/
struct rdtgroup {
@@ -229,6 +231,8 @@ struct rdtgroup {
struct mongroup mon;
enum rdtgrp_mode mode;
enum resctrl_event_id mba_mbps_event;
+ bool kmode;
+ struct cpumask kmode_cpu_mask;
struct pseudo_lock_region *plr;
};

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 346aa4df62a4..0d5c94169d03 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -392,6 +392,37 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
return ret;
}

+/*
+ * Display per-rdtgroup CPU bindings for kernel-mode enabled groups.
+ * Supports both "kmode_cpus" (bitmap format) and "kmode_cpus_list"
+ * (range list format); the output format is selected accordingly.
+ *
+ * Returns -ENOENT if the group has been deleted, and -ENODEV for
+ * pseudo-locked groups, which cannot host a kernel-mode binding.
+ */
+static int rdtgroup_kmode_cpus_show(struct kernfs_open_file *of,
+ struct seq_file *s, void *v)
+{
+ struct rdtgroup *rdtgrp;
+ int ret = 0;
+
+ rdtgrp = rdtgroup_kn_lock_live(of->kn);
+
+ if (rdtgrp) {
+ if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
+ ret = -ENODEV;
+ } else {
+ seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
+ cpumask_pr_args(&rdtgrp->kmode_cpu_mask));
+ }
+ } else {
+ ret = -ENOENT;
+ }
+ rdtgroup_kn_unlock(of->kn);
+
+ return ret;
+}
+
/*
* Update the PGR_ASSOC MSR on all cpus in @cpu_mask,
*
@@ -2181,6 +2212,21 @@ static struct rftype res_common_files[] = {
.flags = RFTYPE_FLAGS_CPUS_LIST,
.fflags = RFTYPE_BASE,
},
+ {
+ .name = "kmode_cpus",
+ .mode = 0444,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .seq_show = rdtgroup_kmode_cpus_show,
+ .fflags = RFTYPE_BASE,
+ },
+ {
+ .name = "kmode_cpus_list",
+ .mode = 0444,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .seq_show = rdtgroup_kmode_cpus_show,
+ .flags = RFTYPE_FLAGS_CPUS_LIST,
+ .fflags = RFTYPE_BASE,
+ },
{
.name = "tasks",
.mode = 0644,
--
2.43.0