[PATCH 09/12] arm_mpam: Program the hard limit for the software controller
From: Jinjie Ruan
Date: Sun Nov 29 2026 - 22:25:29 EST
MPAM's maximum bandwidth control has a HARDLIM bit:
- when set, a PARTID that uses more than its maximum gets no
further bandwidth
- when clear, requests above the maximum are serviced when no other
request is waiting.
The driver writes only the 16-bit maximum, so the control is a soft
limit and the controller cannot keep a single requester below its target.
Carry the hard limit in mpam_config and set it when the controller is
enabled. MPAMF_MBW_IDR.MAX_LIM reports the implemented behaviors: 00
both, 01 soft only, 10 hard only. HARDLIM is RAZ/WI with 01 and RAO/WI
with 10, so writing it is harmless on a device that implements one
limit, and the percentage interface there behaves as that limit.
Record in mpam_props only whether the hard limit is implemented, and
set resctrl_membw::max_is_soft_limit when it is not, so that mba_MBps
is refused. The reserved value 0b11 counts as not implemented. Merging
resources into a class keeps the hard limit only if every resource has
it.
The percentage interface never sets the hard limit, and resctrl clears
a limit set by the controller when it resets the controls on unmount.
Write the bit from the controller state on every write, so that a hard
limit left by an interrupted reset is cleared.
Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
drivers/resctrl/mpam_devices.c | 48 +++++++++++++++++++++++++--------
drivers/resctrl/mpam_internal.h | 4 +++
drivers/resctrl/mpam_resctrl.c | 3 +++
3 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 24f9cb45766a..1c58c7b6c920 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -1025,8 +1025,20 @@ static int mpam_ris_hw_probe(struct mpam_msc_ris *ris)
*/
props->bwa_wd = min(props->bwa_wd, 16);
- if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MAX, mbw_features))
+ if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MAX, mbw_features)) {
+ /*
+ * MAX_LIM: 0b00 both limits, 0b01 the soft limit
+ * only, 0b10 the hard limit only. 0b11 is reserved
+ * and is treated as having no hard limit, so that
+ * the software controller is refused rather than
+ * rely on an unknown behavior.
+ */
+ u32 max_lim = FIELD_GET(MPAMF_MBW_IDR_MAX_LIM, mbw_features);
+
+ props->has_hardlim = max_lim == 0 || max_lim == 2;
mpam_set_feature(mpam_feat_mbw_max, props);
+ mpam_set_feature(mpam_feat_max_limit, props);
+ }
if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MIN, mbw_features))
mpam_set_feature(mpam_feat_mbw_min, props);
@@ -1911,16 +1923,21 @@ static int mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,
}
if (mpam_has_feature(mpam_feat_mbw_max, rprops)) {
- if (mpam_has_feature(mpam_feat_mbw_max, cfg)) {
- ret = mpam_write_partsel_reg(msc, MBW_MAX, cfg->mbw_max);
- if (ret)
- return ret;
- } else {
- ret = mpam_write_partsel_reg(msc, MBW_MAX,
- MPAMCFG_MBW_MAX_MAX);
- if (ret)
- return ret;
- }
+ u32 val = MPAMCFG_MBW_MAX_MAX;
+
+ if (mpam_has_feature(mpam_feat_mbw_max, cfg))
+ val = cfg->mbw_max;
+
+ /*
+ * The hard-limit bit follows its own feature bit so that it
+ * can be set without changing the maximum.
+ */
+ if (mpam_has_feature(mpam_feat_max_limit, cfg) && cfg->max_limit)
+ val |= MPAMCFG_MBW_MAX_HARDLIM;
+
+ ret = mpam_write_partsel_reg(msc, MBW_MAX, val);
+ if (ret)
+ return ret;
}
if (mpam_has_feature(mpam_feat_mbw_prop, rprops)) {
@@ -2661,6 +2678,14 @@ static void __props_mismatch(struct mpam_props *parent,
parent->bwa_wd = min(parent->bwa_wd, child->bwa_wd);
}
+ if (CAN_MERGE_FEAT(parent, child, mpam_feat_mbw_max, alias))
+ parent->has_hardlim = child->has_hardlim;
+ else if (mpam_has_feature(mpam_feat_mbw_max, parent) &&
+ mpam_has_feature(mpam_feat_mbw_max, child))
+ parent->has_hardlim &= child->has_hardlim;
+ else if (mpam_has_feature(mpam_feat_mbw_max, parent) && !alias)
+ parent->has_hardlim = false;
+
if (alias && !mpam_has_cmax_wd_feature(parent) && mpam_has_cmax_wd_feature(child)) {
parent->cmax_wd = child->cmax_wd;
} else if (MISMATCHED_HELPER(parent, child, mpam_has_cmax_wd_feature,
@@ -3408,6 +3433,7 @@ static bool mpam_update_config(struct mpam_config *cfg,
maybe_update_config(cfg, mpam_feat_cpor_part, newcfg, cpbm, has_changes);
maybe_update_config(cfg, mpam_feat_mbw_part, newcfg, mbw_pbm, has_changes);
maybe_update_config(cfg, mpam_feat_mbw_max, newcfg, mbw_max, has_changes);
+ maybe_update_config(cfg, mpam_feat_max_limit, newcfg, max_limit, has_changes);
return has_changes;
}
diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
index 1f86cc158100..bf597b7e2129 100644
--- a/drivers/resctrl/mpam_internal.h
+++ b/drivers/resctrl/mpam_internal.h
@@ -234,6 +234,7 @@ enum mpam_device_features {
mpam_feat_msmon_mbwu_capture,
mpam_feat_msmon_mbwu_rwbw,
mpam_feat_partid_nrw,
+ mpam_feat_max_limit,
MPAM_FEATURE_LAST
};
@@ -243,6 +244,7 @@ struct mpam_props {
u16 cpbm_wd;
u16 mbw_pbm_bits;
u16 bwa_wd;
+ bool has_hardlim;
u16 cmax_wd;
u16 cassoc_wd;
u16 intpri_wd;
@@ -364,6 +366,7 @@ struct mpam_config {
u32 cpbm;
u32 mbw_pbm;
u16 mbw_max;
+ bool max_limit;
struct mpam_garbage garbage;
};
@@ -628,6 +631,7 @@ int mpam_fb_check_shared_buffer_size(struct mpam_msc *msc);
/* MPAMF_MBW_IDR - MPAM features memory bandwidth partitioning ID register */
#define MPAMF_MBW_IDR_BWA_WD GENMASK(5, 0)
+#define MPAMF_MBW_IDR_MAX_LIM GENMASK(9, 8)
#define MPAMF_MBW_IDR_HAS_MIN BIT(10)
#define MPAMF_MBW_IDR_HAS_MAX BIT(11)
#define MPAMF_MBW_IDR_HAS_PBM BIT(12)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 3ae3e9253a02..9653b3f8641d 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -1429,6 +1429,7 @@ static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
r->ctrl_scope = RESCTRL_L3_CACHE;
r->membw.delay_linear = true;
+ r->membw.max_is_soft_limit = !cprops->has_hardlim;
r->membw.throttle_mode = THREAD_THROTTLE_UNDEFINED;
r->membw.min_bw = get_mba_min(cprops);
r->membw.max_bw = MAX_MBA_BW;
@@ -1679,6 +1680,8 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
if (mpam_has_feature(mpam_feat_mbw_max, cprops)) {
cfg.mbw_max = percent_to_mbw_max(cfg_val, cprops);
mpam_set_feature(mpam_feat_mbw_max, &cfg);
+ mpam_set_feature(mpam_feat_max_limit, &cfg);
+ cfg.max_limit = r->membw.mba_sc;
break;
}
fallthrough;
--
2.34.1