Skip to content

Commit 2cf9ca3

Browse files
author
James Morse
committed
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. Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com> Tested-by: Jesse Chick <jessechick@os.amperecomputing.com> Cc: Dave Martin <Dave.Martin@arm.com> Reviewed-by: Zeng Heng <zengheng4@huawei.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Co-developed-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: James Morse <james.morse@arm.com>
1 parent 37fe0f9 commit 2cf9ca3

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

arch/arm64/include/asm/mpam.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef __ASM__MPAM_H
55
#define __ASM__MPAM_H
66

7+
#include <linux/bitfield.h>
78
#include <linux/jump_label.h>
89
#include <linux/percpu.h>
910
#include <linux/sched.h>
@@ -22,6 +23,23 @@ DECLARE_PER_CPU(u64, arm64_mpam_current);
2223
*/
2324
extern u64 arm64_mpam_global_default;
2425

26+
#ifdef CONFIG_ARM64_MPAM
27+
static inline u64 __mpam_regval(u16 partid_d, u16 partid_i, u8 pmg_d, u8 pmg_i)
28+
{
29+
return FIELD_PREP(MPAM0_EL1_PARTID_D, partid_d) |
30+
FIELD_PREP(MPAM0_EL1_PARTID_I, partid_i) |
31+
FIELD_PREP(MPAM0_EL1_PMG_D, pmg_d) |
32+
FIELD_PREP(MPAM0_EL1_PMG_I, pmg_i);
33+
}
34+
35+
static inline void mpam_set_cpu_defaults(int cpu, u16 partid_d, u16 partid_i,
36+
u8 pmg_d, u8 pmg_i)
37+
{
38+
u64 default_val = __mpam_regval(partid_d, partid_i, pmg_d, pmg_i);
39+
40+
WRITE_ONCE(per_cpu(arm64_mpam_default, cpu), default_val);
41+
}
42+
2543
/*
2644
* The resctrl filesystem writes to the partid/pmg values for threads and CPUs,
2745
* which may race with reads in mpam_thread_switch(). Ensure only one of the old
@@ -30,12 +48,20 @@ extern u64 arm64_mpam_global_default;
3048
* value to be stored with cache allocations, despite being considered 'free' by
3149
* resctrl.
3250
*/
33-
#ifdef CONFIG_ARM64_MPAM
3451
static inline u64 mpam_get_regval(struct task_struct *tsk)
3552
{
3653
return READ_ONCE(task_thread_info(tsk)->mpam_partid_pmg);
3754
}
3855

56+
static inline void mpam_set_task_partid_pmg(struct task_struct *tsk,
57+
u16 partid_d, u16 partid_i,
58+
u8 pmg_d, u8 pmg_i)
59+
{
60+
u64 regval = __mpam_regval(partid_d, partid_i, pmg_d, pmg_i);
61+
62+
WRITE_ONCE(task_thread_info(tsk)->mpam_partid_pmg, regval);
63+
}
64+
3965
static inline void mpam_thread_switch(struct task_struct *tsk)
4066
{
4167
u64 oldregval;

0 commit comments

Comments
 (0)