2 * Copyright (C) 2015 - ARM Ltd
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
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.
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.
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/>.
18 #include <linux/linkage.h>
20 #include <asm/alternative.h>
21 #include <asm/assembler.h>
22 #include <asm/asm-offsets.h>
23 #include <asm/cpufeature.h>
24 #include <asm/kvm_arm.h>
25 #include <asm/kvm_asm.h>
26 #include <asm/kvm_mmu.h>
29 .pushsection .hyp.text, "ax"
32 stp x0, x1, [sp, #-16]!
33 stp x2, x3, [sp, #-16]!
36 .macro restore_x0_to_x3
41 el1_sync: // Guest trapped into EL2
45 lsr x2, x1, #ESR_ELx_EC_SHIFT
47 cmp x2, #ESR_ELx_EC_HVC64
50 mrs x3, vttbr_el2 // If vttbr is valid, the 64bit guest
51 cbnz x3, el1_trap // called HVC
53 /* Here, we're pretty sure the host called HVC. */
56 /* Check for __hyp_get_vectors */
61 1: stp lr, xzr, [sp, #-16]!
64 * Compute the function address in EL2, and shuffle the parameters.
73 ldp lr, xzr, [sp], #16
82 /* Guest accessed VFP/SIMD registers, save host, restore Guest */
83 cmp x2, #ESR_ELx_EC_FP_ASIMD
84 b.eq __fpsimd_guest_restore
86 cmp x2, #ESR_ELx_EC_DABT_LOW
87 mov x0, #ESR_ELx_EC_IABT_LOW
89 b.ne 1f // Not an abort we care about
91 /* This is an abort. Check for permission fault */
92 alternative_if_not ARM64_WORKAROUND_834220
93 and x2, x1, #ESR_ELx_FSC_TYPE
95 b.ne 1f // Not a permission fault
97 nop // Use the permission fault path to
98 nop // check for a valid S1 translation,
99 nop // regardless of the ESR value.
103 * Check for Stage-1 page table walk, which is guaranteed
104 * to give a valid HPFAR_EL2.
106 tbnz x1, #7, 1f // S1PTW is set
108 /* Preserve PAR_EL1 */
110 stp x3, xzr, [sp, #-16]!
113 * Permission fault, HPFAR_EL2 is invalid.
114 * Resolve the IPA the hard way using the guest VA.
115 * Stage-1 translation already validated the memory access rights.
116 * As such, we can use the EL1 translation regime, and don't have
117 * to distinguish between EL0 and EL1 access.
125 ldp x0, xzr, [sp], #16 // Restore PAR_EL1 from the stack
127 tbnz x3, #0, 3f // Bail out if we failed the translation
128 ubfx x3, x3, #12, #36 // Extract IPA
129 lsl x3, x3, #4 // and present it like HPFAR
136 str w1, [x0, #VCPU_ESR_EL2]
137 str x2, [x0, #VCPU_FAR_EL2]
138 str x3, [x0, #VCPU_HPFAR_EL2]
140 mov x1, #ARM_EXCEPTION_TRAP
144 * Translation failed. Just return to the guest and
145 * let it fault again. Another CPU is probably playing
155 mov x1, #ARM_EXCEPTION_IRQ
158 ENTRY(__hyp_do_panic)
159 mov lr, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\
165 ENDPROC(__hyp_do_panic)
167 .macro invalid_vector label, target = __hyp_panic
174 /* None of these should ever happen */
175 invalid_vector el2t_sync_invalid
176 invalid_vector el2t_irq_invalid
177 invalid_vector el2t_fiq_invalid
178 invalid_vector el2t_error_invalid
179 invalid_vector el2h_sync_invalid
180 invalid_vector el2h_irq_invalid
181 invalid_vector el2h_fiq_invalid
182 invalid_vector el2h_error_invalid
183 invalid_vector el1_sync_invalid
184 invalid_vector el1_irq_invalid
185 invalid_vector el1_fiq_invalid
186 invalid_vector el1_error_invalid
192 ENTRY(__kvm_hyp_vector)
193 ventry el2t_sync_invalid // Synchronous EL2t
194 ventry el2t_irq_invalid // IRQ EL2t
195 ventry el2t_fiq_invalid // FIQ EL2t
196 ventry el2t_error_invalid // Error EL2t
198 ventry el2h_sync_invalid // Synchronous EL2h
199 ventry el2h_irq_invalid // IRQ EL2h
200 ventry el2h_fiq_invalid // FIQ EL2h
201 ventry el2h_error_invalid // Error EL2h
203 ventry el1_sync // Synchronous 64-bit EL1
204 ventry el1_irq // IRQ 64-bit EL1
205 ventry el1_fiq_invalid // FIQ 64-bit EL1
206 ventry el1_error_invalid // Error 64-bit EL1
208 ventry el1_sync // Synchronous 32-bit EL1
209 ventry el1_irq // IRQ 32-bit EL1
210 ventry el1_fiq_invalid // FIQ 32-bit EL1
211 ventry el1_error_invalid // Error 32-bit EL1
212 ENDPROC(__kvm_hyp_vector)