vectors.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2022 ARM Ltd.
  4. */
  5. #ifndef __ASM_VECTORS_H
  6. #define __ASM_VECTORS_H
  7. #include <linux/bug.h>
  8. #include <linux/percpu.h>
  9. #include <asm/fixmap.h>
  10. extern char vectors[];
  11. extern char tramp_vectors[];
  12. extern char __bp_harden_el1_vectors[];
  13. /*
  14. * Note: the order of this enum corresponds to two arrays in entry.S:
  15. * tramp_vecs and __bp_harden_el1_vectors. By default the canonical
  16. * 'full fat' vectors are used directly.
  17. */
  18. enum arm64_bp_harden_el1_vectors {
  19. #ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
  20. /*
  21. * Perform the BHB loop mitigation, before branching to the canonical
  22. * vectors.
  23. */
  24. EL1_VECTOR_BHB_LOOP,
  25. /*
  26. * Make the SMC call for firmware mitigation, before branching to the
  27. * canonical vectors.
  28. */
  29. EL1_VECTOR_BHB_FW,
  30. /*
  31. * Use the ClearBHB instruction, before branching to the canonical
  32. * vectors.
  33. */
  34. EL1_VECTOR_BHB_CLEAR_INSN,
  35. #endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
  36. /*
  37. * Remap the kernel before branching to the canonical vectors.
  38. */
  39. EL1_VECTOR_KPTI,
  40. };
  41. #ifndef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
  42. #define EL1_VECTOR_BHB_LOOP -1
  43. #define EL1_VECTOR_BHB_FW -1
  44. #define EL1_VECTOR_BHB_CLEAR_INSN -1
  45. #endif /* !CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */
  46. /* The vectors to use on return from EL0. e.g. to remap the kernel */
  47. DECLARE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector);
  48. #ifndef CONFIG_UNMAP_KERNEL_AT_EL0
  49. #define TRAMP_VALIAS 0ul
  50. #endif
  51. static inline const char *
  52. arm64_get_bp_hardening_vector(enum arm64_bp_harden_el1_vectors slot)
  53. {
  54. if (arm64_kernel_unmapped_at_el0())
  55. return (char *)(TRAMP_VALIAS + SZ_2K * slot);
  56. WARN_ON_ONCE(slot == EL1_VECTOR_KPTI);
  57. return __bp_harden_el1_vectors + SZ_2K * slot;
  58. }
  59. #endif /* __ASM_VECTORS_H */