From nobody Tue Feb 10 04:03:07 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ADD7837881C; Tue, 3 Feb 2026 21:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770155159; cv=none; b=D01TbO5N7yMrs1txG82dxOM2SseJvMIYocvwJ1DcSnbQj9yaTSYk2E1X+emVSd5qoqgwWBpDwWvDeT2XqJg3qy0LkORJwTKA54Q2B0Rm4AHS93p/+A+CZ4Yc8l0bVflwa6IC/tJ0tjVvyK1N/5822q019Ht2rK1RKJ631cV3e5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770155159; c=relaxed/simple; bh=mpjZsxraFB8kPx8lDe2up6Llteda/H7a2ubV/Y+U10Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MdczZdMflgWhEOzkUfj5bzSme0QlOEj1/4uH6RpCBs8ua1VY5tugV9kxZ1l9TceDB/BHx39rqrAyNfaj+ZE5m/24j8udQROOmRnCE7WJVdB48vUukiL0deAjE4vP+RX2fkVWrzxCxuz2CpEr71UMmgRp1X+VuRh49bHLrze6dxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E4F76497; Tue, 3 Feb 2026 13:45:50 -0800 (PST) Received: from e134344.cambridge.arm.com (e134344.arm.com [10.1.196.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 982393F778; Tue, 3 Feb 2026 13:45:51 -0800 (PST) From: Ben Horgan To: ben.horgan@arm.com Cc: amitsinght@marvell.com, baisheng.gao@unisoc.com, baolin.wang@linux.alibaba.com, carl@os.amperecomputing.com, dave.martin@arm.com, david@kernel.org, dfustini@baylibre.com, fenghuay@nvidia.com, gshan@redhat.com, james.morse@arm.com, jonathan.cameron@huawei.com, kobak@nvidia.com, lcherian@marvell.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, peternewman@google.com, punit.agrawal@oss.qualcomm.com, quic_jiles@quicinc.com, reinette.chatre@intel.com, rohit.mathew@arm.com, scott@os.amperecomputing.com, sdonthineni@nvidia.com, tan.shaopeng@fujitsu.com, xhao@linux.alibaba.com, catalin.marinas@arm.com, will@kernel.org, corbet@lwn.net, maz@kernel.org, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, kvmarm@lists.linux.dev, zengheng4@huawei.com, linux-doc@vger.kernel.org, Shaopeng Tan , Dave Martin Subject: [PATCH v4 20/41] arm_mpam: resctrl: Add CDP emulation Date: Tue, 3 Feb 2026 21:43:21 +0000 Message-ID: <20260203214342.584712-21-ben.horgan@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260203214342.584712-1-ben.horgan@arm.com> References: <20260203214342.584712-1-ben.horgan@arm.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 Content-Type: text/plain; charset="utf-8" From: James Morse Intel RDT's CDP feature allows the cache to use a different control value depending on whether the accesses was for instruction fetch or a data access. MPAM's equivalent feature is the other way up: the CPU assigns a different partid label to traffic depending on whether it was instruction fetch or a data access, which causes the cache to use a different control value based solely on the partid. MPAM can emulate CDP, with the side effect that the alternative partid is seen by all MSC, it can't be enabled per-MSC. Add the resctrl hooks to turn this on or off. Add the helpers that match a closid against a task, which need to be aware that the value written to hardware is not the same as the one resctrl is using. Update the 'arm64_mpam_global_default' variable the arch code uses during context switch to know when the per-cpu value should be used instead. Also, update these per-cpu values and sync the resulting mpam partid/pmg configuration to hardware. Awkwardly, the MB controls don't implement CDP. To emulate this, the MPAM equivalent needs programming twice by the resctrl glue, as resctrl expects the bandwidth controls to be applied independently for both data and instruction-fetch. Tested-by: Gavin Shan Tested-by: Shaopeng Tan Tested-by: Peter Newman CC: Dave Martin CC: Amit Singh Tomar Reviewed-by: Jonathan Cameron Signed-off-by: James Morse Signed-off-by: Ben Horgan --- Changes since rfc: Fail cdp initialisation if there is only one partid Correct data/code confusion Changes since v2: Don't include unused header Changes since v3: Update the per-cpu values and sync to h/w --- arch/arm64/include/asm/mpam.h | 1 + drivers/resctrl/mpam_resctrl.c | 117 +++++++++++++++++++++++++++++++++ include/linux/arm_mpam.h | 2 + 3 files changed, 120 insertions(+) diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h index 05aa71200f61..70d396e7b6da 100644 --- a/arch/arm64/include/asm/mpam.h +++ b/arch/arm64/include/asm/mpam.h @@ -4,6 +4,7 @@ #ifndef __ASM__MPAM_H #define __ASM__MPAM_H =20 +#include #include #include #include diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index cd52ca279651..12017264530a 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -38,6 +38,10 @@ static DEFINE_MUTEX(domain_list_lock); static bool exposed_alloc_capable; static bool exposed_mon_capable; =20 +/* + * MPAM emulates CDP by setting different PARTID in the I/D fields of MPAM= 0_EL1. + * This applies globally to all traffic the CPU generates. + */ static bool cdp_enabled; =20 bool resctrl_arch_alloc_capable(void) @@ -50,6 +54,72 @@ bool resctrl_arch_mon_capable(void) return exposed_mon_capable; } =20 +bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level rid) +{ + switch (rid) { + case RDT_RESOURCE_L2: + case RDT_RESOURCE_L3: + return cdp_enabled; + case RDT_RESOURCE_MBA: + default: + /* + * x86's MBA control doesn't support CDP, so user-space doesn't + * expect it. + */ + return false; + } +} + +/** + * resctrl_reset_task_closids() - Reset the PARTID/PMG values for all task= s. + * + * At boot, all existing tasks use partid zero for D and I. + * To enable/disable CDP emulation, all these tasks need relabelling. + */ +static void resctrl_reset_task_closids(void) +{ + struct task_struct *p, *t; + + read_lock(&tasklist_lock); + for_each_process_thread(p, t) { + resctrl_arch_set_closid_rmid(t, RESCTRL_RESERVED_CLOSID, + RESCTRL_RESERVED_RMID); + } + read_unlock(&tasklist_lock); +} + +int resctrl_arch_set_cdp_enabled(enum resctrl_res_level ignored, bool enab= le) +{ + u32 partid_i =3D RESCTRL_RESERVED_CLOSID, partid_d =3D RESCTRL_RESERVED_C= LOSID; + int cpu; + + cdp_enabled =3D enable; + + if (enable) { + if (mpam_partid_max < 1) + return -EINVAL; + + partid_d =3D resctrl_get_config_index(RESCTRL_RESERVED_CLOSID, CDP_DATA); + partid_i =3D resctrl_get_config_index(RESCTRL_RESERVED_CLOSID, CDP_CODE); + } + + mpam_set_task_partid_pmg(current, partid_d, partid_i, 0, 0); + WRITE_ONCE(arm64_mpam_global_default, mpam_get_regval(current)); + + resctrl_reset_task_closids(); + + for_each_possible_cpu(cpu) + mpam_set_cpu_defaults(cpu, partid_d, partid_i, 0, 0); + on_each_cpu(resctrl_arch_sync_cpu_closid_rmid, NULL, 1); + + return 0; +} + +static bool mpam_resctrl_hide_cdp(enum resctrl_res_level rid) +{ + return cdp_enabled && !resctrl_arch_get_cdp_enabled(rid); +} + /* * MSC may raise an error interrupt if it sees an out or range partid/pmg, * and go on to truncate the value. Regardless of what the hardware suppor= ts, @@ -115,6 +185,30 @@ void resctrl_arch_set_closid_rmid(struct task_struct *= tsk, u32 closid, u32 rmid) } } =20 +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); + + if (cdp_enabled) + tsk_closid >>=3D 1; + + return tsk_closid =3D=3D closid; +} + +/* The task's pmg is not unique, the partid must be considered too */ +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; + + return (tsk_closid =3D=3D closid) && (tsk_rmid =3D=3D rmid); +} + struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l) { if (l >=3D RDT_NUM_RESOURCES) @@ -246,6 +340,14 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, st= ruct rdt_ctrl_domain *d, dom =3D container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom); cprops =3D &res->class->props; =20 + /* + * When CDP is enabled, but the resource doesn't support it, + * the control is cloned across both partids. + * Pick one at random to read: + */ + if (mpam_resctrl_hide_cdp(r->rid)) + type =3D CDP_DATA; + partid =3D resctrl_get_config_index(closid, type); cfg =3D &dom->ctrl_comp->cfg[partid]; =20 @@ -273,6 +375,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, str= uct rdt_ctrl_domain *d, int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain= *d, u32 closid, enum resctrl_conf_type t, u32 cfg_val) { + int err; u32 partid; struct mpam_config cfg; struct mpam_props *cprops; @@ -312,6 +415,20 @@ int resctrl_arch_update_one(struct rdt_resource *r, st= ruct rdt_ctrl_domain *d, return -EINVAL; } =20 + /* + * When CDP is enabled, but the resource doesn't support it, we need to + * apply the same configuration to the other partid. + */ + 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); + if (err) + return err; + + 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); } =20 diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h index 5a78299ec464..d329b1dc148b 100644 --- a/include/linux/arm_mpam.h +++ b/include/linux/arm_mpam.h @@ -56,6 +56,8 @@ void resctrl_arch_set_cpu_default_closid(int cpu, u32 clo= sid); void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32= rmid); void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmi= d); 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= ); =20 /** * mpam_register_requestor() - Register a requestor with the MPAM driver --=20 2.43.0