[PATCH v4 06/15] fs/resctrl: Introduce resctrl_set_kmode_support() to initialize supported modes
From: Babu Moger
Date: Tue Jul 07 2026 - 17:19:36 EST
Architectures need a way to advertise which kernel-mode resctrl policies
they support before generic resctrl exposes those policies through the
filesystem.
Add the `struct resctrl_kmode_cfg` to define the default mode statically,
and introduce `resctrl_set_kmode_support()` so architecture code can
register supported kernel-mode policies during resctrl initialization. The
`INHERIT_CTRL_AND_MON` policy is supported by default, so architectures
only need to register any additional modes.
Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v4: New patch to initialize supported kernel-mode's.
https://lore.kernel.org/lkml/737a4228-52fb-4583-ac64-8efe79c107e6@xxxxxxxxx/
Changed the kmode_cur to enum resctrl_kernel_mode in resctrl_kmode_cfg.
Moved the resctrl_kmode_cfg to filesystem code.
---
fs/resctrl/internal.h | 12 ++++++++++++
fs/resctrl/rdtgroup.c | 23 +++++++++++++++++++++++
include/linux/resctrl.h | 10 ++++++++++
3 files changed, 45 insertions(+)
diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index 48af75b9dc85..178126bb2da5 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -314,6 +314,18 @@ struct mbm_state {
u32 prev_bw;
};
+/**
+ * struct resctrl_kmode_cfg - Kernel-mode policy snapshot from architecture
+ * @kmode: Bitmap of supported &enum resctrl_kernel_mode values. Each
+ * supported mode is represented by BIT(mode).
+ * @kmode_cur: Currently selected kernel-mode policy.
+ * @k_rdtgrp: Resource group backing global-assign modes when applicable;
+ */
+struct resctrl_kmode_cfg {
+ unsigned long kmode;
+ enum resctrl_kernel_mode kmode_cur;
+ struct rdtgroup *k_rdtgrp;
+};
extern struct mutex rdtgroup_mutex;
static inline const char *rdt_kn_name(const struct kernfs_node *kn)
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index cc9966ff6cdf..0ee0dfaf9065 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -78,6 +78,16 @@ static void mon_put_kn_priv(void);
struct dentry *debugfs_resctrl;
+/*
+ * Global kernel-mode resctrl policy. Architectures add supported modes before
+ * resctrl is mounted; @kmode_cur tracks the active policy after user selection.
+ */
+static struct resctrl_kmode_cfg resctrl_kcfg = {
+ .kmode = BIT(INHERIT_CTRL_AND_MON),
+ .kmode_cur = INHERIT_CTRL_AND_MON,
+ .k_rdtgrp = NULL
+};
+
/*
* Memory bandwidth monitoring event to use for the default CTRL_MON group
* and each new CTRL_MON group created by the user. Only relevant when
@@ -888,6 +898,19 @@ static int rdtgroup_rmid_show(struct kernfs_open_file *of,
return ret;
}
+/**
+ * resctrl_set_kmode_support() - Advertise support for a kernel-mode policy
+ * @kmode: Kernel-mode policy supported by the architecture.
+ *
+ * Architectures call this during resctrl initialization to make @kmode visible
+ * to the resctrl filesystem. INHERIT_CTRL_AND_MON is always supported.
+ */
+void resctrl_set_kmode_support(enum resctrl_kernel_mode kmode)
+{
+ if (kmode <= RESCTRL_KMODE_LAST)
+ __set_bit(kmode, &resctrl_kcfg.kmode);
+}
+
#ifdef CONFIG_PROC_CPU_RESCTRL
/*
* A task can only be part of one resctrl control group and of one monitor
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 47db34dd167e..8dd02579f354 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -734,6 +734,16 @@ enum resctrl_kernel_mode {
#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1)
+/**
+ * resctrl_set_kmode_support() - Advertise a supported kernel-mode policy
+ * @kmode: Kernel-mode policy supported by the architecture.
+ *
+ * Architectures use this during resctrl initialization to make additional
+ * kernel-mode policies available to the filesystem. INHERIT_CTRL_AND_MON is
+ * supported by default and does not need to be registered.
+ */
+void resctrl_set_kmode_support(enum resctrl_kernel_mode kmode);
+
/**
* resctrl_arch_configure_kmode() - Program kernel-mode association on CPUs
* @cpu_mask: CPUs to update; the architecture applies the change on the
--
2.43.0