From: Yunhui Cui <cuiyunhui@bytedance.com>
To: tony.luck@intel.com, reinette.chatre@intel.com,
ben.horgan@arm.com, Dave.Martin@arm.com, james.morse@arm.com,
babu.moger@amd.com, fustini@kernel.org, tglx@kernel.org,
mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
hpa@zytor.com, fenghuay@nvidia.com, shuah@kernel.org,
corbet@lwn.net, skhan@linuxfoundation.org, rdunlap@infradead.org,
x86@kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, linux-doc@vger.kernel.org
Cc: Yunhui Cui <cuiyunhui@bytedance.com>
Subject: [RFC PATCH 07/13] arm_mpam: Add request-to-internal PARTID mapping
Date: Mon, 30 Nov 2026 10:29:23 +0800 [thread overview]
Message-ID: <20261130022929.71748-8-cuiyunhui@bytedance.com> (raw)
In-Reply-To: <20261130022929.71748-1-cuiyunhui@bytedance.com>
PARTID narrowing separates the request PARTID carried by a request from
the internal PARTID containing its policy. A newly allocated internal
entry must be configured on every RIS in the MSC before requests are
mapped to it, otherwise requests may observe an uninitialized or partial
policy.
Add the mapping lifecycle for allocated internal PARTIDs. Publish the
request-to-internal mapping only after configuration succeeds, map the
request PARTID back to the root entry before releasing an entry, and
keep new allocations pending until all MSC updates complete so a failure
can undo mappings that were already published.
Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
---
drivers/resctrl/mpam_devices.c | 262 ++++++++++++++++++++++++++++++--
drivers/resctrl/mpam_internal.h | 10 ++
2 files changed, 261 insertions(+), 11 deletions(-)
diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index b4ee5a0354bfa..f2abb69914959 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -1838,31 +1838,43 @@ static u16 mpam_wa_t241_calc_min_from_max(struct mpam_props *props,
}
/* Called via IPI. Call while holding an SRCU reference */
-static int mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,
- struct mpam_config *cfg)
+static int __mpam_reprogram_ris_partid(struct mpam_msc_ris *ris,
+ u16 logical_partid,
+ struct mpam_config *cfg,
+ bool use_internal)
{
u16 cmax = MPAMCFG_CMAX_CMAX;
struct mpam_msc *msc = ris->vmsc->msc;
struct mpam_props *rprops = &ris->props;
+ u16 intpartid = logical_partid;
int ret;
guard(mutex)(&msc->part_sel_lock);
- ret = __mpam_part_sel(ris->ris_idx, partid, msc);
- if (ret)
- return ret;
+ if (use_internal) {
+ if (!test_bit(logical_partid, msc->partid_has_entry))
+ return -EINVAL;
+ intpartid = msc->partid_to_intpartid[logical_partid];
+ ret = __mpam_intpart_sel(ris->ris_idx, intpartid, msc);
+ if (ret)
+ return ret;
+ } else {
+ ret = __mpam_part_sel(ris->ris_idx, logical_partid, msc);
+ if (ret)
+ return ret;
+ }
- if (mpam_has_feature(mpam_feat_partid_nrw, rprops)) {
+ if (!use_internal && mpam_has_feature(mpam_feat_partid_nrw, rprops)) {
/* Update the intpartid mapping */
ret = mpam_write_partsel_reg(msc, INTPARTID,
- MPAMCFG_INTPARTID_INTERNAL | partid);
+ MPAMCFG_INTPARTID_INTERNAL | logical_partid);
if (ret)
return ret;
/*
- * Then switch to the 'internal' partid to update the
+ * Then switch to the 'internal' logical_partid to update the
* configuration.
*/
- ret = __mpam_intpart_sel(ris->ris_idx, partid, msc);
+ ret = __mpam_intpart_sel(ris->ris_idx, logical_partid, msc);
if (ret)
return ret;
}
@@ -1972,11 +1984,24 @@ static int mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,
return ret;
}
- mpam_quirk_post_config_change(ris, partid, cfg);
+ mpam_quirk_post_config_change(ris, intpartid, cfg);
return 0;
}
+static int mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,
+ struct mpam_config *cfg)
+{
+ return __mpam_reprogram_ris_partid(ris, partid, cfg, false);
+}
+
+static int mpam_reprogram_ris_mapped_partid(struct mpam_msc_ris *ris,
+ u16 logical_partid,
+ struct mpam_config *cfg)
+{
+ return __mpam_reprogram_ris_partid(ris, logical_partid, cfg, true);
+}
+
/* Call with msc cfg_lock held */
static int mpam_restore_mbwu_state(void *_ris)
{
@@ -2158,6 +2183,14 @@ static int __write_config(void *arg)
&c->comp->cfg[c->partid]);
}
+static int __write_internal_config(void *arg)
+{
+ struct mpam_write_config_arg *c = arg;
+
+ return mpam_reprogram_ris_mapped_partid(c->ris, c->partid,
+ &c->comp->cfg[c->partid]);
+}
+
static void mpam_reprogram_msc(struct mpam_msc *msc)
{
bool reset;
@@ -2958,6 +2991,7 @@ static void mpam_allocate_partid_entries(struct mpam_component *comp,
__set_bit(intpartid, msc->intpartid_allocated);
msc->partid_to_intpartid[logical_partid] = intpartid;
__set_bit(logical_partid, msc->partid_has_entry);
+ __set_bit(logical_partid, msc->partid_pending);
}
}
}
@@ -2980,6 +3014,205 @@ int mpam_prepare_partid_entries(struct mpam_component *comp,
return 0;
}
+struct mpam_partid_map_arg {
+ struct mpam_msc *msc;
+ u16 partid;
+ u16 intpartid;
+};
+
+static int __mpam_set_partid_map(void *_arg)
+{
+ struct mpam_partid_map_arg *arg = _arg;
+ struct mpam_msc *msc = arg->msc;
+ u32 partsel;
+ int ret;
+
+ guard(mutex)(&msc->part_sel_lock);
+
+ /* MPAMCFG_INTPARTID is selected by PARTID, but not by RIS. */
+ partsel = FIELD_PREP(MPAMCFG_PART_SEL_PARTID_SEL, arg->partid);
+ ret = __mpam_part_sel_raw(partsel, msc);
+ if (ret)
+ return ret;
+
+ return mpam_write_partsel_reg(msc, INTPARTID,
+ MPAMCFG_INTPARTID_INTERNAL | arg->intpartid);
+}
+
+static int mpam_set_msc_partid_map(struct mpam_msc *msc, u16 logical_partid,
+ u16 intpartid)
+{
+ struct mpam_partid_map_arg arg = {
+ .msc = msc,
+ .partid = logical_partid,
+ .intpartid = intpartid,
+ };
+
+ guard(mutex)(&msc->cfg_lock);
+
+ return mpam_touch_msc(msc, __mpam_set_partid_map, &arg);
+}
+
+static void mpam_copy_partid_config(struct mpam_config *dst,
+ const struct mpam_config *src)
+{
+ bitmap_copy(dst->features, src->features, MPAM_FEATURE_LAST);
+ dst->cpbm = src->cpbm;
+ dst->mbw_pbm = src->mbw_pbm;
+ dst->mbw_max = src->mbw_max;
+}
+
+static int mpam_configure_msc_partid(struct mpam_msc *msc, u16 logical_partid,
+ u16 root_partid)
+{
+ struct mpam_msc_ris *ris;
+ int ret;
+
+ guard(mutex)(&msc->cfg_lock);
+ list_for_each_entry_srcu(ris, &msc->ris, msc_list,
+ srcu_read_lock_held(&mpam_srcu)) {
+ struct mpam_component *comp = ris->vmsc->comp;
+ struct mpam_write_config_arg arg = {
+ .ris = ris,
+ .comp = comp,
+ .partid = logical_partid,
+ };
+
+ mpam_copy_partid_config(&comp->cfg[logical_partid], &comp->cfg[root_partid]);
+
+ ret = mpam_touch_msc(msc, __write_internal_config, &arg);
+ if (ret)
+ return ret;
+ ris->in_reset_state = false;
+ }
+
+ return 0;
+}
+
+int mpam_configure_pending_partid(struct mpam_component *comp,
+ u16 logical_partid, u16 root_partid)
+{
+ struct mpam_vmsc *vmsc;
+ int ret;
+
+ guard(mutex)(&partid_map_lock);
+ guard(srcu)(&mpam_srcu);
+
+ if (!comp->uses_partid_narrowing || !logical_partid)
+ return 0;
+ if (!__mpam_component_has_partid_entries(comp, logical_partid))
+ return -EINVAL;
+
+ list_for_each_entry_srcu(vmsc, &comp->vmsc, comp_list,
+ srcu_read_lock_held(&mpam_srcu)) {
+ struct mpam_msc *msc = vmsc->msc;
+
+ if (!test_bit(logical_partid, msc->partid_pending))
+ continue;
+ ret = mpam_configure_msc_partid(msc, logical_partid, root_partid);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+int mpam_commit_partid(struct mpam_component *comp, u16 logical_partid)
+{
+ struct mpam_vmsc *vmsc;
+ int ret;
+
+ guard(mutex)(&partid_map_lock);
+ guard(srcu)(&mpam_srcu);
+
+ if (!comp->uses_partid_narrowing || !logical_partid)
+ return 0;
+
+ list_for_each_entry_srcu(vmsc, &comp->vmsc, comp_list,
+ srcu_read_lock_held(&mpam_srcu)) {
+ struct mpam_msc *msc = vmsc->msc;
+ u16 intpartid;
+
+ if (!test_bit(logical_partid, msc->partid_pending))
+ continue;
+ intpartid = msc->partid_to_intpartid[logical_partid];
+ ret = mpam_set_msc_partid_map(msc, logical_partid, intpartid);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+void mpam_finish_partid(struct mpam_component *comp, u16 logical_partid)
+{
+ struct mpam_vmsc *vmsc;
+
+ guard(mutex)(&partid_map_lock);
+
+ if (!comp->uses_partid_narrowing || !logical_partid)
+ return;
+
+ list_for_each_entry(vmsc, &comp->vmsc, comp_list)
+ __clear_bit(logical_partid, vmsc->msc->partid_pending);
+}
+
+static int __mpam_unmap_partid(struct mpam_component *comp, u16 logical_partid,
+ u16 root_partid, bool pending_only)
+{
+ struct mpam_vmsc *vmsc;
+ int ret;
+
+ if (!comp->uses_partid_narrowing || !logical_partid)
+ return 0;
+
+ guard(mutex)(&partid_map_lock);
+ guard(srcu)(&mpam_srcu);
+
+ list_for_each_entry_srcu(vmsc, &comp->vmsc, comp_list,
+ srcu_read_lock_held(&mpam_srcu)) {
+ struct mpam_msc *msc = vmsc->msc;
+ u16 intpartid;
+
+ if (!test_bit(logical_partid, msc->partid_has_entry) ||
+ (pending_only && !test_bit(logical_partid, msc->partid_pending)))
+ continue;
+ intpartid = msc->partid_to_intpartid[root_partid];
+ ret = mpam_set_msc_partid_map(msc, logical_partid, intpartid);
+ if (ret)
+ return ret;
+ }
+
+ list_for_each_entry(vmsc, &comp->vmsc, comp_list) {
+ struct mpam_msc *msc = vmsc->msc;
+ u16 intpartid;
+
+ if (!test_bit(logical_partid, msc->partid_has_entry) ||
+ (pending_only && !test_bit(logical_partid, msc->partid_pending)))
+ continue;
+ intpartid = msc->partid_to_intpartid[logical_partid];
+ msc->partid_to_intpartid[logical_partid] =
+ msc->partid_to_intpartid[root_partid];
+ __clear_bit(logical_partid, msc->partid_pending);
+ __clear_bit(logical_partid, msc->partid_has_entry);
+ __clear_bit(intpartid, msc->intpartid_allocated);
+ }
+
+ return 0;
+}
+
+int mpam_abort_partid(struct mpam_component *comp, u16 logical_partid,
+ u16 root_partid)
+{
+ return __mpam_unmap_partid(comp, logical_partid, root_partid, true);
+}
+
+int mpam_release_partid(struct mpam_component *comp, u16 logical_partid,
+ u16 root_partid)
+{
+ return __mpam_unmap_partid(comp, logical_partid, root_partid, false);
+}
+
static bool mpam_component_shares_direct_msc(struct mpam_component *comp)
{
struct mpam_vmsc *vmsc;
@@ -3318,7 +3551,7 @@ static int mpam_alloc_msc_partid_state(struct mpam_msc *msc)
struct device *dev = &msc->pdev->dev;
size_t nr_partids = mpam_partid_max + 1;
unsigned long *intpartids, *entries;
-
+ unsigned long *pending;
u16 *map;
if (msc->partid_to_intpartid)
@@ -3334,14 +3567,21 @@ static int mpam_alloc_msc_partid_state(struct mpam_msc *msc)
if (!entries)
goto out_free_intpartids;
+ pending = devm_bitmap_zalloc(dev, nr_partids, GFP_KERNEL);
+ if (!pending)
+ goto out_free_entries;
+
__set_bit(0, intpartids);
__set_bit(0, entries);
msc->partid_to_intpartid = map;
msc->intpartid_allocated = intpartids;
msc->partid_has_entry = entries;
+ msc->partid_pending = pending;
return 0;
+out_free_entries:
+ devm_kfree(dev, entries);
out_free_intpartids:
devm_kfree(dev, intpartids);
out_free_map:
diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
index f45a129689301..6055cf52972a5 100644
--- a/drivers/resctrl/mpam_internal.h
+++ b/drivers/resctrl/mpam_internal.h
@@ -98,6 +98,8 @@ struct mpam_msc {
u16 *partid_to_intpartid;
unsigned long *intpartid_allocated;
unsigned long *partid_has_entry;
+ /* New reservations stay pending until the entire update finishes. */
+ unsigned long *partid_pending;
u8 pmg_max;
unsigned long ris_idxs;
u32 ris_max;
@@ -524,6 +526,14 @@ bool mpam_component_has_partid_entries(struct mpam_component *comp,
u16 logical_partid);
int mpam_prepare_partid_entries(struct mpam_component *comp,
const u16 *logical_partids, size_t nr_partids);
+int mpam_configure_pending_partid(struct mpam_component *comp,
+ u16 logical_partid, u16 root_partid);
+int mpam_commit_partid(struct mpam_component *comp, u16 logical_partid);
+void mpam_finish_partid(struct mpam_component *comp, u16 logical_partid);
+int mpam_abort_partid(struct mpam_component *comp, u16 logical_partid,
+ u16 root_partid);
+int mpam_release_partid(struct mpam_component *comp, u16 logical_partid,
+ u16 root_partid);
int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,
enum mpam_device_features, u64 *val);
--
2.39.2 (Apple Git-143)
next prev parent reply other threads:[~2026-11-30 2:31 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 2:29 [RFC PATCH 00/13] resctrl: Introduce a framework for logical control IDs Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 01/13] resctrl: Introduce interfaces " Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 02/13] resctrl: Add prepare, commit and abort hooks for control updates Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 03/13] resctrl: Add a release hook before logical control ID reuse Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 04/13] arm_mpam: Record PARTID narrowing capacity per MSC Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 05/13] arm_mpam: Select PARTID narrowing per component Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 06/13] arm_mpam: Add an internal PARTID allocator Yunhui Cui
2026-11-30 2:29 ` Yunhui Cui [this message]
2026-11-30 2:29 ` [RFC PATCH 08/13] arm_mpam: Apply PARTID narrowing to resctrl control groups Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 09/13] arm_mpam: Separate request and internal PARTID limits Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 10/13] arm_mpam: Map CDP data and code defaults separately Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 11/13] arm_mpam: Add kunit tests for PARTID narrowing Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 12/13] selftests/resctrl: Add a test for control ID allocation and reuse Yunhui Cui
2026-11-30 2:29 ` [RFC PATCH 13/13] docs/resctrl: Document logical control IDs and hardware entries Yunhui Cui
2026-11-30 6:15 ` [RFC PATCH 00/13] resctrl: Introduce a framework for logical control IDs Jinjie Ruan
2026-11-30 6:56 ` [External] " yunhui cui
2026-11-30 7:29 ` Jinjie Ruan
2026-11-30 11:22 ` Ben Horgan
2026-11-30 12:09 ` Jinjie Ruan
2026-11-30 14:09 ` [External] " yunhui cui
2026-11-30 15:22 ` Ben Horgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130022929.71748-8-cuiyunhui@bytedance.com \
--to=cuiyunhui@bytedance.com \
--cc=Dave.Martin@arm.com \
--cc=babu.moger@amd.com \
--cc=ben.horgan@arm.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=fenghuay@nvidia.com \
--cc=fustini@kernel.org \
--cc=hpa@zytor.com \
--cc=james.morse@arm.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mingo@redhat.com \
--cc=rdunlap@infradead.org \
--cc=reinette.chatre@intel.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tglx@kernel.org \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®