[RFC PATCH v2 8/9] x86,fs/resctrl: Let the architecture cap the RMIDs for the software controller

From: Jinjie Ruan

Date: Thu Nov 12 2026 - 08:40:28 EST


The MBA software controller measures every monitor group. When the
architecture assigns each group a counter from a shared pool as the
group is created, the number of groups must not exceed the number of
counters while the controller is in use. resctrl has no way to learn
this from the architecture.

The rmid_idx space cannot change for this: rmid_ptrs[] is set up on
the first mount, and RMIDs in limbo outlive an unmount.

Add two hooks instead.
- resctrl_arch_set_mba_sc(). Called when the controller is enabled
or disabled, so the architecture can update what it reports
- resctrl_arch_rmid_valid(). Skips the RMIDs that arch refuses.

The hook runs before the number of CLOSIDs is read again, so the reset
of the bandwidth targets covers the CLOSIDs the controller may use.
The reset is skipped when the controller is disabled: the targets are
not read while it is off, and a domain that came online while it was
enabled may have allocated mbps_val for the capped, smaller number of
CLOSIDs.

Both hooks are no-ops on x86 and, for now, on MPAM.

Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
arch/x86/include/asm/resctrl.h | 6 ++++++
fs/resctrl/monitor.c | 6 ++++--
fs/resctrl/rdtgroup.c | 25 ++++++++++++++++++++-----
include/linux/arm_mpam.h | 8 ++++++++
4 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h
index 8f6edcdcfd87..ac51b63f6dde 100644
--- a/arch/x86/include/asm/resctrl.h
+++ b/arch/x86/include/asm/resctrl.h
@@ -181,6 +181,12 @@ static inline u32 resctrl_arch_rmid_idx_encode(u32 ignored, u32 rmid)
return rmid;
}

+static inline void resctrl_arch_set_mba_sc(bool enable) { }
+static inline bool resctrl_arch_rmid_valid(u32 closid, u32 rmid)
+{
+ return true;
+}
+
/* x86 can always read an rmid, nothing needs allocating */
struct rdt_resource;
static inline void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r,
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 5a67c8089615..bcd809083f18 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -216,12 +216,14 @@ static struct rmid_entry *resctrl_find_free_rmid(u32 closid)
* to be if it were used with this CLOSID.
* If the CLOSID is irrelevant on this architecture, the two
* index values are always the same on every entry and thus the
- * very first entry will be returned.
+ * very first entry will be returned. Skip the RMIDs the
+ * architecture does not allow.
*/
itr_idx = resctrl_arch_rmid_idx_encode(itr->closid, itr->rmid);
cmp_idx = resctrl_arch_rmid_idx_encode(closid, itr->rmid);

- if (itr_idx == cmp_idx)
+ if (itr_idx == cmp_idx &&
+ resctrl_arch_rmid_valid(closid, itr->rmid))
return itr;
}

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 9f10b6ceff8a..e186ae322f08 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -2640,16 +2640,20 @@ static int set_mba_sc(bool mba_sc)
{
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
struct rdt_resource *rmbm = resctrl_arch_get_resource(RDT_RESOURCE_L3);
- u32 num_closid = resctrl_arch_get_num_closid(r);
struct rdt_ctrl_domain *d;
unsigned long fflags;
- int i;

if (!supports_mba_mbps() || mba_sc == is_mba_sc(r))
return -EINVAL;

r->membw.mba_sc = mba_sc;

+ /*
+ * The architecture may cap the groups to what the controller can
+ * measure. Do it before the number of CLOSIDs is used below.
+ */
+ resctrl_arch_set_mba_sc(mba_sc);
+
/*
* The controller needs its event counted in every monitoring group:
* force automatic assignment on, and restore the user's setting when
@@ -2666,9 +2670,20 @@ static int set_mba_sc(bool mba_sc)

rdtgroup_default.mba_mbps_event = mba_mbps_default_event;

- list_for_each_entry_rcu(d, &r->ctrl_domains, hdr.list, lockdep_is_cpus_held()) {
- for (i = 0; i < num_closid; i++)
- d->mbps_val[i] = MBA_MAX_MBPS;
+ /*
+ * Reset the targets of the CLOSIDs the controller uses. Skip this
+ * when disabling: nothing reads the targets while the controller is
+ * off, and a domain that came online while it was enabled may have
+ * allocated mbps_val for the capped, smaller number of CLOSIDs.
+ */
+ if (mba_sc) {
+ u32 num_closid = resctrl_arch_get_num_closid(r);
+ int i;
+
+ list_for_each_entry_rcu(d, &r->ctrl_domains, hdr.list, lockdep_is_cpus_held()) {
+ for (i = 0; i < num_closid; i++)
+ d->mbps_val[i] = MBA_MAX_MBPS;
+ }
}

fflags = mba_sc ? RFTYPE_CTRL_BASE | RFTYPE_MON_BASE : 0;
diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h
index 002f56e15362..73a6277f688c 100644
--- a/include/linux/arm_mpam.h
+++ b/include/linux/arm_mpam.h
@@ -63,6 +63,14 @@ u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid);
void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid);
u32 resctrl_arch_system_num_rmid_idx(void);

+/* MPAM does not limit the RMIDs for the MBA software controller yet. */
+static inline void resctrl_arch_set_mba_sc(bool enable) { }
+
+static inline bool resctrl_arch_rmid_valid(u32 closid, u32 rmid)
+{
+ return true;
+}
+
struct rdt_resource;
void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, enum resctrl_event_id evtid);
void resctrl_arch_mon_ctx_free(struct rdt_resource *r, enum resctrl_event_id evtid, void *ctx);
--
2.34.1