Skip to content

Commit 34cddad

Browse files
James MorseMingcongBai
authored andcommitted
BACKPORT: OPENEULER: arm64: cpufeature: discover CPU support for MPAM
maillist inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8T2RT Reference: https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/log/?h=mpam/snapshot/v6.7-rc2 --------------------------- ARMv8.4 adds support for 'Memory Partitioning And Monitoring' (MPAM) which describes an interface to cache and bandwidth controls wherever they appear in the system. Add support to detect MPAM. Like SVE, MPAM has an extra id register that describes the virtualisation support, which is optional. Detect this separately so we can detect mismatched/insane systems, but still use MPAM on the host even if the virtualisation support is missing. MPAM needs enabling at the highest implemented exception level, otherwise the register accesses trap. The 'enabled' flag is accessible to lower exception levels, but its in a register that traps when MPAM isn't enabled. The cpufeature 'matches' hook is extended to test this on one of the CPUs, so that firwmare can emulate MPAM as disabled if it is reserved for use by secure world. (If you have a boot failure that bisects here its likely your CPUs advertise MPAM in the id registers, but firmware failed to either enable or MPAM, or emulate the trap as if it were disabled) Signed-off-by: James Morse <[email protected]> Signed-off-by: Zeng Heng <[email protected]> Link: https://gitee.com/openeuler/kernel/commit/21771eaaf93a7c5212106412b00d97e8d083b5a1 [Kexy: Resolved minor conflict in arch/arm64/kernel/cpufeature.c, dropped changes in arch/arm64/Kconfig, arch/arm64/include/asm/cpufeature.h, arch/arm64/include/asm/sysreg.h, arch/arm64/kernel/Makefile, arch/arm64/kernel/cpuinfo.c, arch/arm64/kernel/mpam.c, arch/arm64/tools/cpucaps, and arch/arm64/tools/sysreg] Signed-off-by: Kexy Biscuit <[email protected]>
1 parent 613163b commit 34cddad

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

arch/arm64/include/asm/mpam.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (C) 2021 Arm Ltd. */
3+
4+
#ifndef __ASM__MPAM_H
5+
#define __ASM__MPAM_H
6+
7+
#include <linux/bitops.h>
8+
#include <linux/init.h>
9+
#include <linux/jump_label.h>
10+
11+
#include <asm/cpucaps.h>
12+
#include <asm/cpufeature.h>
13+
#include <asm/sysreg.h>
14+
15+
/* CPU Registers */
16+
#define MPAM_SYSREG_EN BIT_ULL(63)
17+
#define MPAM_SYSREG_TRAP_IDR BIT_ULL(58)
18+
#define MPAM_SYSREG_TRAP_MPAM0_EL1 BIT_ULL(49)
19+
#define MPAM_SYSREG_TRAP_MPAM1_EL1 BIT_ULL(48)
20+
#define MPAM_SYSREG_PMG_D GENMASK(47, 40)
21+
#define MPAM_SYSREG_PMG_I GENMASK(39, 32)
22+
#define MPAM_SYSREG_PARTID_D GENMASK(31, 16)
23+
#define MPAM_SYSREG_PARTID_I GENMASK(15, 0)
24+
25+
#define MPAMIDR_PMG_MAX GENMASK(40, 32)
26+
#define MPAMIDR_PMG_MAX_SHIFT 32
27+
#define MPAMIDR_PMG_MAX_LEN 8
28+
#define MPAMIDR_VPMR_MAX GENMASK(20, 18)
29+
#define MPAMIDR_VPMR_MAX_SHIFT 18
30+
#define MPAMIDR_VPMR_MAX_LEN 3
31+
#define MPAMIDR_HAS_HCR BIT(17)
32+
#define MPAMIDR_HAS_HCR_SHIFT 17
33+
#define MPAMIDR_PARTID_MAX GENMASK(15, 0)
34+
#define MPAMIDR_PARTID_MAX_SHIFT 0
35+
#define MPAMIDR_PARTID_MAX_LEN 15
36+
37+
#define MPAMHCR_EL0_VPMEN BIT_ULL(0)
38+
#define MPAMHCR_EL1_VPMEN BIT_ULL(1)
39+
#define MPAMHCR_GSTAPP_PLK BIT_ULL(8)
40+
#define MPAMHCR_TRAP_MPAMIDR BIT_ULL(31)
41+
42+
/* Properties of the VPM registers */
43+
#define MPAM_VPM_NUM_REGS 8
44+
#define MPAM_VPM_PARTID_LEN 16
45+
#define MPAM_VPM_PARTID_MASK 0xffff
46+
#define MPAM_VPM_REG_LEN 64
47+
#define MPAM_VPM_PARTIDS_PER_REG (MPAM_VPM_REG_LEN / MPAM_VPM_PARTID_LEN)
48+
#define MPAM_VPM_MAX_PARTID (MPAM_VPM_NUM_REGS * MPAM_VPM_PARTIDS_PER_REG)
49+
50+
51+
DECLARE_STATIC_KEY_FALSE(arm64_mpam_has_hcr);
52+
53+
/* check whether all CPUs have MPAM support */
54+
static inline bool mpam_cpus_have_feature(void)
55+
{
56+
if (IS_ENABLED(CONFIG_ARM64_MPAM))
57+
return cpus_have_final_cap(ARM64_MPAM);
58+
return false;
59+
}
60+
61+
/* check whether all CPUs have MPAM virtualisation support */
62+
static inline bool mpam_cpus_have_mpam_hcr(void)
63+
{
64+
if (IS_ENABLED(CONFIG_ARM64_MPAM))
65+
return static_branch_unlikely(&arm64_mpam_has_hcr);
66+
return false;
67+
}
68+
69+
/* enable MPAM virtualisation support */
70+
static inline void __init __enable_mpam_hcr(void)
71+
{
72+
if (IS_ENABLED(CONFIG_ARM64_MPAM))
73+
static_branch_enable(&arm64_mpam_has_hcr);
74+
}
75+
76+
#endif /* __ASM__MPAM_H */

arch/arm64/kernel/cpufeature.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include <asm/insn.h>
8686
#include <asm/kvm_host.h>
8787
#include <asm/mmu_context.h>
88+
#include <asm/mpam.h>
8889
#include <asm/mte.h>
8990
#include <asm/processor.h>
9091
#include <asm/smp.h>

0 commit comments

Comments
 (0)