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