[PATCH v4 3/3] arm_mpam: resctrl: Limit num_rmids to the CLOSIDs in use
From: Jinjie Ruan
Date: Wed Nov 11 2026 - 03:17:58 EST
On MPAM an RMID is a PMG within a PARTID, so resctrl can only allocate
the PMGs of the CLOSIDs it uses. info/L3_MON/num_rmids is instead set
to the whole PARTID and PMG space when the monitors are initialised,
and halved when CDP is enabled. It reports more RMIDs than resctrl can
allocate in two cases:
- With CDP each CLOSID takes two PARTIDs, and resctrl halves the
CLOSID count rounding down, while MPAM halves the whole RMID space.
With 5 PARTIDs and 2 PMGs resctrl has 2 CLOSIDs and 4 RMIDs, but
num_rmids reads 5. The count is too high whenever the number of
PARTIDs is odd and there is more than one PMG.
- On a monitor-only system there are no control groups and resctrl
only uses the default CLOSID, but num_rmids still covers every
PARTID. With 5 PARTIDs and 2 PMGs it reads 10 while only 2 RMIDs
can be allocated.
RMID allocation is limited to the CLOSIDs in use, so only the value
reported to userspace is too high. Creating as many monitor groups as
num_rmids allows fails with -ENOSPC before that number is reached.
Count the CLOSIDs resctrl uses instead: every resource has
mpam_partid_max + 1 CLOSIDs, halved and rounded down while CDP is
enabled, and a system with no resource that can allocate uses only the
default CLOSID. Report (pmg_max + 1) RMIDs for each of those CLOSIDs.
Count at monitor initialisation and from resctrl_arch_set_cdp_enabled(),
which resctrl calls whenever a mount or unmount enables or disables
CDP.
Fixes: 264c285999fc ("arm_mpam: resctrl: Add monitor initialisation and domain boilerplate")
Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
Cc: <stable@xxxxxxxxxxxxxxx> # 7.1+
Cc: James Morse <james.morse@xxxxxxx>
Cc: Ben Horgan <ben.horgan@xxxxxxx>
Cc: Reinette Chatre <reinette.chatre@xxxxxxxxx>
Cc: Fenghua Yu <fenghuay@xxxxxxxxxx>
---
v4:
- Simplify the fix with mpam_partid_max, cdp_enabled
and resctrl_arch_alloc_capable() as Ben suggested.
v3:
- Drop resctrl_arch_set_mon_rmid_count() and count the CLOSIDs in the
MPAM driver instead, as Ben suggested.
- v2: https://lore.kernel.org/all/20261105123304.2281987-1-ruanjinjie@xxxxxxxxxx/
v2:
- Also fix num_rmids on monitor-only systems, as Ben suggested.
- Retitle from "arm_mpam: Round the CDP RMID count down to whole CLOSIDs".
- v1: https://lore.kernel.org/all/20261104101622.563280-1-ruanjinjie@xxxxxxxxxx/
---
drivers/resctrl/mpam_resctrl.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index afa3c084c475..fcd41ddffc74 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -200,6 +200,21 @@ static void mpam_resctrl_monitor_sync_abmc_vals(struct rdt_resource *l3)
*/
}
+/* The RMID count follows the CLOSIDs resctrl uses. */
+static void mpam_resctrl_set_num_rmid(void)
+{
+ struct rdt_resource *l3 = &mpam_resctrl_controls[RDT_RESOURCE_L3].resctrl_res;
+ u32 num_closid = 1;
+
+ if (resctrl_arch_alloc_capable()) {
+ num_closid = mpam_partid_max + 1;
+ if (cdp_enabled)
+ num_closid /= 2;
+ }
+
+ l3->mon.num_rmid = (mpam_pmg_max + 1) * num_closid;
+}
+
int resctrl_arch_set_cdp_enabled(enum resctrl_res_level rid, bool enable)
{
u32 partid_i = RESCTRL_RESERVED_CLOSID, partid_d = RESCTRL_RESERVED_CLOSID;
@@ -233,10 +248,7 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level rid, bool enable)
cdp_enabled = enable;
mpam_resctrl_controls[rid].cdp_enabled = enable;
- if (enable)
- l3->mon.num_rmid = resctrl_arch_system_num_rmid_idx() / 2;
- else
- l3->mon.num_rmid = resctrl_arch_system_num_rmid_idx();
+ mpam_resctrl_set_num_rmid();
/* The mbw_max feature can't hide cdp as it's a per-partid maximum. */
if (cdp_enabled && !mpam_resctrl_controls[RDT_RESOURCE_MBA].cdp_enabled)
@@ -1357,15 +1369,7 @@ static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
l3->name = "L3";
l3->mon_scope = RESCTRL_L3_CACHE;
- /*
- * num-rmid is the upper bound for the number of monitoring groups that
- * can exist simultaneously, including the default monitoring group for
- * each control group. Hence, advertise the whole rmid_idx space even
- * though each control group has its own pmg/rmid space. Unfortunately,
- * this does mean userspace needs to know the architecture to correctly
- * interpret this value.
- */
- l3->mon.num_rmid = resctrl_arch_system_num_rmid_idx();
+ mpam_resctrl_set_num_rmid();
if (type == QOS_L3_MBM_TOTAL_EVENT_ID) {
int err;
--
2.34.1