bpi.S 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Contains CPU specific branch predictor invalidation sequences
  3. *
  4. * Copyright (C) 2018 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/linkage.h>
  19. #include <linux/arm-smccc.h>
  20. #include <asm/alternative.h>
  21. #include <asm/mmu.h>
  22. .macro hyp_ventry
  23. .align 7
  24. 1: .rept 27
  25. nop
  26. .endr
  27. /*
  28. * The default sequence is to directly branch to the KVM vectors,
  29. * using the computed offset. This applies for VHE as well as
  30. * !ARM64_HARDEN_EL2_VECTORS.
  31. *
  32. * For ARM64_HARDEN_EL2_VECTORS configurations, this gets replaced
  33. * with:
  34. *
  35. * stp x0, x1, [sp, #-16]!
  36. * movz x0, #(addr & 0xffff)
  37. * movk x0, #((addr >> 16) & 0xffff), lsl #16
  38. * movk x0, #((addr >> 32) & 0xffff), lsl #32
  39. * br x0
  40. *
  41. * Where addr = kern_hyp_va(__kvm_hyp_vector) + vector-offset + 4.
  42. * See kvm_patch_vector_branch for details.
  43. */
  44. alternative_cb kvm_patch_vector_branch
  45. b __kvm_hyp_vector + (1b - 0b)
  46. nop
  47. nop
  48. nop
  49. nop
  50. alternative_cb_end
  51. .endm
  52. .macro generate_vectors
  53. 0:
  54. .rept 16
  55. hyp_ventry
  56. .endr
  57. .org 0b + SZ_2K // Safety measure
  58. .endm
  59. .text
  60. .pushsection .hyp.text, "ax"
  61. .align 11
  62. ENTRY(__bp_harden_hyp_vecs_start)
  63. .rept BP_HARDEN_EL2_SLOTS
  64. generate_vectors
  65. .endr
  66. ENTRY(__bp_harden_hyp_vecs_end)
  67. .popsection
  68. ENTRY(__smccc_workaround_1_smc_start)
  69. sub sp, sp, #(8 * 4)
  70. stp x2, x3, [sp, #(8 * 0)]
  71. stp x0, x1, [sp, #(8 * 2)]
  72. mov w0, #ARM_SMCCC_ARCH_WORKAROUND_1
  73. smc #0
  74. ldp x2, x3, [sp, #(8 * 0)]
  75. ldp x0, x1, [sp, #(8 * 2)]
  76. add sp, sp, #(8 * 4)
  77. ENTRY(__smccc_workaround_1_smc_end)