blob: 401246e095e711dade152b74e0aaff93b2596493 [file] [log] [blame]
Thomas Gleixnercaab2772019-06-03 07:44:50 +02001// SPDX-License-Identifier: GPL-2.0-only
Andre Przywarae116a372014-11-14 15:54:09 +00002/*
3 * Contains CPU specific errata definitions
4 *
5 * Copyright (C) 2014 ARM Ltd.
Andre Przywarae116a372014-11-14 15:54:09 +00006 */
7
Arnd Bergmann94a5d872018-06-05 13:50:07 +02008#include <linux/arm-smccc.h>
Andre Przywarae116a372014-11-14 15:54:09 +00009#include <linux/types.h>
Josh Poimboeufa111b7c2019-04-12 15:39:32 -050010#include <linux/cpu.h>
Andre Przywarae116a372014-11-14 15:54:09 +000011#include <asm/cpu.h>
12#include <asm/cputype.h>
13#include <asm/cpufeature.h>
14
Andre Przywara301bcfa2014-11-14 15:54:10 +000015static bool __maybe_unused
Suzuki K Poulose92406f02016-04-22 12:25:31 +010016is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope)
Andre Przywara301bcfa2014-11-14 15:54:10 +000017{
Ard Biesheuvele8002e02018-03-06 17:15:34 +000018 const struct arm64_midr_revidr *fix;
19 u32 midr = read_cpuid_id(), revidr;
20
Suzuki K Poulose92406f02016-04-22 12:25:31 +010021 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
Suzuki K Poulose1df31052018-03-26 15:12:44 +010022 if (!is_midr_in_range(midr, &entry->midr_range))
Ard Biesheuvele8002e02018-03-06 17:15:34 +000023 return false;
24
25 midr &= MIDR_REVISION_MASK | MIDR_VARIANT_MASK;
26 revidr = read_cpuid(REVIDR_EL1);
27 for (fix = entry->fixed_revs; fix && fix->revidr_mask; fix++)
28 if (midr == fix->midr_rv && (revidr & fix->revidr_mask))
29 return false;
30
31 return true;
Andre Przywara301bcfa2014-11-14 15:54:10 +000032}
33
Stephen Boydbb487112017-12-13 14:19:37 -080034static bool __maybe_unused
Suzuki K Poulosebe5b2992018-03-26 15:12:45 +010035is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry,
36 int scope)
37{
38 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
39 return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list);
Andre Przywara301bcfa2014-11-14 15:54:10 +000040}
41
Stephen Boydbb487112017-12-13 14:19:37 -080042static bool __maybe_unused
43is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope)
44{
45 u32 model;
46
47 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
48
49 model = read_cpuid_id();
50 model &= MIDR_IMPLEMENTOR_MASK | (0xf00 << MIDR_PARTNUM_SHIFT) |
51 MIDR_ARCHITECTURE_MASK;
52
Suzuki K Poulose1df31052018-03-26 15:12:44 +010053 return model == entry->midr_range.model;
Stephen Boydbb487112017-12-13 14:19:37 -080054}
55
Suzuki K Poulose116c81f2016-09-09 14:07:16 +010056static bool
Suzuki K Poulose314d53d2018-07-04 23:07:46 +010057has_mismatched_cache_type(const struct arm64_cpu_capabilities *entry,
58 int scope)
Suzuki K Poulose116c81f2016-09-09 14:07:16 +010059{
Suzuki K Poulose1602df02018-10-09 14:47:06 +010060 u64 mask = arm64_ftr_reg_ctrel0.strict_mask;
61 u64 sys = arm64_ftr_reg_ctrel0.sys_val & mask;
62 u64 ctr_raw, ctr_real;
Suzuki K Poulose314d53d2018-07-04 23:07:46 +010063
Suzuki K Poulose116c81f2016-09-09 14:07:16 +010064 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
Suzuki K Poulose1602df02018-10-09 14:47:06 +010065
66 /*
67 * We want to make sure that all the CPUs in the system expose
68 * a consistent CTR_EL0 to make sure that applications behaves
69 * correctly with migration.
70 *
71 * If a CPU has CTR_EL0.IDC but does not advertise it via CTR_EL0 :
72 *
73 * 1) It is safe if the system doesn't support IDC, as CPU anyway
74 * reports IDC = 0, consistent with the rest.
75 *
76 * 2) If the system has IDC, it is still safe as we trap CTR_EL0
77 * access on this CPU via the ARM64_HAS_CACHE_IDC capability.
78 *
79 * So, we need to make sure either the raw CTR_EL0 or the effective
80 * CTR_EL0 matches the system's copy to allow a secondary CPU to boot.
81 */
82 ctr_raw = read_cpuid_cachetype() & mask;
83 ctr_real = read_cpuid_effective_cachetype() & mask;
84
85 return (ctr_real != sys) && (ctr_raw != sys);
Suzuki K Poulose116c81f2016-09-09 14:07:16 +010086}
87
Dave Martinc0cda3b2018-03-26 15:12:28 +010088static void
89cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *__unused)
Suzuki K Poulose116c81f2016-09-09 14:07:16 +010090{
Suzuki K Poulose4afe8e72018-10-09 14:47:07 +010091 u64 mask = arm64_ftr_reg_ctrel0.strict_mask;
92
93 /* Trap CTR_EL0 access on this CPU, only if it has a mismatch */
94 if ((read_cpuid_cachetype() & mask) !=
95 (arm64_ftr_reg_ctrel0.sys_val & mask))
96 sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCT, 0);
Suzuki K Poulose116c81f2016-09-09 14:07:16 +010097}
98
Marc Zyngier4205a892018-03-13 12:40:39 +000099atomic_t arm64_el2_vector_last_slot = ATOMIC_INIT(-1);
100
Will Deacon0f15adb2018-01-03 11:17:58 +0000101#include <asm/mmu_context.h>
102#include <asm/cacheflush.h>
103
104DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);
105
Marc Zyngiere8b22d0f2018-04-10 11:36:45 +0100106#ifdef CONFIG_KVM_INDIRECT_VECTORS
Marc Zyngierb0922012018-02-06 17:56:20 +0000107extern char __smccc_workaround_1_smc_start[];
108extern char __smccc_workaround_1_smc_end[];
Will Deaconaa6acde2018-01-03 12:46:21 +0000109
Will Deacon0f15adb2018-01-03 11:17:58 +0000110static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start,
111 const char *hyp_vecs_end)
112{
113 void *dst = lm_alias(__bp_harden_hyp_vecs_start + slot * SZ_2K);
114 int i;
115
116 for (i = 0; i < SZ_2K; i += 0x80)
117 memcpy(dst + i, hyp_vecs_start, hyp_vecs_end - hyp_vecs_start);
118
Will Deacon3b8c9f12018-06-11 14:22:09 +0100119 __flush_icache_range((uintptr_t)dst, (uintptr_t)dst + SZ_2K);
Will Deacon0f15adb2018-01-03 11:17:58 +0000120}
121
Marc Zyngier73f38162019-04-15 16:21:23 -0500122static void install_bp_hardening_cb(bp_hardening_cb_t fn,
123 const char *hyp_vecs_start,
124 const char *hyp_vecs_end)
Will Deacon0f15adb2018-01-03 11:17:58 +0000125{
James Morsed8797b12018-11-27 15:35:21 +0000126 static DEFINE_RAW_SPINLOCK(bp_lock);
Will Deacon0f15adb2018-01-03 11:17:58 +0000127 int cpu, slot = -1;
128
James Morse4debef52018-09-21 21:49:19 +0100129 /*
Thierry Reding7a292b62019-09-23 11:12:29 +0200130 * detect_harden_bp_fw() passes NULL for the hyp_vecs start/end if
131 * we're a guest. Skip the hyp-vectors work.
James Morse4debef52018-09-21 21:49:19 +0100132 */
133 if (!hyp_vecs_start) {
134 __this_cpu_write(bp_hardening_data.fn, fn);
135 return;
136 }
137
James Morsed8797b12018-11-27 15:35:21 +0000138 raw_spin_lock(&bp_lock);
Will Deacon0f15adb2018-01-03 11:17:58 +0000139 for_each_possible_cpu(cpu) {
140 if (per_cpu(bp_hardening_data.fn, cpu) == fn) {
141 slot = per_cpu(bp_hardening_data.hyp_vectors_slot, cpu);
142 break;
143 }
144 }
145
146 if (slot == -1) {
Marc Zyngier4205a892018-03-13 12:40:39 +0000147 slot = atomic_inc_return(&arm64_el2_vector_last_slot);
148 BUG_ON(slot >= BP_HARDEN_EL2_SLOTS);
Will Deacon0f15adb2018-01-03 11:17:58 +0000149 __copy_hyp_vect_bpi(slot, hyp_vecs_start, hyp_vecs_end);
150 }
151
152 __this_cpu_write(bp_hardening_data.hyp_vectors_slot, slot);
153 __this_cpu_write(bp_hardening_data.fn, fn);
James Morsed8797b12018-11-27 15:35:21 +0000154 raw_spin_unlock(&bp_lock);
Will Deacon0f15adb2018-01-03 11:17:58 +0000155}
156#else
Marc Zyngierb0922012018-02-06 17:56:20 +0000157#define __smccc_workaround_1_smc_start NULL
158#define __smccc_workaround_1_smc_end NULL
Will Deaconaa6acde2018-01-03 12:46:21 +0000159
Marc Zyngier73f38162019-04-15 16:21:23 -0500160static void install_bp_hardening_cb(bp_hardening_cb_t fn,
Will Deacon0f15adb2018-01-03 11:17:58 +0000161 const char *hyp_vecs_start,
162 const char *hyp_vecs_end)
163{
164 __this_cpu_write(bp_hardening_data.fn, fn);
165}
Marc Zyngiere8b22d0f2018-04-10 11:36:45 +0100166#endif /* CONFIG_KVM_INDIRECT_VECTORS */
Will Deacon0f15adb2018-01-03 11:17:58 +0000167
Marc Zyngierb0922012018-02-06 17:56:20 +0000168#include <linux/arm-smccc.h>
Will Deaconaa6acde2018-01-03 12:46:21 +0000169
Marc Zyngierb0922012018-02-06 17:56:20 +0000170static void call_smc_arch_workaround_1(void)
171{
172 arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL);
173}
174
175static void call_hvc_arch_workaround_1(void)
176{
177 arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL);
178}
179
Shanker Donthineni4bc352f2018-04-10 11:36:42 +0100180static void qcom_link_stack_sanitization(void)
181{
182 u64 tmp;
183
184 asm volatile("mov %0, x30 \n"
185 ".rept 16 \n"
186 "bl . + 4 \n"
187 ".endr \n"
188 "mov x30, %0 \n"
189 : "=&r" (tmp));
190}
191
Jeremy Lintone5ce5e72019-04-15 16:21:20 -0500192static bool __nospectre_v2;
193static int __init parse_nospectre_v2(char *str)
194{
195 __nospectre_v2 = true;
196 return 0;
197}
198early_param("nospectre_v2", parse_nospectre_v2);
199
Marc Zyngier73f38162019-04-15 16:21:23 -0500200/*
201 * -1: No workaround
202 * 0: No workaround required
203 * 1: Workaround installed
204 */
205static int detect_harden_bp_fw(void)
Marc Zyngierb0922012018-02-06 17:56:20 +0000206{
207 bp_hardening_cb_t cb;
208 void *smccc_start, *smccc_end;
209 struct arm_smccc_res res;
Shanker Donthineni4bc352f2018-04-10 11:36:42 +0100210 u32 midr = read_cpuid_id();
Marc Zyngierb0922012018-02-06 17:56:20 +0000211
Steven Pricece4d5ca2019-10-21 16:28:22 +0100212 arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
213 ARM_SMCCC_ARCH_WORKAROUND_1, &res);
214
215 switch ((int)res.a0) {
216 case 1:
217 /* Firmware says we're just fine */
218 return 0;
219 case 0:
220 break;
221 default:
222 return -1;
223 }
224
Mark Rutlandc98bd292019-08-09 14:22:41 +0100225 switch (arm_smccc_1_1_get_conduit()) {
226 case SMCCC_CONDUIT_HVC:
Steven Pricece4d5ca2019-10-21 16:28:22 +0100227 cb = call_hvc_arch_workaround_1;
228 /* This is a guest, no need to patch KVM vectors */
229 smccc_start = NULL;
230 smccc_end = NULL;
Marc Zyngierb0922012018-02-06 17:56:20 +0000231 break;
232
Mark Rutlandc98bd292019-08-09 14:22:41 +0100233 case SMCCC_CONDUIT_SMC:
Steven Pricece4d5ca2019-10-21 16:28:22 +0100234 cb = call_smc_arch_workaround_1;
235 smccc_start = __smccc_workaround_1_smc_start;
236 smccc_end = __smccc_workaround_1_smc_end;
Marc Zyngierb0922012018-02-06 17:56:20 +0000237 break;
238
239 default:
Marc Zyngier73f38162019-04-15 16:21:23 -0500240 return -1;
Marc Zyngierb0922012018-02-06 17:56:20 +0000241 }
242
Shanker Donthineni4bc352f2018-04-10 11:36:42 +0100243 if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) ||
244 ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1))
245 cb = qcom_link_stack_sanitization;
246
Jeremy Linton8c1e3d22019-04-15 16:21:25 -0500247 if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR))
248 install_bp_hardening_cb(cb, smccc_start, smccc_end);
Marc Zyngierb0922012018-02-06 17:56:20 +0000249
Marc Zyngier73f38162019-04-15 16:21:23 -0500250 return 1;
Will Deaconaa6acde2018-01-03 12:46:21 +0000251}
Will Deacon0f15adb2018-01-03 11:17:58 +0000252
Marc Zyngier5cf9ce62018-05-29 13:11:07 +0100253DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required);
254
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100255int ssbd_state __read_mostly = ARM64_SSBD_KERNEL;
Jeremy Linton526e0652019-04-15 16:21:28 -0500256static bool __ssb_safe = true;
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100257
258static const struct ssbd_options {
259 const char *str;
260 int state;
261} ssbd_options[] = {
262 { "force-on", ARM64_SSBD_FORCE_ENABLE, },
263 { "force-off", ARM64_SSBD_FORCE_DISABLE, },
264 { "kernel", ARM64_SSBD_KERNEL, },
265};
266
267static int __init ssbd_cfg(char *buf)
268{
269 int i;
270
271 if (!buf || !buf[0])
272 return -EINVAL;
273
274 for (i = 0; i < ARRAY_SIZE(ssbd_options); i++) {
275 int len = strlen(ssbd_options[i].str);
276
277 if (strncmp(buf, ssbd_options[i].str, len))
278 continue;
279
280 ssbd_state = ssbd_options[i].state;
281 return 0;
282 }
283
284 return -EINVAL;
285}
286early_param("ssbd", ssbd_cfg);
287
Marc Zyngier8e290622018-05-29 13:11:06 +0100288void __init arm64_update_smccc_conduit(struct alt_instr *alt,
289 __le32 *origptr, __le32 *updptr,
290 int nr_inst)
291{
292 u32 insn;
293
294 BUG_ON(nr_inst != 1);
295
Mark Rutlandc98bd292019-08-09 14:22:41 +0100296 switch (arm_smccc_1_1_get_conduit()) {
297 case SMCCC_CONDUIT_HVC:
Marc Zyngier8e290622018-05-29 13:11:06 +0100298 insn = aarch64_insn_get_hvc_value();
299 break;
Mark Rutlandc98bd292019-08-09 14:22:41 +0100300 case SMCCC_CONDUIT_SMC:
Marc Zyngier8e290622018-05-29 13:11:06 +0100301 insn = aarch64_insn_get_smc_value();
302 break;
303 default:
304 return;
305 }
306
307 *updptr = cpu_to_le32(insn);
308}
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100309
Marc Zyngier986372c2018-05-29 13:11:11 +0100310void __init arm64_enable_wa2_handling(struct alt_instr *alt,
311 __le32 *origptr, __le32 *updptr,
312 int nr_inst)
313{
314 BUG_ON(nr_inst != 1);
315 /*
316 * Only allow mitigation on EL1 entry/exit and guest
317 * ARCH_WORKAROUND_2 handling if the SSBD state allows it to
318 * be flipped.
319 */
320 if (arm64_get_ssbd_state() == ARM64_SSBD_KERNEL)
321 *updptr = cpu_to_le32(aarch64_insn_gen_nop());
322}
323
Marc Zyngier647d0512018-05-29 13:11:12 +0100324void arm64_set_ssbd_mitigation(bool state)
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100325{
Steven Pricece4d5ca2019-10-21 16:28:22 +0100326 int conduit;
327
Jeremy Lintond42281b2019-04-15 16:21:27 -0500328 if (!IS_ENABLED(CONFIG_ARM64_SSBD)) {
329 pr_info_once("SSBD disabled by kernel configuration\n");
330 return;
331 }
332
Will Deacon8f04e8e2018-08-07 13:47:06 +0100333 if (this_cpu_has_cap(ARM64_SSBS)) {
334 if (state)
335 asm volatile(SET_PSTATE_SSBS(0));
336 else
337 asm volatile(SET_PSTATE_SSBS(1));
338 return;
339 }
340
Steven Pricece4d5ca2019-10-21 16:28:22 +0100341 conduit = arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_WORKAROUND_2, state,
342 NULL);
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100343
Steven Pricece4d5ca2019-10-21 16:28:22 +0100344 WARN_ON_ONCE(conduit == SMCCC_CONDUIT_NONE);
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100345}
346
347static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry,
348 int scope)
349{
350 struct arm_smccc_res res;
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100351 bool required = true;
352 s32 val;
Jeremy Linton526e0652019-04-15 16:21:28 -0500353 bool this_cpu_safe = false;
Steven Pricece4d5ca2019-10-21 16:28:22 +0100354 int conduit;
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100355
356 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
357
Josh Poimboeufa111b7c2019-04-12 15:39:32 -0500358 if (cpu_mitigations_off())
359 ssbd_state = ARM64_SSBD_FORCE_DISABLE;
360
Jeremy Linton526e0652019-04-15 16:21:28 -0500361 /* delay setting __ssb_safe until we get a firmware response */
362 if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list))
363 this_cpu_safe = true;
364
Will Deaconeb337cd2019-04-30 16:58:56 +0100365 if (this_cpu_has_cap(ARM64_SSBS)) {
366 if (!this_cpu_safe)
367 __ssb_safe = false;
368 required = false;
369 goto out_printmsg;
370 }
371
Steven Pricece4d5ca2019-10-21 16:28:22 +0100372 conduit = arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
373 ARM_SMCCC_ARCH_WORKAROUND_2, &res);
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100374
Steven Pricece4d5ca2019-10-21 16:28:22 +0100375 if (conduit == SMCCC_CONDUIT_NONE) {
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100376 ssbd_state = ARM64_SSBD_UNKNOWN;
Jeremy Linton526e0652019-04-15 16:21:28 -0500377 if (!this_cpu_safe)
378 __ssb_safe = false;
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100379 return false;
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100380 }
381
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100382 val = (s32)res.a0;
383
384 switch (val) {
385 case SMCCC_RET_NOT_SUPPORTED:
386 ssbd_state = ARM64_SSBD_UNKNOWN;
Jeremy Linton526e0652019-04-15 16:21:28 -0500387 if (!this_cpu_safe)
388 __ssb_safe = false;
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100389 return false;
390
Jeremy Linton526e0652019-04-15 16:21:28 -0500391 /* machines with mixed mitigation requirements must not return this */
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100392 case SMCCC_RET_NOT_REQUIRED:
393 pr_info_once("%s mitigation not required\n", entry->desc);
394 ssbd_state = ARM64_SSBD_MITIGATED;
395 return false;
396
397 case SMCCC_RET_SUCCESS:
Jeremy Linton526e0652019-04-15 16:21:28 -0500398 __ssb_safe = false;
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100399 required = true;
400 break;
401
402 case 1: /* Mitigation not required on this CPU */
403 required = false;
404 break;
405
406 default:
407 WARN_ON(1);
Jeremy Linton526e0652019-04-15 16:21:28 -0500408 if (!this_cpu_safe)
409 __ssb_safe = false;
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100410 return false;
411 }
412
413 switch (ssbd_state) {
414 case ARM64_SSBD_FORCE_DISABLE:
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100415 arm64_set_ssbd_mitigation(false);
416 required = false;
417 break;
418
419 case ARM64_SSBD_KERNEL:
420 if (required) {
421 __this_cpu_write(arm64_ssbd_callback_required, 1);
422 arm64_set_ssbd_mitigation(true);
423 }
424 break;
425
426 case ARM64_SSBD_FORCE_ENABLE:
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100427 arm64_set_ssbd_mitigation(true);
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100428 required = true;
429 break;
430
431 default:
432 WARN_ON(1);
433 break;
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100434 }
435
Will Deacon8f04e8e2018-08-07 13:47:06 +0100436out_printmsg:
437 switch (ssbd_state) {
438 case ARM64_SSBD_FORCE_DISABLE:
439 pr_info_once("%s disabled from command-line\n", entry->desc);
440 break;
441
442 case ARM64_SSBD_FORCE_ENABLE:
443 pr_info_once("%s forced from command-line\n", entry->desc);
444 break;
445 }
446
Marc Zyngiera43ae4d2018-05-29 13:11:09 +0100447 return required;
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100448}
Marc Zyngier8e290622018-05-29 13:11:06 +0100449
Jeremy Linton526e0652019-04-15 16:21:28 -0500450/* known invulnerable cores */
451static const struct midr_range arm64_ssb_cpus[] = {
452 MIDR_ALL_VERSIONS(MIDR_CORTEX_A35),
453 MIDR_ALL_VERSIONS(MIDR_CORTEX_A53),
454 MIDR_ALL_VERSIONS(MIDR_CORTEX_A55),
455 {},
456};
457
Will Deacon969f5ea2019-04-29 13:03:57 +0100458#ifdef CONFIG_ARM64_ERRATUM_1463225
459DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa);
460
461static bool
462has_cortex_a76_erratum_1463225(const struct arm64_cpu_capabilities *entry,
463 int scope)
464{
465 u32 midr = read_cpuid_id();
466 /* Cortex-A76 r0p0 - r3p1 */
467 struct midr_range range = MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1);
468
469 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
470 return is_midr_in_range(midr, &range) && is_kernel_in_hyp_mode();
471}
472#endif
473
Will Deaconb8925ee2018-08-07 13:53:41 +0100474static void __maybe_unused
475cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused)
476{
477 sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCI, 0);
478}
479
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100480#define CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \
481 .matches = is_affected_midr_range, \
Suzuki K Poulose1df31052018-03-26 15:12:44 +0100482 .midr_range = MIDR_RANGE(model, v_min, r_min, v_max, r_max)
Andre Przywara301bcfa2014-11-14 15:54:10 +0000483
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100484#define CAP_MIDR_ALL_VERSIONS(model) \
485 .matches = is_affected_midr_range, \
Suzuki K Poulose1df31052018-03-26 15:12:44 +0100486 .midr_range = MIDR_ALL_VERSIONS(model)
Marc Zyngier06f14942017-02-01 14:38:46 +0000487
Ard Biesheuvele8002e02018-03-06 17:15:34 +0000488#define MIDR_FIXED(rev, revidr_mask) \
489 .fixed_revs = (struct arm64_midr_revidr[]){{ (rev), (revidr_mask) }, {}}
490
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100491#define ERRATA_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \
492 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
493 CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max)
494
Suzuki K Poulosebe5b2992018-03-26 15:12:45 +0100495#define CAP_MIDR_RANGE_LIST(list) \
496 .matches = is_affected_midr_range_list, \
497 .midr_range_list = list
498
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100499/* Errata affecting a range of revisions of given model variant */
500#define ERRATA_MIDR_REV_RANGE(m, var, r_min, r_max) \
501 ERRATA_MIDR_RANGE(m, var, r_min, var, r_max)
502
503/* Errata affecting a single variant/revision of a model */
504#define ERRATA_MIDR_REV(model, var, rev) \
505 ERRATA_MIDR_RANGE(model, var, rev, var, rev)
506
507/* Errata affecting all variants/revisions of a given a model */
508#define ERRATA_MIDR_ALL_VERSIONS(model) \
509 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
510 CAP_MIDR_ALL_VERSIONS(model)
511
Suzuki K Poulosebe5b2992018-03-26 15:12:45 +0100512/* Errata affecting a list of midr ranges, with same work around */
513#define ERRATA_MIDR_RANGE_LIST(midr_list) \
514 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
515 CAP_MIDR_RANGE_LIST(midr_list)
516
Jeremy Lintond2532e22019-04-15 16:21:26 -0500517/* Track overall mitigation state. We are only mitigated if all cores are ok */
518static bool __hardenbp_enab = true;
519static bool __spectrev2_safe = true;
520
Andre Przywarac118bbb2019-05-03 15:27:48 +0100521int get_spectre_v2_workaround_state(void)
522{
523 if (__spectrev2_safe)
524 return ARM64_BP_HARDEN_NOT_REQUIRED;
525
526 if (!__hardenbp_enab)
527 return ARM64_BP_HARDEN_UNKNOWN;
528
529 return ARM64_BP_HARDEN_WA_NEEDED;
530}
531
Suzuki K Poulosebe5b2992018-03-26 15:12:45 +0100532/*
Marc Zyngier73f38162019-04-15 16:21:23 -0500533 * List of CPUs that do not need any Spectre-v2 mitigation at all.
Suzuki K Poulosebe5b2992018-03-26 15:12:45 +0100534 */
Marc Zyngier73f38162019-04-15 16:21:23 -0500535static const struct midr_range spectre_v2_safe_list[] = {
536 MIDR_ALL_VERSIONS(MIDR_CORTEX_A35),
537 MIDR_ALL_VERSIONS(MIDR_CORTEX_A53),
538 MIDR_ALL_VERSIONS(MIDR_CORTEX_A55),
539 { /* sentinel */ }
Suzuki K Poulosebe5b2992018-03-26 15:12:45 +0100540};
541
Jeremy Lintond2532e22019-04-15 16:21:26 -0500542/*
543 * Track overall bp hardening for all heterogeneous cores in the machine.
544 * We are only considered "safe" if all booted cores are known safe.
545 */
Marc Zyngier73f38162019-04-15 16:21:23 -0500546static bool __maybe_unused
547check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope)
548{
549 int need_wa;
550
551 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
552
553 /* If the CPU has CSV2 set, we're safe */
554 if (cpuid_feature_extract_unsigned_field(read_cpuid(ID_AA64PFR0_EL1),
555 ID_AA64PFR0_CSV2_SHIFT))
556 return false;
557
558 /* Alternatively, we have a list of unaffected CPUs */
559 if (is_midr_in_range_list(read_cpuid_id(), spectre_v2_safe_list))
560 return false;
561
562 /* Fallback to firmware detection */
563 need_wa = detect_harden_bp_fw();
564 if (!need_wa)
565 return false;
566
Jeremy Lintond2532e22019-04-15 16:21:26 -0500567 __spectrev2_safe = false;
568
Jeremy Linton8c1e3d22019-04-15 16:21:25 -0500569 if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) {
570 pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n");
571 __hardenbp_enab = false;
572 return false;
573 }
574
Marc Zyngier73f38162019-04-15 16:21:23 -0500575 /* forced off */
Josh Poimboeufa111b7c2019-04-12 15:39:32 -0500576 if (__nospectre_v2 || cpu_mitigations_off()) {
Marc Zyngier73f38162019-04-15 16:21:23 -0500577 pr_info_once("spectrev2 mitigation disabled by command line option\n");
Jeremy Lintond2532e22019-04-15 16:21:26 -0500578 __hardenbp_enab = false;
Marc Zyngier73f38162019-04-15 16:21:23 -0500579 return false;
580 }
581
Jeremy Lintond2532e22019-04-15 16:21:26 -0500582 if (need_wa < 0) {
Marc Zyngier73f38162019-04-15 16:21:23 -0500583 pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n");
Jeremy Lintond2532e22019-04-15 16:21:26 -0500584 __hardenbp_enab = false;
585 }
Marc Zyngier73f38162019-04-15 16:21:23 -0500586
587 return (need_wa > 0);
588}
Andre Przywara301bcfa2014-11-14 15:54:10 +0000589
Marc Zyngier8892b712018-04-10 11:36:43 +0100590#ifdef CONFIG_HARDEN_EL2_VECTORS
591
592static const struct midr_range arm64_harden_el2_vectors[] = {
593 MIDR_ALL_VERSIONS(MIDR_CORTEX_A57),
594 MIDR_ALL_VERSIONS(MIDR_CORTEX_A72),
595 {},
596};
597
Marc Zyngierdc6ed612018-03-28 12:46:07 +0100598#endif
599
Catalin Marinasce8c80c2018-11-19 11:27:28 +0000600#ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI
601
602static const struct midr_range arm64_repeat_tlbi_cpus[] = {
603#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009
604 MIDR_RANGE(MIDR_QCOM_FALKOR_V1, 0, 0, 0, 0),
605#endif
606#ifdef CONFIG_ARM64_ERRATUM_1286807
607 MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 0),
608#endif
609 {},
610};
611
612#endif
613
Suzuki K Poulosef58cdf72018-11-30 17:18:01 +0000614#ifdef CONFIG_CAVIUM_ERRATUM_27456
Will Deaconb89d82e2019-01-08 16:19:01 +0000615const struct midr_range cavium_erratum_27456_cpus[] = {
Suzuki K Poulosef58cdf72018-11-30 17:18:01 +0000616 /* Cavium ThunderX, T88 pass 1.x - 2.1 */
617 MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 1),
618 /* Cavium ThunderX, T81 pass 1.0 */
619 MIDR_REV(MIDR_THUNDERX_81XX, 0, 0),
620 {},
621};
622#endif
623
624#ifdef CONFIG_CAVIUM_ERRATUM_30115
625static const struct midr_range cavium_erratum_30115_cpus[] = {
626 /* Cavium ThunderX, T88 pass 1.x - 2.2 */
627 MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 2),
628 /* Cavium ThunderX, T81 pass 1.0 - 1.2 */
629 MIDR_REV_RANGE(MIDR_THUNDERX_81XX, 0, 0, 2),
630 /* Cavium ThunderX, T83 pass 1.0 */
631 MIDR_REV(MIDR_THUNDERX_83XX, 0, 0),
632 {},
633};
634#endif
635
Suzuki K Poulosea3dcea2c2018-11-30 17:18:02 +0000636#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
637static const struct arm64_cpu_capabilities qcom_erratum_1003_list[] = {
638 {
639 ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0),
640 },
641 {
642 .midr_range.model = MIDR_QCOM_KRYO,
643 .matches = is_kryo_midr,
644 },
645 {},
646};
647#endif
648
Suzuki K Poulosec9460dc2018-11-30 17:18:00 +0000649#ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE
650static const struct midr_range workaround_clean_cache[] = {
Andre Przywarae116a372014-11-14 15:54:09 +0000651#if defined(CONFIG_ARM64_ERRATUM_826319) || \
652 defined(CONFIG_ARM64_ERRATUM_827319) || \
653 defined(CONFIG_ARM64_ERRATUM_824069)
Suzuki K Poulosec9460dc2018-11-30 17:18:00 +0000654 /* Cortex-A53 r0p[012]: ARM errata 826319, 827319, 824069 */
655 MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 2),
Andre Przywarac0a01b82014-11-14 15:54:12 +0000656#endif
Suzuki K Poulosec9460dc2018-11-30 17:18:00 +0000657#ifdef CONFIG_ARM64_ERRATUM_819472
658 /* Cortex-A53 r0p[01] : ARM errata 819472 */
659 MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 1),
660#endif
661 {},
662};
663#endif
664
Marc Zyngiera5325082019-05-23 11:24:50 +0100665#ifdef CONFIG_ARM64_ERRATUM_1418040
666/*
667 * - 1188873 affects r0p0 to r2p0
668 * - 1418040 affects r0p0 to r3p1
669 */
670static const struct midr_range erratum_1418040_list[] = {
671 /* Cortex-A76 r0p0 to r3p1 */
672 MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1),
673 /* Neoverse-N1 r0p0 to r3p1 */
674 MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 0, 3, 1),
Marc Zyngier69893032019-04-15 13:03:54 +0100675 {},
676};
677#endif
678
Suzuki K Poulosec9460dc2018-11-30 17:18:00 +0000679const struct arm64_cpu_capabilities arm64_errata[] = {
680#ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE
Andre Przywarac0a01b82014-11-14 15:54:12 +0000681 {
Suzuki K Poulosec9460dc2018-11-30 17:18:00 +0000682 .desc = "ARM errata 826319, 827319, 824069, 819472",
Andre Przywarac0a01b82014-11-14 15:54:12 +0000683 .capability = ARM64_WORKAROUND_CLEAN_CACHE,
Suzuki K Poulosec9460dc2018-11-30 17:18:00 +0000684 ERRATA_MIDR_RANGE_LIST(workaround_clean_cache),
Dave Martinc0cda3b2018-03-26 15:12:28 +0100685 .cpu_enable = cpu_enable_cache_maint_trap,
Andre Przywarac0a01b82014-11-14 15:54:12 +0000686 },
687#endif
688#ifdef CONFIG_ARM64_ERRATUM_832075
Andre Przywara301bcfa2014-11-14 15:54:10 +0000689 {
Andre Przywara5afaa1f2014-11-14 15:54:11 +0000690 /* Cortex-A57 r0p0 - r1p2 */
691 .desc = "ARM erratum 832075",
692 .capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE,
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100693 ERRATA_MIDR_RANGE(MIDR_CORTEX_A57,
694 0, 0,
695 1, 2),
Andre Przywara5afaa1f2014-11-14 15:54:11 +0000696 },
Andre Przywarac0a01b82014-11-14 15:54:12 +0000697#endif
Marc Zyngier498cd5c2015-11-16 10:28:18 +0000698#ifdef CONFIG_ARM64_ERRATUM_834220
699 {
700 /* Cortex-A57 r0p0 - r1p2 */
701 .desc = "ARM erratum 834220",
702 .capability = ARM64_WORKAROUND_834220,
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100703 ERRATA_MIDR_RANGE(MIDR_CORTEX_A57,
704 0, 0,
705 1, 2),
Marc Zyngier498cd5c2015-11-16 10:28:18 +0000706 },
707#endif
Ard Biesheuvelca79acc2018-03-06 17:15:35 +0000708#ifdef CONFIG_ARM64_ERRATUM_843419
709 {
710 /* Cortex-A53 r0p[01234] */
711 .desc = "ARM erratum 843419",
712 .capability = ARM64_WORKAROUND_843419,
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100713 ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4),
Ard Biesheuvelca79acc2018-03-06 17:15:35 +0000714 MIDR_FIXED(0x4, BIT(8)),
Will Deacon905e8c52015-03-23 19:07:02 +0000715 },
Robert Richter6d4e11c2015-09-21 22:58:35 +0200716#endif
717#ifdef CONFIG_ARM64_ERRATUM_845719
718 {
719 /* Cortex-A53 r0p[01234] */
720 .desc = "ARM erratum 845719",
721 .capability = ARM64_WORKAROUND_845719,
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100722 ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4),
Marc Zyngier359b7062015-03-27 13:09:23 +0000723 },
Andre Przywarae116a372014-11-14 15:54:09 +0000724#endif
Robert Richter6d4e11c2015-09-21 22:58:35 +0200725#ifdef CONFIG_CAVIUM_ERRATUM_23154
726 {
727 /* Cavium ThunderX, pass 1.x */
728 .desc = "Cavium erratum 23154",
729 .capability = ARM64_WORKAROUND_CAVIUM_23154,
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100730 ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1),
Robert Richter6d4e11c2015-09-21 22:58:35 +0200731 },
732#endif
Andrew Pinski104a0c02016-02-24 17:44:57 -0800733#ifdef CONFIG_CAVIUM_ERRATUM_27456
734 {
Andrew Pinski104a0c02016-02-24 17:44:57 -0800735 .desc = "Cavium erratum 27456",
736 .capability = ARM64_WORKAROUND_CAVIUM_27456,
Suzuki K Poulosef58cdf72018-11-30 17:18:01 +0000737 ERRATA_MIDR_RANGE_LIST(cavium_erratum_27456_cpus),
Ganapatrao Kulkarni47c459b2016-07-07 10:18:17 +0530738 },
Andrew Pinski104a0c02016-02-24 17:44:57 -0800739#endif
David Daney690a3412017-06-09 12:49:48 +0100740#ifdef CONFIG_CAVIUM_ERRATUM_30115
741 {
David Daney690a3412017-06-09 12:49:48 +0100742 .desc = "Cavium erratum 30115",
743 .capability = ARM64_WORKAROUND_CAVIUM_30115,
Suzuki K Poulosef58cdf72018-11-30 17:18:01 +0000744 ERRATA_MIDR_RANGE_LIST(cavium_erratum_30115_cpus),
David Daney690a3412017-06-09 12:49:48 +0100745 },
746#endif
Andre Przywarae116a372014-11-14 15:54:09 +0000747 {
Will Deacon880f7cc2018-09-19 11:41:21 +0100748 .desc = "Mismatched cache type (CTR_EL0)",
Suzuki K Poulose314d53d2018-07-04 23:07:46 +0100749 .capability = ARM64_MISMATCHED_CACHE_TYPE,
750 .matches = has_mismatched_cache_type,
Suzuki K Poulose5b4747c2018-03-26 15:12:32 +0100751 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
Dave Martinc0cda3b2018-03-26 15:12:28 +0100752 .cpu_enable = cpu_enable_trap_ctr_access,
Suzuki K Poulose116c81f2016-09-09 14:07:16 +0100753 },
Christopher Covington38fd94b2017-02-08 15:08:37 -0500754#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
755 {
Suzuki K Poulosea3dcea2c2018-11-30 17:18:02 +0000756 .desc = "Qualcomm Technologies Falkor/Kryo erratum 1003",
Christopher Covington38fd94b2017-02-08 15:08:37 -0500757 .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003,
Will Deacon1e013d02018-12-12 15:53:54 +0000758 .matches = cpucap_multi_entry_cap_matches,
Suzuki K Poulosea3dcea2c2018-11-30 17:18:02 +0000759 .match_list = qcom_erratum_1003_list,
Stephen Boydbb487112017-12-13 14:19:37 -0800760 },
Christopher Covington38fd94b2017-02-08 15:08:37 -0500761#endif
Catalin Marinasce8c80c2018-11-19 11:27:28 +0000762#ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI
Christopher Covingtond9ff80f2017-01-31 12:50:19 -0500763 {
Catalin Marinasce8c80c2018-11-19 11:27:28 +0000764 .desc = "Qualcomm erratum 1009, ARM erratum 1286807",
Christopher Covingtond9ff80f2017-01-31 12:50:19 -0500765 .capability = ARM64_WORKAROUND_REPEAT_TLBI,
Catalin Marinasce8c80c2018-11-19 11:27:28 +0000766 ERRATA_MIDR_RANGE_LIST(arm64_repeat_tlbi_cpus),
Christopher Covingtond9ff80f2017-01-31 12:50:19 -0500767 },
768#endif
Marc Zyngiereeb1efb2017-03-20 17:18:06 +0000769#ifdef CONFIG_ARM64_ERRATUM_858921
770 {
771 /* Cortex-A73 all versions */
772 .desc = "ARM erratum 858921",
773 .capability = ARM64_WORKAROUND_858921,
Suzuki K Poulose5e7951c2018-03-26 15:12:43 +0100774 ERRATA_MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
Marc Zyngiereeb1efb2017-03-20 17:18:06 +0000775 },
776#endif
Will Deaconaa6acde2018-01-03 12:46:21 +0000777 {
778 .capability = ARM64_HARDEN_BRANCH_PREDICTOR,
Marc Zyngier73f38162019-04-15 16:21:23 -0500779 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
780 .matches = check_branch_predictor,
Jayachandran Cf3d795d2018-01-19 04:22:47 -0800781 },
Marc Zyngier4b472ff2018-02-15 11:49:20 +0000782#ifdef CONFIG_HARDEN_EL2_VECTORS
783 {
Marc Zyngier8892b712018-04-10 11:36:43 +0100784 .desc = "EL2 vector hardening",
Marc Zyngier4b472ff2018-02-15 11:49:20 +0000785 .capability = ARM64_HARDEN_EL2_VECTORS,
Marc Zyngier8892b712018-04-10 11:36:43 +0100786 ERRATA_MIDR_RANGE_LIST(arm64_harden_el2_vectors),
Marc Zyngier4b472ff2018-02-15 11:49:20 +0000787 },
788#endif
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100789 {
790 .desc = "Speculative Store Bypass Disable",
791 .capability = ARM64_SSBD,
792 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
793 .matches = has_ssbd_mitigation,
Jeremy Linton526e0652019-04-15 16:21:28 -0500794 .midr_range_list = arm64_ssb_cpus,
Marc Zyngiera725e3d2018-05-29 13:11:08 +0100795 },
Marc Zyngiera5325082019-05-23 11:24:50 +0100796#ifdef CONFIG_ARM64_ERRATUM_1418040
Marc Zyngier95b861a42018-09-27 17:15:34 +0100797 {
Marc Zyngiera5325082019-05-23 11:24:50 +0100798 .desc = "ARM erratum 1418040",
799 .capability = ARM64_WORKAROUND_1418040,
800 ERRATA_MIDR_RANGE_LIST(erratum_1418040_list),
Marc Zyngier95b861a42018-09-27 17:15:34 +0100801 },
802#endif
Marc Zyngier8b2cca92018-12-06 17:31:23 +0000803#ifdef CONFIG_ARM64_ERRATUM_1165522
804 {
805 /* Cortex-A76 r0p0 to r2p0 */
806 .desc = "ARM erratum 1165522",
807 .capability = ARM64_WORKAROUND_1165522,
808 ERRATA_MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 2, 0),
809 },
810#endif
Will Deacon969f5ea2019-04-29 13:03:57 +0100811#ifdef CONFIG_ARM64_ERRATUM_1463225
812 {
813 .desc = "ARM erratum 1463225",
814 .capability = ARM64_WORKAROUND_1463225,
815 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
816 .matches = has_cortex_a76_erratum_1463225,
817 },
818#endif
Suzuki K Poulose116c81f2016-09-09 14:07:16 +0100819 {
Andre Przywarae116a372014-11-14 15:54:09 +0000820 }
821};
Mian Yousaf Kaukab3891ebc2019-04-15 16:21:21 -0500822
823ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr,
824 char *buf)
825{
826 return sprintf(buf, "Mitigation: __user pointer sanitization\n");
827}
Jeremy Lintond2532e22019-04-15 16:21:26 -0500828
829ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
830 char *buf)
831{
Andre Przywarac118bbb2019-05-03 15:27:48 +0100832 switch (get_spectre_v2_workaround_state()) {
833 case ARM64_BP_HARDEN_NOT_REQUIRED:
Jeremy Lintond2532e22019-04-15 16:21:26 -0500834 return sprintf(buf, "Not affected\n");
Andre Przywarac118bbb2019-05-03 15:27:48 +0100835 case ARM64_BP_HARDEN_WA_NEEDED:
Jeremy Lintond2532e22019-04-15 16:21:26 -0500836 return sprintf(buf, "Mitigation: Branch predictor hardening\n");
Andre Przywarac118bbb2019-05-03 15:27:48 +0100837 case ARM64_BP_HARDEN_UNKNOWN:
838 default:
839 return sprintf(buf, "Vulnerable\n");
840 }
Jeremy Lintond2532e22019-04-15 16:21:26 -0500841}
Jeremy Linton526e0652019-04-15 16:21:28 -0500842
843ssize_t cpu_show_spec_store_bypass(struct device *dev,
844 struct device_attribute *attr, char *buf)
845{
846 if (__ssb_safe)
847 return sprintf(buf, "Not affected\n");
848
849 switch (ssbd_state) {
850 case ARM64_SSBD_KERNEL:
851 case ARM64_SSBD_FORCE_ENABLE:
852 if (IS_ENABLED(CONFIG_ARM64_SSBD))
853 return sprintf(buf,
854 "Mitigation: Speculative Store Bypass disabled via prctl\n");
855 }
856
857 return sprintf(buf, "Vulnerable\n");
858}