[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251205215901.17772-6-james.morse@arm.com>
Date: Fri, 5 Dec 2025 21:58:28 +0000
From: James Morse <james.morse@....com>
To: linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org
Cc: James Morse <james.morse@....com>,
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,
Jonathan Cameron <jonathan.cameron@...wei.com>,
Gavin Shan <gshan@...hat.com>,
Ben Horgan <ben.horgan@....com>,
rohit.mathew@....com,
reinette.chatre@...el.com,
Punit Agrawal <punit.agrawal@....qualcomm.com>,
Dave Martin <Dave.Martin@....com>
Subject: [RFC PATCH 05/38] arm64: mpam: Add helpers to change a task or cpu's MPAM PARTID/PMG values
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'.
*/
+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);
+
+ 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
--
2.39.5
Powered by blists - more mailing lists