[PATCH 11/12] fs/resctrl: Allow mba_MBps with assignable MBM counters

From: Jinjie Ruan

Date: Sun Nov 29 2026 - 22:25:54 EST


The controller needs a counter for the event selected by mba_MBps_event
in every monitoring group, so mba_MBps is refused when MBM counters are
assignable. On MPAM the counters are always assignable, so mba_MBps
cannot be used.

Allow the controller when the counter assignment mode can be switched:
mounting then switches to the default assignment mode, where the
architecture gives every monitoring group a counter, and restores the
mode the user selected when resctrl is unmounted. set_mba_sc() switches
the mode before the number of CLOSIDs is read, 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.

The mode cannot be switched back to "mbm_event" while the controller is
enabled, as the groups it measures would lose their counters.

The assignment interfaces are only usable in the "mbm_event" mode,
which the mount leaves, so there is no need to force automatic
assignment on or to keep the controller's counter assigned. The files
that manage the counters are still present, as they are when mbm_event
mode is off, and fail with -EINVAL and an explanation in
last_cmd_status. Document the mount option, and the lower num_closids
and num_rmids until resctrl is unmounted.

On x86 nothing changes: the only systems with assignable counters
refuse the controller, as their MBA is not linear.

Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
Documentation/filesystems/resctrl.rst | 9 ++++-
fs/resctrl/monitor.c | 9 +++++
fs/resctrl/rdtgroup.c | 52 +++++++++++++++++++++------
3 files changed, 59 insertions(+), 11 deletions(-)

diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst
index 5bec3d2197ac..8b1523b2e1de 100644
--- a/Documentation/filesystems/resctrl.rst
+++ b/Documentation/filesystems/resctrl.rst
@@ -47,7 +47,12 @@ mount options are:
Enable code/data prioritization in L2 cache allocations.
"mba_MBps":
Enable the MBA Software Controller(mba_sc) to specify MBA
- bandwidth in MiBps
+ bandwidth in MiBps. On architectures that assign MBM counters to
+ monitoring groups the default counter assignment mode is used
+ while the controller is enabled. The number of CLOSIDs and of
+ RMIDs may then be limited to the number of counters, and
+ "num_closids" and "num_rmids" report the limited numbers until
+ resctrl is unmounted, when the mode the user selected is restored.
"debug":
Make debug files accessible. Available debug files are annotated with
"Available only with debug option".
@@ -391,6 +396,8 @@ with the following files:
limited to the number of counters: "num_rmids" reports the limited
number, "num_closids" keeps the value from the mount, and monitoring
groups beyond them cannot be read until the mode is switched back.
+ While the MBA software controller is enabled the mode cannot be
+ switched back, as the controller measures every monitoring group.

* To enable "mbm_event" counter assignment mode:
::
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 8ca9477ed825..7edd5458f1aa 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -1588,6 +1588,13 @@ int resctrl_mbm_assign_mode_set(struct rdt_resource *r, bool enable)
struct rdt_l3_mon_domain *d;
int ret;

+ /*
+ * The MBA software controller measures every group, which would
+ * lose its counter.
+ */
+ if (enable && resctrl_arch_get_resource(RDT_RESOURCE_MBA)->membw.mba_sc)
+ return -EBUSY;
+
if (enable == resctrl_arch_mbm_cntr_assign_enabled(r))
return 0;

@@ -1665,6 +1672,8 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf,
}

ret = resctrl_mbm_assign_mode_set(r, enable);
+ if (ret == -EBUSY)
+ rdt_last_cmd_puts("mbm_assign_mode: mba_MBps needs the default mode\n");
if (ret)
goto out_unlock;

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index ac674f830c58..2d7237ba2bfb 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -2610,10 +2610,10 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
* The MBA software controller is supported only if MBM is supported and MBA is
* in linear scale, and the MBM monitor scope is the same as MBA control scope.
*
- * The software controller cannot be supported when the MBM counters are
- * assignable. There is no guarantee that MBM counters are assigned to the
- * event backing the software controller in all monitoring domains of all
- * monitoring groups.
+ * The controller measures every monitoring group, so every group needs
+ * a counter for the event selected by mba_MBps_event. Counters that
+ * are not assignable always provide one, and mounting switches
+ * assignable counters to the default mode, which has to be switchable.
*
* The maximum control must also be a hard limit, see max_is_soft_limit.
*/
@@ -2626,36 +2626,68 @@ static bool supports_mba_mbps(void)
r->alloc_capable && is_mba_linear() &&
r->ctrl_scope == rmbm->mon_scope &&
!r->membw.max_is_soft_limit &&
- !rmbm->mon.mbm_cntr_assignable);
+ (!rmbm->mon.mbm_cntr_assignable ||
+ !rmbm->mon.mbm_cntr_assign_fixed));
}

+/*
+ * Set while the MBA software controller is enabled and its mount switched
+ * the counter assignment mode, which is restored when it is disabled.
+ */
+static bool mba_sc_switched_mode;
+
/*
* Enable or disable the MBA software controller
* which helps user specify bandwidth in MBps.
*/
static int set_mba_sc(bool mba_sc)
{
+ struct rdt_resource *rmbm = resctrl_arch_get_resource(RDT_RESOURCE_L3);
struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
- u32 num_closid = resctrl_arch_get_num_closid(r);
struct rdt_ctrl_domain *d;
unsigned long fflags;
- int i;
+ int i, ret;

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

+ if (mba_sc) {
+ /*
+ * The controller measures every monitoring group, so every
+ * group needs a counter. Switch before the number of CLOSIDs
+ * is read below, as the switch caps it.
+ */
+ mba_sc_switched_mode = resctrl_arch_mbm_cntr_assign_enabled(rmbm);
+ ret = resctrl_mbm_assign_mode_set(rmbm, false);
+ if (ret) {
+ mba_sc_switched_mode = false;
+ rdt_last_cmd_puts("mba_MBps: cannot switch the assignment mode\n");
+ return ret;
+ }
+ }
+
r->membw.mba_sc = 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;
+ if (mba_sc) {
+ u32 num_closid = resctrl_arch_get_num_closid(r);
+
+ 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;
resctrl_file_fflags_init("mba_MBps_event", fflags);

+ if (!mba_sc && mba_sc_switched_mode) {
+ mba_sc_switched_mode = false;
+ if (resctrl_mbm_assign_mode_set(rmbm, true))
+ pr_warn("Failed to restore the counter assignment mode\n");
+ }
+
return 0;
}

--
2.34.1