1 // SPDX-License-Identifier: GPL-2.0-only
3 * Contains CPU feature definitions
5 * Copyright (C) 2015 ARM Ltd.
8 #define pr_fmt(fmt) "CPU features: " fmt
10 #include <linux/bsearch.h>
11 #include <linux/cpumask.h>
12 #include <linux/crash_dump.h>
13 #include <linux/sort.h>
14 #include <linux/stop_machine.h>
15 #include <linux/types.h>
17 #include <linux/cpu.h>
19 #include <asm/cpufeature.h>
20 #include <asm/cpu_ops.h>
21 #include <asm/fpsimd.h>
22 #include <asm/mmu_context.h>
23 #include <asm/processor.h>
24 #include <asm/sysreg.h>
25 #include <asm/traps.h>
28 /* Kernel representation of AT_HWCAP and AT_HWCAP2 */
29 static unsigned long elf_hwcap __read_mostly
;
32 #define COMPAT_ELF_HWCAP_DEFAULT \
33 (COMPAT_HWCAP_HALF|COMPAT_HWCAP_THUMB|\
34 COMPAT_HWCAP_FAST_MULT|COMPAT_HWCAP_EDSP|\
35 COMPAT_HWCAP_TLS|COMPAT_HWCAP_IDIV|\
37 unsigned int compat_elf_hwcap __read_mostly
= COMPAT_ELF_HWCAP_DEFAULT
;
38 unsigned int compat_elf_hwcap2 __read_mostly
;
41 DECLARE_BITMAP(cpu_hwcaps
, ARM64_NCAPS
);
42 EXPORT_SYMBOL(cpu_hwcaps
);
43 static struct arm64_cpu_capabilities
const __ro_after_init
*cpu_hwcaps_ptrs
[ARM64_NCAPS
];
45 /* Need also bit for ARM64_CB_PATCH */
46 DECLARE_BITMAP(boot_capabilities
, ARM64_NPATCHABLE
);
48 bool arm64_use_ng_mappings
= false;
49 EXPORT_SYMBOL(arm64_use_ng_mappings
);
52 * Flag to indicate if we have computed the system wide
53 * capabilities based on the boot time active CPUs. This
54 * will be used to determine if a new booting CPU should
55 * go through the verification process to make sure that it
56 * supports the system capabilities, without using a hotplug
57 * notifier. This is also used to decide if we could use
58 * the fast path for checking constant CPU caps.
60 DEFINE_STATIC_KEY_FALSE(arm64_const_caps_ready
);
61 EXPORT_SYMBOL(arm64_const_caps_ready
);
62 static inline void finalize_system_capabilities(void)
64 static_branch_enable(&arm64_const_caps_ready
);
67 static int dump_cpu_hwcaps(struct notifier_block
*self
, unsigned long v
, void *p
)
69 /* file-wide pr_fmt adds "CPU features: " prefix */
70 pr_emerg("0x%*pb\n", ARM64_NCAPS
, &cpu_hwcaps
);
74 static struct notifier_block cpu_hwcaps_notifier
= {
75 .notifier_call
= dump_cpu_hwcaps
78 static int __init
register_cpu_hwcaps_dumper(void)
80 atomic_notifier_chain_register(&panic_notifier_list
,
81 &cpu_hwcaps_notifier
);
84 __initcall(register_cpu_hwcaps_dumper
);
86 DEFINE_STATIC_KEY_ARRAY_FALSE(cpu_hwcap_keys
, ARM64_NCAPS
);
87 EXPORT_SYMBOL(cpu_hwcap_keys
);
89 #define __ARM64_FTR_BITS(SIGNED, VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \
97 .safe_val = SAFE_VAL, \
100 /* Define a feature with unsigned values */
101 #define ARM64_FTR_BITS(VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \
102 __ARM64_FTR_BITS(FTR_UNSIGNED, VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL)
104 /* Define a feature with a signed value */
105 #define S_ARM64_FTR_BITS(VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \
106 __ARM64_FTR_BITS(FTR_SIGNED, VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL)
108 #define ARM64_FTR_END \
113 /* meta feature for alternatives */
114 static bool __maybe_unused
115 cpufeature_pan_not_uao(const struct arm64_cpu_capabilities
*entry
, int __unused
);
117 static void cpu_enable_cnp(struct arm64_cpu_capabilities
const *cap
);
120 * NOTE: Any changes to the visibility of features should be kept in
121 * sync with the documentation of the CPU feature register ABI.
123 static const struct arm64_ftr_bits ftr_id_aa64isar0
[] = {
124 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_RNDR_SHIFT
, 4, 0),
125 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_TS_SHIFT
, 4, 0),
126 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_FHM_SHIFT
, 4, 0),
127 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_DP_SHIFT
, 4, 0),
128 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_SM4_SHIFT
, 4, 0),
129 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_SM3_SHIFT
, 4, 0),
130 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_SHA3_SHIFT
, 4, 0),
131 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_RDM_SHIFT
, 4, 0),
132 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_ATOMICS_SHIFT
, 4, 0),
133 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_CRC32_SHIFT
, 4, 0),
134 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_SHA2_SHIFT
, 4, 0),
135 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_SHA1_SHIFT
, 4, 0),
136 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR0_AES_SHIFT
, 4, 0),
140 static const struct arm64_ftr_bits ftr_id_aa64isar1
[] = {
141 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_I8MM_SHIFT
, 4, 0),
142 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_DGH_SHIFT
, 4, 0),
143 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_BF16_SHIFT
, 4, 0),
144 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_SPECRES_SHIFT
, 4, 0),
145 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_SB_SHIFT
, 4, 0),
146 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_FRINTTS_SHIFT
, 4, 0),
147 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH
),
148 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_GPI_SHIFT
, 4, 0),
149 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH
),
150 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_GPA_SHIFT
, 4, 0),
151 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_LRCPC_SHIFT
, 4, 0),
152 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_FCMA_SHIFT
, 4, 0),
153 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_JSCVT_SHIFT
, 4, 0),
154 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH
),
155 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_API_SHIFT
, 4, 0),
156 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_PTR_AUTH
),
157 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_APA_SHIFT
, 4, 0),
158 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ISAR1_DPB_SHIFT
, 4, 0),
162 static const struct arm64_ftr_bits ftr_id_aa64pfr0
[] = {
163 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_CSV3_SHIFT
, 4, 0),
164 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_CSV2_SHIFT
, 4, 0),
165 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_DIT_SHIFT
, 4, 0),
166 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
167 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_SVE_SHIFT
, 4, 0),
168 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_RAS_SHIFT
, 4, 0),
169 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_GIC_SHIFT
, 4, 0),
170 S_ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_ASIMD_SHIFT
, 4, ID_AA64PFR0_ASIMD_NI
),
171 S_ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_FP_SHIFT
, 4, ID_AA64PFR0_FP_NI
),
172 /* Linux doesn't care about the EL3 */
173 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_EL3_SHIFT
, 4, 0),
174 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_EL2_SHIFT
, 4, 0),
175 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_EL1_SHIFT
, 4, ID_AA64PFR0_EL1_64BIT_ONLY
),
176 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR0_EL0_SHIFT
, 4, ID_AA64PFR0_EL0_64BIT_ONLY
),
180 static const struct arm64_ftr_bits ftr_id_aa64pfr1
[] = {
181 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64PFR1_SSBS_SHIFT
, 4, ID_AA64PFR1_SSBS_PSTATE_NI
),
185 static const struct arm64_ftr_bits ftr_id_aa64zfr0
[] = {
186 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
187 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ZFR0_F64MM_SHIFT
, 4, 0),
188 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
189 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ZFR0_F32MM_SHIFT
, 4, 0),
190 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
191 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ZFR0_I8MM_SHIFT
, 4, 0),
192 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
193 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ZFR0_SM4_SHIFT
, 4, 0),
194 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
195 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ZFR0_SHA3_SHIFT
, 4, 0),
196 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
197 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ZFR0_BF16_SHIFT
, 4, 0),
198 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
199 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ZFR0_BITPERM_SHIFT
, 4, 0),
200 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
201 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ZFR0_AES_SHIFT
, 4, 0),
202 ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE
),
203 FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64ZFR0_SVEVER_SHIFT
, 4, 0),
207 static const struct arm64_ftr_bits ftr_id_aa64mmfr0
[] = {
209 * We already refuse to boot CPUs that don't support our configured
210 * page size, so we can only detect mismatches for a page size other
211 * than the one we're currently using. Unfortunately, SoCs like this
212 * exist in the wild so, even though we don't like it, we'll have to go
213 * along with it and treat them as non-strict.
215 S_ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR0_TGRAN4_SHIFT
, 4, ID_AA64MMFR0_TGRAN4_NI
),
216 S_ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR0_TGRAN64_SHIFT
, 4, ID_AA64MMFR0_TGRAN64_NI
),
217 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR0_TGRAN16_SHIFT
, 4, ID_AA64MMFR0_TGRAN16_NI
),
219 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR0_BIGENDEL0_SHIFT
, 4, 0),
220 /* Linux shouldn't care about secure memory */
221 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR0_SNSMEM_SHIFT
, 4, 0),
222 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR0_BIGENDEL_SHIFT
, 4, 0),
223 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR0_ASID_SHIFT
, 4, 0),
225 * Differing PARange is fine as long as all peripherals and memory are mapped
226 * within the minimum PARange of all CPUs
228 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR0_PARANGE_SHIFT
, 4, 0),
232 static const struct arm64_ftr_bits ftr_id_aa64mmfr1
[] = {
233 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR1_PAN_SHIFT
, 4, 0),
234 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR1_LOR_SHIFT
, 4, 0),
235 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR1_HPD_SHIFT
, 4, 0),
236 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR1_VHE_SHIFT
, 4, 0),
237 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR1_VMIDBITS_SHIFT
, 4, 0),
238 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR1_HADBS_SHIFT
, 4, 0),
242 static const struct arm64_ftr_bits ftr_id_aa64mmfr2
[] = {
243 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR2_E0PD_SHIFT
, 4, 0),
244 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR2_FWB_SHIFT
, 4, 0),
245 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR2_AT_SHIFT
, 4, 0),
246 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR2_LVA_SHIFT
, 4, 0),
247 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR2_IESB_SHIFT
, 4, 0),
248 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR2_LSM_SHIFT
, 4, 0),
249 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR2_UAO_SHIFT
, 4, 0),
250 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64MMFR2_CNP_SHIFT
, 4, 0),
254 static const struct arm64_ftr_bits ftr_ctr
[] = {
255 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_EXACT
, 31, 1, 1), /* RES1 */
256 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, CTR_DIC_SHIFT
, 1, 1),
257 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, CTR_IDC_SHIFT
, 1, 1),
258 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_HIGHER_OR_ZERO_SAFE
, CTR_CWG_SHIFT
, 4, 0),
259 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_HIGHER_OR_ZERO_SAFE
, CTR_ERG_SHIFT
, 4, 0),
260 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, CTR_DMINLINE_SHIFT
, 4, 1),
262 * Linux can handle differing I-cache policies. Userspace JITs will
263 * make use of *minLine.
264 * If we have differing I-cache policies, report it as the weakest - VIPT.
266 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_NONSTRICT
, FTR_EXACT
, 14, 2, ICACHE_POLICY_VIPT
), /* L1Ip */
267 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, CTR_IMINLINE_SHIFT
, 4, 0),
271 struct arm64_ftr_reg arm64_ftr_reg_ctrel0
= {
272 .name
= "SYS_CTR_EL0",
276 static const struct arm64_ftr_bits ftr_id_mmfr0
[] = {
277 S_ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 28, 4, 0xf), /* InnerShr */
278 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 24, 4, 0), /* FCSE */
279 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, 20, 4, 0), /* AuxReg */
280 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 16, 4, 0), /* TCM */
281 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 12, 4, 0), /* ShareLvl */
282 S_ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 8, 4, 0xf), /* OuterShr */
283 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 4, 4, 0), /* PMSA */
284 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 0, 4, 0), /* VMSA */
288 static const struct arm64_ftr_bits ftr_id_aa64dfr0
[] = {
289 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_EXACT
, 36, 28, 0),
290 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
, ID_AA64DFR0_PMSVER_SHIFT
, 4, 0),
291 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64DFR0_CTX_CMPS_SHIFT
, 4, 0),
292 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64DFR0_WRPS_SHIFT
, 4, 0),
293 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_AA64DFR0_BRPS_SHIFT
, 4, 0),
295 * We can instantiate multiple PMU instances with different levels
298 S_ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_EXACT
, ID_AA64DFR0_PMUVER_SHIFT
, 4, 0),
299 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_EXACT
, ID_AA64DFR0_TRACEVER_SHIFT
, 4, 0),
300 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_EXACT
, ID_AA64DFR0_DEBUGVER_SHIFT
, 4, 0x6),
304 static const struct arm64_ftr_bits ftr_mvfr2
[] = {
305 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 4, 4, 0), /* FPMisc */
306 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 0, 4, 0), /* SIMDMisc */
310 static const struct arm64_ftr_bits ftr_dczid
[] = {
311 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_EXACT
, 4, 1, 1), /* DZP */
312 ARM64_FTR_BITS(FTR_VISIBLE
, FTR_STRICT
, FTR_LOWER_SAFE
, 0, 4, 0), /* BS */
317 static const struct arm64_ftr_bits ftr_id_isar5
[] = {
318 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR5_RDM_SHIFT
, 4, 0),
319 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR5_CRC32_SHIFT
, 4, 0),
320 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR5_SHA2_SHIFT
, 4, 0),
321 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR5_SHA1_SHIFT
, 4, 0),
322 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR5_AES_SHIFT
, 4, 0),
323 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR5_SEVL_SHIFT
, 4, 0),
327 static const struct arm64_ftr_bits ftr_id_mmfr4
[] = {
328 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 4, 4, 0), /* ac2 */
332 static const struct arm64_ftr_bits ftr_id_isar6
[] = {
333 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR6_I8MM_SHIFT
, 4, 0),
334 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR6_BF16_SHIFT
, 4, 0),
335 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR6_SPECRES_SHIFT
, 4, 0),
336 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR6_SB_SHIFT
, 4, 0),
337 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR6_FHM_SHIFT
, 4, 0),
338 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR6_DP_SHIFT
, 4, 0),
339 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, ID_ISAR6_JSCVT_SHIFT
, 4, 0),
343 static const struct arm64_ftr_bits ftr_id_pfr0
[] = {
344 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 12, 4, 0), /* State3 */
345 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 8, 4, 0), /* State2 */
346 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 4, 4, 0), /* State1 */
347 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 0, 4, 0), /* State0 */
351 static const struct arm64_ftr_bits ftr_id_dfr0
[] = {
352 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 28, 4, 0),
353 S_ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 24, 4, 0xf), /* PerfMon */
354 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 20, 4, 0),
355 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 16, 4, 0),
356 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 12, 4, 0),
357 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 8, 4, 0),
358 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 4, 4, 0),
359 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 0, 4, 0),
363 static const struct arm64_ftr_bits ftr_zcr
[] = {
364 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_NONSTRICT
, FTR_LOWER_SAFE
,
365 ZCR_ELx_LEN_SHIFT
, ZCR_ELx_LEN_SIZE
, 0), /* LEN */
370 * Common ftr bits for a 32bit register with all hidden, strict
371 * attributes, with 4bit feature fields and a default safe value of
372 * 0. Covers the following 32bit registers:
373 * id_isar[0-4], id_mmfr[1-3], id_pfr1, mvfr[0-1]
375 static const struct arm64_ftr_bits ftr_generic_32bits
[] = {
376 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 28, 4, 0),
377 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 24, 4, 0),
378 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 20, 4, 0),
379 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 16, 4, 0),
380 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 12, 4, 0),
381 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 8, 4, 0),
382 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 4, 4, 0),
383 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_LOWER_SAFE
, 0, 4, 0),
387 /* Table for a single 32bit feature value */
388 static const struct arm64_ftr_bits ftr_single32
[] = {
389 ARM64_FTR_BITS(FTR_HIDDEN
, FTR_STRICT
, FTR_EXACT
, 0, 32, 0),
393 static const struct arm64_ftr_bits ftr_raz
[] = {
397 #define ARM64_FTR_REG(id, table) { \
399 .reg = &(struct arm64_ftr_reg){ \
401 .ftr_bits = &((table)[0]), \
404 static const struct __ftr_reg_entry
{
406 struct arm64_ftr_reg
*reg
;
407 } arm64_ftr_regs
[] = {
409 /* Op1 = 0, CRn = 0, CRm = 1 */
410 ARM64_FTR_REG(SYS_ID_PFR0_EL1
, ftr_id_pfr0
),
411 ARM64_FTR_REG(SYS_ID_PFR1_EL1
, ftr_generic_32bits
),
412 ARM64_FTR_REG(SYS_ID_DFR0_EL1
, ftr_id_dfr0
),
413 ARM64_FTR_REG(SYS_ID_MMFR0_EL1
, ftr_id_mmfr0
),
414 ARM64_FTR_REG(SYS_ID_MMFR1_EL1
, ftr_generic_32bits
),
415 ARM64_FTR_REG(SYS_ID_MMFR2_EL1
, ftr_generic_32bits
),
416 ARM64_FTR_REG(SYS_ID_MMFR3_EL1
, ftr_generic_32bits
),
418 /* Op1 = 0, CRn = 0, CRm = 2 */
419 ARM64_FTR_REG(SYS_ID_ISAR0_EL1
, ftr_generic_32bits
),
420 ARM64_FTR_REG(SYS_ID_ISAR1_EL1
, ftr_generic_32bits
),
421 ARM64_FTR_REG(SYS_ID_ISAR2_EL1
, ftr_generic_32bits
),
422 ARM64_FTR_REG(SYS_ID_ISAR3_EL1
, ftr_generic_32bits
),
423 ARM64_FTR_REG(SYS_ID_ISAR4_EL1
, ftr_generic_32bits
),
424 ARM64_FTR_REG(SYS_ID_ISAR5_EL1
, ftr_id_isar5
),
425 ARM64_FTR_REG(SYS_ID_MMFR4_EL1
, ftr_id_mmfr4
),
426 ARM64_FTR_REG(SYS_ID_ISAR6_EL1
, ftr_id_isar6
),
428 /* Op1 = 0, CRn = 0, CRm = 3 */
429 ARM64_FTR_REG(SYS_MVFR0_EL1
, ftr_generic_32bits
),
430 ARM64_FTR_REG(SYS_MVFR1_EL1
, ftr_generic_32bits
),
431 ARM64_FTR_REG(SYS_MVFR2_EL1
, ftr_mvfr2
),
433 /* Op1 = 0, CRn = 0, CRm = 4 */
434 ARM64_FTR_REG(SYS_ID_AA64PFR0_EL1
, ftr_id_aa64pfr0
),
435 ARM64_FTR_REG(SYS_ID_AA64PFR1_EL1
, ftr_id_aa64pfr1
),
436 ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1
, ftr_id_aa64zfr0
),
438 /* Op1 = 0, CRn = 0, CRm = 5 */
439 ARM64_FTR_REG(SYS_ID_AA64DFR0_EL1
, ftr_id_aa64dfr0
),
440 ARM64_FTR_REG(SYS_ID_AA64DFR1_EL1
, ftr_raz
),
442 /* Op1 = 0, CRn = 0, CRm = 6 */
443 ARM64_FTR_REG(SYS_ID_AA64ISAR0_EL1
, ftr_id_aa64isar0
),
444 ARM64_FTR_REG(SYS_ID_AA64ISAR1_EL1
, ftr_id_aa64isar1
),
446 /* Op1 = 0, CRn = 0, CRm = 7 */
447 ARM64_FTR_REG(SYS_ID_AA64MMFR0_EL1
, ftr_id_aa64mmfr0
),
448 ARM64_FTR_REG(SYS_ID_AA64MMFR1_EL1
, ftr_id_aa64mmfr1
),
449 ARM64_FTR_REG(SYS_ID_AA64MMFR2_EL1
, ftr_id_aa64mmfr2
),
451 /* Op1 = 0, CRn = 1, CRm = 2 */
452 ARM64_FTR_REG(SYS_ZCR_EL1
, ftr_zcr
),
454 /* Op1 = 3, CRn = 0, CRm = 0 */
455 { SYS_CTR_EL0
, &arm64_ftr_reg_ctrel0
},
456 ARM64_FTR_REG(SYS_DCZID_EL0
, ftr_dczid
),
458 /* Op1 = 3, CRn = 14, CRm = 0 */
459 ARM64_FTR_REG(SYS_CNTFRQ_EL0
, ftr_single32
),
462 static int search_cmp_ftr_reg(const void *id
, const void *regp
)
464 return (int)(unsigned long)id
- (int)((const struct __ftr_reg_entry
*)regp
)->sys_id
;
468 * get_arm64_ftr_reg - Lookup a feature register entry using its
469 * sys_reg() encoding. With the array arm64_ftr_regs sorted in the
470 * ascending order of sys_id , we use binary search to find a matching
473 * returns - Upon success, matching ftr_reg entry for id.
474 * - NULL on failure. It is upto the caller to decide
475 * the impact of a failure.
477 static struct arm64_ftr_reg
*get_arm64_ftr_reg(u32 sys_id
)
479 const struct __ftr_reg_entry
*ret
;
481 ret
= bsearch((const void *)(unsigned long)sys_id
,
483 ARRAY_SIZE(arm64_ftr_regs
),
484 sizeof(arm64_ftr_regs
[0]),
491 static u64
arm64_ftr_set_value(const struct arm64_ftr_bits
*ftrp
, s64 reg
,
494 u64 mask
= arm64_ftr_mask(ftrp
);
497 reg
|= (ftr_val
<< ftrp
->shift
) & mask
;
501 static s64
arm64_ftr_safe_value(const struct arm64_ftr_bits
*ftrp
, s64
new,
506 switch (ftrp
->type
) {
508 ret
= ftrp
->safe_val
;
511 ret
= new < cur
? new : cur
;
513 case FTR_HIGHER_OR_ZERO_SAFE
:
517 case FTR_HIGHER_SAFE
:
518 ret
= new > cur
? new : cur
;
527 static void __init
sort_ftr_regs(void)
531 /* Check that the array is sorted so that we can do the binary search */
532 for (i
= 1; i
< ARRAY_SIZE(arm64_ftr_regs
); i
++)
533 BUG_ON(arm64_ftr_regs
[i
].sys_id
< arm64_ftr_regs
[i
- 1].sys_id
);
537 * Initialise the CPU feature register from Boot CPU values.
538 * Also initiliases the strict_mask for the register.
539 * Any bits that are not covered by an arm64_ftr_bits entry are considered
540 * RES0 for the system-wide value, and must strictly match.
542 static void __init
init_cpu_ftr_reg(u32 sys_reg
, u64
new)
545 u64 strict_mask
= ~0x0ULL
;
549 const struct arm64_ftr_bits
*ftrp
;
550 struct arm64_ftr_reg
*reg
= get_arm64_ftr_reg(sys_reg
);
554 for (ftrp
= reg
->ftr_bits
; ftrp
->width
; ftrp
++) {
555 u64 ftr_mask
= arm64_ftr_mask(ftrp
);
556 s64 ftr_new
= arm64_ftr_value(ftrp
, new);
558 val
= arm64_ftr_set_value(ftrp
, val
, ftr_new
);
560 valid_mask
|= ftr_mask
;
562 strict_mask
&= ~ftr_mask
;
564 user_mask
|= ftr_mask
;
566 reg
->user_val
= arm64_ftr_set_value(ftrp
,
574 reg
->strict_mask
= strict_mask
;
575 reg
->user_mask
= user_mask
;
578 extern const struct arm64_cpu_capabilities arm64_errata
[];
579 static const struct arm64_cpu_capabilities arm64_features
[];
582 init_cpu_hwcaps_indirect_list_from_array(const struct arm64_cpu_capabilities
*caps
)
584 for (; caps
->matches
; caps
++) {
585 if (WARN(caps
->capability
>= ARM64_NCAPS
,
586 "Invalid capability %d\n", caps
->capability
))
588 if (WARN(cpu_hwcaps_ptrs
[caps
->capability
],
589 "Duplicate entry for capability %d\n",
592 cpu_hwcaps_ptrs
[caps
->capability
] = caps
;
596 static void __init
init_cpu_hwcaps_indirect_list(void)
598 init_cpu_hwcaps_indirect_list_from_array(arm64_features
);
599 init_cpu_hwcaps_indirect_list_from_array(arm64_errata
);
602 static void __init
setup_boot_cpu_capabilities(void);
604 void __init
init_cpu_features(struct cpuinfo_arm64
*info
)
606 /* Before we start using the tables, make sure it is sorted */
609 init_cpu_ftr_reg(SYS_CTR_EL0
, info
->reg_ctr
);
610 init_cpu_ftr_reg(SYS_DCZID_EL0
, info
->reg_dczid
);
611 init_cpu_ftr_reg(SYS_CNTFRQ_EL0
, info
->reg_cntfrq
);
612 init_cpu_ftr_reg(SYS_ID_AA64DFR0_EL1
, info
->reg_id_aa64dfr0
);
613 init_cpu_ftr_reg(SYS_ID_AA64DFR1_EL1
, info
->reg_id_aa64dfr1
);
614 init_cpu_ftr_reg(SYS_ID_AA64ISAR0_EL1
, info
->reg_id_aa64isar0
);
615 init_cpu_ftr_reg(SYS_ID_AA64ISAR1_EL1
, info
->reg_id_aa64isar1
);
616 init_cpu_ftr_reg(SYS_ID_AA64MMFR0_EL1
, info
->reg_id_aa64mmfr0
);
617 init_cpu_ftr_reg(SYS_ID_AA64MMFR1_EL1
, info
->reg_id_aa64mmfr1
);
618 init_cpu_ftr_reg(SYS_ID_AA64MMFR2_EL1
, info
->reg_id_aa64mmfr2
);
619 init_cpu_ftr_reg(SYS_ID_AA64PFR0_EL1
, info
->reg_id_aa64pfr0
);
620 init_cpu_ftr_reg(SYS_ID_AA64PFR1_EL1
, info
->reg_id_aa64pfr1
);
621 init_cpu_ftr_reg(SYS_ID_AA64ZFR0_EL1
, info
->reg_id_aa64zfr0
);
623 if (id_aa64pfr0_32bit_el0(info
->reg_id_aa64pfr0
)) {
624 init_cpu_ftr_reg(SYS_ID_DFR0_EL1
, info
->reg_id_dfr0
);
625 init_cpu_ftr_reg(SYS_ID_ISAR0_EL1
, info
->reg_id_isar0
);
626 init_cpu_ftr_reg(SYS_ID_ISAR1_EL1
, info
->reg_id_isar1
);
627 init_cpu_ftr_reg(SYS_ID_ISAR2_EL1
, info
->reg_id_isar2
);
628 init_cpu_ftr_reg(SYS_ID_ISAR3_EL1
, info
->reg_id_isar3
);
629 init_cpu_ftr_reg(SYS_ID_ISAR4_EL1
, info
->reg_id_isar4
);
630 init_cpu_ftr_reg(SYS_ID_ISAR5_EL1
, info
->reg_id_isar5
);
631 init_cpu_ftr_reg(SYS_ID_ISAR6_EL1
, info
->reg_id_isar6
);
632 init_cpu_ftr_reg(SYS_ID_MMFR0_EL1
, info
->reg_id_mmfr0
);
633 init_cpu_ftr_reg(SYS_ID_MMFR1_EL1
, info
->reg_id_mmfr1
);
634 init_cpu_ftr_reg(SYS_ID_MMFR2_EL1
, info
->reg_id_mmfr2
);
635 init_cpu_ftr_reg(SYS_ID_MMFR3_EL1
, info
->reg_id_mmfr3
);
636 init_cpu_ftr_reg(SYS_ID_PFR0_EL1
, info
->reg_id_pfr0
);
637 init_cpu_ftr_reg(SYS_ID_PFR1_EL1
, info
->reg_id_pfr1
);
638 init_cpu_ftr_reg(SYS_MVFR0_EL1
, info
->reg_mvfr0
);
639 init_cpu_ftr_reg(SYS_MVFR1_EL1
, info
->reg_mvfr1
);
640 init_cpu_ftr_reg(SYS_MVFR2_EL1
, info
->reg_mvfr2
);
643 if (id_aa64pfr0_sve(info
->reg_id_aa64pfr0
)) {
644 init_cpu_ftr_reg(SYS_ZCR_EL1
, info
->reg_zcr
);
649 * Initialize the indirect array of CPU hwcaps capabilities pointers
650 * before we handle the boot CPU below.
652 init_cpu_hwcaps_indirect_list();
655 * Detect and enable early CPU capabilities based on the boot CPU,
656 * after we have initialised the CPU feature infrastructure.
658 setup_boot_cpu_capabilities();
661 static void update_cpu_ftr_reg(struct arm64_ftr_reg
*reg
, u64
new)
663 const struct arm64_ftr_bits
*ftrp
;
665 for (ftrp
= reg
->ftr_bits
; ftrp
->width
; ftrp
++) {
666 s64 ftr_cur
= arm64_ftr_value(ftrp
, reg
->sys_val
);
667 s64 ftr_new
= arm64_ftr_value(ftrp
, new);
669 if (ftr_cur
== ftr_new
)
671 /* Find a safe value */
672 ftr_new
= arm64_ftr_safe_value(ftrp
, ftr_new
, ftr_cur
);
673 reg
->sys_val
= arm64_ftr_set_value(ftrp
, reg
->sys_val
, ftr_new
);
678 static int check_update_ftr_reg(u32 sys_id
, int cpu
, u64 val
, u64 boot
)
680 struct arm64_ftr_reg
*regp
= get_arm64_ftr_reg(sys_id
);
683 update_cpu_ftr_reg(regp
, val
);
684 if ((boot
& regp
->strict_mask
) == (val
& regp
->strict_mask
))
686 pr_warn("SANITY CHECK: Unexpected variation in %s. Boot CPU: %#016llx, CPU%d: %#016llx\n",
687 regp
->name
, boot
, cpu
, val
);
692 * Update system wide CPU feature registers with the values from a
693 * non-boot CPU. Also performs SANITY checks to make sure that there
694 * aren't any insane variations from that of the boot CPU.
696 void update_cpu_features(int cpu
,
697 struct cpuinfo_arm64
*info
,
698 struct cpuinfo_arm64
*boot
)
703 * The kernel can handle differing I-cache policies, but otherwise
704 * caches should look identical. Userspace JITs will make use of
707 taint
|= check_update_ftr_reg(SYS_CTR_EL0
, cpu
,
708 info
->reg_ctr
, boot
->reg_ctr
);
711 * Userspace may perform DC ZVA instructions. Mismatched block sizes
712 * could result in too much or too little memory being zeroed if a
713 * process is preempted and migrated between CPUs.
715 taint
|= check_update_ftr_reg(SYS_DCZID_EL0
, cpu
,
716 info
->reg_dczid
, boot
->reg_dczid
);
718 /* If different, timekeeping will be broken (especially with KVM) */
719 taint
|= check_update_ftr_reg(SYS_CNTFRQ_EL0
, cpu
,
720 info
->reg_cntfrq
, boot
->reg_cntfrq
);
723 * The kernel uses self-hosted debug features and expects CPUs to
724 * support identical debug features. We presently need CTX_CMPs, WRPs,
725 * and BRPs to be identical.
726 * ID_AA64DFR1 is currently RES0.
728 taint
|= check_update_ftr_reg(SYS_ID_AA64DFR0_EL1
, cpu
,
729 info
->reg_id_aa64dfr0
, boot
->reg_id_aa64dfr0
);
730 taint
|= check_update_ftr_reg(SYS_ID_AA64DFR1_EL1
, cpu
,
731 info
->reg_id_aa64dfr1
, boot
->reg_id_aa64dfr1
);
733 * Even in big.LITTLE, processors should be identical instruction-set
736 taint
|= check_update_ftr_reg(SYS_ID_AA64ISAR0_EL1
, cpu
,
737 info
->reg_id_aa64isar0
, boot
->reg_id_aa64isar0
);
738 taint
|= check_update_ftr_reg(SYS_ID_AA64ISAR1_EL1
, cpu
,
739 info
->reg_id_aa64isar1
, boot
->reg_id_aa64isar1
);
742 * Differing PARange support is fine as long as all peripherals and
743 * memory are mapped within the minimum PARange of all CPUs.
744 * Linux should not care about secure memory.
746 taint
|= check_update_ftr_reg(SYS_ID_AA64MMFR0_EL1
, cpu
,
747 info
->reg_id_aa64mmfr0
, boot
->reg_id_aa64mmfr0
);
748 taint
|= check_update_ftr_reg(SYS_ID_AA64MMFR1_EL1
, cpu
,
749 info
->reg_id_aa64mmfr1
, boot
->reg_id_aa64mmfr1
);
750 taint
|= check_update_ftr_reg(SYS_ID_AA64MMFR2_EL1
, cpu
,
751 info
->reg_id_aa64mmfr2
, boot
->reg_id_aa64mmfr2
);
754 * EL3 is not our concern.
756 taint
|= check_update_ftr_reg(SYS_ID_AA64PFR0_EL1
, cpu
,
757 info
->reg_id_aa64pfr0
, boot
->reg_id_aa64pfr0
);
758 taint
|= check_update_ftr_reg(SYS_ID_AA64PFR1_EL1
, cpu
,
759 info
->reg_id_aa64pfr1
, boot
->reg_id_aa64pfr1
);
761 taint
|= check_update_ftr_reg(SYS_ID_AA64ZFR0_EL1
, cpu
,
762 info
->reg_id_aa64zfr0
, boot
->reg_id_aa64zfr0
);
765 * If we have AArch32, we care about 32-bit features for compat.
766 * If the system doesn't support AArch32, don't update them.
768 if (id_aa64pfr0_32bit_el0(read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1
)) &&
769 id_aa64pfr0_32bit_el0(info
->reg_id_aa64pfr0
)) {
771 taint
|= check_update_ftr_reg(SYS_ID_DFR0_EL1
, cpu
,
772 info
->reg_id_dfr0
, boot
->reg_id_dfr0
);
773 taint
|= check_update_ftr_reg(SYS_ID_ISAR0_EL1
, cpu
,
774 info
->reg_id_isar0
, boot
->reg_id_isar0
);
775 taint
|= check_update_ftr_reg(SYS_ID_ISAR1_EL1
, cpu
,
776 info
->reg_id_isar1
, boot
->reg_id_isar1
);
777 taint
|= check_update_ftr_reg(SYS_ID_ISAR2_EL1
, cpu
,
778 info
->reg_id_isar2
, boot
->reg_id_isar2
);
779 taint
|= check_update_ftr_reg(SYS_ID_ISAR3_EL1
, cpu
,
780 info
->reg_id_isar3
, boot
->reg_id_isar3
);
781 taint
|= check_update_ftr_reg(SYS_ID_ISAR4_EL1
, cpu
,
782 info
->reg_id_isar4
, boot
->reg_id_isar4
);
783 taint
|= check_update_ftr_reg(SYS_ID_ISAR5_EL1
, cpu
,
784 info
->reg_id_isar5
, boot
->reg_id_isar5
);
785 taint
|= check_update_ftr_reg(SYS_ID_ISAR6_EL1
, cpu
,
786 info
->reg_id_isar6
, boot
->reg_id_isar6
);
789 * Regardless of the value of the AuxReg field, the AIFSR, ADFSR, and
790 * ACTLR formats could differ across CPUs and therefore would have to
791 * be trapped for virtualization anyway.
793 taint
|= check_update_ftr_reg(SYS_ID_MMFR0_EL1
, cpu
,
794 info
->reg_id_mmfr0
, boot
->reg_id_mmfr0
);
795 taint
|= check_update_ftr_reg(SYS_ID_MMFR1_EL1
, cpu
,
796 info
->reg_id_mmfr1
, boot
->reg_id_mmfr1
);
797 taint
|= check_update_ftr_reg(SYS_ID_MMFR2_EL1
, cpu
,
798 info
->reg_id_mmfr2
, boot
->reg_id_mmfr2
);
799 taint
|= check_update_ftr_reg(SYS_ID_MMFR3_EL1
, cpu
,
800 info
->reg_id_mmfr3
, boot
->reg_id_mmfr3
);
801 taint
|= check_update_ftr_reg(SYS_ID_PFR0_EL1
, cpu
,
802 info
->reg_id_pfr0
, boot
->reg_id_pfr0
);
803 taint
|= check_update_ftr_reg(SYS_ID_PFR1_EL1
, cpu
,
804 info
->reg_id_pfr1
, boot
->reg_id_pfr1
);
805 taint
|= check_update_ftr_reg(SYS_MVFR0_EL1
, cpu
,
806 info
->reg_mvfr0
, boot
->reg_mvfr0
);
807 taint
|= check_update_ftr_reg(SYS_MVFR1_EL1
, cpu
,
808 info
->reg_mvfr1
, boot
->reg_mvfr1
);
809 taint
|= check_update_ftr_reg(SYS_MVFR2_EL1
, cpu
,
810 info
->reg_mvfr2
, boot
->reg_mvfr2
);
813 if (id_aa64pfr0_sve(info
->reg_id_aa64pfr0
)) {
814 taint
|= check_update_ftr_reg(SYS_ZCR_EL1
, cpu
,
815 info
->reg_zcr
, boot
->reg_zcr
);
817 /* Probe vector lengths, unless we already gave up on SVE */
818 if (id_aa64pfr0_sve(read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1
)) &&
819 !system_capabilities_finalized())
824 * Mismatched CPU features are a recipe for disaster. Don't even
825 * pretend to support them.
828 pr_warn_once("Unsupported CPU feature variation detected.\n");
829 add_taint(TAINT_CPU_OUT_OF_SPEC
, LOCKDEP_STILL_OK
);
833 u64
read_sanitised_ftr_reg(u32 id
)
835 struct arm64_ftr_reg
*regp
= get_arm64_ftr_reg(id
);
837 /* We shouldn't get a request for an unsupported register */
839 return regp
->sys_val
;
842 #define read_sysreg_case(r) \
843 case r: return read_sysreg_s(r)
846 * __read_sysreg_by_encoding() - Used by a STARTING cpu before cpuinfo is populated.
847 * Read the system register on the current CPU
849 static u64
__read_sysreg_by_encoding(u32 sys_id
)
852 read_sysreg_case(SYS_ID_PFR0_EL1
);
853 read_sysreg_case(SYS_ID_PFR1_EL1
);
854 read_sysreg_case(SYS_ID_DFR0_EL1
);
855 read_sysreg_case(SYS_ID_MMFR0_EL1
);
856 read_sysreg_case(SYS_ID_MMFR1_EL1
);
857 read_sysreg_case(SYS_ID_MMFR2_EL1
);
858 read_sysreg_case(SYS_ID_MMFR3_EL1
);
859 read_sysreg_case(SYS_ID_ISAR0_EL1
);
860 read_sysreg_case(SYS_ID_ISAR1_EL1
);
861 read_sysreg_case(SYS_ID_ISAR2_EL1
);
862 read_sysreg_case(SYS_ID_ISAR3_EL1
);
863 read_sysreg_case(SYS_ID_ISAR4_EL1
);
864 read_sysreg_case(SYS_ID_ISAR5_EL1
);
865 read_sysreg_case(SYS_ID_ISAR6_EL1
);
866 read_sysreg_case(SYS_MVFR0_EL1
);
867 read_sysreg_case(SYS_MVFR1_EL1
);
868 read_sysreg_case(SYS_MVFR2_EL1
);
870 read_sysreg_case(SYS_ID_AA64PFR0_EL1
);
871 read_sysreg_case(SYS_ID_AA64PFR1_EL1
);
872 read_sysreg_case(SYS_ID_AA64ZFR0_EL1
);
873 read_sysreg_case(SYS_ID_AA64DFR0_EL1
);
874 read_sysreg_case(SYS_ID_AA64DFR1_EL1
);
875 read_sysreg_case(SYS_ID_AA64MMFR0_EL1
);
876 read_sysreg_case(SYS_ID_AA64MMFR1_EL1
);
877 read_sysreg_case(SYS_ID_AA64MMFR2_EL1
);
878 read_sysreg_case(SYS_ID_AA64ISAR0_EL1
);
879 read_sysreg_case(SYS_ID_AA64ISAR1_EL1
);
881 read_sysreg_case(SYS_CNTFRQ_EL0
);
882 read_sysreg_case(SYS_CTR_EL0
);
883 read_sysreg_case(SYS_DCZID_EL0
);
891 #include <linux/irqchip/arm-gic-v3.h>
894 feature_matches(u64 reg
, const struct arm64_cpu_capabilities
*entry
)
896 int val
= cpuid_feature_extract_field(reg
, entry
->field_pos
, entry
->sign
);
898 return val
>= entry
->min_field_value
;
902 has_cpuid_feature(const struct arm64_cpu_capabilities
*entry
, int scope
)
906 WARN_ON(scope
== SCOPE_LOCAL_CPU
&& preemptible());
907 if (scope
== SCOPE_SYSTEM
)
908 val
= read_sanitised_ftr_reg(entry
->sys_reg
);
910 val
= __read_sysreg_by_encoding(entry
->sys_reg
);
912 return feature_matches(val
, entry
);
915 static bool has_useable_gicv3_cpuif(const struct arm64_cpu_capabilities
*entry
, int scope
)
919 if (!has_cpuid_feature(entry
, scope
))
922 has_sre
= gic_enable_sre();
924 pr_warn_once("%s present but disabled by higher exception level\n",
930 static bool has_no_hw_prefetch(const struct arm64_cpu_capabilities
*entry
, int __unused
)
932 u32 midr
= read_cpuid_id();
934 /* Cavium ThunderX pass 1.x and 2.x */
935 return midr_is_cpu_model_range(midr
, MIDR_THUNDERX
,
936 MIDR_CPU_VAR_REV(0, 0),
937 MIDR_CPU_VAR_REV(1, MIDR_REVISION_MASK
));
940 static bool has_no_fpsimd(const struct arm64_cpu_capabilities
*entry
, int __unused
)
942 u64 pfr0
= read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1
);
944 return cpuid_feature_extract_signed_field(pfr0
,
945 ID_AA64PFR0_FP_SHIFT
) < 0;
948 static bool has_cache_idc(const struct arm64_cpu_capabilities
*entry
,
953 if (scope
== SCOPE_SYSTEM
)
954 ctr
= arm64_ftr_reg_ctrel0
.sys_val
;
956 ctr
= read_cpuid_effective_cachetype();
958 return ctr
& BIT(CTR_IDC_SHIFT
);
961 static void cpu_emulate_effective_ctr(const struct arm64_cpu_capabilities
*__unused
)
964 * If the CPU exposes raw CTR_EL0.IDC = 0, while effectively
965 * CTR_EL0.IDC = 1 (from CLIDR values), we need to trap accesses
966 * to the CTR_EL0 on this CPU and emulate it with the real/safe
969 if (!(read_cpuid_cachetype() & BIT(CTR_IDC_SHIFT
)))
970 sysreg_clear_set(sctlr_el1
, SCTLR_EL1_UCT
, 0);
973 static bool has_cache_dic(const struct arm64_cpu_capabilities
*entry
,
978 if (scope
== SCOPE_SYSTEM
)
979 ctr
= arm64_ftr_reg_ctrel0
.sys_val
;
981 ctr
= read_cpuid_cachetype();
983 return ctr
& BIT(CTR_DIC_SHIFT
);
986 static bool __maybe_unused
987 has_useable_cnp(const struct arm64_cpu_capabilities
*entry
, int scope
)
990 * Kdump isn't guaranteed to power-off all secondary CPUs, CNP
991 * may share TLB entries with a CPU stuck in the crashed
994 if (is_kdump_kernel())
997 return has_cpuid_feature(entry
, scope
);
1001 * This check is triggered during the early boot before the cpufeature
1002 * is initialised. Checking the status on the local CPU allows the boot
1003 * CPU to detect the need for non-global mappings and thus avoiding a
1004 * pagetable re-write after all the CPUs are booted. This check will be
1005 * anyway run on individual CPUs, allowing us to get the consistent
1006 * state once the SMP CPUs are up and thus make the switch to non-global
1007 * mappings if required.
1009 bool kaslr_requires_kpti(void)
1011 if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE
))
1015 * E0PD does a similar job to KPTI so can be used instead
1018 if (IS_ENABLED(CONFIG_ARM64_E0PD
)) {
1019 u64 mmfr2
= read_sysreg_s(SYS_ID_AA64MMFR2_EL1
);
1020 if (cpuid_feature_extract_unsigned_field(mmfr2
,
1021 ID_AA64MMFR2_E0PD_SHIFT
))
1026 * Systems affected by Cavium erratum 24756 are incompatible
1029 if (IS_ENABLED(CONFIG_CAVIUM_ERRATUM_27456
)) {
1030 extern const struct midr_range cavium_erratum_27456_cpus
[];
1032 if (is_midr_in_range_list(read_cpuid_id(),
1033 cavium_erratum_27456_cpus
))
1037 return kaslr_offset() > 0;
1040 static bool __meltdown_safe
= true;
1041 static int __kpti_forced
; /* 0: not forced, >0: forced on, <0: forced off */
1043 static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities
*entry
,
1046 /* List of CPUs that are not vulnerable and don't need KPTI */
1047 static const struct midr_range kpti_safe_list
[] = {
1048 MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2
),
1049 MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN
),
1050 MIDR_ALL_VERSIONS(MIDR_BRAHMA_B53
),
1051 MIDR_ALL_VERSIONS(MIDR_CORTEX_A35
),
1052 MIDR_ALL_VERSIONS(MIDR_CORTEX_A53
),
1053 MIDR_ALL_VERSIONS(MIDR_CORTEX_A55
),
1054 MIDR_ALL_VERSIONS(MIDR_CORTEX_A57
),
1055 MIDR_ALL_VERSIONS(MIDR_CORTEX_A72
),
1056 MIDR_ALL_VERSIONS(MIDR_CORTEX_A73
),
1057 MIDR_ALL_VERSIONS(MIDR_HISI_TSV110
),
1058 MIDR_ALL_VERSIONS(MIDR_NVIDIA_CARMEL
),
1061 char const *str
= "kpti command line option";
1064 meltdown_safe
= is_midr_in_range_list(read_cpuid_id(), kpti_safe_list
);
1066 /* Defer to CPU feature registers */
1067 if (has_cpuid_feature(entry
, scope
))
1068 meltdown_safe
= true;
1071 __meltdown_safe
= false;
1074 * For reasons that aren't entirely clear, enabling KPTI on Cavium
1075 * ThunderX leads to apparent I-cache corruption of kernel text, which
1076 * ends as well as you might imagine. Don't even try.
1078 if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_27456
)) {
1079 str
= "ARM64_WORKAROUND_CAVIUM_27456";
1083 /* Useful for KASLR robustness */
1084 if (kaslr_requires_kpti()) {
1085 if (!__kpti_forced
) {
1091 if (cpu_mitigations_off() && !__kpti_forced
) {
1092 str
= "mitigations=off";
1096 if (!IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0
)) {
1097 pr_info_once("kernel page table isolation disabled by kernel configuration\n");
1102 if (__kpti_forced
) {
1103 pr_info_once("kernel page table isolation forced %s by %s\n",
1104 __kpti_forced
> 0 ? "ON" : "OFF", str
);
1105 return __kpti_forced
> 0;
1108 return !meltdown_safe
;
1111 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1113 kpti_install_ng_mappings(const struct arm64_cpu_capabilities
*__unused
)
1115 typedef void (kpti_remap_fn
)(int, int, phys_addr_t
);
1116 extern kpti_remap_fn idmap_kpti_install_ng_mappings
;
1117 kpti_remap_fn
*remap_fn
;
1119 int cpu
= smp_processor_id();
1122 * We don't need to rewrite the page-tables if either we've done
1123 * it already or we have KASLR enabled and therefore have not
1124 * created any global mappings at all.
1126 if (arm64_use_ng_mappings
)
1129 remap_fn
= (void *)__pa_symbol(idmap_kpti_install_ng_mappings
);
1131 cpu_install_idmap();
1132 remap_fn(cpu
, num_online_cpus(), __pa_symbol(swapper_pg_dir
));
1133 cpu_uninstall_idmap();
1136 arm64_use_ng_mappings
= true;
1142 kpti_install_ng_mappings(const struct arm64_cpu_capabilities
*__unused
)
1145 #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
1147 static int __init
parse_kpti(char *str
)
1150 int ret
= strtobool(str
, &enabled
);
1155 __kpti_forced
= enabled
? 1 : -1;
1158 early_param("kpti", parse_kpti
);
1160 #ifdef CONFIG_ARM64_HW_AFDBM
1161 static inline void __cpu_enable_hw_dbm(void)
1163 u64 tcr
= read_sysreg(tcr_el1
) | TCR_HD
;
1165 write_sysreg(tcr
, tcr_el1
);
1169 static bool cpu_has_broken_dbm(void)
1171 /* List of CPUs which have broken DBM support. */
1172 static const struct midr_range cpus
[] = {
1173 #ifdef CONFIG_ARM64_ERRATUM_1024718
1174 MIDR_RANGE(MIDR_CORTEX_A55
, 0, 0, 1, 0), // A55 r0p0 -r1p0
1179 return is_midr_in_range_list(read_cpuid_id(), cpus
);
1182 static bool cpu_can_use_dbm(const struct arm64_cpu_capabilities
*cap
)
1184 return has_cpuid_feature(cap
, SCOPE_LOCAL_CPU
) &&
1185 !cpu_has_broken_dbm();
1188 static void cpu_enable_hw_dbm(struct arm64_cpu_capabilities
const *cap
)
1190 if (cpu_can_use_dbm(cap
))
1191 __cpu_enable_hw_dbm();
1194 static bool has_hw_dbm(const struct arm64_cpu_capabilities
*cap
,
1197 static bool detected
= false;
1199 * DBM is a non-conflicting feature. i.e, the kernel can safely
1200 * run a mix of CPUs with and without the feature. So, we
1201 * unconditionally enable the capability to allow any late CPU
1202 * to use the feature. We only enable the control bits on the
1203 * CPU, if it actually supports.
1205 * We have to make sure we print the "feature" detection only
1206 * when at least one CPU actually uses it. So check if this CPU
1207 * can actually use it and print the message exactly once.
1209 * This is safe as all CPUs (including secondary CPUs - due to the
1210 * LOCAL_CPU scope - and the hotplugged CPUs - via verification)
1211 * goes through the "matches" check exactly once. Also if a CPU
1212 * matches the criteria, it is guaranteed that the CPU will turn
1213 * the DBM on, as the capability is unconditionally enabled.
1215 if (!detected
&& cpu_can_use_dbm(cap
)) {
1217 pr_info("detected: Hardware dirty bit management\n");
1225 #ifdef CONFIG_ARM64_VHE
1226 static bool runs_at_el2(const struct arm64_cpu_capabilities
*entry
, int __unused
)
1228 return is_kernel_in_hyp_mode();
1231 static void cpu_copy_el2regs(const struct arm64_cpu_capabilities
*__unused
)
1234 * Copy register values that aren't redirected by hardware.
1236 * Before code patching, we only set tpidr_el1, all CPUs need to copy
1237 * this value to tpidr_el2 before we patch the code. Once we've done
1238 * that, freshly-onlined CPUs will set tpidr_el2, so we don't need to
1241 if (!alternative_is_applied(ARM64_HAS_VIRT_HOST_EXTN
))
1242 write_sysreg(read_sysreg(tpidr_el1
), tpidr_el2
);
1246 static void cpu_has_fwb(const struct arm64_cpu_capabilities
*__unused
)
1248 u64 val
= read_sysreg_s(SYS_CLIDR_EL1
);
1250 /* Check that CLIDR_EL1.LOU{U,IS} are both 0 */
1251 WARN_ON(val
& (7 << 27 | 7 << 21));
1254 #ifdef CONFIG_ARM64_SSBD
1255 static int ssbs_emulation_handler(struct pt_regs
*regs
, u32 instr
)
1257 if (user_mode(regs
))
1260 if (instr
& BIT(PSTATE_Imm_shift
))
1261 regs
->pstate
|= PSR_SSBS_BIT
;
1263 regs
->pstate
&= ~PSR_SSBS_BIT
;
1265 arm64_skip_faulting_instruction(regs
, 4);
1269 static struct undef_hook ssbs_emulation_hook
= {
1270 .instr_mask
= ~(1U << PSTATE_Imm_shift
),
1271 .instr_val
= 0xd500401f | PSTATE_SSBS
,
1272 .fn
= ssbs_emulation_handler
,
1275 static void cpu_enable_ssbs(const struct arm64_cpu_capabilities
*__unused
)
1277 static bool undef_hook_registered
= false;
1278 static DEFINE_RAW_SPINLOCK(hook_lock
);
1280 raw_spin_lock(&hook_lock
);
1281 if (!undef_hook_registered
) {
1282 register_undef_hook(&ssbs_emulation_hook
);
1283 undef_hook_registered
= true;
1285 raw_spin_unlock(&hook_lock
);
1287 if (arm64_get_ssbd_state() == ARM64_SSBD_FORCE_DISABLE
) {
1288 sysreg_clear_set(sctlr_el1
, 0, SCTLR_ELx_DSSBS
);
1289 arm64_set_ssbd_mitigation(false);
1291 arm64_set_ssbd_mitigation(true);
1294 #endif /* CONFIG_ARM64_SSBD */
1296 #ifdef CONFIG_ARM64_PAN
1297 static void cpu_enable_pan(const struct arm64_cpu_capabilities
*__unused
)
1300 * We modify PSTATE. This won't work from irq context as the PSTATE
1301 * is discarded once we return from the exception.
1303 WARN_ON_ONCE(in_interrupt());
1305 sysreg_clear_set(sctlr_el1
, SCTLR_EL1_SPAN
, 0);
1306 asm(SET_PSTATE_PAN(1));
1308 #endif /* CONFIG_ARM64_PAN */
1310 #ifdef CONFIG_ARM64_RAS_EXTN
1311 static void cpu_clear_disr(const struct arm64_cpu_capabilities
*__unused
)
1313 /* Firmware may have left a deferred SError in this register. */
1314 write_sysreg_s(0, SYS_DISR_EL1
);
1316 #endif /* CONFIG_ARM64_RAS_EXTN */
1318 #ifdef CONFIG_ARM64_PTR_AUTH
1319 static void cpu_enable_address_auth(struct arm64_cpu_capabilities
const *cap
)
1321 sysreg_clear_set(sctlr_el1
, 0, SCTLR_ELx_ENIA
| SCTLR_ELx_ENIB
|
1322 SCTLR_ELx_ENDA
| SCTLR_ELx_ENDB
);
1324 #endif /* CONFIG_ARM64_PTR_AUTH */
1326 #ifdef CONFIG_ARM64_E0PD
1327 static void cpu_enable_e0pd(struct arm64_cpu_capabilities
const *cap
)
1329 if (this_cpu_has_cap(ARM64_HAS_E0PD
))
1330 sysreg_clear_set(tcr_el1
, 0, TCR_E0PD1
);
1332 #endif /* CONFIG_ARM64_E0PD */
1334 #ifdef CONFIG_ARM64_PSEUDO_NMI
1335 static bool enable_pseudo_nmi
;
1337 static int __init
early_enable_pseudo_nmi(char *p
)
1339 return strtobool(p
, &enable_pseudo_nmi
);
1341 early_param("irqchip.gicv3_pseudo_nmi", early_enable_pseudo_nmi
);
1343 static bool can_use_gic_priorities(const struct arm64_cpu_capabilities
*entry
,
1346 return enable_pseudo_nmi
&& has_useable_gicv3_cpuif(entry
, scope
);
1350 static const struct arm64_cpu_capabilities arm64_features
[] = {
1352 .desc
= "GIC system register CPU interface",
1353 .capability
= ARM64_HAS_SYSREG_GIC_CPUIF
,
1354 .type
= ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE
,
1355 .matches
= has_useable_gicv3_cpuif
,
1356 .sys_reg
= SYS_ID_AA64PFR0_EL1
,
1357 .field_pos
= ID_AA64PFR0_GIC_SHIFT
,
1358 .sign
= FTR_UNSIGNED
,
1359 .min_field_value
= 1,
1361 #ifdef CONFIG_ARM64_PAN
1363 .desc
= "Privileged Access Never",
1364 .capability
= ARM64_HAS_PAN
,
1365 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1366 .matches
= has_cpuid_feature
,
1367 .sys_reg
= SYS_ID_AA64MMFR1_EL1
,
1368 .field_pos
= ID_AA64MMFR1_PAN_SHIFT
,
1369 .sign
= FTR_UNSIGNED
,
1370 .min_field_value
= 1,
1371 .cpu_enable
= cpu_enable_pan
,
1373 #endif /* CONFIG_ARM64_PAN */
1374 #ifdef CONFIG_ARM64_LSE_ATOMICS
1376 .desc
= "LSE atomic instructions",
1377 .capability
= ARM64_HAS_LSE_ATOMICS
,
1378 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1379 .matches
= has_cpuid_feature
,
1380 .sys_reg
= SYS_ID_AA64ISAR0_EL1
,
1381 .field_pos
= ID_AA64ISAR0_ATOMICS_SHIFT
,
1382 .sign
= FTR_UNSIGNED
,
1383 .min_field_value
= 2,
1385 #endif /* CONFIG_ARM64_LSE_ATOMICS */
1387 .desc
= "Software prefetching using PRFM",
1388 .capability
= ARM64_HAS_NO_HW_PREFETCH
,
1389 .type
= ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE
,
1390 .matches
= has_no_hw_prefetch
,
1392 #ifdef CONFIG_ARM64_UAO
1394 .desc
= "User Access Override",
1395 .capability
= ARM64_HAS_UAO
,
1396 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1397 .matches
= has_cpuid_feature
,
1398 .sys_reg
= SYS_ID_AA64MMFR2_EL1
,
1399 .field_pos
= ID_AA64MMFR2_UAO_SHIFT
,
1400 .min_field_value
= 1,
1402 * We rely on stop_machine() calling uao_thread_switch() to set
1403 * UAO immediately after patching.
1406 #endif /* CONFIG_ARM64_UAO */
1407 #ifdef CONFIG_ARM64_PAN
1409 .capability
= ARM64_ALT_PAN_NOT_UAO
,
1410 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1411 .matches
= cpufeature_pan_not_uao
,
1413 #endif /* CONFIG_ARM64_PAN */
1414 #ifdef CONFIG_ARM64_VHE
1416 .desc
= "Virtualization Host Extensions",
1417 .capability
= ARM64_HAS_VIRT_HOST_EXTN
,
1418 .type
= ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE
,
1419 .matches
= runs_at_el2
,
1420 .cpu_enable
= cpu_copy_el2regs
,
1422 #endif /* CONFIG_ARM64_VHE */
1424 .desc
= "32-bit EL0 Support",
1425 .capability
= ARM64_HAS_32BIT_EL0
,
1426 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1427 .matches
= has_cpuid_feature
,
1428 .sys_reg
= SYS_ID_AA64PFR0_EL1
,
1429 .sign
= FTR_UNSIGNED
,
1430 .field_pos
= ID_AA64PFR0_EL0_SHIFT
,
1431 .min_field_value
= ID_AA64PFR0_EL0_32BIT_64BIT
,
1434 .desc
= "Kernel page table isolation (KPTI)",
1435 .capability
= ARM64_UNMAP_KERNEL_AT_EL0
,
1436 .type
= ARM64_CPUCAP_BOOT_RESTRICTED_CPU_LOCAL_FEATURE
,
1438 * The ID feature fields below are used to indicate that
1439 * the CPU doesn't need KPTI. See unmap_kernel_at_el0 for
1442 .sys_reg
= SYS_ID_AA64PFR0_EL1
,
1443 .field_pos
= ID_AA64PFR0_CSV3_SHIFT
,
1444 .min_field_value
= 1,
1445 .matches
= unmap_kernel_at_el0
,
1446 .cpu_enable
= kpti_install_ng_mappings
,
1449 /* FP/SIMD is not implemented */
1450 .capability
= ARM64_HAS_NO_FPSIMD
,
1451 .type
= ARM64_CPUCAP_BOOT_RESTRICTED_CPU_LOCAL_FEATURE
,
1452 .min_field_value
= 0,
1453 .matches
= has_no_fpsimd
,
1455 #ifdef CONFIG_ARM64_PMEM
1457 .desc
= "Data cache clean to Point of Persistence",
1458 .capability
= ARM64_HAS_DCPOP
,
1459 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1460 .matches
= has_cpuid_feature
,
1461 .sys_reg
= SYS_ID_AA64ISAR1_EL1
,
1462 .field_pos
= ID_AA64ISAR1_DPB_SHIFT
,
1463 .min_field_value
= 1,
1466 .desc
= "Data cache clean to Point of Deep Persistence",
1467 .capability
= ARM64_HAS_DCPODP
,
1468 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1469 .matches
= has_cpuid_feature
,
1470 .sys_reg
= SYS_ID_AA64ISAR1_EL1
,
1471 .sign
= FTR_UNSIGNED
,
1472 .field_pos
= ID_AA64ISAR1_DPB_SHIFT
,
1473 .min_field_value
= 2,
1476 #ifdef CONFIG_ARM64_SVE
1478 .desc
= "Scalable Vector Extension",
1479 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1480 .capability
= ARM64_SVE
,
1481 .sys_reg
= SYS_ID_AA64PFR0_EL1
,
1482 .sign
= FTR_UNSIGNED
,
1483 .field_pos
= ID_AA64PFR0_SVE_SHIFT
,
1484 .min_field_value
= ID_AA64PFR0_SVE
,
1485 .matches
= has_cpuid_feature
,
1486 .cpu_enable
= sve_kernel_enable
,
1488 #endif /* CONFIG_ARM64_SVE */
1489 #ifdef CONFIG_ARM64_RAS_EXTN
1491 .desc
= "RAS Extension Support",
1492 .capability
= ARM64_HAS_RAS_EXTN
,
1493 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1494 .matches
= has_cpuid_feature
,
1495 .sys_reg
= SYS_ID_AA64PFR0_EL1
,
1496 .sign
= FTR_UNSIGNED
,
1497 .field_pos
= ID_AA64PFR0_RAS_SHIFT
,
1498 .min_field_value
= ID_AA64PFR0_RAS_V1
,
1499 .cpu_enable
= cpu_clear_disr
,
1501 #endif /* CONFIG_ARM64_RAS_EXTN */
1503 .desc
= "Data cache clean to the PoU not required for I/D coherence",
1504 .capability
= ARM64_HAS_CACHE_IDC
,
1505 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1506 .matches
= has_cache_idc
,
1507 .cpu_enable
= cpu_emulate_effective_ctr
,
1510 .desc
= "Instruction cache invalidation not required for I/D coherence",
1511 .capability
= ARM64_HAS_CACHE_DIC
,
1512 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1513 .matches
= has_cache_dic
,
1516 .desc
= "Stage-2 Force Write-Back",
1517 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1518 .capability
= ARM64_HAS_STAGE2_FWB
,
1519 .sys_reg
= SYS_ID_AA64MMFR2_EL1
,
1520 .sign
= FTR_UNSIGNED
,
1521 .field_pos
= ID_AA64MMFR2_FWB_SHIFT
,
1522 .min_field_value
= 1,
1523 .matches
= has_cpuid_feature
,
1524 .cpu_enable
= cpu_has_fwb
,
1526 #ifdef CONFIG_ARM64_HW_AFDBM
1529 * Since we turn this on always, we don't want the user to
1530 * think that the feature is available when it may not be.
1531 * So hide the description.
1533 * .desc = "Hardware pagetable Dirty Bit Management",
1536 .type
= ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE
,
1537 .capability
= ARM64_HW_DBM
,
1538 .sys_reg
= SYS_ID_AA64MMFR1_EL1
,
1539 .sign
= FTR_UNSIGNED
,
1540 .field_pos
= ID_AA64MMFR1_HADBS_SHIFT
,
1541 .min_field_value
= 2,
1542 .matches
= has_hw_dbm
,
1543 .cpu_enable
= cpu_enable_hw_dbm
,
1547 .desc
= "CRC32 instructions",
1548 .capability
= ARM64_HAS_CRC32
,
1549 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1550 .matches
= has_cpuid_feature
,
1551 .sys_reg
= SYS_ID_AA64ISAR0_EL1
,
1552 .field_pos
= ID_AA64ISAR0_CRC32_SHIFT
,
1553 .min_field_value
= 1,
1555 #ifdef CONFIG_ARM64_SSBD
1557 .desc
= "Speculative Store Bypassing Safe (SSBS)",
1558 .capability
= ARM64_SSBS
,
1559 .type
= ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE
,
1560 .matches
= has_cpuid_feature
,
1561 .sys_reg
= SYS_ID_AA64PFR1_EL1
,
1562 .field_pos
= ID_AA64PFR1_SSBS_SHIFT
,
1563 .sign
= FTR_UNSIGNED
,
1564 .min_field_value
= ID_AA64PFR1_SSBS_PSTATE_ONLY
,
1565 .cpu_enable
= cpu_enable_ssbs
,
1568 #ifdef CONFIG_ARM64_CNP
1570 .desc
= "Common not Private translations",
1571 .capability
= ARM64_HAS_CNP
,
1572 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1573 .matches
= has_useable_cnp
,
1574 .sys_reg
= SYS_ID_AA64MMFR2_EL1
,
1575 .sign
= FTR_UNSIGNED
,
1576 .field_pos
= ID_AA64MMFR2_CNP_SHIFT
,
1577 .min_field_value
= 1,
1578 .cpu_enable
= cpu_enable_cnp
,
1582 .desc
= "Speculation barrier (SB)",
1583 .capability
= ARM64_HAS_SB
,
1584 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1585 .matches
= has_cpuid_feature
,
1586 .sys_reg
= SYS_ID_AA64ISAR1_EL1
,
1587 .field_pos
= ID_AA64ISAR1_SB_SHIFT
,
1588 .sign
= FTR_UNSIGNED
,
1589 .min_field_value
= 1,
1591 #ifdef CONFIG_ARM64_PTR_AUTH
1593 .desc
= "Address authentication (architected algorithm)",
1594 .capability
= ARM64_HAS_ADDRESS_AUTH_ARCH
,
1595 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1596 .sys_reg
= SYS_ID_AA64ISAR1_EL1
,
1597 .sign
= FTR_UNSIGNED
,
1598 .field_pos
= ID_AA64ISAR1_APA_SHIFT
,
1599 .min_field_value
= ID_AA64ISAR1_APA_ARCHITECTED
,
1600 .matches
= has_cpuid_feature
,
1601 .cpu_enable
= cpu_enable_address_auth
,
1604 .desc
= "Address authentication (IMP DEF algorithm)",
1605 .capability
= ARM64_HAS_ADDRESS_AUTH_IMP_DEF
,
1606 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1607 .sys_reg
= SYS_ID_AA64ISAR1_EL1
,
1608 .sign
= FTR_UNSIGNED
,
1609 .field_pos
= ID_AA64ISAR1_API_SHIFT
,
1610 .min_field_value
= ID_AA64ISAR1_API_IMP_DEF
,
1611 .matches
= has_cpuid_feature
,
1612 .cpu_enable
= cpu_enable_address_auth
,
1615 .desc
= "Generic authentication (architected algorithm)",
1616 .capability
= ARM64_HAS_GENERIC_AUTH_ARCH
,
1617 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1618 .sys_reg
= SYS_ID_AA64ISAR1_EL1
,
1619 .sign
= FTR_UNSIGNED
,
1620 .field_pos
= ID_AA64ISAR1_GPA_SHIFT
,
1621 .min_field_value
= ID_AA64ISAR1_GPA_ARCHITECTED
,
1622 .matches
= has_cpuid_feature
,
1625 .desc
= "Generic authentication (IMP DEF algorithm)",
1626 .capability
= ARM64_HAS_GENERIC_AUTH_IMP_DEF
,
1627 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1628 .sys_reg
= SYS_ID_AA64ISAR1_EL1
,
1629 .sign
= FTR_UNSIGNED
,
1630 .field_pos
= ID_AA64ISAR1_GPI_SHIFT
,
1631 .min_field_value
= ID_AA64ISAR1_GPI_IMP_DEF
,
1632 .matches
= has_cpuid_feature
,
1634 #endif /* CONFIG_ARM64_PTR_AUTH */
1635 #ifdef CONFIG_ARM64_PSEUDO_NMI
1638 * Depends on having GICv3
1640 .desc
= "IRQ priority masking",
1641 .capability
= ARM64_HAS_IRQ_PRIO_MASKING
,
1642 .type
= ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE
,
1643 .matches
= can_use_gic_priorities
,
1644 .sys_reg
= SYS_ID_AA64PFR0_EL1
,
1645 .field_pos
= ID_AA64PFR0_GIC_SHIFT
,
1646 .sign
= FTR_UNSIGNED
,
1647 .min_field_value
= 1,
1650 #ifdef CONFIG_ARM64_E0PD
1653 .capability
= ARM64_HAS_E0PD
,
1654 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1655 .sys_reg
= SYS_ID_AA64MMFR2_EL1
,
1656 .sign
= FTR_UNSIGNED
,
1657 .field_pos
= ID_AA64MMFR2_E0PD_SHIFT
,
1658 .matches
= has_cpuid_feature
,
1659 .min_field_value
= 1,
1660 .cpu_enable
= cpu_enable_e0pd
,
1663 #ifdef CONFIG_ARCH_RANDOM
1665 .desc
= "Random Number Generator",
1666 .capability
= ARM64_HAS_RNG
,
1667 .type
= ARM64_CPUCAP_SYSTEM_FEATURE
,
1668 .matches
= has_cpuid_feature
,
1669 .sys_reg
= SYS_ID_AA64ISAR0_EL1
,
1670 .field_pos
= ID_AA64ISAR0_RNDR_SHIFT
,
1671 .sign
= FTR_UNSIGNED
,
1672 .min_field_value
= 1,
1678 #define HWCAP_CPUID_MATCH(reg, field, s, min_value) \
1679 .matches = has_cpuid_feature, \
1681 .field_pos = field, \
1683 .min_field_value = min_value,
1685 #define __HWCAP_CAP(name, cap_type, cap) \
1687 .type = ARM64_CPUCAP_SYSTEM_FEATURE, \
1688 .hwcap_type = cap_type, \
1691 #define HWCAP_CAP(reg, field, s, min_value, cap_type, cap) \
1693 __HWCAP_CAP(#cap, cap_type, cap) \
1694 HWCAP_CPUID_MATCH(reg, field, s, min_value) \
1697 #define HWCAP_MULTI_CAP(list, cap_type, cap) \
1699 __HWCAP_CAP(#cap, cap_type, cap) \
1700 .matches = cpucap_multi_entry_cap_matches, \
1701 .match_list = list, \
1704 #define HWCAP_CAP_MATCH(match, cap_type, cap) \
1706 __HWCAP_CAP(#cap, cap_type, cap) \
1710 #ifdef CONFIG_ARM64_PTR_AUTH
1711 static const struct arm64_cpu_capabilities ptr_auth_hwcap_addr_matches
[] = {
1713 HWCAP_CPUID_MATCH(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_APA_SHIFT
,
1714 FTR_UNSIGNED
, ID_AA64ISAR1_APA_ARCHITECTED
)
1717 HWCAP_CPUID_MATCH(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_API_SHIFT
,
1718 FTR_UNSIGNED
, ID_AA64ISAR1_API_IMP_DEF
)
1723 static const struct arm64_cpu_capabilities ptr_auth_hwcap_gen_matches
[] = {
1725 HWCAP_CPUID_MATCH(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_GPA_SHIFT
,
1726 FTR_UNSIGNED
, ID_AA64ISAR1_GPA_ARCHITECTED
)
1729 HWCAP_CPUID_MATCH(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_GPI_SHIFT
,
1730 FTR_UNSIGNED
, ID_AA64ISAR1_GPI_IMP_DEF
)
1736 static const struct arm64_cpu_capabilities arm64_elf_hwcaps
[] = {
1737 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_AES_SHIFT
, FTR_UNSIGNED
, 2, CAP_HWCAP
, KERNEL_HWCAP_PMULL
),
1738 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_AES_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_AES
),
1739 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_SHA1_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_SHA1
),
1740 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_SHA2_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_SHA2
),
1741 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_SHA2_SHIFT
, FTR_UNSIGNED
, 2, CAP_HWCAP
, KERNEL_HWCAP_SHA512
),
1742 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_CRC32_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_CRC32
),
1743 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_ATOMICS_SHIFT
, FTR_UNSIGNED
, 2, CAP_HWCAP
, KERNEL_HWCAP_ATOMICS
),
1744 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_RDM_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_ASIMDRDM
),
1745 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_SHA3_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_SHA3
),
1746 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_SM3_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_SM3
),
1747 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_SM4_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_SM4
),
1748 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_DP_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_ASIMDDP
),
1749 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_FHM_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_ASIMDFHM
),
1750 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_TS_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_FLAGM
),
1751 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_TS_SHIFT
, FTR_UNSIGNED
, 2, CAP_HWCAP
, KERNEL_HWCAP_FLAGM2
),
1752 HWCAP_CAP(SYS_ID_AA64ISAR0_EL1
, ID_AA64ISAR0_RNDR_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_RNG
),
1753 HWCAP_CAP(SYS_ID_AA64PFR0_EL1
, ID_AA64PFR0_FP_SHIFT
, FTR_SIGNED
, 0, CAP_HWCAP
, KERNEL_HWCAP_FP
),
1754 HWCAP_CAP(SYS_ID_AA64PFR0_EL1
, ID_AA64PFR0_FP_SHIFT
, FTR_SIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_FPHP
),
1755 HWCAP_CAP(SYS_ID_AA64PFR0_EL1
, ID_AA64PFR0_ASIMD_SHIFT
, FTR_SIGNED
, 0, CAP_HWCAP
, KERNEL_HWCAP_ASIMD
),
1756 HWCAP_CAP(SYS_ID_AA64PFR0_EL1
, ID_AA64PFR0_ASIMD_SHIFT
, FTR_SIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_ASIMDHP
),
1757 HWCAP_CAP(SYS_ID_AA64PFR0_EL1
, ID_AA64PFR0_DIT_SHIFT
, FTR_SIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_DIT
),
1758 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_DPB_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_DCPOP
),
1759 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_DPB_SHIFT
, FTR_UNSIGNED
, 2, CAP_HWCAP
, KERNEL_HWCAP_DCPODP
),
1760 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_JSCVT_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_JSCVT
),
1761 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_FCMA_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_FCMA
),
1762 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_LRCPC_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_LRCPC
),
1763 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_LRCPC_SHIFT
, FTR_UNSIGNED
, 2, CAP_HWCAP
, KERNEL_HWCAP_ILRCPC
),
1764 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_FRINTTS_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_FRINT
),
1765 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_SB_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_SB
),
1766 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_BF16_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_BF16
),
1767 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_DGH_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_DGH
),
1768 HWCAP_CAP(SYS_ID_AA64ISAR1_EL1
, ID_AA64ISAR1_I8MM_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_I8MM
),
1769 HWCAP_CAP(SYS_ID_AA64MMFR2_EL1
, ID_AA64MMFR2_AT_SHIFT
, FTR_UNSIGNED
, 1, CAP_HWCAP
, KERNEL_HWCAP_USCAT
),
1770 #ifdef CONFIG_ARM64_SVE
1771 HWCAP_CAP(SYS_ID_AA64PFR0_EL1
, ID_AA64PFR0_SVE_SHIFT
, FTR_UNSIGNED
, ID_AA64PFR0_SVE
, CAP_HWCAP
, KERNEL_HWCAP_SVE
),
1772 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_SVEVER_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_SVEVER_SVE2
, CAP_HWCAP
, KERNEL_HWCAP_SVE2
),
1773 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_AES_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_AES
, CAP_HWCAP
, KERNEL_HWCAP_SVEAES
),
1774 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_AES_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_AES_PMULL
, CAP_HWCAP
, KERNEL_HWCAP_SVEPMULL
),
1775 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_BITPERM_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_BITPERM
, CAP_HWCAP
, KERNEL_HWCAP_SVEBITPERM
),
1776 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_BF16_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_BF16
, CAP_HWCAP
, KERNEL_HWCAP_SVEBF16
),
1777 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_SHA3_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_SHA3
, CAP_HWCAP
, KERNEL_HWCAP_SVESHA3
),
1778 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_SM4_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_SM4
, CAP_HWCAP
, KERNEL_HWCAP_SVESM4
),
1779 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_I8MM_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_I8MM
, CAP_HWCAP
, KERNEL_HWCAP_SVEI8MM
),
1780 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_F32MM_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_F32MM
, CAP_HWCAP
, KERNEL_HWCAP_SVEF32MM
),
1781 HWCAP_CAP(SYS_ID_AA64ZFR0_EL1
, ID_AA64ZFR0_F64MM_SHIFT
, FTR_UNSIGNED
, ID_AA64ZFR0_F64MM
, CAP_HWCAP
, KERNEL_HWCAP_SVEF64MM
),
1783 HWCAP_CAP(SYS_ID_AA64PFR1_EL1
, ID_AA64PFR1_SSBS_SHIFT
, FTR_UNSIGNED
, ID_AA64PFR1_SSBS_PSTATE_INSNS
, CAP_HWCAP
, KERNEL_HWCAP_SSBS
),
1784 #ifdef CONFIG_ARM64_PTR_AUTH
1785 HWCAP_MULTI_CAP(ptr_auth_hwcap_addr_matches
, CAP_HWCAP
, KERNEL_HWCAP_PACA
),
1786 HWCAP_MULTI_CAP(ptr_auth_hwcap_gen_matches
, CAP_HWCAP
, KERNEL_HWCAP_PACG
),
1791 #ifdef CONFIG_COMPAT
1792 static bool compat_has_neon(const struct arm64_cpu_capabilities
*cap
, int scope
)
1795 * Check that all of MVFR1_EL1.{SIMDSP, SIMDInt, SIMDLS} are available,
1796 * in line with that of arm32 as in vfp_init(). We make sure that the
1797 * check is future proof, by making sure value is non-zero.
1801 WARN_ON(scope
== SCOPE_LOCAL_CPU
&& preemptible());
1802 if (scope
== SCOPE_SYSTEM
)
1803 mvfr1
= read_sanitised_ftr_reg(SYS_MVFR1_EL1
);
1805 mvfr1
= read_sysreg_s(SYS_MVFR1_EL1
);
1807 return cpuid_feature_extract_unsigned_field(mvfr1
, MVFR1_SIMDSP_SHIFT
) &&
1808 cpuid_feature_extract_unsigned_field(mvfr1
, MVFR1_SIMDINT_SHIFT
) &&
1809 cpuid_feature_extract_unsigned_field(mvfr1
, MVFR1_SIMDLS_SHIFT
);
1813 static const struct arm64_cpu_capabilities compat_elf_hwcaps
[] = {
1814 #ifdef CONFIG_COMPAT
1815 HWCAP_CAP_MATCH(compat_has_neon
, CAP_COMPAT_HWCAP
, COMPAT_HWCAP_NEON
),
1816 HWCAP_CAP(SYS_MVFR1_EL1
, MVFR1_SIMDFMAC_SHIFT
, FTR_UNSIGNED
, 1, CAP_COMPAT_HWCAP
, COMPAT_HWCAP_VFPv4
),
1817 /* Arm v8 mandates MVFR0.FPDP == {0, 2}. So, piggy back on this for the presence of VFP support */
1818 HWCAP_CAP(SYS_MVFR0_EL1
, MVFR0_FPDP_SHIFT
, FTR_UNSIGNED
, 2, CAP_COMPAT_HWCAP
, COMPAT_HWCAP_VFP
),
1819 HWCAP_CAP(SYS_MVFR0_EL1
, MVFR0_FPDP_SHIFT
, FTR_UNSIGNED
, 2, CAP_COMPAT_HWCAP
, COMPAT_HWCAP_VFPv3
),
1820 HWCAP_CAP(SYS_ID_ISAR5_EL1
, ID_ISAR5_AES_SHIFT
, FTR_UNSIGNED
, 2, CAP_COMPAT_HWCAP2
, COMPAT_HWCAP2_PMULL
),
1821 HWCAP_CAP(SYS_ID_ISAR5_EL1
, ID_ISAR5_AES_SHIFT
, FTR_UNSIGNED
, 1, CAP_COMPAT_HWCAP2
, COMPAT_HWCAP2_AES
),
1822 HWCAP_CAP(SYS_ID_ISAR5_EL1
, ID_ISAR5_SHA1_SHIFT
, FTR_UNSIGNED
, 1, CAP_COMPAT_HWCAP2
, COMPAT_HWCAP2_SHA1
),
1823 HWCAP_CAP(SYS_ID_ISAR5_EL1
, ID_ISAR5_SHA2_SHIFT
, FTR_UNSIGNED
, 1, CAP_COMPAT_HWCAP2
, COMPAT_HWCAP2_SHA2
),
1824 HWCAP_CAP(SYS_ID_ISAR5_EL1
, ID_ISAR5_CRC32_SHIFT
, FTR_UNSIGNED
, 1, CAP_COMPAT_HWCAP2
, COMPAT_HWCAP2_CRC32
),
1829 static void __init
cap_set_elf_hwcap(const struct arm64_cpu_capabilities
*cap
)
1831 switch (cap
->hwcap_type
) {
1833 cpu_set_feature(cap
->hwcap
);
1835 #ifdef CONFIG_COMPAT
1836 case CAP_COMPAT_HWCAP
:
1837 compat_elf_hwcap
|= (u32
)cap
->hwcap
;
1839 case CAP_COMPAT_HWCAP2
:
1840 compat_elf_hwcap2
|= (u32
)cap
->hwcap
;
1849 /* Check if we have a particular HWCAP enabled */
1850 static bool cpus_have_elf_hwcap(const struct arm64_cpu_capabilities
*cap
)
1854 switch (cap
->hwcap_type
) {
1856 rc
= cpu_have_feature(cap
->hwcap
);
1858 #ifdef CONFIG_COMPAT
1859 case CAP_COMPAT_HWCAP
:
1860 rc
= (compat_elf_hwcap
& (u32
)cap
->hwcap
) != 0;
1862 case CAP_COMPAT_HWCAP2
:
1863 rc
= (compat_elf_hwcap2
& (u32
)cap
->hwcap
) != 0;
1874 static void __init
setup_elf_hwcaps(const struct arm64_cpu_capabilities
*hwcaps
)
1876 /* We support emulation of accesses to CPU ID feature registers */
1877 cpu_set_named_feature(CPUID
);
1878 for (; hwcaps
->matches
; hwcaps
++)
1879 if (hwcaps
->matches(hwcaps
, cpucap_default_scope(hwcaps
)))
1880 cap_set_elf_hwcap(hwcaps
);
1883 static void update_cpu_capabilities(u16 scope_mask
)
1886 const struct arm64_cpu_capabilities
*caps
;
1888 scope_mask
&= ARM64_CPUCAP_SCOPE_MASK
;
1889 for (i
= 0; i
< ARM64_NCAPS
; i
++) {
1890 caps
= cpu_hwcaps_ptrs
[i
];
1891 if (!caps
|| !(caps
->type
& scope_mask
) ||
1892 cpus_have_cap(caps
->capability
) ||
1893 !caps
->matches(caps
, cpucap_default_scope(caps
)))
1897 pr_info("detected: %s\n", caps
->desc
);
1898 cpus_set_cap(caps
->capability
);
1900 if ((scope_mask
& SCOPE_BOOT_CPU
) && (caps
->type
& SCOPE_BOOT_CPU
))
1901 set_bit(caps
->capability
, boot_capabilities
);
1906 * Enable all the available capabilities on this CPU. The capabilities
1907 * with BOOT_CPU scope are handled separately and hence skipped here.
1909 static int cpu_enable_non_boot_scope_capabilities(void *__unused
)
1912 u16 non_boot_scope
= SCOPE_ALL
& ~SCOPE_BOOT_CPU
;
1914 for_each_available_cap(i
) {
1915 const struct arm64_cpu_capabilities
*cap
= cpu_hwcaps_ptrs
[i
];
1920 if (!(cap
->type
& non_boot_scope
))
1923 if (cap
->cpu_enable
)
1924 cap
->cpu_enable(cap
);
1930 * Run through the enabled capabilities and enable() it on all active
1933 static void __init
enable_cpu_capabilities(u16 scope_mask
)
1936 const struct arm64_cpu_capabilities
*caps
;
1939 scope_mask
&= ARM64_CPUCAP_SCOPE_MASK
;
1940 boot_scope
= !!(scope_mask
& SCOPE_BOOT_CPU
);
1942 for (i
= 0; i
< ARM64_NCAPS
; i
++) {
1945 caps
= cpu_hwcaps_ptrs
[i
];
1946 if (!caps
|| !(caps
->type
& scope_mask
))
1948 num
= caps
->capability
;
1949 if (!cpus_have_cap(num
))
1952 /* Ensure cpus_have_const_cap(num) works */
1953 static_branch_enable(&cpu_hwcap_keys
[num
]);
1955 if (boot_scope
&& caps
->cpu_enable
)
1957 * Capabilities with SCOPE_BOOT_CPU scope are finalised
1958 * before any secondary CPU boots. Thus, each secondary
1959 * will enable the capability as appropriate via
1960 * check_local_cpu_capabilities(). The only exception is
1961 * the boot CPU, for which the capability must be
1962 * enabled here. This approach avoids costly
1963 * stop_machine() calls for this case.
1965 caps
->cpu_enable(caps
);
1969 * For all non-boot scope capabilities, use stop_machine()
1970 * as it schedules the work allowing us to modify PSTATE,
1971 * instead of on_each_cpu() which uses an IPI, giving us a
1972 * PSTATE that disappears when we return.
1975 stop_machine(cpu_enable_non_boot_scope_capabilities
,
1976 NULL
, cpu_online_mask
);
1980 * Run through the list of capabilities to check for conflicts.
1981 * If the system has already detected a capability, take necessary
1982 * action on this CPU.
1984 * Returns "false" on conflicts.
1986 static bool verify_local_cpu_caps(u16 scope_mask
)
1989 bool cpu_has_cap
, system_has_cap
;
1990 const struct arm64_cpu_capabilities
*caps
;
1992 scope_mask
&= ARM64_CPUCAP_SCOPE_MASK
;
1994 for (i
= 0; i
< ARM64_NCAPS
; i
++) {
1995 caps
= cpu_hwcaps_ptrs
[i
];
1996 if (!caps
|| !(caps
->type
& scope_mask
))
1999 cpu_has_cap
= caps
->matches(caps
, SCOPE_LOCAL_CPU
);
2000 system_has_cap
= cpus_have_cap(caps
->capability
);
2002 if (system_has_cap
) {
2004 * Check if the new CPU misses an advertised feature,
2005 * which is not safe to miss.
2007 if (!cpu_has_cap
&& !cpucap_late_cpu_optional(caps
))
2010 * We have to issue cpu_enable() irrespective of
2011 * whether the CPU has it or not, as it is enabeld
2012 * system wide. It is upto the call back to take
2013 * appropriate action on this CPU.
2015 if (caps
->cpu_enable
)
2016 caps
->cpu_enable(caps
);
2019 * Check if the CPU has this capability if it isn't
2020 * safe to have when the system doesn't.
2022 if (cpu_has_cap
&& !cpucap_late_cpu_permitted(caps
))
2027 if (i
< ARM64_NCAPS
) {
2028 pr_crit("CPU%d: Detected conflict for capability %d (%s), System: %d, CPU: %d\n",
2029 smp_processor_id(), caps
->capability
,
2030 caps
->desc
, system_has_cap
, cpu_has_cap
);
2038 * Check for CPU features that are used in early boot
2039 * based on the Boot CPU value.
2041 static void check_early_cpu_features(void)
2043 verify_cpu_asid_bits();
2045 * Early features are used by the kernel already. If there
2046 * is a conflict, we cannot proceed further.
2048 if (!verify_local_cpu_caps(SCOPE_BOOT_CPU
))
2053 verify_local_elf_hwcaps(const struct arm64_cpu_capabilities
*caps
)
2056 for (; caps
->matches
; caps
++)
2057 if (cpus_have_elf_hwcap(caps
) && !caps
->matches(caps
, SCOPE_LOCAL_CPU
)) {
2058 pr_crit("CPU%d: missing HWCAP: %s\n",
2059 smp_processor_id(), caps
->desc
);
2064 static void verify_sve_features(void)
2066 u64 safe_zcr
= read_sanitised_ftr_reg(SYS_ZCR_EL1
);
2067 u64 zcr
= read_zcr_features();
2069 unsigned int safe_len
= safe_zcr
& ZCR_ELx_LEN_MASK
;
2070 unsigned int len
= zcr
& ZCR_ELx_LEN_MASK
;
2072 if (len
< safe_len
|| sve_verify_vq_map()) {
2073 pr_crit("CPU%d: SVE: vector length support mismatch\n",
2074 smp_processor_id());
2078 /* Add checks on other ZCR bits here if necessary */
2083 * Run through the enabled system capabilities and enable() it on this CPU.
2084 * The capabilities were decided based on the available CPUs at the boot time.
2085 * Any new CPU should match the system wide status of the capability. If the
2086 * new CPU doesn't have a capability which the system now has enabled, we
2087 * cannot do anything to fix it up and could cause unexpected failures. So
2090 static void verify_local_cpu_capabilities(void)
2093 * The capabilities with SCOPE_BOOT_CPU are checked from
2094 * check_early_cpu_features(), as they need to be verified
2095 * on all secondary CPUs.
2097 if (!verify_local_cpu_caps(SCOPE_ALL
& ~SCOPE_BOOT_CPU
))
2100 verify_local_elf_hwcaps(arm64_elf_hwcaps
);
2102 if (system_supports_32bit_el0())
2103 verify_local_elf_hwcaps(compat_elf_hwcaps
);
2105 if (system_supports_sve())
2106 verify_sve_features();
2109 void check_local_cpu_capabilities(void)
2112 * All secondary CPUs should conform to the early CPU features
2113 * in use by the kernel based on boot CPU.
2115 check_early_cpu_features();
2118 * If we haven't finalised the system capabilities, this CPU gets
2119 * a chance to update the errata work arounds and local features.
2120 * Otherwise, this CPU should verify that it has all the system
2121 * advertised capabilities.
2123 if (!system_capabilities_finalized())
2124 update_cpu_capabilities(SCOPE_LOCAL_CPU
);
2126 verify_local_cpu_capabilities();
2129 static void __init
setup_boot_cpu_capabilities(void)
2131 /* Detect capabilities with either SCOPE_BOOT_CPU or SCOPE_LOCAL_CPU */
2132 update_cpu_capabilities(SCOPE_BOOT_CPU
| SCOPE_LOCAL_CPU
);
2133 /* Enable the SCOPE_BOOT_CPU capabilities alone right away */
2134 enable_cpu_capabilities(SCOPE_BOOT_CPU
);
2137 bool this_cpu_has_cap(unsigned int n
)
2139 if (!WARN_ON(preemptible()) && n
< ARM64_NCAPS
) {
2140 const struct arm64_cpu_capabilities
*cap
= cpu_hwcaps_ptrs
[n
];
2143 return cap
->matches(cap
, SCOPE_LOCAL_CPU
);
2149 void cpu_set_feature(unsigned int num
)
2151 WARN_ON(num
>= MAX_CPU_FEATURES
);
2152 elf_hwcap
|= BIT(num
);
2154 EXPORT_SYMBOL_GPL(cpu_set_feature
);
2156 bool cpu_have_feature(unsigned int num
)
2158 WARN_ON(num
>= MAX_CPU_FEATURES
);
2159 return elf_hwcap
& BIT(num
);
2161 EXPORT_SYMBOL_GPL(cpu_have_feature
);
2163 unsigned long cpu_get_elf_hwcap(void)
2166 * We currently only populate the first 32 bits of AT_HWCAP. Please
2167 * note that for userspace compatibility we guarantee that bits 62
2168 * and 63 will always be returned as 0.
2170 return lower_32_bits(elf_hwcap
);
2173 unsigned long cpu_get_elf_hwcap2(void)
2175 return upper_32_bits(elf_hwcap
);
2178 static void __init
setup_system_capabilities(void)
2181 * We have finalised the system-wide safe feature
2182 * registers, finalise the capabilities that depend
2183 * on it. Also enable all the available capabilities,
2184 * that are not enabled already.
2186 update_cpu_capabilities(SCOPE_SYSTEM
);
2187 enable_cpu_capabilities(SCOPE_ALL
& ~SCOPE_BOOT_CPU
);
2190 void __init
setup_cpu_features(void)
2194 setup_system_capabilities();
2195 setup_elf_hwcaps(arm64_elf_hwcaps
);
2197 if (system_supports_32bit_el0())
2198 setup_elf_hwcaps(compat_elf_hwcaps
);
2200 if (system_uses_ttbr0_pan())
2201 pr_info("emulated: Privileged Access Never (PAN) using TTBR0_EL1 switching\n");
2204 minsigstksz_setup();
2206 /* Advertise that we have computed the system capabilities */
2207 finalize_system_capabilities();
2210 * Check for sane CTR_EL0.CWG value.
2212 cwg
= cache_type_cwg();
2214 pr_warn("No Cache Writeback Granule information, assuming %d\n",
2218 static bool __maybe_unused
2219 cpufeature_pan_not_uao(const struct arm64_cpu_capabilities
*entry
, int __unused
)
2221 return (cpus_have_const_cap(ARM64_HAS_PAN
) && !cpus_have_const_cap(ARM64_HAS_UAO
));
2224 static void __maybe_unused
cpu_enable_cnp(struct arm64_cpu_capabilities
const *cap
)
2226 cpu_replace_ttbr1(lm_alias(swapper_pg_dir
));
2230 * We emulate only the following system register space.
2231 * Op0 = 0x3, CRn = 0x0, Op1 = 0x0, CRm = [0, 4 - 7]
2232 * See Table C5-6 System instruction encodings for System register accesses,
2233 * ARMv8 ARM(ARM DDI 0487A.f) for more details.
2235 static inline bool __attribute_const__
is_emulated(u32 id
)
2237 return (sys_reg_Op0(id
) == 0x3 &&
2238 sys_reg_CRn(id
) == 0x0 &&
2239 sys_reg_Op1(id
) == 0x0 &&
2240 (sys_reg_CRm(id
) == 0 ||
2241 ((sys_reg_CRm(id
) >= 4) && (sys_reg_CRm(id
) <= 7))));
2245 * With CRm == 0, reg should be one of :
2246 * MIDR_EL1, MPIDR_EL1 or REVIDR_EL1.
2248 static inline int emulate_id_reg(u32 id
, u64
*valp
)
2252 *valp
= read_cpuid_id();
2255 *valp
= SYS_MPIDR_SAFE_VAL
;
2257 case SYS_REVIDR_EL1
:
2258 /* IMPLEMENTATION DEFINED values are emulated with 0 */
2268 static int emulate_sys_reg(u32 id
, u64
*valp
)
2270 struct arm64_ftr_reg
*regp
;
2272 if (!is_emulated(id
))
2275 if (sys_reg_CRm(id
) == 0)
2276 return emulate_id_reg(id
, valp
);
2278 regp
= get_arm64_ftr_reg(id
);
2280 *valp
= arm64_ftr_reg_user_value(regp
);
2283 * The untracked registers are either IMPLEMENTATION DEFINED
2284 * (e.g, ID_AFR0_EL1) or reserved RAZ.
2290 int do_emulate_mrs(struct pt_regs
*regs
, u32 sys_reg
, u32 rt
)
2295 rc
= emulate_sys_reg(sys_reg
, &val
);
2297 pt_regs_write_reg(regs
, rt
, val
);
2298 arm64_skip_faulting_instruction(regs
, AARCH64_INSN_SIZE
);
2303 static int emulate_mrs(struct pt_regs
*regs
, u32 insn
)
2308 * sys_reg values are defined as used in mrs/msr instruction.
2309 * shift the imm value to get the encoding.
2311 sys_reg
= (u32
)aarch64_insn_decode_immediate(AARCH64_INSN_IMM_16
, insn
) << 5;
2312 rt
= aarch64_insn_decode_register(AARCH64_INSN_REGTYPE_RT
, insn
);
2313 return do_emulate_mrs(regs
, sys_reg
, rt
);
2316 static struct undef_hook mrs_hook
= {
2317 .instr_mask
= 0xfff00000,
2318 .instr_val
= 0xd5300000,
2319 .pstate_mask
= PSR_AA32_MODE_MASK
,
2320 .pstate_val
= PSR_MODE_EL0t
,
2324 static int __init
enable_mrs_emulation(void)
2326 register_undef_hook(&mrs_hook
);
2330 core_initcall(enable_mrs_emulation
);
2332 ssize_t
cpu_show_meltdown(struct device
*dev
, struct device_attribute
*attr
,
2335 if (__meltdown_safe
)
2336 return sprintf(buf
, "Not affected\n");
2338 if (arm64_kernel_unmapped_at_el0())
2339 return sprintf(buf
, "Mitigation: PTI\n");
2341 return sprintf(buf
, "Vulnerable\n");