1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2020 - Google Inc
4 * Author: Andrew Scull <ascull@google.com>
7 #include <linux/linkage.h>
9 #include <asm/assembler.h>
10 #include <asm/kvm_asm.h>
11 #include <asm/kvm_mmu.h>
15 SYM_FUNC_START(__host_exit)
16 stp x0, x1, [sp, #-16]!
20 /* Store the host regs x2 and x3 */
21 stp x2, x3, [x0, #CPU_XREG_OFFSET(2)]
23 /* Retrieve the host regs x0-x1 from the stack */
24 ldp x2, x3, [sp], #16 // x0, x1
26 /* Store the host regs x0-x1 and x4-x17 */
27 stp x2, x3, [x0, #CPU_XREG_OFFSET(0)]
28 stp x4, x5, [x0, #CPU_XREG_OFFSET(4)]
29 stp x6, x7, [x0, #CPU_XREG_OFFSET(6)]
30 stp x8, x9, [x0, #CPU_XREG_OFFSET(8)]
31 stp x10, x11, [x0, #CPU_XREG_OFFSET(10)]
32 stp x12, x13, [x0, #CPU_XREG_OFFSET(12)]
33 stp x14, x15, [x0, #CPU_XREG_OFFSET(14)]
34 stp x16, x17, [x0, #CPU_XREG_OFFSET(16)]
36 /* Store the host regs x18-x29, lr */
37 save_callee_saved_regs x0
39 /* Save the host context pointer in x29 across the function call */
43 /* Restore host regs x0-x17 */
44 ldp x0, x1, [x29, #CPU_XREG_OFFSET(0)]
45 ldp x2, x3, [x29, #CPU_XREG_OFFSET(2)]
46 ldp x4, x5, [x29, #CPU_XREG_OFFSET(4)]
47 ldp x6, x7, [x29, #CPU_XREG_OFFSET(6)]
49 /* x0-7 are use for panic arguments */
50 __host_enter_for_panic:
51 ldp x8, x9, [x29, #CPU_XREG_OFFSET(8)]
52 ldp x10, x11, [x29, #CPU_XREG_OFFSET(10)]
53 ldp x12, x13, [x29, #CPU_XREG_OFFSET(12)]
54 ldp x14, x15, [x29, #CPU_XREG_OFFSET(14)]
55 ldp x16, x17, [x29, #CPU_XREG_OFFSET(16)]
57 /* Restore host regs x18-x29, lr */
58 restore_callee_saved_regs x29
60 /* Do not touch any register after this! */
61 __host_enter_without_restoring:
64 SYM_FUNC_END(__host_exit)
67 * void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 par);
69 SYM_FUNC_START(__hyp_do_panic)
70 /* Load the format arguments into x1-7 */
78 /* Prepare and exit to the host's panic funciton. */
79 mov lr, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\
86 * Set the panic format string and enter the host, conditionally
87 * restoring the host context.
90 ldr x0, =__hyp_panic_string
91 b.eq __host_enter_without_restoring
92 b __host_enter_for_panic
93 SYM_FUNC_END(__hyp_do_panic)
95 .macro host_el1_sync_vect
98 stp x0, x1, [sp, #-16]!
100 lsr x0, x0, #ESR_ELx_EC_SHIFT
101 cmp x0, #ESR_ELx_EC_HVC64
102 ldp x0, x1, [sp], #16
105 /* Check for a stub HVC call */
106 cmp x0, #HVC_STUB_HCALL_NR
110 * Compute the idmap address of __kvm_handle_stub_hvc and
111 * jump there. Since we use kimage_voffset, do not use the
112 * HYP VA for __kvm_handle_stub_hvc, but the kernel VA instead
113 * (by loading it from the constant pool).
115 * Preserve x0-x4, which may contain stub parameters.
117 ldr x5, =__kvm_handle_stub_hvc
118 ldr_l x6, kimage_voffset
124 .if ((.L__vect_end\@ - .L__vect_start\@) > 0x80)
125 .error "host_el1_sync_vect larger than vector entry"
129 .macro invalid_host_el2_vect
131 /* If a guest is loaded, panic out of it. */
132 stp x0, x1, [sp, #-16]!
133 get_loaded_vcpu x0, x1
134 cbnz x0, __guest_exit_panic
138 * The panic may not be clean if the exception is taken before the host
139 * context has been saved by __host_exit or after the hyp context has
140 * been partially clobbered by __host_enter.
145 .macro invalid_host_el1_vect
147 mov x0, xzr /* restore_host = false */
155 * The host vector does not use an ESB instruction in order to avoid consuming
156 * SErrors that should only be consumed by the host. Guest entry is deferred by
157 * __guest_enter if there are any pending asynchronous exceptions so hyp will
158 * always return to the host without having consumerd host SErrors.
160 * CONFIG_KVM_INDIRECT_VECTORS is not applied to the host vectors because the
161 * host knows about the EL2 vectors already, and there is no point in hiding
165 SYM_CODE_START(__kvm_hyp_host_vector)
166 invalid_host_el2_vect // Synchronous EL2t
167 invalid_host_el2_vect // IRQ EL2t
168 invalid_host_el2_vect // FIQ EL2t
169 invalid_host_el2_vect // Error EL2t
171 invalid_host_el2_vect // Synchronous EL2h
172 invalid_host_el2_vect // IRQ EL2h
173 invalid_host_el2_vect // FIQ EL2h
174 invalid_host_el2_vect // Error EL2h
176 host_el1_sync_vect // Synchronous 64-bit EL1
177 invalid_host_el1_vect // IRQ 64-bit EL1
178 invalid_host_el1_vect // FIQ 64-bit EL1
179 invalid_host_el1_vect // Error 64-bit EL1
181 invalid_host_el1_vect // Synchronous 32-bit EL1
182 invalid_host_el1_vect // IRQ 32-bit EL1
183 invalid_host_el1_vect // FIQ 32-bit EL1
184 invalid_host_el1_vect // Error 32-bit EL1
185 SYM_CODE_END(__kvm_hyp_host_vector)