From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0782C34B187 for ; Tue, 16 Dec 2025 14:24:51 +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=1765895094; cv=none; b=jHlg7+bnOIgb5+CCg6CGHdKTZ5fjVa0sczjFmQA5mm7fOzN6Zi9oadsaHgn6Vl7RlSwm4NL3016zX4gY4Ar5mo3O3cXRkfJxOmCY5/iZC/Qqg51J8PMrODrMYudqyqJ/TIV7h8UaWX8SLFZj+tRztpjabX4AejJ0KZnrtNg+6qY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765895094; c=relaxed/simple; bh=q2Cj1+ekvJ5ds8ypdP6VDKEC3px75rPG/jweksQpDCE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oWIl5Kn+z5KkWNpbSWvBcB2yFcqAWrjA7s2DADsM2NPEgV9tzqj7tmLZszgnPORzhy9GaN0dndtRqtFWASG5sTLRIy/PiCPf5HzAX3yxvfMz5oHx9nfKb1kScW6uA14KDWcE8fSmH6oXlFyzP9pL0Yb3LRzY31Qz9cX5xdjZm9U= 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 15AAEFEC; Tue, 16 Dec 2025 06:24:44 -0800 (PST) Received: from [10.1.196.46] (e134344.arm.com [10.1.196.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E48A13F694; Tue, 16 Dec 2025 06:24:47 -0800 (PST) Message-ID: <16b5063a-1201-4453-8038-4ef937d20abd@arm.com> Date: Tue, 16 Dec 2025 14:24:46 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 13/38] arm_mpam: resctrl: Add CDP emulation To: James Morse , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Dave Martin , Koba Ko , Shanker Donthineni , fenghuay@nvidia.com, baisheng.gao@unisoc.com, Jonathan Cameron , Gavin Shan , rohit.mathew@arm.com, reinette.chatre@intel.com, Punit Agrawal References: <20251205215901.17772-1-james.morse@arm.com> <20251205215901.17772-14-james.morse@arm.com> From: Ben Horgan Content-Language: en-US In-Reply-To: <20251205215901.17772-14-james.morse@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi James, On 12/5/25 21:58, James Morse wrote: > 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. > > 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 isntruction-fetch. > > CC: Dave Martin > CC: Ben Horgan > CC: Amit Singh Tomar > Signed-off-by: James Morse > --- > arch/arm64/include/asm/mpam.h | 1 + > drivers/resctrl/mpam_resctrl.c | 115 ++++++++++++++++++++++++++++++++- > include/linux/arm_mpam.h | 3 + > 3 files changed, 118 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h > index 2960ffaf6574..689285c4c61f 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 > > +#include > #include > #include > #include > diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c > index c2650abb99ec..d5f75ed67e46 100644 > --- a/drivers/resctrl/mpam_resctrl.c > +++ b/drivers/resctrl/mpam_resctrl.c > @@ -33,6 +33,10 @@ static DEFINE_MUTEX(domain_list_lock); > static bool exposed_alloc_capable; > static bool exposed_mon_capable; > > +/* > + * MPAM emulates CDP by setting different PARTID in the I/D fields of MPAM0_EL1. > + * This applies globally to all traffic the CPU generates. > + */ > static bool cdp_enabled; > > bool resctrl_arch_alloc_capable(void) > @@ -45,6 +49,67 @@ bool resctrl_arch_mon_capable(void) > return exposed_mon_capable; > } > > +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 tasks. > + * > + * 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 enable) > +{ > + u32 partid_i, partid_d; > + > + cdp_enabled = enable; > + partid_i = partid_d = RESCTRL_RESERVED_CLOSID; > + > + if (enable) { > + u32 partid = RESCTRL_RESERVED_CLOSID; > + > + partid_d = resctrl_get_config_index(partid, CDP_CODE); > + partid_i = resctrl_get_config_index(partid, CDP_DATA); These are back to front, partid_d is data and partid_i is code. Also, if there is only one partid then we don't have 2 different partids and we should fail to enable cdp. > + } > + > + 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(); > + > + return 0; > +} Thanks, Ben