lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251218104433.00002196@huawei.com>
Date: Thu, 18 Dec 2025 10:44:33 +0000
From: Jonathan Cameron <jonathan.cameron@...wei.com>
To: James Morse <james.morse@....com>
CC: <linux-kernel@...r.kernel.org>, <linux-arm-kernel@...ts.infradead.org>, D
 Scott Phillips OS <scott@...amperecomputing.com>,
	<carl@...amperecomputing.com>, <lcherian@...vell.com>,
	<bobo.shaobowang@...wei.com>, <tan.shaopeng@...itsu.com>,
	<baolin.wang@...ux.alibaba.com>, Jamie Iles <quic_jiles@...cinc.com>, "Xin
 Hao" <xhao@...ux.alibaba.com>, <peternewman@...gle.com>,
	<dfustini@...libre.com>, <amitsinght@...vell.com>, David Hildenbrand
	<david@...nel.org>, Dave Martin <dave.martin@....com>, Koba Ko
	<kobak@...dia.com>, Shanker Donthineni <sdonthineni@...dia.com>,
	<fenghuay@...dia.com>, <baisheng.gao@...soc.com>, Gavin Shan
	<gshan@...hat.com>, Ben Horgan <ben.horgan@....com>, <rohit.mathew@....com>,
	<reinette.chatre@...el.com>, Punit Agrawal <punit.agrawal@....qualcomm.com>
Subject: Re: [RFC PATCH 05/38] arm64: mpam: Add helpers to change a task or
 cpu's MPAM PARTID/PMG values

On Fri, 5 Dec 2025 21:58:28 +0000
James Morse <james.morse@....com> 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 <Dave.Martin@....com>
> CC: Ben Horgan <ben.horgan@....com>
> Signed-off-by: James Morse <james.morse@....com>
> ---
>  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 <linux/bitops.h>
> +#include <linux/bitfield.h>
>  #include <linux/init.h>
>  #include <linux/jump_label.h>
>  #include <linux/percpu.h>
> @@ -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()


> +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!

> +
> +	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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ