hyp.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*
  2. * Copyright (C) 2012,2013 - ARM Ltd
  3. * Author: Marc Zyngier <marc.zyngier@arm.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <linux/linkage.h>
  18. #include <linux/irqchip/arm-gic.h>
  19. #include <asm/assembler.h>
  20. #include <asm/memory.h>
  21. #include <asm/asm-offsets.h>
  22. #include <asm/fpsimdmacros.h>
  23. #include <asm/kvm.h>
  24. #include <asm/kvm_asm.h>
  25. #include <asm/kvm_arm.h>
  26. #include <asm/kvm_mmu.h>
  27. #define CPU_GP_REG_OFFSET(x) (CPU_GP_REGS + x)
  28. #define CPU_XREG_OFFSET(x) CPU_GP_REG_OFFSET(CPU_USER_PT_REGS + 8*x)
  29. #define CPU_SPSR_OFFSET(x) CPU_GP_REG_OFFSET(CPU_SPSR + 8*x)
  30. #define CPU_SYSREG_OFFSET(x) (CPU_SYSREGS + 8*x)
  31. .text
  32. .pushsection .hyp.text, "ax"
  33. .align PAGE_SHIFT
  34. __kvm_hyp_code_start:
  35. .globl __kvm_hyp_code_start
  36. .macro save_common_regs
  37. // x2: base address for cpu context
  38. // x3: tmp register
  39. add x3, x2, #CPU_XREG_OFFSET(19)
  40. stp x19, x20, [x3]
  41. stp x21, x22, [x3, #16]
  42. stp x23, x24, [x3, #32]
  43. stp x25, x26, [x3, #48]
  44. stp x27, x28, [x3, #64]
  45. stp x29, lr, [x3, #80]
  46. mrs x19, sp_el0
  47. mrs x20, elr_el2 // EL1 PC
  48. mrs x21, spsr_el2 // EL1 pstate
  49. stp x19, x20, [x3, #96]
  50. str x21, [x3, #112]
  51. mrs x22, sp_el1
  52. mrs x23, elr_el1
  53. mrs x24, spsr_el1
  54. str x22, [x2, #CPU_GP_REG_OFFSET(CPU_SP_EL1)]
  55. str x23, [x2, #CPU_GP_REG_OFFSET(CPU_ELR_EL1)]
  56. str x24, [x2, #CPU_SPSR_OFFSET(KVM_SPSR_EL1)]
  57. .endm
  58. .macro restore_common_regs
  59. // x2: base address for cpu context
  60. // x3: tmp register
  61. ldr x22, [x2, #CPU_GP_REG_OFFSET(CPU_SP_EL1)]
  62. ldr x23, [x2, #CPU_GP_REG_OFFSET(CPU_ELR_EL1)]
  63. ldr x24, [x2, #CPU_SPSR_OFFSET(KVM_SPSR_EL1)]
  64. msr sp_el1, x22
  65. msr elr_el1, x23
  66. msr spsr_el1, x24
  67. add x3, x2, #CPU_XREG_OFFSET(31) // SP_EL0
  68. ldp x19, x20, [x3]
  69. ldr x21, [x3, #16]
  70. msr sp_el0, x19
  71. msr elr_el2, x20 // EL1 PC
  72. msr spsr_el2, x21 // EL1 pstate
  73. add x3, x2, #CPU_XREG_OFFSET(19)
  74. ldp x19, x20, [x3]
  75. ldp x21, x22, [x3, #16]
  76. ldp x23, x24, [x3, #32]
  77. ldp x25, x26, [x3, #48]
  78. ldp x27, x28, [x3, #64]
  79. ldp x29, lr, [x3, #80]
  80. .endm
  81. .macro save_host_regs
  82. save_common_regs
  83. .endm
  84. .macro restore_host_regs
  85. restore_common_regs
  86. .endm
  87. .macro save_fpsimd
  88. // x2: cpu context address
  89. // x3, x4: tmp regs
  90. add x3, x2, #CPU_GP_REG_OFFSET(CPU_FP_REGS)
  91. fpsimd_save x3, 4
  92. .endm
  93. .macro restore_fpsimd
  94. // x2: cpu context address
  95. // x3, x4: tmp regs
  96. add x3, x2, #CPU_GP_REG_OFFSET(CPU_FP_REGS)
  97. fpsimd_restore x3, 4
  98. .endm
  99. .macro save_guest_regs
  100. // x0 is the vcpu address
  101. // x1 is the return code, do not corrupt!
  102. // x2 is the cpu context
  103. // x3 is a tmp register
  104. // Guest's x0-x3 are on the stack
  105. // Compute base to save registers
  106. add x3, x2, #CPU_XREG_OFFSET(4)
  107. stp x4, x5, [x3]
  108. stp x6, x7, [x3, #16]
  109. stp x8, x9, [x3, #32]
  110. stp x10, x11, [x3, #48]
  111. stp x12, x13, [x3, #64]
  112. stp x14, x15, [x3, #80]
  113. stp x16, x17, [x3, #96]
  114. str x18, [x3, #112]
  115. pop x6, x7 // x2, x3
  116. pop x4, x5 // x0, x1
  117. add x3, x2, #CPU_XREG_OFFSET(0)
  118. stp x4, x5, [x3]
  119. stp x6, x7, [x3, #16]
  120. save_common_regs
  121. .endm
  122. .macro restore_guest_regs
  123. // x0 is the vcpu address.
  124. // x2 is the cpu context
  125. // x3 is a tmp register
  126. // Prepare x0-x3 for later restore
  127. add x3, x2, #CPU_XREG_OFFSET(0)
  128. ldp x4, x5, [x3]
  129. ldp x6, x7, [x3, #16]
  130. push x4, x5 // Push x0-x3 on the stack
  131. push x6, x7
  132. // x4-x18
  133. ldp x4, x5, [x3, #32]
  134. ldp x6, x7, [x3, #48]
  135. ldp x8, x9, [x3, #64]
  136. ldp x10, x11, [x3, #80]
  137. ldp x12, x13, [x3, #96]
  138. ldp x14, x15, [x3, #112]
  139. ldp x16, x17, [x3, #128]
  140. ldr x18, [x3, #144]
  141. // x19-x29, lr, sp*, elr*, spsr*
  142. restore_common_regs
  143. // Last bits of the 64bit state
  144. pop x2, x3
  145. pop x0, x1
  146. // Do not touch any register after this!
  147. .endm
  148. /*
  149. * Macros to perform system register save/restore.
  150. *
  151. * Ordering here is absolutely critical, and must be kept consistent
  152. * in {save,restore}_sysregs, {save,restore}_guest_32bit_state,
  153. * and in kvm_asm.h.
  154. *
  155. * In other words, don't touch any of these unless you know what
  156. * you are doing.
  157. */
  158. .macro save_sysregs
  159. // x2: base address for cpu context
  160. // x3: tmp register
  161. add x3, x2, #CPU_SYSREG_OFFSET(MPIDR_EL1)
  162. mrs x4, vmpidr_el2
  163. mrs x5, csselr_el1
  164. mrs x6, sctlr_el1
  165. mrs x7, actlr_el1
  166. mrs x8, cpacr_el1
  167. mrs x9, ttbr0_el1
  168. mrs x10, ttbr1_el1
  169. mrs x11, tcr_el1
  170. mrs x12, esr_el1
  171. mrs x13, afsr0_el1
  172. mrs x14, afsr1_el1
  173. mrs x15, far_el1
  174. mrs x16, mair_el1
  175. mrs x17, vbar_el1
  176. mrs x18, contextidr_el1
  177. mrs x19, tpidr_el0
  178. mrs x20, tpidrro_el0
  179. mrs x21, tpidr_el1
  180. mrs x22, amair_el1
  181. mrs x23, cntkctl_el1
  182. stp x4, x5, [x3]
  183. stp x6, x7, [x3, #16]
  184. stp x8, x9, [x3, #32]
  185. stp x10, x11, [x3, #48]
  186. stp x12, x13, [x3, #64]
  187. stp x14, x15, [x3, #80]
  188. stp x16, x17, [x3, #96]
  189. stp x18, x19, [x3, #112]
  190. stp x20, x21, [x3, #128]
  191. stp x22, x23, [x3, #144]
  192. .endm
  193. .macro restore_sysregs
  194. // x2: base address for cpu context
  195. // x3: tmp register
  196. add x3, x2, #CPU_SYSREG_OFFSET(MPIDR_EL1)
  197. ldp x4, x5, [x3]
  198. ldp x6, x7, [x3, #16]
  199. ldp x8, x9, [x3, #32]
  200. ldp x10, x11, [x3, #48]
  201. ldp x12, x13, [x3, #64]
  202. ldp x14, x15, [x3, #80]
  203. ldp x16, x17, [x3, #96]
  204. ldp x18, x19, [x3, #112]
  205. ldp x20, x21, [x3, #128]
  206. ldp x22, x23, [x3, #144]
  207. msr vmpidr_el2, x4
  208. msr csselr_el1, x5
  209. msr sctlr_el1, x6
  210. msr actlr_el1, x7
  211. msr cpacr_el1, x8
  212. msr ttbr0_el1, x9
  213. msr ttbr1_el1, x10
  214. msr tcr_el1, x11
  215. msr esr_el1, x12
  216. msr afsr0_el1, x13
  217. msr afsr1_el1, x14
  218. msr far_el1, x15
  219. msr mair_el1, x16
  220. msr vbar_el1, x17
  221. msr contextidr_el1, x18
  222. msr tpidr_el0, x19
  223. msr tpidrro_el0, x20
  224. msr tpidr_el1, x21
  225. msr amair_el1, x22
  226. msr cntkctl_el1, x23
  227. .endm
  228. .macro activate_traps
  229. ldr x2, [x0, #VCPU_IRQ_LINES]
  230. ldr x1, [x0, #VCPU_HCR_EL2]
  231. orr x2, x2, x1
  232. msr hcr_el2, x2
  233. ldr x2, =(CPTR_EL2_TTA)
  234. msr cptr_el2, x2
  235. ldr x2, =(1 << 15) // Trap CP15 Cr=15
  236. msr hstr_el2, x2
  237. mrs x2, mdcr_el2
  238. and x2, x2, #MDCR_EL2_HPMN_MASK
  239. orr x2, x2, #(MDCR_EL2_TPM | MDCR_EL2_TPMCR)
  240. msr mdcr_el2, x2
  241. .endm
  242. .macro deactivate_traps
  243. mov x2, #HCR_RW
  244. msr hcr_el2, x2
  245. msr cptr_el2, xzr
  246. msr hstr_el2, xzr
  247. mrs x2, mdcr_el2
  248. and x2, x2, #MDCR_EL2_HPMN_MASK
  249. msr mdcr_el2, x2
  250. .endm
  251. .macro activate_vm
  252. ldr x1, [x0, #VCPU_KVM]
  253. kern_hyp_va x1
  254. ldr x2, [x1, #KVM_VTTBR]
  255. msr vttbr_el2, x2
  256. .endm
  257. .macro deactivate_vm
  258. msr vttbr_el2, xzr
  259. .endm
  260. /*
  261. * Save the VGIC CPU state into memory
  262. * x0: Register pointing to VCPU struct
  263. * Do not corrupt x1!!!
  264. */
  265. .macro save_vgic_state
  266. /* Get VGIC VCTRL base into x2 */
  267. ldr x2, [x0, #VCPU_KVM]
  268. kern_hyp_va x2
  269. ldr x2, [x2, #KVM_VGIC_VCTRL]
  270. kern_hyp_va x2
  271. cbz x2, 2f // disabled
  272. /* Compute the address of struct vgic_cpu */
  273. add x3, x0, #VCPU_VGIC_CPU
  274. /* Save all interesting registers */
  275. ldr w4, [x2, #GICH_HCR]
  276. ldr w5, [x2, #GICH_VMCR]
  277. ldr w6, [x2, #GICH_MISR]
  278. ldr w7, [x2, #GICH_EISR0]
  279. ldr w8, [x2, #GICH_EISR1]
  280. ldr w9, [x2, #GICH_ELRSR0]
  281. ldr w10, [x2, #GICH_ELRSR1]
  282. ldr w11, [x2, #GICH_APR]
  283. str w4, [x3, #VGIC_CPU_HCR]
  284. str w5, [x3, #VGIC_CPU_VMCR]
  285. str w6, [x3, #VGIC_CPU_MISR]
  286. str w7, [x3, #VGIC_CPU_EISR]
  287. str w8, [x3, #(VGIC_CPU_EISR + 4)]
  288. str w9, [x3, #VGIC_CPU_ELRSR]
  289. str w10, [x3, #(VGIC_CPU_ELRSR + 4)]
  290. str w11, [x3, #VGIC_CPU_APR]
  291. /* Clear GICH_HCR */
  292. str wzr, [x2, #GICH_HCR]
  293. /* Save list registers */
  294. add x2, x2, #GICH_LR0
  295. ldr w4, [x3, #VGIC_CPU_NR_LR]
  296. add x3, x3, #VGIC_CPU_LR
  297. 1: ldr w5, [x2], #4
  298. str w5, [x3], #4
  299. sub w4, w4, #1
  300. cbnz w4, 1b
  301. 2:
  302. .endm
  303. /*
  304. * Restore the VGIC CPU state from memory
  305. * x0: Register pointing to VCPU struct
  306. */
  307. .macro restore_vgic_state
  308. /* Get VGIC VCTRL base into x2 */
  309. ldr x2, [x0, #VCPU_KVM]
  310. kern_hyp_va x2
  311. ldr x2, [x2, #KVM_VGIC_VCTRL]
  312. kern_hyp_va x2
  313. cbz x2, 2f // disabled
  314. /* Compute the address of struct vgic_cpu */
  315. add x3, x0, #VCPU_VGIC_CPU
  316. /* We only restore a minimal set of registers */
  317. ldr w4, [x3, #VGIC_CPU_HCR]
  318. ldr w5, [x3, #VGIC_CPU_VMCR]
  319. ldr w6, [x3, #VGIC_CPU_APR]
  320. str w4, [x2, #GICH_HCR]
  321. str w5, [x2, #GICH_VMCR]
  322. str w6, [x2, #GICH_APR]
  323. /* Restore list registers */
  324. add x2, x2, #GICH_LR0
  325. ldr w4, [x3, #VGIC_CPU_NR_LR]
  326. add x3, x3, #VGIC_CPU_LR
  327. 1: ldr w5, [x3], #4
  328. str w5, [x2], #4
  329. sub w4, w4, #1
  330. cbnz w4, 1b
  331. 2:
  332. .endm
  333. __save_sysregs:
  334. save_sysregs
  335. ret
  336. __restore_sysregs:
  337. restore_sysregs
  338. ret
  339. __save_fpsimd:
  340. save_fpsimd
  341. ret
  342. __restore_fpsimd:
  343. restore_fpsimd
  344. ret
  345. /*
  346. * u64 __kvm_vcpu_run(struct kvm_vcpu *vcpu);
  347. *
  348. * This is the world switch. The first half of the function
  349. * deals with entering the guest, and anything from __kvm_vcpu_return
  350. * to the end of the function deals with reentering the host.
  351. * On the enter path, only x0 (vcpu pointer) must be preserved until
  352. * the last moment. On the exit path, x0 (vcpu pointer) and x1 (exception
  353. * code) must both be preserved until the epilogue.
  354. * In both cases, x2 points to the CPU context we're saving/restoring from/to.
  355. */
  356. ENTRY(__kvm_vcpu_run)
  357. kern_hyp_va x0
  358. msr tpidr_el2, x0 // Save the vcpu register
  359. // Host context
  360. ldr x2, [x0, #VCPU_HOST_CONTEXT]
  361. kern_hyp_va x2
  362. save_host_regs
  363. bl __save_fpsimd
  364. bl __save_sysregs
  365. activate_traps
  366. activate_vm
  367. restore_vgic_state
  368. // Guest context
  369. add x2, x0, #VCPU_CONTEXT
  370. bl __restore_sysregs
  371. bl __restore_fpsimd
  372. restore_guest_regs
  373. // That's it, no more messing around.
  374. eret
  375. __kvm_vcpu_return:
  376. // Assume x0 is the vcpu pointer, x1 the return code
  377. // Guest's x0-x3 are on the stack
  378. // Guest context
  379. add x2, x0, #VCPU_CONTEXT
  380. save_guest_regs
  381. bl __save_fpsimd
  382. bl __save_sysregs
  383. save_vgic_state
  384. deactivate_traps
  385. deactivate_vm
  386. // Host context
  387. ldr x2, [x0, #VCPU_HOST_CONTEXT]
  388. kern_hyp_va x2
  389. bl __restore_sysregs
  390. bl __restore_fpsimd
  391. restore_host_regs
  392. mov x0, x1
  393. ret
  394. END(__kvm_vcpu_run)
  395. // void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
  396. ENTRY(__kvm_tlb_flush_vmid_ipa)
  397. kern_hyp_va x0
  398. ldr x2, [x0, #KVM_VTTBR]
  399. msr vttbr_el2, x2
  400. isb
  401. /*
  402. * We could do so much better if we had the VA as well.
  403. * Instead, we invalidate Stage-2 for this IPA, and the
  404. * whole of Stage-1. Weep...
  405. */
  406. tlbi ipas2e1is, x1
  407. dsb sy
  408. tlbi vmalle1is
  409. dsb sy
  410. isb
  411. msr vttbr_el2, xzr
  412. ret
  413. ENDPROC(__kvm_tlb_flush_vmid_ipa)
  414. ENTRY(__kvm_flush_vm_context)
  415. tlbi alle1is
  416. ic ialluis
  417. dsb sy
  418. ret
  419. ENDPROC(__kvm_flush_vm_context)
  420. __kvm_hyp_panic:
  421. // Guess the context by looking at VTTBR:
  422. // If zero, then we're already a host.
  423. // Otherwise restore a minimal host context before panicing.
  424. mrs x0, vttbr_el2
  425. cbz x0, 1f
  426. mrs x0, tpidr_el2
  427. deactivate_traps
  428. deactivate_vm
  429. ldr x2, [x0, #VCPU_HOST_CONTEXT]
  430. kern_hyp_va x2
  431. bl __restore_sysregs
  432. 1: adr x0, __hyp_panic_str
  433. adr x1, 2f
  434. ldp x2, x3, [x1]
  435. sub x0, x0, x2
  436. add x0, x0, x3
  437. mrs x1, spsr_el2
  438. mrs x2, elr_el2
  439. mrs x3, esr_el2
  440. mrs x4, far_el2
  441. mrs x5, hpfar_el2
  442. mrs x6, par_el1
  443. mrs x7, tpidr_el2
  444. mov lr, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\
  445. PSR_MODE_EL1h)
  446. msr spsr_el2, lr
  447. ldr lr, =panic
  448. msr elr_el2, lr
  449. eret
  450. .align 3
  451. 2: .quad HYP_PAGE_OFFSET
  452. .quad PAGE_OFFSET
  453. ENDPROC(__kvm_hyp_panic)
  454. __hyp_panic_str:
  455. .ascii "HYP panic:\nPS:%08x PC:%p ESR:%p\nFAR:%p HPFAR:%p PAR:%p\nVCPU:%p\n\0"
  456. .align 2
  457. ENTRY(kvm_call_hyp)
  458. hvc #0
  459. ret
  460. ENDPROC(kvm_call_hyp)
  461. .macro invalid_vector label, target
  462. .align 2
  463. \label:
  464. b \target
  465. ENDPROC(\label)
  466. .endm
  467. /* None of these should ever happen */
  468. invalid_vector el2t_sync_invalid, __kvm_hyp_panic
  469. invalid_vector el2t_irq_invalid, __kvm_hyp_panic
  470. invalid_vector el2t_fiq_invalid, __kvm_hyp_panic
  471. invalid_vector el2t_error_invalid, __kvm_hyp_panic
  472. invalid_vector el2h_sync_invalid, __kvm_hyp_panic
  473. invalid_vector el2h_irq_invalid, __kvm_hyp_panic
  474. invalid_vector el2h_fiq_invalid, __kvm_hyp_panic
  475. invalid_vector el2h_error_invalid, __kvm_hyp_panic
  476. invalid_vector el1_sync_invalid, __kvm_hyp_panic
  477. invalid_vector el1_irq_invalid, __kvm_hyp_panic
  478. invalid_vector el1_fiq_invalid, __kvm_hyp_panic
  479. invalid_vector el1_error_invalid, __kvm_hyp_panic
  480. el1_sync: // Guest trapped into EL2
  481. push x0, x1
  482. push x2, x3
  483. mrs x1, esr_el2
  484. lsr x2, x1, #ESR_EL2_EC_SHIFT
  485. cmp x2, #ESR_EL2_EC_HVC64
  486. b.ne el1_trap
  487. mrs x3, vttbr_el2 // If vttbr is valid, the 64bit guest
  488. cbnz x3, el1_trap // called HVC
  489. /* Here, we're pretty sure the host called HVC. */
  490. pop x2, x3
  491. pop x0, x1
  492. push lr, xzr
  493. /*
  494. * Compute the function address in EL2, and shuffle the parameters.
  495. */
  496. kern_hyp_va x0
  497. mov lr, x0
  498. mov x0, x1
  499. mov x1, x2
  500. mov x2, x3
  501. blr lr
  502. pop lr, xzr
  503. eret
  504. el1_trap:
  505. /*
  506. * x1: ESR
  507. * x2: ESR_EC
  508. */
  509. cmp x2, #ESR_EL2_EC_DABT
  510. mov x0, #ESR_EL2_EC_IABT
  511. ccmp x2, x0, #4, ne
  512. b.ne 1f // Not an abort we care about
  513. /* This is an abort. Check for permission fault */
  514. and x2, x1, #ESR_EL2_FSC_TYPE
  515. cmp x2, #FSC_PERM
  516. b.ne 1f // Not a permission fault
  517. /*
  518. * Check for Stage-1 page table walk, which is guaranteed
  519. * to give a valid HPFAR_EL2.
  520. */
  521. tbnz x1, #7, 1f // S1PTW is set
  522. /*
  523. * Permission fault, HPFAR_EL2 is invalid.
  524. * Resolve the IPA the hard way using the guest VA.
  525. * Stage-1 translation already validated the memory access rights.
  526. * As such, we can use the EL1 translation regime, and don't have
  527. * to distinguish between EL0 and EL1 access.
  528. */
  529. mrs x2, far_el2
  530. at s1e1r, x2
  531. isb
  532. /* Read result */
  533. mrs x3, par_el1
  534. tbnz x3, #0, 3f // Bail out if we failed the translation
  535. ubfx x3, x3, #12, #36 // Extract IPA
  536. lsl x3, x3, #4 // and present it like HPFAR
  537. b 2f
  538. 1: mrs x3, hpfar_el2
  539. mrs x2, far_el2
  540. 2: mrs x0, tpidr_el2
  541. str x1, [x0, #VCPU_ESR_EL2]
  542. str x2, [x0, #VCPU_FAR_EL2]
  543. str x3, [x0, #VCPU_HPFAR_EL2]
  544. mov x1, #ARM_EXCEPTION_TRAP
  545. b __kvm_vcpu_return
  546. /*
  547. * Translation failed. Just return to the guest and
  548. * let it fault again. Another CPU is probably playing
  549. * behind our back.
  550. */
  551. 3: pop x2, x3
  552. pop x0, x1
  553. eret
  554. el1_irq:
  555. push x0, x1
  556. push x2, x3
  557. mrs x0, tpidr_el2
  558. mov x1, #ARM_EXCEPTION_IRQ
  559. b __kvm_vcpu_return
  560. .ltorg
  561. .align 11
  562. ENTRY(__kvm_hyp_vector)
  563. ventry el2t_sync_invalid // Synchronous EL2t
  564. ventry el2t_irq_invalid // IRQ EL2t
  565. ventry el2t_fiq_invalid // FIQ EL2t
  566. ventry el2t_error_invalid // Error EL2t
  567. ventry el2h_sync_invalid // Synchronous EL2h
  568. ventry el2h_irq_invalid // IRQ EL2h
  569. ventry el2h_fiq_invalid // FIQ EL2h
  570. ventry el2h_error_invalid // Error EL2h
  571. ventry el1_sync // Synchronous 64-bit EL1
  572. ventry el1_irq // IRQ 64-bit EL1
  573. ventry el1_fiq_invalid // FIQ 64-bit EL1
  574. ventry el1_error_invalid // Error 64-bit EL1
  575. ventry el1_sync // Synchronous 32-bit EL1
  576. ventry el1_irq // IRQ 32-bit EL1
  577. ventry el1_fiq_invalid // FIQ 32-bit EL1
  578. ventry el1_error_invalid // Error 32-bit EL1
  579. ENDPROC(__kvm_hyp_vector)
  580. __kvm_hyp_code_end:
  581. .globl __kvm_hyp_code_end
  582. .popsection