From nobody Thu Jun 11 17:32:14 2026 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24AD73AB29F for ; Mon, 13 Apr 2026 08:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070462; cv=none; b=hpOKVTn0+35Yf6GWPq2Wzca/h5/0AUKoJYKIHyL28uVNnjxj4G16fTnLtoiMBBy0Ntj/km80wY/GhRMVlkH9qDeV2zi/OXn2IdpPa1dRx/J6nRj2tpBESIjdiLmPgDgzPrl6YfZGFkBzhVjeQU8DYBbQY3Fi/ogHRX9U9fmu8L8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070462; c=relaxed/simple; bh=ALgp9yvWFp+sfN+yE12xdxympmH8U5QnCYiwDK1fHIg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=okRMYYycuLlZgdCaryJkg0FUDmv4xXRYtHfa3tS75pZ/IsmS2E0krczJ1gipvRFCObZW0xs3u9sZl6DXAjijRp7wWRHMXs3dIgjUySjQyFEzuqPKhmgwgcBUVoA4PwXvevrEjaPi1mZjsflS3WoPZn+3sHuuW3Kmv58oNba1Z9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=G2FLyrGr; arc=none smtp.client-ip=113.46.200.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="G2FLyrGr" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=op08HCqJ4u4oJC1zLRF5Zh2ZqxSUZczSTa3QNhH8QVA=; b=G2FLyrGrPKf+8n2pI2yjcDLwbWNb6INdPxOhRr6yWLH71z2EQondVn7PF1bd6al4gjqmGE/E4 Cef/wBNiNoPrycoMuwQn9j8JES9tGwR1GzorG8WFLDb9KC0wtLKW3AYw0BLg3EhsgCadNf9AJpp 2SyrGg5C9yO+/ySKohZ2ePY= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4fvLdm54zxz1prNH; Mon, 13 Apr 2026 16:47:56 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id 97BDD40561; Mon, 13 Apr 2026 16:54:16 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:15 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 01/10] fs/resctrl: Fix MPAM Partid parsing errors by preserving CDP state during umount Date: Mon, 13 Apr 2026 16:53:56 +0800 Message-ID: <20260413085405.1166412-2-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) Content-Type: text/plain; charset="utf-8" This patch fixes a pre-existing issue in the resctrl filesystem teardown sequence where premature clearing of cdp_enabled could lead to MPAM Partid parsing errors. The closid to partid conversion logic inherently depends on the global cdp_enabled state. However, rdt_disable_ctx() clears this flag early in the umount path, while free_rmid() operations will reference after that. This creates a window where partid parsing operates with inconsistent CDP state, potentially makes monitor reads with wrong partid mapping. Additionally, rmid_entry remaining in limbo between mount sessions may trigger potential partid out-of-range errors, leading to MPAM fault interrupts and subsequent MPAM disablement. Reorder rdt_kill_sb() to delay rdt_disable_ctx() until after rmdir_all_sub() and resctrl_fs_teardown() complete. This ensures all rmid-related operations finish with correct CDP state. Introduce rdt_flush_limbo() to flush and cancel limbo work before the filesystem teardown completes. An alternative approach would be to cancel limbo work on umount and restart it on remount with remaked bitmap. However, this would require substantial changes in the resctrl layer to handle CDP state transitions across mount sessions, which is beyond the scope of the reqpartid feature work this patchset focuses on. The current fix addresses the immediate correctness issue with minimal churn. Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- fs/resctrl/rdtgroup.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5dfdaa6f9d8f..69966589713f 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -3169,6 +3169,25 @@ static void resctrl_fs_teardown(void) rdtgroup_destroy_root(); } =20 +static void rdt_flush_limbo(void) +{ + struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); + struct rdt_l3_mon_domain *d; + + if (!IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) + return; + + if (!resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) + return; + + list_for_each_entry(d, &r->mon_domains, hdr.list) { + if (has_busy_rmid(d)) { + __check_limbo(d, true); + cancel_delayed_work(&d->cqm_limbo); + } + } +} + static void rdt_kill_sb(struct super_block *sb) { struct rdt_resource *r; @@ -3176,13 +3195,14 @@ static void rdt_kill_sb(struct super_block *sb) cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 - rdt_disable_ctx(); - /* Put everything back to default values. */ for_each_alloc_capable_rdt_resource(r) resctrl_arch_reset_all_ctrls(r); =20 resctrl_fs_teardown(); + rdt_flush_limbo(); + rdt_disable_ctx(); + if (resctrl_arch_alloc_capable()) resctrl_arch_disable_alloc(); if (resctrl_arch_mon_capable()) --=20 2.25.1 From nobody Thu Jun 11 17:32:14 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B6F23B0AFE for ; Mon, 13 Apr 2026 08:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070469; cv=none; b=oGYKND4jD1fiacv3UGb0NGl70Fkr617/u+ennqFq242L1ByWTWYAVYq3h57Y87Qs8PlUIxQxaO4Y+RBeWQCk5ukIwKVdx3lAzX7s19j6QRW/lcLRwZxjjM0ofrhZtAccUnJYb1B5uuktGt3nGkJ1DbGs9CgVRl86umTNnV0oIq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070469; c=relaxed/simple; bh=VIqRhwDvI2IEG6BRv/kV/DKLDLNx68wPL+rMd5VDMoM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fZMeZ6L8OIgdXzEFEUfG0yZvclmcVzSUAmPEbyNqfyh0+5o1ghnD93e3i1V9FeEtrrZND4mYtKKexqGXHqLpgv5MNRgNap10b6dqTMHIJ17FIgDpOpT3jOju0tvMtwTkilZ0L8jYYAbFMYrMnmSsHxVS+koxfqKgViTq8o5/ysQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=jc4kTF6m; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=jc4kTF6m; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="jc4kTF6m"; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="jc4kTF6m" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=fKZBhbLqvomHQwozvNv6OmQiXZDyI1OApDbhLlPdwx0=; b=jc4kTF6mGt4rwB0E/oP4iBAxB+QRyj9LyMQ+W+3A5TTv09JX4TLfg+SqAxuDrWTizcv1fTDAl xyj733V8XDw9v7JLbu7uiymKgF4Qv+HNhRsgxb7oAvoZd52JFnOEvapIJVEmPoQcv1Izc9iu2hq mqUs378DQkM3mddqMBTu3vA= Received: from canpmsgout03.his.huawei.com (unknown [172.19.92.159]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4fvLmW3rYWz1BG3K for ; Mon, 13 Apr 2026 16:53:47 +0800 (CST) dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=fKZBhbLqvomHQwozvNv6OmQiXZDyI1OApDbhLlPdwx0=; b=jc4kTF6mGt4rwB0E/oP4iBAxB+QRyj9LyMQ+W+3A5TTv09JX4TLfg+SqAxuDrWTizcv1fTDAl xyj733V8XDw9v7JLbu7uiymKgF4Qv+HNhRsgxb7oAvoZd52JFnOEvapIJVEmPoQcv1Izc9iu2hq mqUs378DQkM3mddqMBTu3vA= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4fvLf00vlgzpStx; Mon, 13 Apr 2026 16:48:08 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id 133B64048F; Mon, 13 Apr 2026 16:54:17 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:16 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 02/10] arm_mpam: Add intPARTID and reqPARTID support for Narrow-PARTID feature Date: Mon, 13 Apr 2026 16:53:57 +0800 Message-ID: <20260413085405.1166412-3-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) Content-Type: text/plain; charset="utf-8" Introduce Narrow-PARTID (partid_nrw) feature support, which enables many-to-one mapping of request PARTIDs (reqPARTID) to internal PARTIDs (intPARTID). This expands monitoring capability by allowing a single control group to track more task types through multiple reqPARTIDs per intPARTID, bypassing the PMG limit in some extent. intPARTID: Internal PARTID used for control group configuration. Configurations are synchronized to all reqPARTIDs mapped to the same intPARTID. Count is indicated by MPAMF_PARTID_NRW_IDR.INTPARTID_MAX, or defaults to PARTID count if Narrow-PARTID is unsupported. reqPARTID: Request PARTID used to expand monitoring groups. Enables a single control group to monitor more task types by multiple reqPARTIDs within one intPARTID, overcoming the PMG count limitation. For systems with homogeneous MSCs (all supporting Narrow-PARTID), the driver exposes the full reqPARTID range directly. For heterogeneous systems where some MSCs lack Narrow-PARTID support, the driver utilizes PARTIDs beyond the intPARTID range as reqPARTIDs to expand monitoring capacity. So, the numbers of control group and monitoring group are calculated as: n =3D min(intPARTID, PARTID) /* the number of control groups */ l =3D min(reqPARTID, PARTID) /* the number of monitoring groups */ m =3D l // n /* monitoring groups per control group */ Where: intPARTID: intPARTIDs on Narrow-PARTID-capable MSCs reqPARTID: reqPARTIDs on Narrow-PARTID-capable MSCs PARTID: PARTIDs on non-Narrow-PARTID-capable MSCs Example: L3 cache (256 PARTIDs, without Narrow-PARTID feature) + MATA (32 intPARTIDs, 256 reqPARTIDs): n =3D min( 32, 256) =3D 32 intPARTIDs l =3D min(256, 256) =3D 256 reqPARTIDs m =3D 256 / 32 =3D 8 reqPARTIDs per intPARTID Implementation notes: * Handle mixed MSC systems (some support Narrow-PARTID, some don't) by taking minimum number of intPARTIDs across all MSCs. * resctrl_arch_get_num_closid() now returns the number of intPARTIDs (was PARTID). Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- drivers/resctrl/mpam_devices.c | 30 ++++++++++++++++++++---------- drivers/resctrl/mpam_internal.h | 2 ++ drivers/resctrl/mpam_resctrl.c | 4 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c index 41b14344b16f..cf067bf5092e 100644 --- a/drivers/resctrl/mpam_devices.c +++ b/drivers/resctrl/mpam_devices.c @@ -63,6 +63,7 @@ static DEFINE_MUTEX(mpam_cpuhp_state_lock); * Generating traffic outside this range will result in screaming interrup= ts. */ u16 mpam_partid_max; +u16 mpam_intpartid_max; u8 mpam_pmg_max; static bool partid_max_init, partid_max_published; static DEFINE_SPINLOCK(partid_max_lock); @@ -288,10 +289,12 @@ int mpam_register_requestor(u16 partid_max, u8 pmg_ma= x) { guard(spinlock)(&partid_max_lock); if (!partid_max_init) { + mpam_intpartid_max =3D partid_max; mpam_partid_max =3D partid_max; mpam_pmg_max =3D pmg_max; partid_max_init =3D true; } else if (!partid_max_published) { + mpam_intpartid_max =3D min(mpam_intpartid_max, partid_max); mpam_partid_max =3D min(mpam_partid_max, partid_max); mpam_pmg_max =3D min(mpam_pmg_max, pmg_max); } else { @@ -931,7 +934,9 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) u16 partid_max =3D FIELD_GET(MPAMF_PARTID_NRW_IDR_INTPARTID_MAX, nrwidr); =20 mpam_set_feature(mpam_feat_partid_nrw, props); - msc->partid_max =3D min(msc->partid_max, partid_max); + msc->intpartid_max =3D min(msc->partid_max, partid_max); + } else { + msc->intpartid_max =3D msc->partid_max; } } =20 @@ -995,6 +1000,7 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc) =20 spin_lock(&partid_max_lock); mpam_partid_max =3D min(mpam_partid_max, msc->partid_max); + mpam_intpartid_max =3D min(mpam_intpartid_max, msc->intpartid_max); mpam_pmg_max =3D min(mpam_pmg_max, msc->pmg_max); spin_unlock(&partid_max_lock); =20 @@ -1711,7 +1717,7 @@ static int mpam_reset_ris(void *arg) return 0; =20 spin_lock(&partid_max_lock); - partid_max =3D mpam_partid_max; + partid_max =3D mpam_intpartid_max; spin_unlock(&partid_max_lock); for (partid =3D 0; partid <=3D partid_max; partid++) mpam_reprogram_ris_partid(ris, partid, &reset_cfg); @@ -1767,7 +1773,7 @@ static void mpam_reprogram_msc(struct mpam_msc *msc) struct mpam_write_config_arg arg; =20 /* - * No lock for mpam_partid_max as partid_max_published has been + * No lock for mpam_intpartid_max as partid_max_published has been * set by mpam_enabled(), so the values can no longer change. */ mpam_assert_partid_sizes_fixed(); @@ -1784,7 +1790,7 @@ static void mpam_reprogram_msc(struct mpam_msc *msc) arg.comp =3D ris->vmsc->comp; arg.ris =3D ris; reset =3D true; - for (partid =3D 0; partid <=3D mpam_partid_max; partid++) { + for (partid =3D 0; partid <=3D mpam_intpartid_max; partid++) { cfg =3D &ris->vmsc->comp->cfg[partid]; if (!bitmap_empty(cfg->features, MPAM_FEATURE_LAST)) reset =3D false; @@ -2607,7 +2613,7 @@ static void mpam_reset_component_cfg(struct mpam_comp= onent *comp) if (!comp->cfg) return; =20 - for (i =3D 0; i <=3D mpam_partid_max; i++) { + for (i =3D 0; i <=3D mpam_intpartid_max; i++) { comp->cfg[i] =3D (struct mpam_config) {}; if (cprops->cpbm_wd) comp->cfg[i].cpbm =3D GENMASK(cprops->cpbm_wd - 1, 0); @@ -2627,7 +2633,7 @@ static int __allocate_component_cfg(struct mpam_compo= nent *comp) if (comp->cfg) return 0; =20 - comp->cfg =3D kzalloc_objs(*comp->cfg, mpam_partid_max + 1); + comp->cfg =3D kzalloc_objs(*comp->cfg, mpam_intpartid_max + 1); if (!comp->cfg) return -ENOMEM; =20 @@ -2694,7 +2700,7 @@ static void mpam_enable_once(void) int err; =20 /* - * Once the cpuhp callbacks have been changed, mpam_partid_max can no + * Once the cpuhp callbacks have been changed, mpam_intpartid_max can no * longer change. */ spin_lock(&partid_max_lock); @@ -2743,9 +2749,13 @@ static void mpam_enable_once(void) mpam_register_cpuhp_callbacks(mpam_cpu_online, mpam_cpu_offline, "mpam:online"); =20 - /* Use printk() to avoid the pr_fmt adding the function name. */ - printk(KERN_INFO "MPAM enabled with %u PARTIDs and %u PMGs\n", - mpam_partid_max + 1, mpam_pmg_max + 1); + if (mpam_partid_max =3D=3D mpam_intpartid_max) + /* Use printk() to avoid the pr_fmt adding the function name. */ + printk(KERN_INFO "MPAM enabled with %u PARTIDs and %u PMGs\n", + mpam_partid_max + 1, mpam_pmg_max + 1); + else + printk(KERN_INFO "MPAM enabled with %u reqPARTIDs, %u intPARTIDs and %u = PMGs\n", + mpam_partid_max + 1, mpam_intpartid_max + 1, mpam_pmg_max + 1); } =20 static void mpam_reset_component_locked(struct mpam_component *comp) diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_interna= l.h index 1914aefdcba9..790a90a5ccd9 100644 --- a/drivers/resctrl/mpam_internal.h +++ b/drivers/resctrl/mpam_internal.h @@ -81,6 +81,7 @@ struct mpam_msc { */ struct mutex probe_lock; bool probed; + u16 intpartid_max; u16 partid_max; u8 pmg_max; unsigned long ris_idxs; @@ -452,6 +453,7 @@ extern struct list_head mpam_classes; =20 /* System wide partid/pmg values */ extern u16 mpam_partid_max; +extern u16 mpam_intpartid_max; extern u8 mpam_pmg_max; =20 /* Scheduled work callback to enable mpam once all MSC have been probed */ diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 161fb8905e28..5f4364c8101a 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -223,7 +223,7 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level= rid, bool enable) mpam_resctrl_controls[RDT_RESOURCE_MBA].resctrl_res.alloc_capable =3D fa= lse; =20 if (enable) { - if (mpam_partid_max < 1) + if (mpam_intpartid_max < 1) return -EINVAL; =20 partid_d =3D resctrl_get_config_index(RESCTRL_RESERVED_CLOSID, CDP_DATA); @@ -254,7 +254,7 @@ static bool mpam_resctrl_hide_cdp(enum resctrl_res_leve= l rid) */ u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored) { - return mpam_partid_max + 1; + return mpam_intpartid_max + 1; } =20 u32 resctrl_arch_system_num_rmid_idx(void) --=20 2.25.1 From nobody Thu Jun 11 17:32:14 2026 Received: from canpmsgout11.his.huawei.com (canpmsgout11.his.huawei.com [113.46.200.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5FE93AEF5F for ; Mon, 13 Apr 2026 08:54:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070467; cv=none; b=X7iYkjSwm2TJVGMjFcXsskkoIDAC5ue6hhdLew4fquU0AOda5euiUQReDF8mI9rOPHMybynxAQW6QlNKRFoH7xdu/AK36Ux7tP5xHDDaE+cvK84P/3RWzsUiIApk1TcYIDvt2zLmAB5s73Rbyjf/vAfYZ/0KFT71Yzck8GFEoEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070467; c=relaxed/simple; bh=35plxa4VsVAUrApz4/Z6C7UzTGEnIEJrsQ1aVILgi0Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rXfGCjYRg6bKkt3IZcAxgslvFOJIQdS0z0WkxhD/c9WFJGlFPqz3meWh3cOjn/JDYMihcXjiGmz7UiQ7oubZYwebEhTkcZyyV3El/2n+sTcjoyqYvyeuNSUpzETw+ud2e+tVwgqNb2Lcl0LOYlInnKvMh8xG4Fu6vElbC2Ct9PI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=p10X20Nx; arc=none smtp.client-ip=113.46.200.226 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="p10X20Nx" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=eJ/Fu8UkQxan6cDqeDBa1wfhWDhaxcfUlfU7YUO4zqI=; b=p10X20NxTM6rnCJL3c2Cl4mb2R6bnAxpvth0gd5Syerxzr6CTWHArByK91h0iRkeUymhWWiyh FGiut8GUr4L40eT51d/Al1GHOAMYTEoc3p1QOL/Y7AfBFGU3z7ctA2K/gXySHvEUFV/3qQfXKcj P8pwvj9/Qjy2d7VWzgIdMiI= Received: from mail.maildlp.com (unknown [172.19.163.127]) by canpmsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4fvLdp4Fl9zKm9R; Mon, 13 Apr 2026 16:47:58 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id 8691940572; Mon, 13 Apr 2026 16:54:17 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:16 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 03/10] arm_mpam: Disable reqPARTID expansion when Narrow-PARTID is unavailable Date: Mon, 13 Apr 2026 16:53:58 +0800 Message-ID: <20260413085405.1166412-4-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) Content-Type: text/plain; charset="utf-8" MPAM supports heterogeneous systems where some type of MSCs may implement Narrow-PARTID while others do not. However, when an MSC uses percentage-based throttling (non-bitmap partition control) and lacks Narrow-PARTID support, resctrl cannot correctly apply control group configurations across multiple PARTIDs. To enable free assignment of multiple reqPARTIDs to resource control groups, all MSCs used by resctrl must either: Implement Narrow-PARTID, allowing explicit PARTID remapping, or only have stateless resource controls (non-percentage-based), such that splitting a control group across multiple PARTIDs does not affect behavior. The detection occurs at initialization time on the first call to get_num_reqpartid() from update_rmid_limits(). This call is guaranteed to occur after mpam_resctrl_pick_{mba,caches}() have set up the resource classes, ensuring the necessary properties are available for the Narrow-PARTID capability check. When an MSC with percentage-based control lacks Narrow-PARTID support, get_num_reqpartid() falls back to returning the number of intPARTIDs, effectively disabling the reqPARTID expansion for monitoring groups. Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- drivers/resctrl/mpam_resctrl.c | 43 +++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 5f4364c8101a..56859f354efa 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -257,9 +257,50 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *i= gnored) return mpam_intpartid_max + 1; } =20 +/* + * Determine the effective number of PARTIDs available for resctrl. + * + * This function performs a one-time check to determine if Narrow-PARTID + * can be used. It must be called after mpam_resctrl_pick_{mba,caches}() + * have initialized the resource classes, as class properties are used + * to detect Narrow-PARTID support. + * + * The first call occurs in update_rmid_limits(), ensuring the + * prerequisite initialization is complete. + */ +static u32 get_num_reqpartid(void) +{ + struct mpam_resctrl_res *res; + struct mpam_props *cprops; + static bool first =3D true; + int rid; + + if (first) { + for_each_mpam_resctrl_control(res, rid) { + if (!res->class) + continue; + + cprops =3D &res->class->props; + if (mpam_has_feature(mpam_feat_partid_nrw, cprops)) + continue; + + if (mpam_has_feature(mpam_feat_mbw_max, cprops) || + mpam_has_feature(mpam_feat_mbw_min, cprops) || + mpam_has_feature(mpam_feat_cmax_cmax, cprops) || + mpam_has_feature(mpam_feat_cmax_cmin, cprops)) { + mpam_partid_max =3D mpam_intpartid_max; + break; + } + } + } + + first =3D false; + return mpam_partid_max + 1; +} + u32 resctrl_arch_system_num_rmid_idx(void) { - return (mpam_pmg_max + 1) * (mpam_partid_max + 1); + return (mpam_pmg_max + 1) * get_num_reqpartid(); } =20 u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid) --=20 2.25.1 From nobody Thu Jun 11 17:32:14 2026 Received: from canpmsgout05.his.huawei.com (canpmsgout05.his.huawei.com [113.46.200.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB5513AF644 for ; Mon, 13 Apr 2026 08:54:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070471; cv=none; b=JCBg5lDGiPXy8mxcdazlUQ3sZN9Uh11i1oN6faQM7V06Cciz5G53FiiT0tdRpmrO/79XKoxKuhqoHoTOYL5ez6+frL2V6LMDEI1rKc+hf4fT2mEHQQ2zlrWLcipnez34lif4sg9xf9+RuiBbn+pir1dtRL5NMnP4jJu1zNFbfs4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070471; c=relaxed/simple; bh=E9uenkXOo++TIWQ0palC2mwA6MFlnb1kZp+vGUDT4xg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tORMpajF1aGDXkSbFDnYKwgEh0mED1Y9BnOxQjGk5LZ2mcT5MdW43PH7Mj5YgqwJ0yKl8mHPgVZe+zhL+pMZaaHT1zWnUmAOTU1VMW3G1mIs61FfJxoFWTdRb++jFafrU0ELs8QN9xa6Kz9iw3eaXkzHxL8/HJ2eh9bea7EH4Sg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=CQ0z8kKN; arc=none smtp.client-ip=113.46.200.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="CQ0z8kKN" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=SjTYAujVa/A1hWxH09DYRfGcLYteC9tZu8XAO6gZGMY=; b=CQ0z8kKNwuQUWaS4RbL+qkujXltU53WtXe0JF34u9tA92LFMSF6++lQrl6pNOLtmJoiNw5Alp zHaaJErt75lw2chMNGQztCu/cOtnjk6Azw+Vrb/KV4Xb+7tDSgyr7sxsvr0oDNXuyaxHi+qLJe2 Q4cTHw0Vcy8siWESzwHtTII= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4fvLdp63B8z12LDP; Mon, 13 Apr 2026 16:47:58 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id EFD9F40576; Mon, 13 Apr 2026 16:54:17 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:17 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 04/10] arm_mpam: Refactor rmid to reqPARTID/PMG mapping Date: Mon, 13 Apr 2026 16:53:59 +0800 Message-ID: <20260413085405.1166412-5-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) The Narrow-PARTID feature allows the MPAM driver to statically or dynamically allocate request PARTIDs (reqPARTIDs) to internal PARTIDs (intPARTIDs). This enables expanding the number of monitoring groups beyond the hardware PMG limit. For systems with mixed MSCs (Memory System Components), MSCs that do not support Narrow-PARTID use PARTIDs exceeding the minimum number of intPARTIDs as reqPARTIDs to expand monitoring groups. Expand RMID to include reqPARTID information: RMID =3D reqPARTID * NUM_PMG + PMG To maintain compatibility with the existing resctrl layer, reqPARTIDs are allocated statically with a linear mapping to intPARTIDs via req2intpartid(). Mapping relationships (n =3D intPARTID count, m =3D reqPARTIDs per intPARTI= D): P - Partition group M - Monitoring group Group closid rmid.reqPARTID MSCs w/ Narrow-PARTID MSCs w/o Narrow-PARTID P1 0 intPARTID_1 PARTID_1 M1_1 0 0 =E2=94=9C=E2=94=80=E2=94=80 reqPARTID_1_1 = =E2=94=9C=E2=94=80=E2=94=80 PARTID_1 M1_2 0 0+n =E2=94=9C=E2=94=80=E2=94=80 reqPARTID_1_2 = =E2=94=9C=E2=94=80=E2=94=80 PARTID_1_2 M1_3 0 0+n*2 =E2=94=9C=E2=94=80=E2=94=80 reqPARTID_1_3 = =E2=94=9C=E2=94=80=E2=94=80 PARTID_1_3 ... =E2=94=9C=E2=94=80=E2=94=80 ... = =E2=94=9C=E2=94=80=E2=94=80 ... M1_m 0 0+n*(m-1) =E2=94=94=E2=94=80=E2=94=80 reqPARTID_1_m = =E2=94=94=E2=94=80=E2=94=80 PARTID_1_m P2 1 intPARTID_2 PARTID_2 M2_1 1 1 =E2=94=9C=E2=94=80=E2=94=80 reqPARTID_2_1 = =E2=94=9C=E2=94=80=E2=94=80 PARTID_2 M2_2 1 1+n =E2=94=9C=E2=94=80=E2=94=80 reqPARTID_2_2 = =E2=94=9C=E2=94=80=E2=94=80 PARTID_2_2 M2_3 1 1+n*2 =E2=94=9C=E2=94=80=E2=94=80 reqPARTID_2_3 = =E2=94=9C=E2=94=80=E2=94=80 PARTID_2_3 ... =E2=94=9C=E2=94=80=E2=94=80 ... = =E2=94=9C=E2=94=80=E2=94=80 ... M2_m 1 1+n*(m-1) =E2=94=94=E2=94=80=E2=94=80 reqPARTID_2_m = =E2=94=94=E2=94=80=E2=94=80 PARTID_2_m Pn n-1 intPARTID_n PARTID_n Mn_1 n-1 n-1 =E2=94=9C=E2=94=80=E2=94=80 reqPARTID_n_1 = =E2=94=9C=E2=94=80=E2=94=80 PARTID_n Mn_2 n-1 n-1+n =E2=94=9C=E2=94=80=E2=94=80 reqPARTID_n_2 = =E2=94=9C=E2=94=80=E2=94=80 PARTID_n_2 Mn_3 n-1 n-1+n*2 =E2=94=9C=E2=94=80=E2=94=80 reqPARTID_n_3 = =E2=94=9C=E2=94=80=E2=94=80 PARTID_n_3 ... =E2=94=9C=E2=94=80=E2=94=80 ... = =E2=94=9C=E2=94=80=E2=94=80 ... Mn_m n-1 n*m-1 =E2=94=94=E2=94=80=E2=94=80 reqPARTID_n_m = =E2=94=94=E2=94=80=E2=94=80 PARTID_n_m Refactor the glue layer between resctrl abstractions (rmid) and MPAM hardware registers (reqPARTID/PMG) to support Narrow-PARTID. The resctrl layer uses rmid2reqpartid() and rmid2pmg() to extract components from rmid. The closid-to-intPARTID translation remains unchanged via resctrl_get_config_index(). Since Narrow-PARTID is a monitoring enhancement, reqPARTID is only used in monitoring paths while configuration paths maintain the original semantics of closid. Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- arch/arm64/include/asm/mpam.h | 12 +++- drivers/resctrl/mpam_resctrl.c | 101 +++++++++++++++++++++++---------- 2 files changed, 82 insertions(+), 31 deletions(-) diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h index 70d396e7b6da..40d60b0ab0fd 100644 --- a/arch/arm64/include/asm/mpam.h +++ b/arch/arm64/include/asm/mpam.h @@ -63,6 +63,15 @@ static inline void mpam_set_task_partid_pmg(struct task_= struct *tsk, WRITE_ONCE(task_thread_info(tsk)->mpam_partid_pmg, regval); } =20 +u16 req2intpartid(u16 reqpartid); + +static inline u16 mpam_get_regval_partid(u64 regval) +{ + u16 reqpartid =3D (regval & MPAMSM_EL1_PARTID_D_MASK) >> MPAMSM_EL1_PARTI= D_D_SHIFT; + + return req2intpartid(reqpartid); +} + static inline void mpam_thread_switch(struct task_struct *tsk) { u64 oldregval; @@ -72,7 +81,8 @@ static inline void mpam_thread_switch(struct task_struct = *tsk) if (!static_branch_likely(&mpam_enabled)) return; =20 - if (regval =3D=3D READ_ONCE(arm64_mpam_global_default)) + if (regval =3D=3D READ_ONCE(arm64_mpam_global_default) || + !mpam_get_regval_partid(regval)) regval =3D READ_ONCE(per_cpu(arm64_mpam_default, cpu)); =20 oldregval =3D READ_ONCE(per_cpu(arm64_mpam_current, cpu)); diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 56859f354efa..9d0a7a4dffd1 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -303,15 +303,60 @@ u32 resctrl_arch_system_num_rmid_idx(void) return (mpam_pmg_max + 1) * get_num_reqpartid(); } =20 +static u16 rmid2reqpartid(u32 rmid) +{ + rmid /=3D (mpam_pmg_max + 1); + + if (cdp_enabled) + return resctrl_get_config_index(rmid, CDP_DATA); + + return resctrl_get_config_index(rmid, CDP_NONE); +} + +static u8 rmid2pmg(u32 rmid) +{ + return rmid % (mpam_pmg_max + 1); +} + +u16 req2intpartid(u16 reqpartid) +{ + return reqpartid % (mpam_intpartid_max + 1); +} + +/* + * To avoid the reuse of rmid across multiple control groups, check + * the incoming closid to prevent rmid from being reallocated by + * resctrl_find_free_rmid(). + * + * If the closid and rmid do not match upon inspection, immediately + * returns an invalid rmid. A valid rmid must not exceed 24 bits. + */ u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid) { - return closid * (mpam_pmg_max + 1) + rmid; + u32 reqpartid =3D rmid2reqpartid(rmid); + u32 intpartid =3D req2intpartid(reqpartid); + + if (cdp_enabled) + intpartid >>=3D 1; + + if (closid !=3D intpartid) + return U32_MAX; + + return rmid; } =20 void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid) { - *closid =3D idx / (mpam_pmg_max + 1); - *rmid =3D idx % (mpam_pmg_max + 1); + u32 reqpartid =3D rmid2reqpartid(idx); + u32 intpartid =3D req2intpartid(reqpartid); + + if (rmid) + *rmid =3D idx; + if (closid) { + if (cdp_enabled) + intpartid >>=3D 1; + *closid =3D intpartid; + } } =20 void resctrl_arch_sched_in(struct task_struct *tsk) @@ -323,21 +368,17 @@ void resctrl_arch_sched_in(struct task_struct *tsk) =20 void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmi= d) { - WARN_ON_ONCE(closid > U16_MAX); - WARN_ON_ONCE(rmid > U8_MAX); + u32 reqpartid =3D rmid2reqpartid(rmid); + u8 pmg =3D rmid2pmg(rmid); =20 - if (!cdp_enabled) { - mpam_set_cpu_defaults(cpu, closid, closid, rmid, rmid); - } else { + if (!cdp_enabled) + mpam_set_cpu_defaults(cpu, reqpartid, reqpartid, pmg, pmg); + else /* * When CDP is enabled, resctrl halves the closid range and we * use odd/even partid for one closid. */ - u32 partid_d =3D resctrl_get_config_index(closid, CDP_DATA); - u32 partid_i =3D resctrl_get_config_index(closid, CDP_CODE); - - mpam_set_cpu_defaults(cpu, partid_d, partid_i, rmid, rmid); - } + mpam_set_cpu_defaults(cpu, reqpartid, reqpartid + 1, pmg, pmg); } =20 void resctrl_arch_sync_cpu_closid_rmid(void *info) @@ -356,17 +397,16 @@ void resctrl_arch_sync_cpu_closid_rmid(void *info) =20 void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32= rmid) { - WARN_ON_ONCE(closid > U16_MAX); - WARN_ON_ONCE(rmid > U8_MAX); + u32 reqpartid =3D rmid2reqpartid(rmid); + u8 pmg =3D rmid2pmg(rmid); =20 - if (!cdp_enabled) { - mpam_set_task_partid_pmg(tsk, closid, closid, rmid, rmid); - } else { - u32 partid_d =3D resctrl_get_config_index(closid, CDP_DATA); - u32 partid_i =3D resctrl_get_config_index(closid, CDP_CODE); + WARN_ON_ONCE(reqpartid > U16_MAX); + WARN_ON_ONCE(pmg > U8_MAX); =20 - mpam_set_task_partid_pmg(tsk, partid_d, partid_i, rmid, rmid); - } + if (!cdp_enabled) + mpam_set_task_partid_pmg(tsk, reqpartid, reqpartid, pmg, pmg); + else + mpam_set_task_partid_pmg(tsk, reqpartid, reqpartid + 1, pmg, pmg); } =20 bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid) @@ -374,6 +414,8 @@ bool resctrl_arch_match_closid(struct task_struct *tsk,= u32 closid) u64 regval =3D mpam_get_regval(tsk); u32 tsk_closid =3D FIELD_GET(MPAM0_EL1_PARTID_D, regval); =20 + tsk_closid =3D req2intpartid(tsk_closid); + if (cdp_enabled) tsk_closid >>=3D 1; =20 @@ -384,13 +426,11 @@ bool resctrl_arch_match_closid(struct task_struct *ts= k, u32 closid) bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid) { u64 regval =3D mpam_get_regval(tsk); - u32 tsk_closid =3D FIELD_GET(MPAM0_EL1_PARTID_D, regval); - u32 tsk_rmid =3D FIELD_GET(MPAM0_EL1_PMG_D, regval); - - if (cdp_enabled) - tsk_closid >>=3D 1; + u32 tsk_partid =3D FIELD_GET(MPAM0_EL1_PARTID_D, regval); + u32 tsk_pmg =3D FIELD_GET(MPAM0_EL1_PMG_D, regval); =20 - return (tsk_closid =3D=3D closid) && (tsk_rmid =3D=3D rmid); + return (tsk_partid =3D=3D rmid2reqpartid(rmid)) && + (tsk_pmg =3D=3D rmid2pmg(rmid)); } =20 struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l) @@ -478,6 +518,7 @@ static int __read_mon(struct mpam_resctrl_mon *mon, str= uct mpam_component *mon_c enum resctrl_conf_type cdp_type, u32 closid, u32 rmid, u64 *val) { struct mon_cfg cfg; + u32 reqpartid =3D rmid2reqpartid(rmid); =20 if (!mpam_is_enabled()) return -EINVAL; @@ -493,8 +534,8 @@ static int __read_mon(struct mpam_resctrl_mon *mon, str= uct mpam_component *mon_c cfg =3D (struct mon_cfg) { .mon =3D mon_idx, .match_pmg =3D true, - .partid =3D closid, - .pmg =3D rmid, + .partid =3D (cdp_type =3D=3D CDP_CODE) ? reqpartid + 1 : reqpartid, + .pmg =3D rmid2pmg(rmid), }; =20 return mpam_msmon_read(mon_comp, &cfg, mon_type, val); --=20 2.25.1 From nobody Thu Jun 11 17:32:14 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C62E3AE706 for ; Mon, 13 Apr 2026 08:54:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070469; cv=none; b=apnQ5KUJvXIY7BfRiyYp2vNyH+iVFYHZTIUsfM5kbJRmXuO9gD2/LxkJ7D5gEUP9wTeK1xZeg+b+fmr0VdPd06+FXN+5ZKEvUDtkQP0MmTr5/hzCUU5ASeP/nbMQoch9TQN3+asGndGzaVQkZDP99M/G3zi2+7KkcehqXF0F6Bs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070469; c=relaxed/simple; bh=w/30nXCtc0ZRdgx5AjWxAhi0QQXm8MER5rrjGZW8tm0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XVd2q9mb3YSCrgnY2+vfs+Y7rbv+7gxTMv0PJICBl2fEKZl9KmzyFNTDB+3sJWvSiNCYVDhKDrcFIlN14hgivBb+8JxNH1BLcgCdVfCMe+iXkmZvBJRs7JOF5ANC7GvzUgBGjBTKNQGupeTv4fivCuMZQxEbBAlIOCzMZEGHqFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=cXDJeFcN; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=cXDJeFcN; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="cXDJeFcN"; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="cXDJeFcN" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=l4UyPVTRcZ3XGIKT+x6CF9L5buHORlMCnapP9Kds0+s=; b=cXDJeFcNmlh9tCWenmToLebL6axovKN79nys0U3QaeT8+1QS7kWxxWEp2aKPWYWOglE9Bc+yj jW/sRq5uagDutz2jf5HSqamvJvQNYJdJXqKz13NugWch7wDdp7VgpOVTIU+xaX+qmr1IBOlkjD5 rQTTeUkkrt4JFtb8X9C97QI= Received: from canpmsgout02.his.huawei.com (unknown [172.19.92.185]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4fvLmX4F3Lz1BG3K for ; Mon, 13 Apr 2026 16:53:48 +0800 (CST) dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=l4UyPVTRcZ3XGIKT+x6CF9L5buHORlMCnapP9Kds0+s=; b=cXDJeFcNmlh9tCWenmToLebL6axovKN79nys0U3QaeT8+1QS7kWxxWEp2aKPWYWOglE9Bc+yj jW/sRq5uagDutz2jf5HSqamvJvQNYJdJXqKz13NugWch7wDdp7VgpOVTIU+xaX+qmr1IBOlkjD5 rQTTeUkkrt4JFtb8X9C97QI= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4fvLdh0VBkzcZyv; Mon, 13 Apr 2026 16:47:52 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id 71BA340576; Mon, 13 Apr 2026 16:54:18 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:17 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 05/10] arm_mpam: Propagate control group config to sub-monitoring groups Date: Mon, 13 Apr 2026 16:54:00 +0800 Message-ID: <20260413085405.1166412-6-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) Content-Type: text/plain; charset="utf-8" With the Narrow-PARTID feature, each control group is assigned multiple (req)PARTIDs to expand monitoring capacity. When a control group's configuration is updated, all associated sub-monitoring groups (each identified by a unique reqPARTID) should be synchronized. In __write_config(), iterate over all reqPARTIDs belonging to the control group and propagate the configuration to each sub-monitoring group: * For MSCs supporting Narrow-PARTID, establish the reqPARTID to intPARTID mapping. * For MSCs without Narrow-PARTID support, synchronize the configuration to new PARTIDs directly. Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- drivers/resctrl/mpam_devices.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c index cf067bf5092e..8fbc8f9f9688 100644 --- a/drivers/resctrl/mpam_devices.c +++ b/drivers/resctrl/mpam_devices.c @@ -1547,6 +1547,7 @@ static void mpam_reprogram_ris_partid(struct mpam_msc= _ris *ris, u16 partid, { u32 pri_val =3D 0; u16 cmax =3D MPAMCFG_CMAX_CMAX; + u16 intpartid =3D req2intpartid(partid); struct mpam_msc *msc =3D ris->vmsc->msc; struct mpam_props *rprops =3D &ris->props; u16 dspri =3D GENMASK(rprops->dspri_wd, 0); @@ -1556,15 +1557,17 @@ static void mpam_reprogram_ris_partid(struct mpam_m= sc_ris *ris, u16 partid, __mpam_part_sel(ris->ris_idx, partid, msc); =20 if (mpam_has_feature(mpam_feat_partid_nrw, rprops)) { - /* Update the intpartid mapping */ mpam_write_partsel_reg(msc, INTPARTID, - MPAMCFG_INTPARTID_INTERNAL | partid); + MPAMCFG_INTPARTID_INTERNAL | intpartid); =20 /* - * Then switch to the 'internal' partid to update the - * configuration. + * Mapping from reqpartid to intpartid already established. + * Sub-monitoring groups share the parent's configuration. */ - __mpam_intpart_sel(ris->ris_idx, partid, msc); + if (partid !=3D intpartid) + goto out; + + __mpam_intpart_sel(ris->ris_idx, intpartid, msc); } =20 if (mpam_has_feature(mpam_feat_cpor_part, rprops)) { @@ -1631,6 +1634,7 @@ static void mpam_reprogram_ris_partid(struct mpam_msc= _ris *ris, u16 partid, =20 mpam_quirk_post_config_change(ris, partid, cfg); =20 +out: mutex_unlock(&msc->part_sel_lock); } =20 @@ -1755,11 +1759,28 @@ struct mpam_write_config_arg { u16 partid; }; =20 +static u32 get_num_reqpartid_per_intpartid(void) +{ + return (mpam_partid_max + 1) / (mpam_intpartid_max + 1); +} + static int __write_config(void *arg) { + int closid_num =3D resctrl_arch_get_num_closid(NULL); struct mpam_write_config_arg *c =3D arg; + u32 reqpartid, req_idx; =20 - mpam_reprogram_ris_partid(c->ris, c->partid, &c->comp->cfg[c->partid]); + /* c->partid should be within the range of intPARTIDs */ + WARN_ON_ONCE(c->partid >=3D closid_num); + + /* Synchronize the configuration to each sub-monitoring group. */ + for (req_idx =3D 0; req_idx < get_num_reqpartid_per_intpartid(); + req_idx++) { + reqpartid =3D req_idx * closid_num + c->partid; + + mpam_reprogram_ris_partid(c->ris, reqpartid, + &c->comp->cfg[c->partid]); + } =20 return 0; } --=20 2.25.1 From nobody Thu Jun 11 17:32:14 2026 Received: from canpmsgout01.his.huawei.com (canpmsgout01.his.huawei.com [113.46.200.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 850F53AE188 for ; Mon, 13 Apr 2026 08:54:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070464; cv=none; b=VunlN6LdbE0V0mErb4kJBlqXpjDuVVZsGLdbRDuKwQrUK7wV49hXn5JS0n+W7qegqgFdyDeMNNe1kW75SjhYt/5emoaq67Am1GMp+Kz4XpF3yn5R+EkNYRLKc7/u6NnbfqdrPiPnHPZVySLaMVpHLwiOVtobu5iT8V4XA2mKEYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070464; c=relaxed/simple; bh=8Za6GlA6kXYmI9uOqgebVLNv5NDQH+uXH1/+ICmM/ac=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t5Orr5vkm0torDyBqH1WJ9AISwB8gVb72kdsAWFro56rnnxWB5FohG+Ko5Dz5QWY26mPSxDA+YlMRjQ48TPhVWAqXtv1WsBKWXbkTf99jKX1GXaJO4uruLh1gw6abLv0l4P5tVRq6I45zoSaPvMGPVfgIHrqq7ox79PLzzNxFkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=qCq87qkV; arc=none smtp.client-ip=113.46.200.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="qCq87qkV" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=kspIqY3IxsH71BJIC1Olrnf73oXURAoru/Y0UiXkbrA=; b=qCq87qkVND4ZsKtl3U6cs/QKcooZ6FL5/Ya/MzsTDneaXpAGciGUnPQ0h5I3yLJvp66wKji8T OGfCxkpxyCksQc/bNtESubwyCs3iA35JY2OItBG0DjtxrLmzmebE+JF+VfLPZ6NrYvEJFz9Okyh MyOEV4DyYylwm0s91R2Y1rY= Received: from mail.maildlp.com (unknown [172.19.162.144]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4fvLfF0ph5z1T4Gh; Mon, 13 Apr 2026 16:48:21 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id DCF4E4056E; Mon, 13 Apr 2026 16:54:18 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:18 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 06/10] arm_mpam: Add boot parameter to limit mpam_intpartid_max Date: Mon, 13 Apr 2026 16:54:01 +0800 Message-ID: <20260413085405.1166412-7-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) Content-Type: text/plain; charset="utf-8" Add a new boot parameter "intpartid_max" to allow system administrators to limit the number of internal PARTIDs used by the MPAM driver for resource control groups. This provides flexibility to configure the trade-off between: * Number of resource control groups (CLOSIDs, limited by intpartid_max) * Number of monitoring groups (RMIDs, limited by reqpartid and intpartid) By default, the driver uses all available intPARTIDs for control groups. With this parameter, users are able to reserve internal PARTIDs to create additional sub-monitoring groups (provided that the narrow PARTID feature is successfully enabled). Example usage: mpam.intpartid_max=3D7 mpam.intpartid_max is set to the maximum number of internal PARTIDs minus one, which is applied as the limit at initialization time. Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- drivers/resctrl/mpam_devices.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c index 8fbc8f9f9688..2aeff798a865 100644 --- a/drivers/resctrl/mpam_devices.c +++ b/drivers/resctrl/mpam_devices.c @@ -3,6 +3,9 @@ =20 #define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__ =20 +#undef KBUILD_MODNAME +#define KBUILD_MODNAME "mpam" + #include #include #include @@ -18,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +69,7 @@ static DEFINE_MUTEX(mpam_cpuhp_state_lock); u16 mpam_partid_max; u16 mpam_intpartid_max; u8 mpam_pmg_max; +static u16 bootparam_intpartid_max =3D USHRT_MAX; static bool partid_max_init, partid_max_published; static DEFINE_SPINLOCK(partid_max_lock); =20 @@ -2725,6 +2730,7 @@ static void mpam_enable_once(void) * longer change. */ spin_lock(&partid_max_lock); + mpam_intpartid_max =3D min(mpam_intpartid_max, bootparam_intpartid_max); partid_max_published =3D true; spin_unlock(&partid_max_lock); =20 @@ -2779,6 +2785,20 @@ static void mpam_enable_once(void) mpam_partid_max + 1, mpam_intpartid_max + 1, mpam_pmg_max + 1); } =20 +static int mpam_intpartid_max_set(const char *val, + const struct kernel_param *kp) +{ + return param_set_uint_minmax(val, kp, 1, USHRT_MAX); +} + +static const struct kernel_param_ops mpam_intpartid_max_ops =3D { + .set =3D mpam_intpartid_max_set, + .get =3D param_get_uint, +}; + +arch_param_cb(intpartid_max, &mpam_intpartid_max_ops, + &bootparam_intpartid_max, 0444); + static void mpam_reset_component_locked(struct mpam_component *comp) { struct mpam_vmsc *vmsc; --=20 2.25.1 From nobody Thu Jun 11 17:32:14 2026 Received: from canpmsgout01.his.huawei.com (canpmsgout01.his.huawei.com [113.46.200.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAD9B3AE189 for ; Mon, 13 Apr 2026 08:54:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070463; cv=none; b=Ns8SaCZyumxxkB1jIiLyZ0MJ2qyoemd8ULU0o/POzZ+rojmcDOVAMPulV/M/vkFnbVJANCW7RUH9AsBHScUbYv3KLMG6TfpEAfq26vTIoqCIGk+8VLCDrQ/2bVHPfNzX9B4rNTOCFdiAVHx9Qj9gZnBGru0k2olzDpX3/pPPRAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070463; c=relaxed/simple; bh=Lr3/CJgIhAYaEWgminvqddnOd7//tAnKPTDDgjSRbcs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=awkI8u4ZN26Yt4ShaX/e+zebAPcyTrgMEA9w0zge5ccU4C0yVt6/hr6SmNXKc/inux8pMIODN/fKfXFFjgKijkp80Z3zjHQ2LUUSga4P4A2/PJlg/0dZzr+Hw2/F4pDt3B6DN7LutRmLEszaqL/JIo2g8AAj6PXGGydiWaj83GM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=dSY7AHX1; arc=none smtp.client-ip=113.46.200.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="dSY7AHX1" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=KvhMMZp/GsQefc49ctoJ7WGEbW2EPdmBkUqroYz7npc=; b=dSY7AHX1foqKvJYvTnxqbZunGF5MwOhCAT7WEjawOb/HZPmZGdaLo76VfQP58fBR1EfujYFuC hsT40wtHMevHvgog4v5vkzO9wjYiTB+gnLokc3+U1shyIIhqgN/1xe4wfnfGBYfmh/Fm/QTIYFs 5B+JvPGbl6ypDFGcTZCUYLQ= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4fvLfF4p37z1T4JS; Mon, 13 Apr 2026 16:48:21 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id 71B664056D; Mon, 13 Apr 2026 16:54:19 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:18 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 07/10] fs/resctrl: Add rmid_entry state helpers Date: Mon, 13 Apr 2026 16:54:02 +0800 Message-ID: <20260413085405.1166412-8-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) Content-Type: text/plain; charset="utf-8" Introduce helper functions for rmid_entry management, in preparation for upcoming patches supporting dynamic monitoring group allocation: * rmid_is_occupied(): Query whether a RMID entry is currently allocated by checking if its list node has been removed from the free list. * rmid_entry_reassign_closid(): Update the closid associated with a RMID entry. Fix list node initialization in alloc_rmid() and dom_data_init() by using list_del_init() instead of list_del(). This ensures list_empty() checks in rmid_is_occupied() work correctly without encountering LIST_POISON values. Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- fs/resctrl/monitor.c | 18 ++++++++++++++++-- include/linux/resctrl.h | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 9fd901c78dc6..7473c43600cf 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -286,7 +286,7 @@ int alloc_rmid(u32 closid) if (IS_ERR(entry)) return PTR_ERR(entry); =20 - list_del(&entry->list); + list_del_init(&entry->list); return entry->rmid; } =20 @@ -346,6 +346,20 @@ void free_rmid(u32 closid, u32 rmid) list_add_tail(&entry->list, &rmid_free_lru); } =20 +bool rmid_is_occupied(u32 closid, u32 rmid) +{ + u32 idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); + + return list_empty(&rmid_ptrs[idx].list); +} + +void rmid_entry_reassign_closid(u32 closid, u32 rmid) +{ + u32 idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); + + rmid_ptrs[idx].closid =3D closid; +} + static struct mbm_state *get_mbm_state(struct rdt_l3_mon_domain *d, u32 cl= osid, u32 rmid, enum resctrl_event_id evtid) { @@ -945,7 +959,7 @@ int setup_rmid_lru_list(void) idx =3D resctrl_arch_rmid_idx_encode(RESCTRL_RESERVED_CLOSID, RESCTRL_RESERVED_RMID); entry =3D __rmid_entry(idx); - list_del(&entry->list); + list_del_init(&entry->list); =20 return 0; } diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 006e57fd7ca5..b636e7250c20 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -702,6 +702,27 @@ bool resctrl_arch_get_io_alloc_enabled(struct rdt_reso= urce *r); extern unsigned int resctrl_rmid_realloc_threshold; extern unsigned int resctrl_rmid_realloc_limit; =20 +/** + * rmid_is_occupied() - Check whether the specified rmid has been + * allocated. + * @closid: Specify the closid that matches the rmid. + * @rmid: Specify the rmid entry to check status. + * + * This function checks if the rmid_entry is currently allocated by testing + * whether its list node is empty (removed from the free list). + * + * Return: + * True if the specified rmid is still in use. + */ +bool rmid_is_occupied(u32 closid, u32 rmid); + +/** + * rmid_entry_reassign_closid() - Update the closid field of a rmid_entry. + * @closid: Specify the reassigned closid. + * @rmid: Specify the rmid entry to update closid. + */ +void rmid_entry_reassign_closid(u32 closid, u32 rmid); + int resctrl_init(void); void resctrl_exit(void); =20 --=20 2.25.1 From nobody Thu Jun 11 17:32:14 2026 Received: from canpmsgout01.his.huawei.com (canpmsgout01.his.huawei.com [113.46.200.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B14C13ACA65 for ; Mon, 13 Apr 2026 08:54:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070463; cv=none; b=MO9qSO62gl2xxmtkGjSMGI/6temN5Gy1rDjCt4CeKbBnGCUYeL7AL7h774P2GpEddEBDELiYfcHJ7bcQTvrit1gPxYQPeZYUdwAv8MA1ro3DqSzYqMCVh4rnItjY5u8UZVbk2TOXBWCy6oSxhLRo7355jhKj5Mep2krLiBb5Dbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070463; c=relaxed/simple; bh=UEpF6RyuybriBOZtKqW4IPSejTORNNutnXY8onidzMs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VQ2G/V0RcQ4mbHh4Sd0whoF6YIjE+wkX/3YguEgWVn8aANPv9StEvRD9PwL2sSBaxuGobAxlauku0EQvcmem87Zil5G/Co/JdafdyIARuq3g2LiiXbSEFynOJVg6lHGPlskKYWfqOXfxIQftpG3UtZg91Eevx16MjRhSe0KiC1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=KukbhkcA; arc=none smtp.client-ip=113.46.200.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="KukbhkcA" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=syaEbXtXRQT7GoR1+WsZALXLm43lQHNnpC9Ahas5V7o=; b=KukbhkcAQesz583MGG42zXTnuBbIG3K+O1F3naIB/Gdyc+x28PbXz4weLYuCo3KsVhIVaXciH /c96sRFVK1O7b0vTv9feIo511+7nJBD7wDFbkqzQGT/mc3Nquk2YvPw3mW6VpX+ySy5mS5Xkxnm uMaK9pCo4KrzXDOr+NY8F9Q= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4fvLfG0cF0z1T4JS; Mon, 13 Apr 2026 16:48:22 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id D700340576; Mon, 13 Apr 2026 16:54:19 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:19 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 08/10] arm_mpam: Implement dynamic reqPARTID allocation for monitoring groups Date: Mon, 13 Apr 2026 16:54:03 +0800 Message-ID: <20260413085405.1166412-9-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) Content-Type: text/plain; charset="utf-8" Replace static reqPARTID allocation with dynamic binding to maximize the monitoring group utilization. Static allocation wastes resources when control groups create fewer sub-groups than the pre-allocated limit. Add a lookup table (reqpartid_map) to dynamically bind reqPARTIDs to control groups needing extended monitoring capacity: * resctrl_arch_rmid_expand(): Find and bind a free reqPARTID to the specified closid when creating monitoring groups. * resctrl_arch_rmid_reclaim(): Unbind reqPARTID when all monitoring groups associated with pmg are freed, making it available for reuse. Update conversion helpers for dynamic mapping: * req2intpartid() switches to lookup table for dynamic allocation. * Add partid2closid() and req_pmg2rmid() helpers. Refactor __write_config() to iterate over all reqPARTIDs that match by intPARTID, removing fixed per-closid slot assumption. Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- drivers/resctrl/mpam_devices.c | 21 ++--- drivers/resctrl/mpam_internal.h | 2 + drivers/resctrl/mpam_resctrl.c | 141 +++++++++++++++++++++++++++++--- include/linux/arm_mpam.h | 17 ++++ 4 files changed, 157 insertions(+), 24 deletions(-) diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c index 2aeff798a865..cf94b45b4f9e 100644 --- a/drivers/resctrl/mpam_devices.c +++ b/drivers/resctrl/mpam_devices.c @@ -1764,27 +1764,24 @@ struct mpam_write_config_arg { u16 partid; }; =20 -static u32 get_num_reqpartid_per_intpartid(void) -{ - return (mpam_partid_max + 1) / (mpam_intpartid_max + 1); -} - static int __write_config(void *arg) { int closid_num =3D resctrl_arch_get_num_closid(NULL); struct mpam_write_config_arg *c =3D arg; - u32 reqpartid, req_idx; + u32 reqpartid; =20 /* c->partid should be within the range of intPARTIDs */ WARN_ON_ONCE(c->partid >=3D closid_num); =20 - /* Synchronize the configuration to each sub-monitoring group. */ - for (req_idx =3D 0; req_idx < get_num_reqpartid_per_intpartid(); - req_idx++) { - reqpartid =3D req_idx * closid_num + c->partid; + mpam_reprogram_ris_partid(c->ris, c->partid, + &c->comp->cfg[c->partid]); =20 - mpam_reprogram_ris_partid(c->ris, reqpartid, - &c->comp->cfg[c->partid]); + /* Synchronize the configuration to each sub-monitoring group. */ + for (reqpartid =3D closid_num; + reqpartid < get_num_reqpartid(); reqpartid++) { + if (req2intpartid(reqpartid) =3D=3D c->partid) + mpam_reprogram_ris_partid(c->ris, reqpartid, + &c->comp->cfg[c->partid]); } =20 return 0; diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_interna= l.h index 790a90a5ccd9..16ce968344d0 100644 --- a/drivers/resctrl/mpam_internal.h +++ b/drivers/resctrl/mpam_internal.h @@ -473,6 +473,8 @@ void mpam_msmon_reset_mbwu(struct mpam_component *comp,= struct mon_cfg *ctx); int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level, cpumask_t *affinity); =20 +u32 get_num_reqpartid(void); + #ifdef CONFIG_RESCTRL_FS int mpam_resctrl_setup(void); void mpam_resctrl_exit(void); diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 9d0a7a4dffd1..2762462d80e5 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -268,7 +268,7 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *ig= nored) * The first call occurs in update_rmid_limits(), ensuring the * prerequisite initialization is complete. */ -static u32 get_num_reqpartid(void) +u32 get_num_reqpartid(void) { struct mpam_resctrl_res *res; struct mpam_props *cprops; @@ -318,9 +318,34 @@ static u8 rmid2pmg(u32 rmid) return rmid % (mpam_pmg_max + 1); } =20 +static u32 req_pmg2rmid(u32 reqpartid, u8 pmg) +{ + if (cdp_enabled) + reqpartid >>=3D 1; + + return reqpartid * (mpam_pmg_max + 1) + pmg; +} + +static u32 *reqpartid_map; + u16 req2intpartid(u16 reqpartid) { - return reqpartid % (mpam_intpartid_max + 1); + /* + * Directly return intPartid in case that mpam_reset_ris() access + * NULL pointer. + */ + if (reqpartid < (mpam_intpartid_max + 1)) + return reqpartid; + + return reqpartid_map[reqpartid]; +} + +static u32 partid2closid(u32 partid) +{ + if (cdp_enabled) + partid >>=3D 1; + + return partid; } =20 /* @@ -334,12 +359,12 @@ u16 req2intpartid(u16 reqpartid) u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid) { u32 reqpartid =3D rmid2reqpartid(rmid); - u32 intpartid =3D req2intpartid(reqpartid); =20 - if (cdp_enabled) - intpartid >>=3D 1; + /* When enable CDP mode, needs to filter invalid rmid entry out */ + if (reqpartid >=3D get_num_reqpartid()) + return U32_MAX; =20 - if (closid !=3D intpartid) + if (closid !=3D partid2closid(req2intpartid(reqpartid))) return U32_MAX; =20 return rmid; @@ -352,11 +377,9 @@ void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid= , u32 *rmid) =20 if (rmid) *rmid =3D idx; - if (closid) { - if (cdp_enabled) - intpartid >>=3D 1; - *closid =3D intpartid; - } + + if (closid) + *closid =3D partid2closid(intpartid); } =20 void resctrl_arch_sched_in(struct task_struct *tsk) @@ -1665,6 +1688,93 @@ void mpam_resctrl_offline_cpu(unsigned int cpu) } } =20 +static int reqpartid_init(void) +{ + int req_num, idx; + + req_num =3D get_num_reqpartid(); + reqpartid_map =3D kcalloc(req_num, sizeof(u32), GFP_KERNEL); + if (!reqpartid_map) + return -ENOMEM; + + for (idx =3D 0; idx < req_num; idx++) + reqpartid_map[idx] =3D idx; + + return 0; +} + +static void reqpartid_exit(void) +{ + kfree(reqpartid_map); +} + +static void update_rmid_entries_for_reqpartid(u32 reqpartid) +{ + int pmg; + u32 intpartid =3D reqpartid_map[reqpartid]; + u32 closid =3D partid2closid(intpartid); + + for (pmg =3D 0; pmg <=3D mpam_pmg_max; pmg++) + rmid_entry_reassign_closid(closid, req_pmg2rmid(reqpartid, pmg)); +} + +int resctrl_arch_rmid_expand(u32 closid) +{ + int i; + + for (i =3D resctrl_arch_get_num_closid(NULL); + i < get_num_reqpartid(); i++) { + + /* Here means the reqpartid 'i' is free. */ + if (reqpartid_map[i] >=3D resctrl_arch_get_num_closid(NULL)) { + if (cdp_enabled) { + reqpartid_map[i] =3D resctrl_get_config_index(closid, CDP_DATA); + /* + * Reqpartids are always allocated in + * pairs, never out-of-bounds access. + */ + reqpartid_map[i + 1] =3D resctrl_get_config_index(closid, CDP_CODE); + } else { + reqpartid_map[i] =3D resctrl_get_config_index(closid, CDP_NONE); + } + update_rmid_entries_for_reqpartid(i); + return i; + } + } + + return -ENOSPC; +} + +void resctrl_arch_rmid_reclaim(u32 closid, u32 rmid) +{ + int pmg; + u32 intpartid; + int reqpartid =3D rmid2reqpartid(rmid); + + if (reqpartid < resctrl_arch_get_num_closid(NULL)) + return; + + if (cdp_enabled) + intpartid =3D resctrl_get_config_index(closid, CDP_DATA); + else + intpartid =3D resctrl_get_config_index(closid, CDP_NONE); + + WARN_ON_ONCE(intpartid !=3D req2intpartid(reqpartid)); + + for (pmg =3D 0; pmg <=3D mpam_pmg_max; pmg++) { + if (rmid_is_occupied(closid, req_pmg2rmid(reqpartid, pmg))) + break; + } + + if (pmg > mpam_pmg_max) { + reqpartid_map[reqpartid] =3D reqpartid; + if (cdp_enabled) + reqpartid_map[reqpartid + 1] =3D reqpartid + 1; + + update_rmid_entries_for_reqpartid(reqpartid); + } +} + int mpam_resctrl_setup(void) { int err =3D 0; @@ -1720,10 +1830,16 @@ int mpam_resctrl_setup(void) return -EOPNOTSUPP; } =20 - err =3D resctrl_init(); + err =3D reqpartid_init(); if (err) return err; =20 + err =3D resctrl_init(); + if (err) { + reqpartid_exit(); + return err; + } + WRITE_ONCE(resctrl_enabled, true); =20 return 0; @@ -1741,6 +1857,7 @@ void mpam_resctrl_exit(void) =20 WRITE_ONCE(resctrl_enabled, false); resctrl_exit(); + reqpartid_exit(); } =20 /* diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h index f92a36187a52..d45422965907 100644 --- a/include/linux/arm_mpam.h +++ b/include/linux/arm_mpam.h @@ -59,6 +59,23 @@ void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u= 32 closid, u32 rmid); void resctrl_arch_sched_in(struct task_struct *tsk); bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid); bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid= ); + +/** + * resctrl_arch_rmid_expand() - Expand the RMID resources for the specifie= d closid. + * @closid: closid that matches the rmid. + * + * Return: + * 0 on success, or -ENOSPC etc on error. + */ +int resctrl_arch_rmid_expand(u32 closid); + +/** + * resctrl_arch_rmid_reclaim() - Reclaim the rmid resources for the specif= ied closid. + * @closid: closid that matches the rmid. + * @rmid: Reclaim the rmid specified. + */ +void resctrl_arch_rmid_reclaim(u32 closid, u32 rmid); + 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); --=20 2.25.1 From nobody Thu Jun 11 17:32:14 2026 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA4F63AE1A0 for ; Mon, 13 Apr 2026 08:54:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070465; cv=none; b=efGrxGb6VB57P+w8dhIImmQrJUOw+dFWsHAPsAedbwwpKD+WSog40YV2PdWOgpACE+SyBjq0YzqgAng5AD7H3kVGqJfdvJQ3mknFvkjBV/Ws0XnixHpT2Qa5gp8e9GZB2mkCo/0eYq+/SM/86W781eJo5dct5+Y1XQvilISCTJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070465; c=relaxed/simple; bh=iPAZyGqQDgqC6JbO2TmiAxkycoPuWJ2V8s9HW2XN6AM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZSyccxgkuHCINkcWqtaiRHy9q1rSRRhxBpbRVLVgHk1FwY70wmMxuy12yQMZZMN+tecr73ZM3gt9xkE1lbmjQQghGbTidK52ZkgH+aZSCTkCAvsL5LrHmPgB7EL9dDme2DV5mtIaxmDQCwzB9nmpA9ztCRl6/ieY9w4TL1ZpaSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=cSgw0M84; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="cSgw0M84" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=yw+HF7RpwhnK0fVJzlDYt8d8/CD4wE+/irYw9MBaZMo=; b=cSgw0M84Ss+O8CGToZbwz/5wVzN23c1/ickwDFelK5Kwe9FW7vVp0D4adfGQoxXE3W7p6smt9 H4qMnKieZgcsLU5ys3BSfGFLKP1K1aJdlPDpWivqW5lbFuan/U+GMvWdMOvnLOsCZ1iv5mACUds ZTyzfaY+FevczLqHOX3kKxw= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4fvLdw0J6xzLlSv; Mon, 13 Apr 2026 16:48:04 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id 5B1EF40565; Mon, 13 Apr 2026 16:54:20 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:19 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 09/10] fs/resctrl: Wire up rmid expansion and reclaim functions Date: Mon, 13 Apr 2026 16:54:04 +0800 Message-ID: <20260413085405.1166412-10-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) Content-Type: text/plain; charset="utf-8" The previous patch implemented resctrl_arch_rmid_expand() and resctrl_arch_rmid_reclaim() for ARM MPAM. This patch integrates these architecture-specific functions into the generic resctrl layer. Refactor resctrl_find_free_rmid() to support dynamic rmid expansion. If no free rmid is available for the current closid, attempt to expand via resctrl_arch_expand_rmid(). On success, retry the rmid allocation. As this capability is architecture-specific, x86 maintains its existing behavior by returning -ENOSPC when rmid resources are exhausted. Additionally, invoke resctrl_arch_rmid_reclaim() when rmids are released to enable architecture-specific resource cleanup. Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- arch/x86/include/asm/resctrl.h | 7 +++++++ fs/resctrl/monitor.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index 575f8408a9e7..7f8c8d84f2a0 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -167,6 +167,13 @@ static inline void resctrl_arch_sched_in(struct task_s= truct *tsk) __resctrl_sched_in(tsk); } =20 +static inline int resctrl_arch_rmid_expand(u32 closid) +{ + return -ENOSPC; +} + +static inline void resctrl_arch_rmid_reclaim(u32 closid, u32 rmid) {} + static inline void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 = *rmid) { *rmid =3D idx; diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 7473c43600cf..3ac86995278e 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -122,6 +122,8 @@ static void limbo_release_entry(struct rmid_entry *entr= y) =20 if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) closid_num_dirty_rmid[entry->closid]--; + + resctrl_arch_rmid_reclaim(entry->closid, entry->rmid); } =20 /* @@ -197,7 +199,7 @@ bool has_busy_rmid(struct rdt_l3_mon_domain *d) return find_first_bit(d->rmid_busy_llc, idx_limit) !=3D idx_limit; } =20 -static struct rmid_entry *resctrl_find_free_rmid(u32 closid) +static struct rmid_entry *__resctrl_find_free_rmid(u32 closid) { struct rmid_entry *itr; u32 itr_idx, cmp_idx; @@ -214,7 +216,12 @@ static struct rmid_entry *resctrl_find_free_rmid(u32 c= losid) * very first entry will be returned. */ itr_idx =3D resctrl_arch_rmid_idx_encode(itr->closid, itr->rmid); + if (itr_idx =3D=3D U32_MAX) + continue; + cmp_idx =3D resctrl_arch_rmid_idx_encode(closid, itr->rmid); + if (cmp_idx =3D=3D U32_MAX) + continue; =20 if (itr_idx =3D=3D cmp_idx) return itr; @@ -223,6 +230,25 @@ static struct rmid_entry *resctrl_find_free_rmid(u32 c= losid) return ERR_PTR(-ENOSPC); } =20 +static struct rmid_entry *resctrl_find_free_rmid(u32 closid) +{ + struct rmid_entry *err; + int ret; + + err =3D __resctrl_find_free_rmid(closid); + if (err =3D=3D ERR_PTR(-ENOSPC)) { + ret =3D resctrl_arch_rmid_expand(closid); + if (ret < 0) + /* Out of rmid */ + goto out; + + /* Try it again */ + return __resctrl_find_free_rmid(closid); + } +out: + return err; +} + /** * resctrl_find_cleanest_closid() - Find a CLOSID where all the associated * RMID are clean, or the CLOSID that has @@ -342,8 +368,10 @@ void free_rmid(u32 closid, u32 rmid) =20 if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) add_rmid_to_limbo(entry); - else + else { list_add_tail(&entry->list, &rmid_free_lru); + resctrl_arch_rmid_reclaim(closid, rmid); + } } =20 bool rmid_is_occupied(u32 closid, u32 rmid) --=20 2.25.1 From nobody Thu Jun 11 17:32:14 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77D473B2FF2 for ; Mon, 13 Apr 2026 08:54:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070473; cv=none; b=N0LvDiBg9sET3jjU/SXt4mBtDi10maL8L1MyLcUbhswZtmxPQ9ZXtOyrvk1rP8tTF4u788vMDi2C3gwiEtQ4wM5mnsbpItejNV3zZSWBhZV039JVsACjZq5IA3OboFHCvLD39R/iGQxaxGNVWiJe6aoIKcgUiBgsnOHh3sKd+h0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776070473; c=relaxed/simple; bh=yGQYbEzfYBPkTGpH7iK1j9hwF8ayOrtQxmPY6ysmX5Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NQ1ttM2/XG6UwL7Ig9NPh6UEhqfs1KUkztEJ3ERq+tbM0I4dBIpOLEqshuRr0ZsjYiYZ+OTIGkLL7eOUHo36O7JqBJI0UVEBbQBaO0ly56urPFlw1S3Q2AWK82QkIFITYDZLlsbnQXpRUm+EBqKKBG8M85+DvEG7Mij7Tk2BAZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=h-partners.com; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=DCtg40KZ; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b=DCtg40KZ; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=h-partners.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="DCtg40KZ"; dkim=pass (1024-bit key) header.d=h-partners.com header.i=@h-partners.com header.b="DCtg40KZ" dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=kKWzw0F9gxmnGXvNqVP7clmFxg02M0HiQi+0w4fA0i0=; b=DCtg40KZ+Zy2aQLVKqn2cVPslF43nPZUaEphC8UpP5Apw+g3xMSN8yzV6WZYvKnICwuAWHF4V faCtKrLSsJajr2uLAricj1BZflQ2KBptuDEmAmUhKGQbs4MyRd1g12MsydLMnrc3Yzt+RMkAdBT e5ZHKT3T8ipK0FlgkcqjAz4= Received: from canpmsgout03.his.huawei.com (unknown [172.19.92.159]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4fvLmc1v8nz1BG3K for ; Mon, 13 Apr 2026 16:53:52 +0800 (CST) dkim-signature: v=1; a=rsa-sha256; d=h-partners.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=kKWzw0F9gxmnGXvNqVP7clmFxg02M0HiQi+0w4fA0i0=; b=DCtg40KZ+Zy2aQLVKqn2cVPslF43nPZUaEphC8UpP5Apw+g3xMSN8yzV6WZYvKnICwuAWHF4V faCtKrLSsJajr2uLAricj1BZflQ2KBptuDEmAmUhKGQbs4MyRd1g12MsydLMnrc3Yzt+RMkAdBT e5ZHKT3T8ipK0FlgkcqjAz4= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4fvLf3690WzpSyb; Mon, 13 Apr 2026 16:48:11 +0800 (CST) Received: from kwepemf100008.china.huawei.com (unknown [7.202.181.222]) by mail.maildlp.com (Postfix) with ESMTPS id C51564048F; Mon, 13 Apr 2026 16:54:20 +0800 (CST) Received: from huawei.com (10.50.87.109) by kwepemf100008.china.huawei.com (7.202.181.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 13 Apr 2026 16:54:20 +0800 From: Zeng Heng To: , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH v8 next 10/10] arm_mpam: Add mpam_sync_config() for dynamic rmid expansion Date: Mon, 13 Apr 2026 16:54:05 +0800 Message-ID: <20260413085405.1166412-11-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260413085405.1166412-1-zengheng4@huawei.com> References: <20260413085405.1166412-1-zengheng4@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemf100008.china.huawei.com (7.202.181.222) Content-Type: text/plain; charset="utf-8" Add mpam_sync_config() to synchronize configuration when dynamically expanding rmid resources. When binding a new reqpartid to a control group, the driver maps the reqpartid to the corresponding intpartid or applies the control group's existing configuration to new partid if without Narrow-PARTID feature. Extend mpam_apply_config() with the 'sync' work mode: * Sync mode: mpam_sync_config() calls this to apply existing configuration without updating config. * Update (non-sync) mode: resctrl_arch_update_one() calls this to compare, update, and apply configuration. This mode retains the original behavior. Signed-off-by: Zeng Heng Tested-by: Zeng Heng --- drivers/resctrl/mpam_devices.c | 23 ++++++++++++++++++----- drivers/resctrl/mpam_internal.h | 2 +- drivers/resctrl/mpam_resctrl.c | 29 ++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c index cf94b45b4f9e..47345b8add3c 100644 --- a/drivers/resctrl/mpam_devices.c +++ b/drivers/resctrl/mpam_devices.c @@ -1762,6 +1762,7 @@ struct mpam_write_config_arg { struct mpam_msc_ris *ris; struct mpam_component *comp; u16 partid; + bool sync; }; =20 static int __write_config(void *arg) @@ -1770,6 +1771,15 @@ static int __write_config(void *arg) struct mpam_write_config_arg *c =3D arg; u32 reqpartid; =20 + if (c->sync) { + /* c->partid should be within the range of reqPARTIDs */ + WARN_ON_ONCE(c->partid < closid_num); + + mpam_reprogram_ris_partid(c->ris, c->partid, + &c->comp->cfg[req2intpartid(c->partid)]); + return 0; + } + /* c->partid should be within the range of intPARTIDs */ WARN_ON_ONCE(c->partid >=3D closid_num); =20 @@ -2942,7 +2952,7 @@ static bool mpam_update_config(struct mpam_config *cf= g, } =20 int mpam_apply_config(struct mpam_component *comp, u16 partid, - struct mpam_config *cfg) + struct mpam_config *cfg, bool sync) { struct mpam_write_config_arg arg; struct mpam_msc_ris *ris; @@ -2951,14 +2961,17 @@ int mpam_apply_config(struct mpam_component *comp, = u16 partid, =20 lockdep_assert_cpus_held(); =20 - /* Don't pass in the current config! */ - WARN_ON_ONCE(&comp->cfg[partid] =3D=3D cfg); + if (!sync) { + /* The partid is within the range of intPARTIDs */ + WARN_ON_ONCE(partid >=3D resctrl_arch_get_num_closid(NULL)); =20 - if (!mpam_update_config(&comp->cfg[partid], cfg)) - return 0; + if (!mpam_update_config(&comp->cfg[partid], cfg)) + return 0; + } =20 arg.comp =3D comp; arg.partid =3D partid; + arg.sync =3D sync; =20 guard(srcu)(&mpam_srcu); list_for_each_entry_srcu(vmsc, &comp->vmsc, comp_list, diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_interna= l.h index 16ce968344d0..90c8f8d16c79 100644 --- a/drivers/resctrl/mpam_internal.h +++ b/drivers/resctrl/mpam_internal.h @@ -464,7 +464,7 @@ void mpam_disable(struct work_struct *work); void mpam_reset_class_locked(struct mpam_class *class); =20 int mpam_apply_config(struct mpam_component *comp, u16 partid, - struct mpam_config *cfg); + struct mpam_config *cfg, bool sync); =20 int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx, enum mpam_device_features, u64 *val); diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 2762462d80e5..5a97a7f18670 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -1329,15 +1329,15 @@ int resctrl_arch_update_one(struct rdt_resource *r,= struct rdt_ctrl_domain *d, */ if (mpam_resctrl_hide_cdp(r->rid)) { partid =3D resctrl_get_config_index(closid, CDP_CODE); - err =3D mpam_apply_config(dom->ctrl_comp, partid, &cfg); + err =3D mpam_apply_config(dom->ctrl_comp, partid, &cfg, false); if (err) return err; =20 partid =3D resctrl_get_config_index(closid, CDP_DATA); - return mpam_apply_config(dom->ctrl_comp, partid, &cfg); + return mpam_apply_config(dom->ctrl_comp, partid, &cfg, false); } =20 - return mpam_apply_config(dom->ctrl_comp, partid, &cfg); + return mpam_apply_config(dom->ctrl_comp, partid, &cfg, false); } =20 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) @@ -1718,6 +1718,23 @@ static void update_rmid_entries_for_reqpartid(u32 re= qpartid) rmid_entry_reassign_closid(closid, req_pmg2rmid(reqpartid, pmg)); } =20 +static int mpam_sync_config(u32 reqpartid) +{ + struct mpam_component *comp; + struct mpam_class *class; + int err; + + list_for_each_entry(class, &mpam_classes, classes_list) { + list_for_each_entry(comp, &class->components, class_list) { + err =3D mpam_apply_config(comp, reqpartid, NULL, true); + if (err) + return err; + } + } + + return 0; +} + int resctrl_arch_rmid_expand(u32 closid) { int i; @@ -1729,14 +1746,20 @@ int resctrl_arch_rmid_expand(u32 closid) if (reqpartid_map[i] >=3D resctrl_arch_get_num_closid(NULL)) { if (cdp_enabled) { reqpartid_map[i] =3D resctrl_get_config_index(closid, CDP_DATA); + mpam_sync_config(i); + /* * Reqpartids are always allocated in * pairs, never out-of-bounds access. */ reqpartid_map[i + 1] =3D resctrl_get_config_index(closid, CDP_CODE); + mpam_sync_config(i + 1); + } else { reqpartid_map[i] =3D resctrl_get_config_index(closid, CDP_NONE); + mpam_sync_config(i); } + update_rmid_entries_for_reqpartid(i); return i; } --=20 2.25.1