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 7ECA9325727 for ; Fri, 19 Dec 2025 11:56:28 +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=1766145390; cv=none; b=oFvuWZVHfasMJ4jE0K28cn6RkYOwHcxH/Ws9V0+SK/8m/VXyara5Nnz6x+8nAAfHmkpEzU1Y7kSKIKg8mWFn6DrpX+cwqNmgaUB/VInnI8Lae18MvNwp97PlToNRXXKzsMsk5l5oBCG83GRomyXV+TQVDDyEF3+1lZxUUB1EcKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766145390; c=relaxed/simple; bh=BbBwRZM6mDSow/t2pB5BFrWMxcORxp6B89hbYuVG/UU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=D925pzM/Lbe20SiopzcvAW8fbVx7JpgQOud6JG5HNTOV1+qQJDduLVejsZqHt+6cVsp+RJa9j7KfOk4qejyAujFhJ5tZxrMF33KZFqSki5vysqO4fu6gT7UifgRGXfLEltMED6KcrostmiaADcCD1B9NdxhBqznJkfpNHRjOVTs= 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 1D44DFEC; Fri, 19 Dec 2025 03:56:15 -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 DF2FC3F5CA; Fri, 19 Dec 2025 03:56:18 -0800 (PST) Message-ID: Date: Fri, 19 Dec 2025 11:56:17 +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 05/38] arm64: mpam: Add helpers to change a task or cpu's MPAM PARTID/PMG values To: Jonathan Cameron , James Morse Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, 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, Gavin Shan , rohit.mathew@arm.com, reinette.chatre@intel.com, Punit Agrawal References: <20251205215901.17772-1-james.morse@arm.com> <20251205215901.17772-6-james.morse@arm.com> <20251218104433.00002196@huawei.com> From: Ben Horgan Content-Language: en-US In-Reply-To: <20251218104433.00002196@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Jonathan, On 12/18/25 10:44, Jonathan Cameron wrote: > On Fri, 5 Dec 2025 21:58:28 +0000 > James Morse wrote: > >> Care must be taken when modifying the PARTID and PMG of a task in any >> per-task structure as writing these values may race with the task being >> scheduled in, and reading the modified values. >> >> Add helpers to set the task properties, and the CPU default value. >> These use WRITE_ONCE() that pairs with the READ_ONCE() in mpam_get_regval() >> to avoid causing torn values. >> >> CC: Dave Martin >> CC: Ben Horgan >> Signed-off-by: James Morse >> --- >> arch/arm64/include/asm/mpam.h | 30 ++++++++++++++++++++++++++++++ >> 1 file changed, 30 insertions(+) >> >> diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h >> index 86a55176f884..2960ffaf6574 100644 >> --- a/arch/arm64/include/asm/mpam.h >> +++ b/arch/arm64/include/asm/mpam.h >> @@ -5,6 +5,7 @@ >> #define __ASM__MPAM_H >> >> #include >> +#include >> #include >> #include >> #include >> @@ -37,6 +38,35 @@ extern u64 arm64_mpam_global_default; >> * A value in struct thread_info is used instead of struct task_struct as the >> * cpu's u64 register format is used, but struct task_struct has two u32'. >> */ > I'd be tempted to reorder this so the comment ends up near at least > one use of task_thread_info(tsk)->mpam_partid_pmg. Otherwise it is even > less obvious what it is referring to. > > Easiest might be to put the mpam_get_regval() before the mpam_set_task_partid_pmg() Yes, this comment positioning was confusing. > > >> +static inline void mpam_set_cpu_defaults(int cpu, u16 partid_d, u16 partid_i, >> + u8 pmg_d, u8 pmg_i) >> +{ >> + u64 default_val; >> + >> + default_val = FIELD_PREP(MPAM0_EL1_PARTID_D, partid_d); >> + default_val |= FIELD_PREP(MPAM0_EL1_PARTID_I, partid_i); >> + default_val |= FIELD_PREP(MPAM0_EL1_PMG_D, pmg_d); >> + default_val |= FIELD_PREP(MPAM0_EL1_PMG_I, pmg_i); >> + >> + WRITE_ONCE(per_cpu(arm64_mpam_default, cpu), default_val); >> +} >> + >> +static inline void mpam_set_task_partid_pmg(struct task_struct *tsk, >> + u16 partid_d, u16 partid_i, >> + u8 pmg_d, u8 pmg_i) >> +{ >> +#ifdef CONFIG_ARM64_MPAM >> + u64 regval; >> + >> + regval = FIELD_PREP(MPAM0_EL1_PARTID_D, partid_d); >> + regval |= FIELD_PREP(MPAM0_EL1_PARTID_I, partid_i); >> + regval |= FIELD_PREP(MPAM0_EL1_PMG_D, pmg_d); >> + regval |= FIELD_PREP(MPAM0_EL1_PMG_I, pmg_i); > > Maybe a macro or helper to build regval given this replicates the block in > mpam_set_cpu_defaults. Obviously ignore if this changes in later patches! I've added a helper. > >> + >> + WRITE_ONCE(task_thread_info(tsk)->mpam_partid_pmg, regval); >> +#endif >> +} >> + >> static inline u64 mpam_get_regval(struct task_struct *tsk) >> { >> #ifdef CONFIG_ARM64_MPAM > Thanks, Ben