cpu_errata.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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. #include <linux/arm-smccc.h>
  19. #include <linux/psci.h>
  20. #include <linux/types.h>
  21. #include <linux/cpu.h>
  22. #include <asm/cpu.h>
  23. #include <asm/cputype.h>
  24. #include <asm/cpufeature.h>
  25. static bool __maybe_unused
  26. is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope)
  27. {
  28. const struct arm64_midr_revidr *fix;
  29. u32 midr = read_cpuid_id(), revidr;
  30. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  31. if (!is_midr_in_range(midr, &entry->midr_range))
  32. return false;
  33. midr &= MIDR_REVISION_MASK | MIDR_VARIANT_MASK;
  34. revidr = read_cpuid(REVIDR_EL1);
  35. for (fix = entry->fixed_revs; fix && fix->revidr_mask; fix++)
  36. if (midr == fix->midr_rv && (revidr & fix->revidr_mask))
  37. return false;
  38. return true;
  39. }
  40. static bool __maybe_unused
  41. is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry,
  42. int scope)
  43. {
  44. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  45. return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list);
  46. }
  47. static bool __maybe_unused
  48. is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope)
  49. {
  50. u32 model;
  51. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  52. model = read_cpuid_id();
  53. model &= MIDR_IMPLEMENTOR_MASK | (0xf00 << MIDR_PARTNUM_SHIFT) |
  54. MIDR_ARCHITECTURE_MASK;
  55. return model == entry->midr_range.model;
  56. }
  57. static bool
  58. has_mismatched_cache_type(const struct arm64_cpu_capabilities *entry,
  59. int scope)
  60. {
  61. u64 mask = CTR_CACHE_MINLINE_MASK;
  62. /* Skip matching the min line sizes for cache type check */
  63. if (entry->capability == ARM64_MISMATCHED_CACHE_TYPE)
  64. mask ^= arm64_ftr_reg_ctrel0.strict_mask;
  65. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  66. return (read_cpuid_cachetype() & mask) !=
  67. (arm64_ftr_reg_ctrel0.sys_val & mask);
  68. }
  69. static void
  70. cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *__unused)
  71. {
  72. sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCT, 0);
  73. }
  74. atomic_t arm64_el2_vector_last_slot = ATOMIC_INIT(-1);
  75. #include <asm/mmu_context.h>
  76. #include <asm/cacheflush.h>
  77. DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);
  78. #ifdef CONFIG_KVM_INDIRECT_VECTORS
  79. extern char __smccc_workaround_1_smc_start[];
  80. extern char __smccc_workaround_1_smc_end[];
  81. static void __copy_hyp_vect_bpi(int slot, const char *hyp_vecs_start,
  82. const char *hyp_vecs_end)
  83. {
  84. void *dst = lm_alias(__bp_harden_hyp_vecs_start + slot * SZ_2K);
  85. int i;
  86. for (i = 0; i < SZ_2K; i += 0x80)
  87. memcpy(dst + i, hyp_vecs_start, hyp_vecs_end - hyp_vecs_start);
  88. __flush_icache_range((uintptr_t)dst, (uintptr_t)dst + SZ_2K);
  89. }
  90. static void install_bp_hardening_cb(bp_hardening_cb_t fn,
  91. const char *hyp_vecs_start,
  92. const char *hyp_vecs_end)
  93. {
  94. static DEFINE_SPINLOCK(bp_lock);
  95. int cpu, slot = -1;
  96. spin_lock(&bp_lock);
  97. for_each_possible_cpu(cpu) {
  98. if (per_cpu(bp_hardening_data.fn, cpu) == fn) {
  99. slot = per_cpu(bp_hardening_data.hyp_vectors_slot, cpu);
  100. break;
  101. }
  102. }
  103. if (slot == -1) {
  104. slot = atomic_inc_return(&arm64_el2_vector_last_slot);
  105. BUG_ON(slot >= BP_HARDEN_EL2_SLOTS);
  106. __copy_hyp_vect_bpi(slot, hyp_vecs_start, hyp_vecs_end);
  107. }
  108. __this_cpu_write(bp_hardening_data.hyp_vectors_slot, slot);
  109. __this_cpu_write(bp_hardening_data.fn, fn);
  110. spin_unlock(&bp_lock);
  111. }
  112. #else
  113. #define __smccc_workaround_1_smc_start NULL
  114. #define __smccc_workaround_1_smc_end NULL
  115. static void install_bp_hardening_cb(bp_hardening_cb_t fn,
  116. const char *hyp_vecs_start,
  117. const char *hyp_vecs_end)
  118. {
  119. __this_cpu_write(bp_hardening_data.fn, fn);
  120. }
  121. #endif /* CONFIG_KVM_INDIRECT_VECTORS */
  122. #include <uapi/linux/psci.h>
  123. #include <linux/arm-smccc.h>
  124. #include <linux/psci.h>
  125. static void call_smc_arch_workaround_1(void)
  126. {
  127. arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL);
  128. }
  129. static void call_hvc_arch_workaround_1(void)
  130. {
  131. arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL);
  132. }
  133. static void qcom_link_stack_sanitization(void)
  134. {
  135. u64 tmp;
  136. asm volatile("mov %0, x30 \n"
  137. ".rept 16 \n"
  138. "bl . + 4 \n"
  139. ".endr \n"
  140. "mov x30, %0 \n"
  141. : "=&r" (tmp));
  142. }
  143. static bool __nospectre_v2;
  144. static int __init parse_nospectre_v2(char *str)
  145. {
  146. __nospectre_v2 = true;
  147. return 0;
  148. }
  149. early_param("nospectre_v2", parse_nospectre_v2);
  150. /*
  151. * -1: No workaround
  152. * 0: No workaround required
  153. * 1: Workaround installed
  154. */
  155. static int detect_harden_bp_fw(void)
  156. {
  157. bp_hardening_cb_t cb;
  158. void *smccc_start, *smccc_end;
  159. struct arm_smccc_res res;
  160. u32 midr = read_cpuid_id();
  161. if (psci_ops.smccc_version == SMCCC_VERSION_1_0)
  162. return -1;
  163. switch (psci_ops.conduit) {
  164. case PSCI_CONDUIT_HVC:
  165. arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
  166. ARM_SMCCC_ARCH_WORKAROUND_1, &res);
  167. switch ((int)res.a0) {
  168. case 1:
  169. /* Firmware says we're just fine */
  170. return 0;
  171. case 0:
  172. cb = call_hvc_arch_workaround_1;
  173. /* This is a guest, no need to patch KVM vectors */
  174. smccc_start = NULL;
  175. smccc_end = NULL;
  176. break;
  177. default:
  178. return -1;
  179. }
  180. break;
  181. case PSCI_CONDUIT_SMC:
  182. arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
  183. ARM_SMCCC_ARCH_WORKAROUND_1, &res);
  184. switch ((int)res.a0) {
  185. case 1:
  186. /* Firmware says we're just fine */
  187. return 0;
  188. case 0:
  189. cb = call_smc_arch_workaround_1;
  190. smccc_start = __smccc_workaround_1_smc_start;
  191. smccc_end = __smccc_workaround_1_smc_end;
  192. break;
  193. default:
  194. return -1;
  195. }
  196. break;
  197. default:
  198. return -1;
  199. }
  200. if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) ||
  201. ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1))
  202. cb = qcom_link_stack_sanitization;
  203. if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR))
  204. install_bp_hardening_cb(cb, smccc_start, smccc_end);
  205. return 1;
  206. }
  207. DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required);
  208. int ssbd_state __read_mostly = ARM64_SSBD_KERNEL;
  209. static bool __ssb_safe = true;
  210. static const struct ssbd_options {
  211. const char *str;
  212. int state;
  213. } ssbd_options[] = {
  214. { "force-on", ARM64_SSBD_FORCE_ENABLE, },
  215. { "force-off", ARM64_SSBD_FORCE_DISABLE, },
  216. { "kernel", ARM64_SSBD_KERNEL, },
  217. };
  218. static int __init ssbd_cfg(char *buf)
  219. {
  220. int i;
  221. if (!buf || !buf[0])
  222. return -EINVAL;
  223. for (i = 0; i < ARRAY_SIZE(ssbd_options); i++) {
  224. int len = strlen(ssbd_options[i].str);
  225. if (strncmp(buf, ssbd_options[i].str, len))
  226. continue;
  227. ssbd_state = ssbd_options[i].state;
  228. return 0;
  229. }
  230. return -EINVAL;
  231. }
  232. early_param("ssbd", ssbd_cfg);
  233. void __init arm64_update_smccc_conduit(struct alt_instr *alt,
  234. __le32 *origptr, __le32 *updptr,
  235. int nr_inst)
  236. {
  237. u32 insn;
  238. BUG_ON(nr_inst != 1);
  239. switch (psci_ops.conduit) {
  240. case PSCI_CONDUIT_HVC:
  241. insn = aarch64_insn_get_hvc_value();
  242. break;
  243. case PSCI_CONDUIT_SMC:
  244. insn = aarch64_insn_get_smc_value();
  245. break;
  246. default:
  247. return;
  248. }
  249. *updptr = cpu_to_le32(insn);
  250. }
  251. void __init arm64_enable_wa2_handling(struct alt_instr *alt,
  252. __le32 *origptr, __le32 *updptr,
  253. int nr_inst)
  254. {
  255. BUG_ON(nr_inst != 1);
  256. /*
  257. * Only allow mitigation on EL1 entry/exit and guest
  258. * ARCH_WORKAROUND_2 handling if the SSBD state allows it to
  259. * be flipped.
  260. */
  261. if (arm64_get_ssbd_state() == ARM64_SSBD_KERNEL)
  262. *updptr = cpu_to_le32(aarch64_insn_gen_nop());
  263. }
  264. void arm64_set_ssbd_mitigation(bool state)
  265. {
  266. if (!IS_ENABLED(CONFIG_ARM64_SSBD)) {
  267. pr_info_once("SSBD disabled by kernel configuration\n");
  268. return;
  269. }
  270. if (this_cpu_has_cap(ARM64_SSBS)) {
  271. if (state)
  272. asm volatile(SET_PSTATE_SSBS(0));
  273. else
  274. asm volatile(SET_PSTATE_SSBS(1));
  275. return;
  276. }
  277. switch (psci_ops.conduit) {
  278. case PSCI_CONDUIT_HVC:
  279. arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_2, state, NULL);
  280. break;
  281. case PSCI_CONDUIT_SMC:
  282. arm_smccc_1_1_smc(ARM_SMCCC_ARCH_WORKAROUND_2, state, NULL);
  283. break;
  284. default:
  285. WARN_ON_ONCE(1);
  286. break;
  287. }
  288. }
  289. static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry,
  290. int scope)
  291. {
  292. struct arm_smccc_res res;
  293. bool required = true;
  294. s32 val;
  295. bool this_cpu_safe = false;
  296. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  297. if (cpu_mitigations_off())
  298. ssbd_state = ARM64_SSBD_FORCE_DISABLE;
  299. /* delay setting __ssb_safe until we get a firmware response */
  300. if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list))
  301. this_cpu_safe = true;
  302. if (this_cpu_has_cap(ARM64_SSBS)) {
  303. if (!this_cpu_safe)
  304. __ssb_safe = false;
  305. required = false;
  306. goto out_printmsg;
  307. }
  308. if (psci_ops.smccc_version == SMCCC_VERSION_1_0) {
  309. ssbd_state = ARM64_SSBD_UNKNOWN;
  310. if (!this_cpu_safe)
  311. __ssb_safe = false;
  312. return false;
  313. }
  314. switch (psci_ops.conduit) {
  315. case PSCI_CONDUIT_HVC:
  316. arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
  317. ARM_SMCCC_ARCH_WORKAROUND_2, &res);
  318. break;
  319. case PSCI_CONDUIT_SMC:
  320. arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
  321. ARM_SMCCC_ARCH_WORKAROUND_2, &res);
  322. break;
  323. default:
  324. ssbd_state = ARM64_SSBD_UNKNOWN;
  325. if (!this_cpu_safe)
  326. __ssb_safe = false;
  327. return false;
  328. }
  329. val = (s32)res.a0;
  330. switch (val) {
  331. case SMCCC_RET_NOT_SUPPORTED:
  332. ssbd_state = ARM64_SSBD_UNKNOWN;
  333. if (!this_cpu_safe)
  334. __ssb_safe = false;
  335. return false;
  336. /* machines with mixed mitigation requirements must not return this */
  337. case SMCCC_RET_NOT_REQUIRED:
  338. pr_info_once("%s mitigation not required\n", entry->desc);
  339. ssbd_state = ARM64_SSBD_MITIGATED;
  340. return false;
  341. case SMCCC_RET_SUCCESS:
  342. __ssb_safe = false;
  343. required = true;
  344. break;
  345. case 1: /* Mitigation not required on this CPU */
  346. required = false;
  347. break;
  348. default:
  349. WARN_ON(1);
  350. if (!this_cpu_safe)
  351. __ssb_safe = false;
  352. return false;
  353. }
  354. switch (ssbd_state) {
  355. case ARM64_SSBD_FORCE_DISABLE:
  356. arm64_set_ssbd_mitigation(false);
  357. required = false;
  358. break;
  359. case ARM64_SSBD_KERNEL:
  360. if (required) {
  361. __this_cpu_write(arm64_ssbd_callback_required, 1);
  362. arm64_set_ssbd_mitigation(true);
  363. }
  364. break;
  365. case ARM64_SSBD_FORCE_ENABLE:
  366. arm64_set_ssbd_mitigation(true);
  367. required = true;
  368. break;
  369. default:
  370. WARN_ON(1);
  371. break;
  372. }
  373. out_printmsg:
  374. switch (ssbd_state) {
  375. case ARM64_SSBD_FORCE_DISABLE:
  376. pr_info_once("%s disabled from command-line\n", entry->desc);
  377. break;
  378. case ARM64_SSBD_FORCE_ENABLE:
  379. pr_info_once("%s forced from command-line\n", entry->desc);
  380. break;
  381. }
  382. return required;
  383. }
  384. /* known invulnerable cores */
  385. static const struct midr_range arm64_ssb_cpus[] = {
  386. MIDR_ALL_VERSIONS(MIDR_CORTEX_A35),
  387. MIDR_ALL_VERSIONS(MIDR_CORTEX_A53),
  388. MIDR_ALL_VERSIONS(MIDR_CORTEX_A55),
  389. {},
  390. };
  391. #ifdef CONFIG_ARM64_ERRATUM_1463225
  392. DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa);
  393. static bool
  394. has_cortex_a76_erratum_1463225(const struct arm64_cpu_capabilities *entry,
  395. int scope)
  396. {
  397. u32 midr = read_cpuid_id();
  398. /* Cortex-A76 r0p0 - r3p1 */
  399. struct midr_range range = MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1);
  400. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  401. return is_midr_in_range(midr, &range) && is_kernel_in_hyp_mode();
  402. }
  403. #endif
  404. #define CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \
  405. .matches = is_affected_midr_range, \
  406. .midr_range = MIDR_RANGE(model, v_min, r_min, v_max, r_max)
  407. #define CAP_MIDR_ALL_VERSIONS(model) \
  408. .matches = is_affected_midr_range, \
  409. .midr_range = MIDR_ALL_VERSIONS(model)
  410. #define MIDR_FIXED(rev, revidr_mask) \
  411. .fixed_revs = (struct arm64_midr_revidr[]){{ (rev), (revidr_mask) }, {}}
  412. #define ERRATA_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \
  413. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
  414. CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max)
  415. #define CAP_MIDR_RANGE_LIST(list) \
  416. .matches = is_affected_midr_range_list, \
  417. .midr_range_list = list
  418. /* Errata affecting a range of revisions of given model variant */
  419. #define ERRATA_MIDR_REV_RANGE(m, var, r_min, r_max) \
  420. ERRATA_MIDR_RANGE(m, var, r_min, var, r_max)
  421. /* Errata affecting a single variant/revision of a model */
  422. #define ERRATA_MIDR_REV(model, var, rev) \
  423. ERRATA_MIDR_RANGE(model, var, rev, var, rev)
  424. /* Errata affecting all variants/revisions of a given a model */
  425. #define ERRATA_MIDR_ALL_VERSIONS(model) \
  426. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
  427. CAP_MIDR_ALL_VERSIONS(model)
  428. /* Errata affecting a list of midr ranges, with same work around */
  429. #define ERRATA_MIDR_RANGE_LIST(midr_list) \
  430. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
  431. CAP_MIDR_RANGE_LIST(midr_list)
  432. /* Track overall mitigation state. We are only mitigated if all cores are ok */
  433. static bool __hardenbp_enab = true;
  434. static bool __spectrev2_safe = true;
  435. /*
  436. * Generic helper for handling capabilties with multiple (match,enable) pairs
  437. * of call backs, sharing the same capability bit.
  438. * Iterate over each entry to see if at least one matches.
  439. */
  440. static bool __maybe_unused
  441. multi_entry_cap_matches(const struct arm64_cpu_capabilities *entry, int scope)
  442. {
  443. const struct arm64_cpu_capabilities *caps;
  444. for (caps = entry->match_list; caps->matches; caps++)
  445. if (caps->matches(caps, scope))
  446. return true;
  447. return false;
  448. }
  449. /*
  450. * Take appropriate action for all matching entries in the shared capability
  451. * entry.
  452. */
  453. static void __maybe_unused
  454. multi_entry_cap_cpu_enable(const struct arm64_cpu_capabilities *entry)
  455. {
  456. const struct arm64_cpu_capabilities *caps;
  457. for (caps = entry->match_list; caps->matches; caps++)
  458. if (caps->matches(caps, SCOPE_LOCAL_CPU) &&
  459. caps->cpu_enable)
  460. caps->cpu_enable(caps);
  461. }
  462. /*
  463. * List of CPUs that do not need any Spectre-v2 mitigation at all.
  464. */
  465. static const struct midr_range spectre_v2_safe_list[] = {
  466. MIDR_ALL_VERSIONS(MIDR_CORTEX_A35),
  467. MIDR_ALL_VERSIONS(MIDR_CORTEX_A53),
  468. MIDR_ALL_VERSIONS(MIDR_CORTEX_A55),
  469. { /* sentinel */ }
  470. };
  471. /*
  472. * Track overall bp hardening for all heterogeneous cores in the machine.
  473. * We are only considered "safe" if all booted cores are known safe.
  474. */
  475. static bool __maybe_unused
  476. check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope)
  477. {
  478. int need_wa;
  479. WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
  480. /* If the CPU has CSV2 set, we're safe */
  481. if (cpuid_feature_extract_unsigned_field(read_cpuid(ID_AA64PFR0_EL1),
  482. ID_AA64PFR0_CSV2_SHIFT))
  483. return false;
  484. /* Alternatively, we have a list of unaffected CPUs */
  485. if (is_midr_in_range_list(read_cpuid_id(), spectre_v2_safe_list))
  486. return false;
  487. /* Fallback to firmware detection */
  488. need_wa = detect_harden_bp_fw();
  489. if (!need_wa)
  490. return false;
  491. __spectrev2_safe = false;
  492. if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) {
  493. pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n");
  494. __hardenbp_enab = false;
  495. return false;
  496. }
  497. /* forced off */
  498. if (__nospectre_v2 || cpu_mitigations_off()) {
  499. pr_info_once("spectrev2 mitigation disabled by command line option\n");
  500. __hardenbp_enab = false;
  501. return false;
  502. }
  503. if (need_wa < 0) {
  504. pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n");
  505. __hardenbp_enab = false;
  506. }
  507. return (need_wa > 0);
  508. }
  509. #ifdef CONFIG_HARDEN_EL2_VECTORS
  510. static const struct midr_range arm64_harden_el2_vectors[] = {
  511. MIDR_ALL_VERSIONS(MIDR_CORTEX_A57),
  512. MIDR_ALL_VERSIONS(MIDR_CORTEX_A72),
  513. {},
  514. };
  515. #endif
  516. const struct arm64_cpu_capabilities arm64_errata[] = {
  517. #if defined(CONFIG_ARM64_ERRATUM_826319) || \
  518. defined(CONFIG_ARM64_ERRATUM_827319) || \
  519. defined(CONFIG_ARM64_ERRATUM_824069)
  520. {
  521. /* Cortex-A53 r0p[012] */
  522. .desc = "ARM errata 826319, 827319, 824069",
  523. .capability = ARM64_WORKAROUND_CLEAN_CACHE,
  524. ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 2),
  525. .cpu_enable = cpu_enable_cache_maint_trap,
  526. },
  527. #endif
  528. #ifdef CONFIG_ARM64_ERRATUM_819472
  529. {
  530. /* Cortex-A53 r0p[01] */
  531. .desc = "ARM errata 819472",
  532. .capability = ARM64_WORKAROUND_CLEAN_CACHE,
  533. ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 1),
  534. .cpu_enable = cpu_enable_cache_maint_trap,
  535. },
  536. #endif
  537. #ifdef CONFIG_ARM64_ERRATUM_832075
  538. {
  539. /* Cortex-A57 r0p0 - r1p2 */
  540. .desc = "ARM erratum 832075",
  541. .capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE,
  542. ERRATA_MIDR_RANGE(MIDR_CORTEX_A57,
  543. 0, 0,
  544. 1, 2),
  545. },
  546. #endif
  547. #ifdef CONFIG_ARM64_ERRATUM_834220
  548. {
  549. /* Cortex-A57 r0p0 - r1p2 */
  550. .desc = "ARM erratum 834220",
  551. .capability = ARM64_WORKAROUND_834220,
  552. ERRATA_MIDR_RANGE(MIDR_CORTEX_A57,
  553. 0, 0,
  554. 1, 2),
  555. },
  556. #endif
  557. #ifdef CONFIG_ARM64_ERRATUM_843419
  558. {
  559. /* Cortex-A53 r0p[01234] */
  560. .desc = "ARM erratum 843419",
  561. .capability = ARM64_WORKAROUND_843419,
  562. ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4),
  563. MIDR_FIXED(0x4, BIT(8)),
  564. },
  565. #endif
  566. #ifdef CONFIG_ARM64_ERRATUM_845719
  567. {
  568. /* Cortex-A53 r0p[01234] */
  569. .desc = "ARM erratum 845719",
  570. .capability = ARM64_WORKAROUND_845719,
  571. ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4),
  572. },
  573. #endif
  574. #ifdef CONFIG_CAVIUM_ERRATUM_23154
  575. {
  576. /* Cavium ThunderX, pass 1.x */
  577. .desc = "Cavium erratum 23154",
  578. .capability = ARM64_WORKAROUND_CAVIUM_23154,
  579. ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1),
  580. },
  581. #endif
  582. #ifdef CONFIG_CAVIUM_ERRATUM_27456
  583. {
  584. /* Cavium ThunderX, T88 pass 1.x - 2.1 */
  585. .desc = "Cavium erratum 27456",
  586. .capability = ARM64_WORKAROUND_CAVIUM_27456,
  587. ERRATA_MIDR_RANGE(MIDR_THUNDERX,
  588. 0, 0,
  589. 1, 1),
  590. },
  591. {
  592. /* Cavium ThunderX, T81 pass 1.0 */
  593. .desc = "Cavium erratum 27456",
  594. .capability = ARM64_WORKAROUND_CAVIUM_27456,
  595. ERRATA_MIDR_REV(MIDR_THUNDERX_81XX, 0, 0),
  596. },
  597. #endif
  598. #ifdef CONFIG_CAVIUM_ERRATUM_30115
  599. {
  600. /* Cavium ThunderX, T88 pass 1.x - 2.2 */
  601. .desc = "Cavium erratum 30115",
  602. .capability = ARM64_WORKAROUND_CAVIUM_30115,
  603. ERRATA_MIDR_RANGE(MIDR_THUNDERX,
  604. 0, 0,
  605. 1, 2),
  606. },
  607. {
  608. /* Cavium ThunderX, T81 pass 1.0 - 1.2 */
  609. .desc = "Cavium erratum 30115",
  610. .capability = ARM64_WORKAROUND_CAVIUM_30115,
  611. ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX_81XX, 0, 0, 2),
  612. },
  613. {
  614. /* Cavium ThunderX, T83 pass 1.0 */
  615. .desc = "Cavium erratum 30115",
  616. .capability = ARM64_WORKAROUND_CAVIUM_30115,
  617. ERRATA_MIDR_REV(MIDR_THUNDERX_83XX, 0, 0),
  618. },
  619. #endif
  620. {
  621. .desc = "Mismatched cache line size",
  622. .capability = ARM64_MISMATCHED_CACHE_LINE_SIZE,
  623. .matches = has_mismatched_cache_type,
  624. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  625. .cpu_enable = cpu_enable_trap_ctr_access,
  626. },
  627. {
  628. .desc = "Mismatched cache type",
  629. .capability = ARM64_MISMATCHED_CACHE_TYPE,
  630. .matches = has_mismatched_cache_type,
  631. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  632. .cpu_enable = cpu_enable_trap_ctr_access,
  633. },
  634. #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
  635. {
  636. .desc = "Qualcomm Technologies Falkor erratum 1003",
  637. .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003,
  638. ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0),
  639. },
  640. {
  641. .desc = "Qualcomm Technologies Kryo erratum 1003",
  642. .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003,
  643. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  644. .midr_range.model = MIDR_QCOM_KRYO,
  645. .matches = is_kryo_midr,
  646. },
  647. #endif
  648. #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009
  649. {
  650. .desc = "Qualcomm Technologies Falkor erratum 1009",
  651. .capability = ARM64_WORKAROUND_REPEAT_TLBI,
  652. ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0),
  653. },
  654. #endif
  655. #ifdef CONFIG_ARM64_ERRATUM_858921
  656. {
  657. /* Cortex-A73 all versions */
  658. .desc = "ARM erratum 858921",
  659. .capability = ARM64_WORKAROUND_858921,
  660. ERRATA_MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
  661. },
  662. #endif
  663. {
  664. .capability = ARM64_HARDEN_BRANCH_PREDICTOR,
  665. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  666. .matches = check_branch_predictor,
  667. },
  668. #ifdef CONFIG_HARDEN_EL2_VECTORS
  669. {
  670. .desc = "EL2 vector hardening",
  671. .capability = ARM64_HARDEN_EL2_VECTORS,
  672. ERRATA_MIDR_RANGE_LIST(arm64_harden_el2_vectors),
  673. },
  674. #endif
  675. {
  676. .desc = "Speculative Store Bypass Disable",
  677. .capability = ARM64_SSBD,
  678. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  679. .matches = has_ssbd_mitigation,
  680. .midr_range_list = arm64_ssb_cpus,
  681. },
  682. #ifdef CONFIG_ARM64_ERRATUM_1463225
  683. {
  684. .desc = "ARM erratum 1463225",
  685. .capability = ARM64_WORKAROUND_1463225,
  686. .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
  687. .matches = has_cortex_a76_erratum_1463225,
  688. },
  689. #endif
  690. {
  691. }
  692. };
  693. ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr,
  694. char *buf)
  695. {
  696. return sprintf(buf, "Mitigation: __user pointer sanitization\n");
  697. }
  698. ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
  699. char *buf)
  700. {
  701. if (__spectrev2_safe)
  702. return sprintf(buf, "Not affected\n");
  703. if (__hardenbp_enab)
  704. return sprintf(buf, "Mitigation: Branch predictor hardening\n");
  705. return sprintf(buf, "Vulnerable\n");
  706. }
  707. ssize_t cpu_show_spec_store_bypass(struct device *dev,
  708. struct device_attribute *attr, char *buf)
  709. {
  710. if (__ssb_safe)
  711. return sprintf(buf, "Not affected\n");
  712. switch (ssbd_state) {
  713. case ARM64_SSBD_KERNEL:
  714. case ARM64_SSBD_FORCE_ENABLE:
  715. if (IS_ENABLED(CONFIG_ARM64_SSBD))
  716. return sprintf(buf,
  717. "Mitigation: Speculative Store Bypass disabled via prctl\n");
  718. }
  719. return sprintf(buf, "Vulnerable\n");
  720. }