Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Contains CPU specific errata definitions |
| 4 | * |
| 5 | * Copyright (C) 2014 ARM Ltd. |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Arnd Bergmann | 94a5d87 | 2018-06-05 13:50:07 +0200 | [diff] [blame] | 8 | #include <linux/arm-smccc.h> |
| 9 | #include <linux/psci.h> |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 10 | #include <linux/types.h> |
Josh Poimboeuf | a111b7c | 2019-04-12 15:39:32 -0500 | [diff] [blame] | 11 | #include <linux/cpu.h> |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 12 | #include <asm/cpu.h> |
| 13 | #include <asm/cputype.h> |
| 14 | #include <asm/cpufeature.h> |
Marc Zyngier | 93916be | 2019-04-09 16:26:21 +0100 | [diff] [blame] | 15 | #include <asm/smp_plat.h> |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 16 | |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 17 | static bool __maybe_unused |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 18 | is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope) |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 19 | { |
Ard Biesheuvel | e8002e0 | 2018-03-06 17:15:34 +0000 | [diff] [blame] | 20 | const struct arm64_midr_revidr *fix; |
| 21 | u32 midr = read_cpuid_id(), revidr; |
| 22 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 23 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
Suzuki K Poulose | 1df3105 | 2018-03-26 15:12:44 +0100 | [diff] [blame] | 24 | if (!is_midr_in_range(midr, &entry->midr_range)) |
Ard Biesheuvel | e8002e0 | 2018-03-06 17:15:34 +0000 | [diff] [blame] | 25 | return false; |
| 26 | |
| 27 | midr &= MIDR_REVISION_MASK | MIDR_VARIANT_MASK; |
| 28 | revidr = read_cpuid(REVIDR_EL1); |
| 29 | for (fix = entry->fixed_revs; fix && fix->revidr_mask; fix++) |
| 30 | if (midr == fix->midr_rv && (revidr & fix->revidr_mask)) |
| 31 | return false; |
| 32 | |
| 33 | return true; |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Stephen Boyd | bb48711 | 2017-12-13 14:19:37 -0800 | [diff] [blame] | 36 | static bool __maybe_unused |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 37 | is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry, |
| 38 | int scope) |
| 39 | { |
| 40 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 41 | return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list); |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Stephen Boyd | bb48711 | 2017-12-13 14:19:37 -0800 | [diff] [blame] | 44 | static bool __maybe_unused |
| 45 | is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope) |
| 46 | { |
| 47 | u32 model; |
| 48 | |
| 49 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 50 | |
| 51 | model = read_cpuid_id(); |
| 52 | model &= MIDR_IMPLEMENTOR_MASK | (0xf00 << MIDR_PARTNUM_SHIFT) | |
| 53 | MIDR_ARCHITECTURE_MASK; |
| 54 | |
Suzuki K Poulose | 1df3105 | 2018-03-26 15:12:44 +0100 | [diff] [blame] | 55 | return model == entry->midr_range.model; |
Stephen Boyd | bb48711 | 2017-12-13 14:19:37 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 58 | static bool |
Suzuki K Poulose | 314d53d | 2018-07-04 23:07:46 +0100 | [diff] [blame] | 59 | has_mismatched_cache_type(const struct arm64_cpu_capabilities *entry, |
| 60 | int scope) |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 61 | { |
Suzuki K Poulose | 1602df0 | 2018-10-09 14:47:06 +0100 | [diff] [blame] | 62 | u64 mask = arm64_ftr_reg_ctrel0.strict_mask; |
| 63 | u64 sys = arm64_ftr_reg_ctrel0.sys_val & mask; |
| 64 | u64 ctr_raw, ctr_real; |
Suzuki K Poulose | 314d53d | 2018-07-04 23:07:46 +0100 | [diff] [blame] | 65 | |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 66 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
Suzuki K Poulose | 1602df0 | 2018-10-09 14:47:06 +0100 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * We want to make sure that all the CPUs in the system expose |
| 70 | * a consistent CTR_EL0 to make sure that applications behaves |
| 71 | * correctly with migration. |
| 72 | * |
| 73 | * If a CPU has CTR_EL0.IDC but does not advertise it via CTR_EL0 : |
| 74 | * |
| 75 | * 1) It is safe if the system doesn't support IDC, as CPU anyway |
| 76 | * reports IDC = 0, consistent with the rest. |
| 77 | * |
| 78 | * 2) If the system has IDC, it is still safe as we trap CTR_EL0 |
| 79 | * access on this CPU via the ARM64_HAS_CACHE_IDC capability. |
| 80 | * |
| 81 | * So, we need to make sure either the raw CTR_EL0 or the effective |
| 82 | * CTR_EL0 matches the system's copy to allow a secondary CPU to boot. |
| 83 | */ |
| 84 | ctr_raw = read_cpuid_cachetype() & mask; |
| 85 | ctr_real = read_cpuid_effective_cachetype() & mask; |
| 86 | |
| 87 | return (ctr_real != sys) && (ctr_raw != sys); |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 90 | static void |
| 91 | cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *__unused) |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 92 | { |
Suzuki K Poulose | 4afe8e7 | 2018-10-09 14:47:07 +0100 | [diff] [blame] | 93 | u64 mask = arm64_ftr_reg_ctrel0.strict_mask; |
| 94 | |
| 95 | /* Trap CTR_EL0 access on this CPU, only if it has a mismatch */ |
| 96 | if ((read_cpuid_cachetype() & mask) != |
| 97 | (arm64_ftr_reg_ctrel0.sys_val & mask)) |
| 98 | sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCT, 0); |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Marc Zyngier | 4205a89 | 2018-03-13 12:40:39 +0000 | [diff] [blame] | 101 | atomic_t arm64_el2_vector_last_slot = ATOMIC_INIT(-1); |
| 102 | |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 103 | #include <asm/mmu_context.h> |
| 104 | #include <asm/cacheflush.h> |
| 105 | |
| 106 | DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); |
| 107 | |
Marc Zyngier | e8b22d0f | 2018-04-10 11:36:45 +0100 | [diff] [blame] | 108 | #ifdef CONFIG_KVM_INDIRECT_VECTORS |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 109 | extern char __smccc_workaround_1_smc_start[]; |
| 110 | extern char __smccc_workaround_1_smc_end[]; |
Will Deacon | aa6acde | 2018-01-03 12:46:21 +0000 | [diff] [blame] | 111 | |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 112 | static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start, |
| 113 | const char *hyp_vecs_end) |
| 114 | { |
| 115 | void *dst = lm_alias(__bp_harden_hyp_vecs_start + slot * SZ_2K); |
| 116 | int i; |
| 117 | |
| 118 | for (i = 0; i < SZ_2K; i += 0x80) |
| 119 | memcpy(dst + i, hyp_vecs_start, hyp_vecs_end - hyp_vecs_start); |
| 120 | |
Will Deacon | 3b8c9f1 | 2018-06-11 14:22:09 +0100 | [diff] [blame] | 121 | __flush_icache_range((uintptr_t)dst, (uintptr_t)dst + SZ_2K); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 124 | static void install_bp_hardening_cb(bp_hardening_cb_t fn, |
| 125 | const char *hyp_vecs_start, |
| 126 | const char *hyp_vecs_end) |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 127 | { |
James Morse | d8797b1 | 2018-11-27 15:35:21 +0000 | [diff] [blame] | 128 | static DEFINE_RAW_SPINLOCK(bp_lock); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 129 | int cpu, slot = -1; |
| 130 | |
James Morse | 4debef5 | 2018-09-21 21:49:19 +0100 | [diff] [blame] | 131 | /* |
| 132 | * enable_smccc_arch_workaround_1() passes NULL for the hyp_vecs |
| 133 | * start/end if we're a guest. Skip the hyp-vectors work. |
| 134 | */ |
| 135 | if (!hyp_vecs_start) { |
| 136 | __this_cpu_write(bp_hardening_data.fn, fn); |
| 137 | return; |
| 138 | } |
| 139 | |
James Morse | d8797b1 | 2018-11-27 15:35:21 +0000 | [diff] [blame] | 140 | raw_spin_lock(&bp_lock); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 141 | for_each_possible_cpu(cpu) { |
| 142 | if (per_cpu(bp_hardening_data.fn, cpu) == fn) { |
| 143 | slot = per_cpu(bp_hardening_data.hyp_vectors_slot, cpu); |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if (slot == -1) { |
Marc Zyngier | 4205a89 | 2018-03-13 12:40:39 +0000 | [diff] [blame] | 149 | slot = atomic_inc_return(&arm64_el2_vector_last_slot); |
| 150 | BUG_ON(slot >= BP_HARDEN_EL2_SLOTS); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 151 | __copy_hyp_vect_bpi(slot, hyp_vecs_start, hyp_vecs_end); |
| 152 | } |
| 153 | |
| 154 | __this_cpu_write(bp_hardening_data.hyp_vectors_slot, slot); |
| 155 | __this_cpu_write(bp_hardening_data.fn, fn); |
James Morse | d8797b1 | 2018-11-27 15:35:21 +0000 | [diff] [blame] | 156 | raw_spin_unlock(&bp_lock); |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 157 | } |
| 158 | #else |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 159 | #define __smccc_workaround_1_smc_start NULL |
| 160 | #define __smccc_workaround_1_smc_end NULL |
Will Deacon | aa6acde | 2018-01-03 12:46:21 +0000 | [diff] [blame] | 161 | |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 162 | static void install_bp_hardening_cb(bp_hardening_cb_t fn, |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 163 | const char *hyp_vecs_start, |
| 164 | const char *hyp_vecs_end) |
| 165 | { |
| 166 | __this_cpu_write(bp_hardening_data.fn, fn); |
| 167 | } |
Marc Zyngier | e8b22d0f | 2018-04-10 11:36:45 +0100 | [diff] [blame] | 168 | #endif /* CONFIG_KVM_INDIRECT_VECTORS */ |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 169 | |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 170 | #include <uapi/linux/psci.h> |
| 171 | #include <linux/arm-smccc.h> |
Will Deacon | aa6acde | 2018-01-03 12:46:21 +0000 | [diff] [blame] | 172 | #include <linux/psci.h> |
| 173 | |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 174 | static void call_smc_arch_workaround_1(void) |
| 175 | { |
| 176 | arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); |
| 177 | } |
| 178 | |
| 179 | static void call_hvc_arch_workaround_1(void) |
| 180 | { |
| 181 | arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); |
| 182 | } |
| 183 | |
Shanker Donthineni | 4bc352f | 2018-04-10 11:36:42 +0100 | [diff] [blame] | 184 | static void qcom_link_stack_sanitization(void) |
| 185 | { |
| 186 | u64 tmp; |
| 187 | |
| 188 | asm volatile("mov %0, x30 \n" |
| 189 | ".rept 16 \n" |
| 190 | "bl . + 4 \n" |
| 191 | ".endr \n" |
| 192 | "mov x30, %0 \n" |
| 193 | : "=&r" (tmp)); |
| 194 | } |
| 195 | |
Jeremy Linton | e5ce5e7 | 2019-04-15 16:21:20 -0500 | [diff] [blame] | 196 | static bool __nospectre_v2; |
| 197 | static int __init parse_nospectre_v2(char *str) |
| 198 | { |
| 199 | __nospectre_v2 = true; |
| 200 | return 0; |
| 201 | } |
| 202 | early_param("nospectre_v2", parse_nospectre_v2); |
| 203 | |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 204 | /* |
| 205 | * -1: No workaround |
| 206 | * 0: No workaround required |
| 207 | * 1: Workaround installed |
| 208 | */ |
| 209 | static int detect_harden_bp_fw(void) |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 210 | { |
| 211 | bp_hardening_cb_t cb; |
| 212 | void *smccc_start, *smccc_end; |
| 213 | struct arm_smccc_res res; |
Shanker Donthineni | 4bc352f | 2018-04-10 11:36:42 +0100 | [diff] [blame] | 214 | u32 midr = read_cpuid_id(); |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 215 | |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 216 | if (psci_ops.smccc_version == SMCCC_VERSION_1_0) |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 217 | return -1; |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 218 | |
| 219 | switch (psci_ops.conduit) { |
| 220 | case PSCI_CONDUIT_HVC: |
| 221 | arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 222 | ARM_SMCCC_ARCH_WORKAROUND_1, &res); |
Marc Zyngier | 517953c | 2019-04-15 16:21:24 -0500 | [diff] [blame] | 223 | switch ((int)res.a0) { |
| 224 | case 1: |
| 225 | /* Firmware says we're just fine */ |
| 226 | return 0; |
| 227 | case 0: |
| 228 | cb = call_hvc_arch_workaround_1; |
| 229 | /* This is a guest, no need to patch KVM vectors */ |
| 230 | smccc_start = NULL; |
| 231 | smccc_end = NULL; |
| 232 | break; |
| 233 | default: |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 234 | return -1; |
Marc Zyngier | 517953c | 2019-04-15 16:21:24 -0500 | [diff] [blame] | 235 | } |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 236 | break; |
| 237 | |
| 238 | case PSCI_CONDUIT_SMC: |
| 239 | arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 240 | ARM_SMCCC_ARCH_WORKAROUND_1, &res); |
Marc Zyngier | 517953c | 2019-04-15 16:21:24 -0500 | [diff] [blame] | 241 | switch ((int)res.a0) { |
| 242 | case 1: |
| 243 | /* Firmware says we're just fine */ |
| 244 | return 0; |
| 245 | case 0: |
| 246 | cb = call_smc_arch_workaround_1; |
| 247 | smccc_start = __smccc_workaround_1_smc_start; |
| 248 | smccc_end = __smccc_workaround_1_smc_end; |
| 249 | break; |
| 250 | default: |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 251 | return -1; |
Marc Zyngier | 517953c | 2019-04-15 16:21:24 -0500 | [diff] [blame] | 252 | } |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 253 | break; |
| 254 | |
| 255 | default: |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 256 | return -1; |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Shanker Donthineni | 4bc352f | 2018-04-10 11:36:42 +0100 | [diff] [blame] | 259 | if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) || |
| 260 | ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1)) |
| 261 | cb = qcom_link_stack_sanitization; |
| 262 | |
Jeremy Linton | 8c1e3d2 | 2019-04-15 16:21:25 -0500 | [diff] [blame] | 263 | if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) |
| 264 | install_bp_hardening_cb(cb, smccc_start, smccc_end); |
Marc Zyngier | b092201 | 2018-02-06 17:56:20 +0000 | [diff] [blame] | 265 | |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 266 | return 1; |
Will Deacon | aa6acde | 2018-01-03 12:46:21 +0000 | [diff] [blame] | 267 | } |
Will Deacon | 0f15adb | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 268 | |
Marc Zyngier | 5cf9ce6 | 2018-05-29 13:11:07 +0100 | [diff] [blame] | 269 | DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required); |
| 270 | |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 271 | int ssbd_state __read_mostly = ARM64_SSBD_KERNEL; |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 272 | static bool __ssb_safe = true; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 273 | |
| 274 | static const struct ssbd_options { |
| 275 | const char *str; |
| 276 | int state; |
| 277 | } ssbd_options[] = { |
| 278 | { "force-on", ARM64_SSBD_FORCE_ENABLE, }, |
| 279 | { "force-off", ARM64_SSBD_FORCE_DISABLE, }, |
| 280 | { "kernel", ARM64_SSBD_KERNEL, }, |
| 281 | }; |
| 282 | |
| 283 | static int __init ssbd_cfg(char *buf) |
| 284 | { |
| 285 | int i; |
| 286 | |
| 287 | if (!buf || !buf[0]) |
| 288 | return -EINVAL; |
| 289 | |
| 290 | for (i = 0; i < ARRAY_SIZE(ssbd_options); i++) { |
| 291 | int len = strlen(ssbd_options[i].str); |
| 292 | |
| 293 | if (strncmp(buf, ssbd_options[i].str, len)) |
| 294 | continue; |
| 295 | |
| 296 | ssbd_state = ssbd_options[i].state; |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | return -EINVAL; |
| 301 | } |
| 302 | early_param("ssbd", ssbd_cfg); |
| 303 | |
Marc Zyngier | 8e29062 | 2018-05-29 13:11:06 +0100 | [diff] [blame] | 304 | void __init arm64_update_smccc_conduit(struct alt_instr *alt, |
| 305 | __le32 *origptr, __le32 *updptr, |
| 306 | int nr_inst) |
| 307 | { |
| 308 | u32 insn; |
| 309 | |
| 310 | BUG_ON(nr_inst != 1); |
| 311 | |
| 312 | switch (psci_ops.conduit) { |
| 313 | case PSCI_CONDUIT_HVC: |
| 314 | insn = aarch64_insn_get_hvc_value(); |
| 315 | break; |
| 316 | case PSCI_CONDUIT_SMC: |
| 317 | insn = aarch64_insn_get_smc_value(); |
| 318 | break; |
| 319 | default: |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | *updptr = cpu_to_le32(insn); |
| 324 | } |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 325 | |
Marc Zyngier | 986372c | 2018-05-29 13:11:11 +0100 | [diff] [blame] | 326 | void __init arm64_enable_wa2_handling(struct alt_instr *alt, |
| 327 | __le32 *origptr, __le32 *updptr, |
| 328 | int nr_inst) |
| 329 | { |
| 330 | BUG_ON(nr_inst != 1); |
| 331 | /* |
| 332 | * Only allow mitigation on EL1 entry/exit and guest |
| 333 | * ARCH_WORKAROUND_2 handling if the SSBD state allows it to |
| 334 | * be flipped. |
| 335 | */ |
| 336 | if (arm64_get_ssbd_state() == ARM64_SSBD_KERNEL) |
| 337 | *updptr = cpu_to_le32(aarch64_insn_gen_nop()); |
| 338 | } |
| 339 | |
Marc Zyngier | 647d051 | 2018-05-29 13:11:12 +0100 | [diff] [blame] | 340 | void arm64_set_ssbd_mitigation(bool state) |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 341 | { |
Jeremy Linton | d42281b | 2019-04-15 16:21:27 -0500 | [diff] [blame] | 342 | if (!IS_ENABLED(CONFIG_ARM64_SSBD)) { |
| 343 | pr_info_once("SSBD disabled by kernel configuration\n"); |
| 344 | return; |
| 345 | } |
| 346 | |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 347 | if (this_cpu_has_cap(ARM64_SSBS)) { |
| 348 | if (state) |
| 349 | asm volatile(SET_PSTATE_SSBS(0)); |
| 350 | else |
| 351 | asm volatile(SET_PSTATE_SSBS(1)); |
| 352 | return; |
| 353 | } |
| 354 | |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 355 | switch (psci_ops.conduit) { |
| 356 | case PSCI_CONDUIT_HVC: |
| 357 | arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_2, state, NULL); |
| 358 | break; |
| 359 | |
| 360 | case PSCI_CONDUIT_SMC: |
| 361 | arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2, state, NULL); |
| 362 | break; |
| 363 | |
| 364 | default: |
| 365 | WARN_ON_ONCE(1); |
| 366 | break; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry, |
| 371 | int scope) |
| 372 | { |
| 373 | struct arm_smccc_res res; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 374 | bool required = true; |
| 375 | s32 val; |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 376 | bool this_cpu_safe = false; |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 377 | |
| 378 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 379 | |
Josh Poimboeuf | a111b7c | 2019-04-12 15:39:32 -0500 | [diff] [blame] | 380 | if (cpu_mitigations_off()) |
| 381 | ssbd_state = ARM64_SSBD_FORCE_DISABLE; |
| 382 | |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 383 | /* delay setting __ssb_safe until we get a firmware response */ |
| 384 | if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list)) |
| 385 | this_cpu_safe = true; |
| 386 | |
Will Deacon | eb337cd | 2019-04-30 16:58:56 +0100 | [diff] [blame] | 387 | if (this_cpu_has_cap(ARM64_SSBS)) { |
| 388 | if (!this_cpu_safe) |
| 389 | __ssb_safe = false; |
| 390 | required = false; |
| 391 | goto out_printmsg; |
| 392 | } |
| 393 | |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 394 | if (psci_ops.smccc_version == SMCCC_VERSION_1_0) { |
| 395 | ssbd_state = ARM64_SSBD_UNKNOWN; |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 396 | if (!this_cpu_safe) |
| 397 | __ssb_safe = false; |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 398 | return false; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 399 | } |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 400 | |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 401 | switch (psci_ops.conduit) { |
| 402 | case PSCI_CONDUIT_HVC: |
| 403 | arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 404 | ARM_SMCCC_ARCH_WORKAROUND_2, &res); |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 405 | break; |
| 406 | |
| 407 | case PSCI_CONDUIT_SMC: |
| 408 | arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, |
| 409 | ARM_SMCCC_ARCH_WORKAROUND_2, &res); |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 410 | break; |
| 411 | |
| 412 | default: |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 413 | ssbd_state = ARM64_SSBD_UNKNOWN; |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 414 | if (!this_cpu_safe) |
| 415 | __ssb_safe = false; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 416 | return false; |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 419 | val = (s32)res.a0; |
| 420 | |
| 421 | switch (val) { |
| 422 | case SMCCC_RET_NOT_SUPPORTED: |
| 423 | ssbd_state = ARM64_SSBD_UNKNOWN; |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 424 | if (!this_cpu_safe) |
| 425 | __ssb_safe = false; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 426 | return false; |
| 427 | |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 428 | /* machines with mixed mitigation requirements must not return this */ |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 429 | case SMCCC_RET_NOT_REQUIRED: |
| 430 | pr_info_once("%s mitigation not required\n", entry->desc); |
| 431 | ssbd_state = ARM64_SSBD_MITIGATED; |
| 432 | return false; |
| 433 | |
| 434 | case SMCCC_RET_SUCCESS: |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 435 | __ssb_safe = false; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 436 | required = true; |
| 437 | break; |
| 438 | |
| 439 | case 1: /* Mitigation not required on this CPU */ |
| 440 | required = false; |
| 441 | break; |
| 442 | |
| 443 | default: |
| 444 | WARN_ON(1); |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 445 | if (!this_cpu_safe) |
| 446 | __ssb_safe = false; |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 447 | return false; |
| 448 | } |
| 449 | |
| 450 | switch (ssbd_state) { |
| 451 | case ARM64_SSBD_FORCE_DISABLE: |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 452 | arm64_set_ssbd_mitigation(false); |
| 453 | required = false; |
| 454 | break; |
| 455 | |
| 456 | case ARM64_SSBD_KERNEL: |
| 457 | if (required) { |
| 458 | __this_cpu_write(arm64_ssbd_callback_required, 1); |
| 459 | arm64_set_ssbd_mitigation(true); |
| 460 | } |
| 461 | break; |
| 462 | |
| 463 | case ARM64_SSBD_FORCE_ENABLE: |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 464 | arm64_set_ssbd_mitigation(true); |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 465 | required = true; |
| 466 | break; |
| 467 | |
| 468 | default: |
| 469 | WARN_ON(1); |
| 470 | break; |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 471 | } |
| 472 | |
Will Deacon | 8f04e8e | 2018-08-07 13:47:06 +0100 | [diff] [blame] | 473 | out_printmsg: |
| 474 | switch (ssbd_state) { |
| 475 | case ARM64_SSBD_FORCE_DISABLE: |
| 476 | pr_info_once("%s disabled from command-line\n", entry->desc); |
| 477 | break; |
| 478 | |
| 479 | case ARM64_SSBD_FORCE_ENABLE: |
| 480 | pr_info_once("%s forced from command-line\n", entry->desc); |
| 481 | break; |
| 482 | } |
| 483 | |
Marc Zyngier | a43ae4d | 2018-05-29 13:11:09 +0100 | [diff] [blame] | 484 | return required; |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 485 | } |
Marc Zyngier | 8e29062 | 2018-05-29 13:11:06 +0100 | [diff] [blame] | 486 | |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 487 | /* known invulnerable cores */ |
| 488 | static const struct midr_range arm64_ssb_cpus[] = { |
| 489 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), |
| 490 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), |
| 491 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), |
| 492 | {}, |
| 493 | }; |
| 494 | |
Will Deacon | 969f5ea | 2019-04-29 13:03:57 +0100 | [diff] [blame] | 495 | #ifdef CONFIG_ARM64_ERRATUM_1463225 |
| 496 | DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa); |
| 497 | |
| 498 | static bool |
| 499 | has_cortex_a76_erratum_1463225(const struct arm64_cpu_capabilities *entry, |
| 500 | int scope) |
| 501 | { |
| 502 | u32 midr = read_cpuid_id(); |
| 503 | /* Cortex-A76 r0p0 - r3p1 */ |
| 504 | struct midr_range range = MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1); |
| 505 | |
| 506 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 507 | return is_midr_in_range(midr, &range) && is_kernel_in_hyp_mode(); |
| 508 | } |
| 509 | #endif |
| 510 | |
Will Deacon | b8925ee | 2018-08-07 13:53:41 +0100 | [diff] [blame] | 511 | static void __maybe_unused |
| 512 | cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused) |
| 513 | { |
| 514 | sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCI, 0); |
| 515 | } |
| 516 | |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 517 | #define CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \ |
| 518 | .matches = is_affected_midr_range, \ |
Suzuki K Poulose | 1df3105 | 2018-03-26 15:12:44 +0100 | [diff] [blame] | 519 | .midr_range = MIDR_RANGE(model, v_min, r_min, v_max, r_max) |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 520 | |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 521 | #define CAP_MIDR_ALL_VERSIONS(model) \ |
| 522 | .matches = is_affected_midr_range, \ |
Suzuki K Poulose | 1df3105 | 2018-03-26 15:12:44 +0100 | [diff] [blame] | 523 | .midr_range = MIDR_ALL_VERSIONS(model) |
Marc Zyngier | 06f1494 | 2017-02-01 14:38:46 +0000 | [diff] [blame] | 524 | |
Ard Biesheuvel | e8002e0 | 2018-03-06 17:15:34 +0000 | [diff] [blame] | 525 | #define MIDR_FIXED(rev, revidr_mask) \ |
| 526 | .fixed_revs = (struct arm64_midr_revidr[]){{ (rev), (revidr_mask) }, {}} |
| 527 | |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 528 | #define ERRATA_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \ |
| 529 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ |
| 530 | CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) |
| 531 | |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 532 | #define CAP_MIDR_RANGE_LIST(list) \ |
| 533 | .matches = is_affected_midr_range_list, \ |
| 534 | .midr_range_list = list |
| 535 | |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 536 | /* Errata affecting a range of revisions of given model variant */ |
| 537 | #define ERRATA_MIDR_REV_RANGE(m, var, r_min, r_max) \ |
| 538 | ERRATA_MIDR_RANGE(m, var, r_min, var, r_max) |
| 539 | |
| 540 | /* Errata affecting a single variant/revision of a model */ |
| 541 | #define ERRATA_MIDR_REV(model, var, rev) \ |
| 542 | ERRATA_MIDR_RANGE(model, var, rev, var, rev) |
| 543 | |
| 544 | /* Errata affecting all variants/revisions of a given a model */ |
| 545 | #define ERRATA_MIDR_ALL_VERSIONS(model) \ |
| 546 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ |
| 547 | CAP_MIDR_ALL_VERSIONS(model) |
| 548 | |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 549 | /* Errata affecting a list of midr ranges, with same work around */ |
| 550 | #define ERRATA_MIDR_RANGE_LIST(midr_list) \ |
| 551 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ |
| 552 | CAP_MIDR_RANGE_LIST(midr_list) |
| 553 | |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 554 | /* Track overall mitigation state. We are only mitigated if all cores are ok */ |
| 555 | static bool __hardenbp_enab = true; |
| 556 | static bool __spectrev2_safe = true; |
| 557 | |
Andre Przywara | c118bbb | 2019-05-03 15:27:48 +0100 | [diff] [blame] | 558 | int get_spectre_v2_workaround_state(void) |
| 559 | { |
| 560 | if (__spectrev2_safe) |
| 561 | return ARM64_BP_HARDEN_NOT_REQUIRED; |
| 562 | |
| 563 | if (!__hardenbp_enab) |
| 564 | return ARM64_BP_HARDEN_UNKNOWN; |
| 565 | |
| 566 | return ARM64_BP_HARDEN_WA_NEEDED; |
| 567 | } |
| 568 | |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 569 | /* |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 570 | * List of CPUs that do not need any Spectre-v2 mitigation at all. |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 571 | */ |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 572 | static const struct midr_range spectre_v2_safe_list[] = { |
| 573 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), |
| 574 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), |
| 575 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), |
| 576 | { /* sentinel */ } |
Suzuki K Poulose | be5b299 | 2018-03-26 15:12:45 +0100 | [diff] [blame] | 577 | }; |
| 578 | |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 579 | /* |
| 580 | * Track overall bp hardening for all heterogeneous cores in the machine. |
| 581 | * We are only considered "safe" if all booted cores are known safe. |
| 582 | */ |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 583 | static bool __maybe_unused |
| 584 | check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) |
| 585 | { |
| 586 | int need_wa; |
| 587 | |
| 588 | WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); |
| 589 | |
| 590 | /* If the CPU has CSV2 set, we're safe */ |
| 591 | if (cpuid_feature_extract_unsigned_field(read_cpuid(ID_AA64PFR0_EL1), |
| 592 | ID_AA64PFR0_CSV2_SHIFT)) |
| 593 | return false; |
| 594 | |
| 595 | /* Alternatively, we have a list of unaffected CPUs */ |
| 596 | if (is_midr_in_range_list(read_cpuid_id(), spectre_v2_safe_list)) |
| 597 | return false; |
| 598 | |
| 599 | /* Fallback to firmware detection */ |
| 600 | need_wa = detect_harden_bp_fw(); |
| 601 | if (!need_wa) |
| 602 | return false; |
| 603 | |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 604 | __spectrev2_safe = false; |
| 605 | |
Jeremy Linton | 8c1e3d2 | 2019-04-15 16:21:25 -0500 | [diff] [blame] | 606 | if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) { |
| 607 | pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n"); |
| 608 | __hardenbp_enab = false; |
| 609 | return false; |
| 610 | } |
| 611 | |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 612 | /* forced off */ |
Josh Poimboeuf | a111b7c | 2019-04-12 15:39:32 -0500 | [diff] [blame] | 613 | if (__nospectre_v2 || cpu_mitigations_off()) { |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 614 | pr_info_once("spectrev2 mitigation disabled by command line option\n"); |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 615 | __hardenbp_enab = false; |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 616 | return false; |
| 617 | } |
| 618 | |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 619 | if (need_wa < 0) { |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 620 | pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n"); |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 621 | __hardenbp_enab = false; |
| 622 | } |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 623 | |
| 624 | return (need_wa > 0); |
| 625 | } |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 626 | |
Marc Zyngier | 93916be | 2019-04-09 16:26:21 +0100 | [diff] [blame] | 627 | static const __maybe_unused struct midr_range tx2_family_cpus[] = { |
| 628 | MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), |
| 629 | MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), |
| 630 | {}, |
| 631 | }; |
| 632 | |
| 633 | static bool __maybe_unused |
| 634 | needs_tx2_tvm_workaround(const struct arm64_cpu_capabilities *entry, |
| 635 | int scope) |
| 636 | { |
| 637 | int i; |
| 638 | |
| 639 | if (!is_affected_midr_range_list(entry, scope) || |
| 640 | !is_hyp_mode_available()) |
| 641 | return false; |
| 642 | |
| 643 | for_each_possible_cpu(i) { |
| 644 | if (MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 0) != 0) |
| 645 | return true; |
| 646 | } |
| 647 | |
| 648 | return false; |
| 649 | } |
| 650 | |
Marc Zyngier | 8892b71 | 2018-04-10 11:36:43 +0100 | [diff] [blame] | 651 | #ifdef CONFIG_HARDEN_EL2_VECTORS |
| 652 | |
| 653 | static const struct midr_range arm64_harden_el2_vectors[] = { |
| 654 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), |
| 655 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), |
| 656 | {}, |
| 657 | }; |
| 658 | |
Marc Zyngier | dc6ed61 | 2018-03-28 12:46:07 +0100 | [diff] [blame] | 659 | #endif |
| 660 | |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 661 | #ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI |
| 662 | |
| 663 | static const struct midr_range arm64_repeat_tlbi_cpus[] = { |
| 664 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009 |
| 665 | MIDR_RANGE(MIDR_QCOM_FALKOR_V1, 0, 0, 0, 0), |
| 666 | #endif |
| 667 | #ifdef CONFIG_ARM64_ERRATUM_1286807 |
| 668 | MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 0), |
| 669 | #endif |
| 670 | {}, |
| 671 | }; |
| 672 | |
| 673 | #endif |
| 674 | |
Suzuki K Poulose | f58cdf7 | 2018-11-30 17:18:01 +0000 | [diff] [blame] | 675 | #ifdef CONFIG_CAVIUM_ERRATUM_27456 |
Will Deacon | b89d82e | 2019-01-08 16:19:01 +0000 | [diff] [blame] | 676 | const struct midr_range cavium_erratum_27456_cpus[] = { |
Suzuki K Poulose | f58cdf7 | 2018-11-30 17:18:01 +0000 | [diff] [blame] | 677 | /* Cavium ThunderX, T88 pass 1.x - 2.1 */ |
| 678 | MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 1), |
| 679 | /* Cavium ThunderX, T81 pass 1.0 */ |
| 680 | MIDR_REV(MIDR_THUNDERX_81XX, 0, 0), |
| 681 | {}, |
| 682 | }; |
| 683 | #endif |
| 684 | |
| 685 | #ifdef CONFIG_CAVIUM_ERRATUM_30115 |
| 686 | static const struct midr_range cavium_erratum_30115_cpus[] = { |
| 687 | /* Cavium ThunderX, T88 pass 1.x - 2.2 */ |
| 688 | MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 2), |
| 689 | /* Cavium ThunderX, T81 pass 1.0 - 1.2 */ |
| 690 | MIDR_REV_RANGE(MIDR_THUNDERX_81XX, 0, 0, 2), |
| 691 | /* Cavium ThunderX, T83 pass 1.0 */ |
| 692 | MIDR_REV(MIDR_THUNDERX_83XX, 0, 0), |
| 693 | {}, |
| 694 | }; |
| 695 | #endif |
| 696 | |
Suzuki K Poulose | a3dcea2c | 2018-11-30 17:18:02 +0000 | [diff] [blame] | 697 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 |
| 698 | static const struct arm64_cpu_capabilities qcom_erratum_1003_list[] = { |
| 699 | { |
| 700 | ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0), |
| 701 | }, |
| 702 | { |
| 703 | .midr_range.model = MIDR_QCOM_KRYO, |
| 704 | .matches = is_kryo_midr, |
| 705 | }, |
| 706 | {}, |
| 707 | }; |
| 708 | #endif |
| 709 | |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 710 | #ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE |
| 711 | static const struct midr_range workaround_clean_cache[] = { |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 712 | #if defined(CONFIG_ARM64_ERRATUM_826319) || \ |
| 713 | defined(CONFIG_ARM64_ERRATUM_827319) || \ |
| 714 | defined(CONFIG_ARM64_ERRATUM_824069) |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 715 | /* Cortex-A53 r0p[012]: ARM errata 826319, 827319, 824069 */ |
| 716 | MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 2), |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 717 | #endif |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 718 | #ifdef CONFIG_ARM64_ERRATUM_819472 |
| 719 | /* Cortex-A53 r0p[01] : ARM errata 819472 */ |
| 720 | MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 1), |
| 721 | #endif |
| 722 | {}, |
| 723 | }; |
| 724 | #endif |
| 725 | |
Marc Zyngier | a532508 | 2019-05-23 11:24:50 +0100 | [diff] [blame] | 726 | #ifdef CONFIG_ARM64_ERRATUM_1418040 |
| 727 | /* |
| 728 | * - 1188873 affects r0p0 to r2p0 |
| 729 | * - 1418040 affects r0p0 to r3p1 |
| 730 | */ |
| 731 | static const struct midr_range erratum_1418040_list[] = { |
| 732 | /* Cortex-A76 r0p0 to r3p1 */ |
| 733 | MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1), |
| 734 | /* Neoverse-N1 r0p0 to r3p1 */ |
| 735 | MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 0, 3, 1), |
Marc Zyngier | 6989303 | 2019-04-15 13:03:54 +0100 | [diff] [blame] | 736 | {}, |
| 737 | }; |
| 738 | #endif |
| 739 | |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 740 | const struct arm64_cpu_capabilities arm64_errata[] = { |
| 741 | #ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 742 | { |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 743 | .desc = "ARM errata 826319, 827319, 824069, 819472", |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 744 | .capability = ARM64_WORKAROUND_CLEAN_CACHE, |
Suzuki K Poulose | c9460dc | 2018-11-30 17:18:00 +0000 | [diff] [blame] | 745 | ERRATA_MIDR_RANGE_LIST(workaround_clean_cache), |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 746 | .cpu_enable = cpu_enable_cache_maint_trap, |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 747 | }, |
| 748 | #endif |
| 749 | #ifdef CONFIG_ARM64_ERRATUM_832075 |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 750 | { |
Andre Przywara | 5afaa1f | 2014-11-14 15:54:11 +0000 | [diff] [blame] | 751 | /* Cortex-A57 r0p0 - r1p2 */ |
| 752 | .desc = "ARM erratum 832075", |
| 753 | .capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 754 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A57, |
| 755 | 0, 0, |
| 756 | 1, 2), |
Andre Przywara | 5afaa1f | 2014-11-14 15:54:11 +0000 | [diff] [blame] | 757 | }, |
Andre Przywara | c0a01b8 | 2014-11-14 15:54:12 +0000 | [diff] [blame] | 758 | #endif |
Marc Zyngier | 498cd5c | 2015-11-16 10:28:18 +0000 | [diff] [blame] | 759 | #ifdef CONFIG_ARM64_ERRATUM_834220 |
| 760 | { |
| 761 | /* Cortex-A57 r0p0 - r1p2 */ |
| 762 | .desc = "ARM erratum 834220", |
| 763 | .capability = ARM64_WORKAROUND_834220, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 764 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A57, |
| 765 | 0, 0, |
| 766 | 1, 2), |
Marc Zyngier | 498cd5c | 2015-11-16 10:28:18 +0000 | [diff] [blame] | 767 | }, |
| 768 | #endif |
Ard Biesheuvel | ca79acc | 2018-03-06 17:15:35 +0000 | [diff] [blame] | 769 | #ifdef CONFIG_ARM64_ERRATUM_843419 |
| 770 | { |
| 771 | /* Cortex-A53 r0p[01234] */ |
| 772 | .desc = "ARM erratum 843419", |
| 773 | .capability = ARM64_WORKAROUND_843419, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 774 | ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4), |
Ard Biesheuvel | ca79acc | 2018-03-06 17:15:35 +0000 | [diff] [blame] | 775 | MIDR_FIXED(0x4, BIT(8)), |
Will Deacon | 905e8c5 | 2015-03-23 19:07:02 +0000 | [diff] [blame] | 776 | }, |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 777 | #endif |
| 778 | #ifdef CONFIG_ARM64_ERRATUM_845719 |
| 779 | { |
| 780 | /* Cortex-A53 r0p[01234] */ |
| 781 | .desc = "ARM erratum 845719", |
| 782 | .capability = ARM64_WORKAROUND_845719, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 783 | ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4), |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 784 | }, |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 785 | #endif |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 786 | #ifdef CONFIG_CAVIUM_ERRATUM_23154 |
| 787 | { |
| 788 | /* Cavium ThunderX, pass 1.x */ |
| 789 | .desc = "Cavium erratum 23154", |
| 790 | .capability = ARM64_WORKAROUND_CAVIUM_23154, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 791 | ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1), |
Robert Richter | 6d4e11c | 2015-09-21 22:58:35 +0200 | [diff] [blame] | 792 | }, |
| 793 | #endif |
Andrew Pinski | 104a0c0 | 2016-02-24 17:44:57 -0800 | [diff] [blame] | 794 | #ifdef CONFIG_CAVIUM_ERRATUM_27456 |
| 795 | { |
Andrew Pinski | 104a0c0 | 2016-02-24 17:44:57 -0800 | [diff] [blame] | 796 | .desc = "Cavium erratum 27456", |
| 797 | .capability = ARM64_WORKAROUND_CAVIUM_27456, |
Suzuki K Poulose | f58cdf7 | 2018-11-30 17:18:01 +0000 | [diff] [blame] | 798 | ERRATA_MIDR_RANGE_LIST(cavium_erratum_27456_cpus), |
Ganapatrao Kulkarni | 47c459b | 2016-07-07 10:18:17 +0530 | [diff] [blame] | 799 | }, |
Andrew Pinski | 104a0c0 | 2016-02-24 17:44:57 -0800 | [diff] [blame] | 800 | #endif |
David Daney | 690a341 | 2017-06-09 12:49:48 +0100 | [diff] [blame] | 801 | #ifdef CONFIG_CAVIUM_ERRATUM_30115 |
| 802 | { |
David Daney | 690a341 | 2017-06-09 12:49:48 +0100 | [diff] [blame] | 803 | .desc = "Cavium erratum 30115", |
| 804 | .capability = ARM64_WORKAROUND_CAVIUM_30115, |
Suzuki K Poulose | f58cdf7 | 2018-11-30 17:18:01 +0000 | [diff] [blame] | 805 | ERRATA_MIDR_RANGE_LIST(cavium_erratum_30115_cpus), |
David Daney | 690a341 | 2017-06-09 12:49:48 +0100 | [diff] [blame] | 806 | }, |
| 807 | #endif |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 808 | { |
Will Deacon | 880f7cc | 2018-09-19 11:41:21 +0100 | [diff] [blame] | 809 | .desc = "Mismatched cache type (CTR_EL0)", |
Suzuki K Poulose | 314d53d | 2018-07-04 23:07:46 +0100 | [diff] [blame] | 810 | .capability = ARM64_MISMATCHED_CACHE_TYPE, |
| 811 | .matches = has_mismatched_cache_type, |
Suzuki K Poulose | 5b4747c | 2018-03-26 15:12:32 +0100 | [diff] [blame] | 812 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
Dave Martin | c0cda3b | 2018-03-26 15:12:28 +0100 | [diff] [blame] | 813 | .cpu_enable = cpu_enable_trap_ctr_access, |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 814 | }, |
Christopher Covington | 38fd94b | 2017-02-08 15:08:37 -0500 | [diff] [blame] | 815 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 |
| 816 | { |
Suzuki K Poulose | a3dcea2c | 2018-11-30 17:18:02 +0000 | [diff] [blame] | 817 | .desc = "Qualcomm Technologies Falkor/Kryo erratum 1003", |
Christopher Covington | 38fd94b | 2017-02-08 15:08:37 -0500 | [diff] [blame] | 818 | .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003, |
Will Deacon | 1e013d0 | 2018-12-12 15:53:54 +0000 | [diff] [blame] | 819 | .matches = cpucap_multi_entry_cap_matches, |
Suzuki K Poulose | a3dcea2c | 2018-11-30 17:18:02 +0000 | [diff] [blame] | 820 | .match_list = qcom_erratum_1003_list, |
Stephen Boyd | bb48711 | 2017-12-13 14:19:37 -0800 | [diff] [blame] | 821 | }, |
Christopher Covington | 38fd94b | 2017-02-08 15:08:37 -0500 | [diff] [blame] | 822 | #endif |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 823 | #ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI |
Christopher Covington | d9ff80f | 2017-01-31 12:50:19 -0500 | [diff] [blame] | 824 | { |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 825 | .desc = "Qualcomm erratum 1009, ARM erratum 1286807", |
Christopher Covington | d9ff80f | 2017-01-31 12:50:19 -0500 | [diff] [blame] | 826 | .capability = ARM64_WORKAROUND_REPEAT_TLBI, |
Catalin Marinas | ce8c80c | 2018-11-19 11:27:28 +0000 | [diff] [blame] | 827 | ERRATA_MIDR_RANGE_LIST(arm64_repeat_tlbi_cpus), |
Christopher Covington | d9ff80f | 2017-01-31 12:50:19 -0500 | [diff] [blame] | 828 | }, |
| 829 | #endif |
Marc Zyngier | eeb1efb | 2017-03-20 17:18:06 +0000 | [diff] [blame] | 830 | #ifdef CONFIG_ARM64_ERRATUM_858921 |
| 831 | { |
| 832 | /* Cortex-A73 all versions */ |
| 833 | .desc = "ARM erratum 858921", |
| 834 | .capability = ARM64_WORKAROUND_858921, |
Suzuki K Poulose | 5e7951c | 2018-03-26 15:12:43 +0100 | [diff] [blame] | 835 | ERRATA_MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), |
Marc Zyngier | eeb1efb | 2017-03-20 17:18:06 +0000 | [diff] [blame] | 836 | }, |
| 837 | #endif |
Will Deacon | aa6acde | 2018-01-03 12:46:21 +0000 | [diff] [blame] | 838 | { |
| 839 | .capability = ARM64_HARDEN_BRANCH_PREDICTOR, |
Marc Zyngier | 73f3816 | 2019-04-15 16:21:23 -0500 | [diff] [blame] | 840 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 841 | .matches = check_branch_predictor, |
Jayachandran C | f3d795d | 2018-01-19 04:22:47 -0800 | [diff] [blame] | 842 | }, |
Marc Zyngier | 4b472ff | 2018-02-15 11:49:20 +0000 | [diff] [blame] | 843 | #ifdef CONFIG_HARDEN_EL2_VECTORS |
| 844 | { |
Marc Zyngier | 8892b71 | 2018-04-10 11:36:43 +0100 | [diff] [blame] | 845 | .desc = "EL2 vector hardening", |
Marc Zyngier | 4b472ff | 2018-02-15 11:49:20 +0000 | [diff] [blame] | 846 | .capability = ARM64_HARDEN_EL2_VECTORS, |
Marc Zyngier | 8892b71 | 2018-04-10 11:36:43 +0100 | [diff] [blame] | 847 | ERRATA_MIDR_RANGE_LIST(arm64_harden_el2_vectors), |
Marc Zyngier | 4b472ff | 2018-02-15 11:49:20 +0000 | [diff] [blame] | 848 | }, |
| 849 | #endif |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 850 | { |
| 851 | .desc = "Speculative Store Bypass Disable", |
| 852 | .capability = ARM64_SSBD, |
| 853 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 854 | .matches = has_ssbd_mitigation, |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 855 | .midr_range_list = arm64_ssb_cpus, |
Marc Zyngier | a725e3d | 2018-05-29 13:11:08 +0100 | [diff] [blame] | 856 | }, |
Marc Zyngier | a532508 | 2019-05-23 11:24:50 +0100 | [diff] [blame] | 857 | #ifdef CONFIG_ARM64_ERRATUM_1418040 |
Marc Zyngier | 95b861a4 | 2018-09-27 17:15:34 +0100 | [diff] [blame] | 858 | { |
Marc Zyngier | a532508 | 2019-05-23 11:24:50 +0100 | [diff] [blame] | 859 | .desc = "ARM erratum 1418040", |
| 860 | .capability = ARM64_WORKAROUND_1418040, |
| 861 | ERRATA_MIDR_RANGE_LIST(erratum_1418040_list), |
Marc Zyngier | 95b861a4 | 2018-09-27 17:15:34 +0100 | [diff] [blame] | 862 | }, |
| 863 | #endif |
Marc Zyngier | 8b2cca9 | 2018-12-06 17:31:23 +0000 | [diff] [blame] | 864 | #ifdef CONFIG_ARM64_ERRATUM_1165522 |
| 865 | { |
| 866 | /* Cortex-A76 r0p0 to r2p0 */ |
| 867 | .desc = "ARM erratum 1165522", |
| 868 | .capability = ARM64_WORKAROUND_1165522, |
| 869 | ERRATA_MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 2, 0), |
| 870 | }, |
| 871 | #endif |
Will Deacon | 969f5ea | 2019-04-29 13:03:57 +0100 | [diff] [blame] | 872 | #ifdef CONFIG_ARM64_ERRATUM_1463225 |
| 873 | { |
| 874 | .desc = "ARM erratum 1463225", |
| 875 | .capability = ARM64_WORKAROUND_1463225, |
| 876 | .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, |
| 877 | .matches = has_cortex_a76_erratum_1463225, |
| 878 | }, |
| 879 | #endif |
Marc Zyngier | 93916be | 2019-04-09 16:26:21 +0100 | [diff] [blame] | 880 | #ifdef CONFIG_CAVIUM_TX2_ERRATUM_219 |
| 881 | { |
| 882 | .desc = "Cavium ThunderX2 erratum 219 (KVM guest sysreg trapping)", |
| 883 | .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_TVM, |
| 884 | ERRATA_MIDR_RANGE_LIST(tx2_family_cpus), |
| 885 | .matches = needs_tx2_tvm_workaround, |
| 886 | }, |
Marc Zyngier | 9405447 | 2019-04-09 16:22:24 +0100 | [diff] [blame^] | 887 | { |
| 888 | .desc = "Cavium ThunderX2 erratum 219 (PRFM removal)", |
| 889 | .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM, |
| 890 | ERRATA_MIDR_RANGE_LIST(tx2_family_cpus), |
| 891 | }, |
Marc Zyngier | 93916be | 2019-04-09 16:26:21 +0100 | [diff] [blame] | 892 | #endif |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 893 | { |
Andre Przywara | e116a37 | 2014-11-14 15:54:09 +0000 | [diff] [blame] | 894 | } |
| 895 | }; |
Mian Yousaf Kaukab | 3891ebc | 2019-04-15 16:21:21 -0500 | [diff] [blame] | 896 | |
| 897 | ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, |
| 898 | char *buf) |
| 899 | { |
| 900 | return sprintf(buf, "Mitigation: __user pointer sanitization\n"); |
| 901 | } |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 902 | |
| 903 | ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, |
| 904 | char *buf) |
| 905 | { |
Andre Przywara | c118bbb | 2019-05-03 15:27:48 +0100 | [diff] [blame] | 906 | switch (get_spectre_v2_workaround_state()) { |
| 907 | case ARM64_BP_HARDEN_NOT_REQUIRED: |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 908 | return sprintf(buf, "Not affected\n"); |
Andre Przywara | c118bbb | 2019-05-03 15:27:48 +0100 | [diff] [blame] | 909 | case ARM64_BP_HARDEN_WA_NEEDED: |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 910 | return sprintf(buf, "Mitigation: Branch predictor hardening\n"); |
Andre Przywara | c118bbb | 2019-05-03 15:27:48 +0100 | [diff] [blame] | 911 | case ARM64_BP_HARDEN_UNKNOWN: |
| 912 | default: |
| 913 | return sprintf(buf, "Vulnerable\n"); |
| 914 | } |
Jeremy Linton | d2532e2 | 2019-04-15 16:21:26 -0500 | [diff] [blame] | 915 | } |
Jeremy Linton | 526e065 | 2019-04-15 16:21:28 -0500 | [diff] [blame] | 916 | |
| 917 | ssize_t cpu_show_spec_store_bypass(struct device *dev, |
| 918 | struct device_attribute *attr, char *buf) |
| 919 | { |
| 920 | if (__ssb_safe) |
| 921 | return sprintf(buf, "Not affected\n"); |
| 922 | |
| 923 | switch (ssbd_state) { |
| 924 | case ARM64_SSBD_KERNEL: |
| 925 | case ARM64_SSBD_FORCE_ENABLE: |
| 926 | if (IS_ENABLED(CONFIG_ARM64_SSBD)) |
| 927 | return sprintf(buf, |
| 928 | "Mitigation: Speculative Store Bypass disabled via prctl\n"); |
| 929 | } |
| 930 | |
| 931 | return sprintf(buf, "Vulnerable\n"); |
| 932 | } |