2019-06-03 08:44:50 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2015-10-25 11:01:56 +03:00
|
|
|
/*
|
2018-04-10 13:36:45 +03:00
|
|
|
* Copyright (C) 2015-2018 - ARM Ltd
|
2015-10-25 11:01:56 +03:00
|
|
|
* Author: Marc Zyngier <marc.zyngier@arm.com>
|
|
|
|
*/
|
|
|
|
|
2018-02-06 20:56:15 +03:00
|
|
|
#include <linux/arm-smccc.h>
|
2015-10-25 11:01:56 +03:00
|
|
|
#include <linux/linkage.h>
|
|
|
|
|
|
|
|
#include <asm/alternative.h>
|
|
|
|
#include <asm/assembler.h>
|
|
|
|
#include <asm/cpufeature.h>
|
|
|
|
#include <asm/kvm_arm.h>
|
|
|
|
#include <asm/kvm_asm.h>
|
|
|
|
#include <asm/kvm_mmu.h>
|
2018-04-10 13:36:45 +03:00
|
|
|
#include <asm/mmu.h>
|
2015-10-25 11:01:56 +03:00
|
|
|
|
|
|
|
.text
|
|
|
|
.pushsection .hyp.text, "ax"
|
|
|
|
|
2015-01-29 16:52:12 +03:00
|
|
|
.macro do_el2_call
|
|
|
|
/*
|
|
|
|
* Shuffle the parameters before calling the function
|
|
|
|
* pointed to in x0. Assumes parameters in x[1,2,3].
|
|
|
|
*/
|
2017-04-03 21:37:35 +03:00
|
|
|
str lr, [sp, #-16]!
|
2015-01-29 16:52:12 +03:00
|
|
|
mov lr, x0
|
|
|
|
mov x0, x1
|
|
|
|
mov x1, x2
|
|
|
|
mov x2, x3
|
|
|
|
blr lr
|
2017-04-03 21:37:35 +03:00
|
|
|
ldr lr, [sp], #16
|
2015-01-29 16:52:12 +03:00
|
|
|
.endm
|
|
|
|
|
2015-10-25 11:01:56 +03:00
|
|
|
el1_sync: // Guest trapped into EL2
|
|
|
|
|
2017-10-08 18:01:56 +03:00
|
|
|
mrs x0, esr_el2
|
|
|
|
lsr x0, x0, #ESR_ELx_EC_SHIFT
|
2016-08-31 05:08:32 +03:00
|
|
|
cmp x0, #ESR_ELx_EC_HVC64
|
2018-02-06 20:56:15 +03:00
|
|
|
ccmp x0, #ESR_ELx_EC_HVC32, #4, ne
|
2015-10-25 11:01:56 +03:00
|
|
|
b.ne el1_trap
|
|
|
|
|
2018-02-06 20:56:15 +03:00
|
|
|
mrs x1, vttbr_el2 // If vttbr is valid, the guest
|
|
|
|
cbnz x1, el1_hvc_guest // called HVC
|
2015-10-25 11:01:56 +03:00
|
|
|
|
|
|
|
/* Here, we're pretty sure the host called HVC. */
|
2016-08-31 05:08:32 +03:00
|
|
|
ldp x0, x1, [sp], #16
|
2015-10-25 11:01:56 +03:00
|
|
|
|
2017-04-03 21:37:42 +03:00
|
|
|
/* Check for a stub HVC call */
|
|
|
|
cmp x0, #HVC_STUB_HCALL_NR
|
|
|
|
b.hs 1f
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the idmap address of __kvm_handle_stub_hvc and
|
|
|
|
* jump there. Since we use kimage_voffset, do not use the
|
|
|
|
* HYP VA for __kvm_handle_stub_hvc, but the kernel VA instead
|
|
|
|
* (by loading it from the constant pool).
|
|
|
|
*
|
|
|
|
* Preserve x0-x4, which may contain stub parameters.
|
|
|
|
*/
|
|
|
|
ldr x5, =__kvm_handle_stub_hvc
|
|
|
|
ldr_l x6, kimage_voffset
|
|
|
|
|
|
|
|
/* x5 = __pa(x5) */
|
|
|
|
sub x5, x5, x6
|
|
|
|
br x5
|
2015-10-25 11:01:56 +03:00
|
|
|
|
2015-01-29 16:52:12 +03:00
|
|
|
1:
|
2015-10-25 11:01:56 +03:00
|
|
|
/*
|
2015-01-29 16:52:12 +03:00
|
|
|
* Perform the EL2 call
|
2015-10-25 11:01:56 +03:00
|
|
|
*/
|
|
|
|
kern_hyp_va x0
|
2015-01-29 16:52:12 +03:00
|
|
|
do_el2_call
|
2015-10-25 11:01:56 +03:00
|
|
|
|
2017-04-03 21:37:42 +03:00
|
|
|
eret
|
2018-06-14 13:23:38 +03:00
|
|
|
sb
|
2015-10-25 11:01:56 +03:00
|
|
|
|
2018-02-06 20:56:15 +03:00
|
|
|
el1_hvc_guest:
|
|
|
|
/*
|
|
|
|
* Fastest possible path for ARM_SMCCC_ARCH_WORKAROUND_1.
|
|
|
|
* The workaround has already been applied on the host,
|
|
|
|
* so let's quickly get back to the guest. We don't bother
|
|
|
|
* restoring x1, as it can be clobbered anyway.
|
|
|
|
*/
|
|
|
|
ldr x1, [sp] // Guest's x0
|
|
|
|
eor w1, w1, #ARM_SMCCC_ARCH_WORKAROUND_1
|
2018-05-29 15:11:17 +03:00
|
|
|
cbz w1, wa_epilogue
|
|
|
|
|
|
|
|
/* ARM_SMCCC_ARCH_WORKAROUND_2 handling */
|
|
|
|
eor w1, w1, #(ARM_SMCCC_ARCH_WORKAROUND_1 ^ \
|
|
|
|
ARM_SMCCC_ARCH_WORKAROUND_2)
|
2018-02-06 20:56:15 +03:00
|
|
|
cbnz w1, el1_trap
|
2018-05-29 15:11:17 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARM64_SSBD
|
|
|
|
alternative_cb arm64_enable_wa2_handling
|
|
|
|
b wa2_end
|
|
|
|
alternative_cb_end
|
|
|
|
get_vcpu_ptr x2, x0
|
|
|
|
ldr x0, [x2, #VCPU_WORKAROUND_FLAGS]
|
|
|
|
|
|
|
|
// Sanitize the argument and update the guest flags
|
|
|
|
ldr x1, [sp, #8] // Guest's x1
|
|
|
|
clz w1, w1 // Murphy's device:
|
|
|
|
lsr w1, w1, #5 // w1 = !!w1 without using
|
|
|
|
eor w1, w1, #1 // the flags...
|
|
|
|
bfi x0, x1, #VCPU_WORKAROUND_2_FLAG_SHIFT, #1
|
|
|
|
str x0, [x2, #VCPU_WORKAROUND_FLAGS]
|
|
|
|
|
|
|
|
/* Check that we actually need to perform the call */
|
|
|
|
hyp_ldr_this_cpu x0, arm64_ssbd_callback_required, x2
|
|
|
|
cbz x0, wa2_end
|
|
|
|
|
|
|
|
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_2
|
|
|
|
smc #0
|
|
|
|
|
|
|
|
/* Don't leak data from the SMC call */
|
|
|
|
mov x3, xzr
|
|
|
|
wa2_end:
|
|
|
|
mov x2, xzr
|
|
|
|
mov x1, xzr
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wa_epilogue:
|
|
|
|
mov x0, xzr
|
2018-02-06 20:56:15 +03:00
|
|
|
add sp, sp, #16
|
|
|
|
eret
|
2018-06-14 13:23:38 +03:00
|
|
|
sb
|
2018-02-06 20:56:15 +03:00
|
|
|
|
2015-10-25 11:01:56 +03:00
|
|
|
el1_trap:
|
2017-10-08 18:01:56 +03:00
|
|
|
get_vcpu_ptr x1, x0
|
2016-08-31 05:08:32 +03:00
|
|
|
mov x0, #ARM_EXCEPTION_TRAP
|
2015-10-25 11:01:56 +03:00
|
|
|
b __guest_exit
|
|
|
|
|
|
|
|
el1_irq:
|
2017-10-08 18:01:56 +03:00
|
|
|
get_vcpu_ptr x1, x0
|
2016-08-31 05:08:32 +03:00
|
|
|
mov x0, #ARM_EXCEPTION_IRQ
|
2015-10-25 11:01:56 +03:00
|
|
|
b __guest_exit
|
|
|
|
|
2016-09-06 16:02:04 +03:00
|
|
|
el1_error:
|
2017-10-08 18:01:56 +03:00
|
|
|
get_vcpu_ptr x1, x0
|
2016-09-06 16:02:04 +03:00
|
|
|
mov x0, #ARM_EXCEPTION_EL1_SERROR
|
|
|
|
b __guest_exit
|
|
|
|
|
2018-10-17 21:21:16 +03:00
|
|
|
el2_sync:
|
|
|
|
/* Check for illegal exception return, otherwise panic */
|
|
|
|
mrs x0, spsr_el2
|
|
|
|
|
|
|
|
/* if this was something else, then panic! */
|
|
|
|
tst x0, #PSR_IL_BIT
|
|
|
|
b.eq __hyp_panic
|
|
|
|
|
|
|
|
/* Let's attempt a recovery from the illegal exception return */
|
|
|
|
get_vcpu_ptr x1, x0
|
|
|
|
mov x0, #ARM_EXCEPTION_IL
|
|
|
|
b __guest_exit
|
|
|
|
|
|
|
|
|
2016-09-06 16:02:07 +03:00
|
|
|
el2_error:
|
2018-02-12 20:53:00 +03:00
|
|
|
ldp x0, x1, [sp], #16
|
|
|
|
|
2016-09-06 16:02:07 +03:00
|
|
|
/*
|
|
|
|
* Only two possibilities:
|
|
|
|
* 1) Either we come from the exit path, having just unmasked
|
|
|
|
* PSTATE.A: change the return code to an EL2 fault, and
|
|
|
|
* carry on, as we're already in a sane state to handle it.
|
|
|
|
* 2) Or we come from anywhere else, and that's a bug: we panic.
|
|
|
|
*
|
|
|
|
* For (1), x0 contains the original return code and x1 doesn't
|
|
|
|
* contain anything meaningful at that stage. We can reuse them
|
|
|
|
* as temp registers.
|
|
|
|
* For (2), who cares?
|
|
|
|
*/
|
|
|
|
mrs x0, elr_el2
|
|
|
|
adr x1, abort_guest_exit_start
|
|
|
|
cmp x0, x1
|
|
|
|
adr x1, abort_guest_exit_end
|
|
|
|
ccmp x0, x1, #4, ne
|
|
|
|
b.ne __hyp_panic
|
|
|
|
mov x0, #(1 << ARM_EXIT_WITH_SERROR_BIT)
|
|
|
|
eret
|
2018-06-14 13:23:38 +03:00
|
|
|
sb
|
2016-09-06 16:02:07 +03:00
|
|
|
|
2020-02-18 22:58:37 +03:00
|
|
|
SYM_FUNC_START(__hyp_do_panic)
|
2015-10-25 18:21:52 +03:00
|
|
|
mov lr, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\
|
|
|
|
PSR_MODE_EL1h)
|
|
|
|
msr spsr_el2, lr
|
|
|
|
ldr lr, =panic
|
|
|
|
msr elr_el2, lr
|
|
|
|
eret
|
2018-06-14 13:23:38 +03:00
|
|
|
sb
|
2020-02-18 22:58:37 +03:00
|
|
|
SYM_FUNC_END(__hyp_do_panic)
|
2015-10-25 18:21:52 +03:00
|
|
|
|
2020-02-18 22:58:37 +03:00
|
|
|
SYM_CODE_START(__hyp_panic)
|
2017-10-08 18:01:56 +03:00
|
|
|
get_host_ctxt x0, x1
|
2018-01-08 18:38:05 +03:00
|
|
|
b hyp_panic
|
2020-02-18 22:58:37 +03:00
|
|
|
SYM_CODE_END(__hyp_panic)
|
2018-01-08 18:38:05 +03:00
|
|
|
|
2015-10-25 18:21:52 +03:00
|
|
|
.macro invalid_vector label, target = __hyp_panic
|
2015-10-25 11:01:56 +03:00
|
|
|
.align 2
|
2020-02-18 22:58:37 +03:00
|
|
|
SYM_CODE_START(\label)
|
2015-10-25 11:01:56 +03:00
|
|
|
\label:
|
|
|
|
b \target
|
2020-02-18 22:58:37 +03:00
|
|
|
SYM_CODE_END(\label)
|
2015-10-25 11:01:56 +03:00
|
|
|
.endm
|
|
|
|
|
|
|
|
/* None of these should ever happen */
|
|
|
|
invalid_vector el2t_sync_invalid
|
|
|
|
invalid_vector el2t_irq_invalid
|
|
|
|
invalid_vector el2t_fiq_invalid
|
|
|
|
invalid_vector el2t_error_invalid
|
|
|
|
invalid_vector el2h_sync_invalid
|
|
|
|
invalid_vector el2h_irq_invalid
|
|
|
|
invalid_vector el2h_fiq_invalid
|
|
|
|
invalid_vector el1_fiq_invalid
|
|
|
|
|
|
|
|
.ltorg
|
|
|
|
|
|
|
|
.align 11
|
|
|
|
|
2019-06-18 18:17:34 +03:00
|
|
|
.macro check_preamble_length start, end
|
|
|
|
/* kvm_patch_vector_branch() generates code that jumps over the preamble. */
|
|
|
|
.if ((\end-\start) != KVM_VECTOR_PREAMBLE)
|
|
|
|
.error "KVM vector preamble length mismatch"
|
|
|
|
.endif
|
|
|
|
.endm
|
|
|
|
|
2018-02-12 20:53:00 +03:00
|
|
|
.macro valid_vect target
|
|
|
|
.align 7
|
2019-06-18 18:17:34 +03:00
|
|
|
661:
|
2019-06-18 18:17:36 +03:00
|
|
|
esb
|
2018-02-12 20:53:00 +03:00
|
|
|
stp x0, x1, [sp, #-16]!
|
2019-06-18 18:17:34 +03:00
|
|
|
662:
|
2018-02-12 20:53:00 +03:00
|
|
|
b \target
|
2019-06-18 18:17:34 +03:00
|
|
|
|
|
|
|
check_preamble_length 661b, 662b
|
2018-02-12 20:53:00 +03:00
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro invalid_vect target
|
|
|
|
.align 7
|
2019-06-18 18:17:34 +03:00
|
|
|
661:
|
2018-02-12 20:53:00 +03:00
|
|
|
b \target
|
2019-06-18 18:17:36 +03:00
|
|
|
nop
|
2019-06-18 18:17:34 +03:00
|
|
|
662:
|
2018-02-27 20:38:08 +03:00
|
|
|
ldp x0, x1, [sp], #16
|
|
|
|
b \target
|
2019-06-18 18:17:34 +03:00
|
|
|
|
|
|
|
check_preamble_length 661b, 662b
|
2018-02-12 20:53:00 +03:00
|
|
|
.endm
|
|
|
|
|
2020-02-18 22:58:37 +03:00
|
|
|
SYM_CODE_START(__kvm_hyp_vector)
|
2018-02-12 20:53:00 +03:00
|
|
|
invalid_vect el2t_sync_invalid // Synchronous EL2t
|
|
|
|
invalid_vect el2t_irq_invalid // IRQ EL2t
|
|
|
|
invalid_vect el2t_fiq_invalid // FIQ EL2t
|
|
|
|
invalid_vect el2t_error_invalid // Error EL2t
|
|
|
|
|
2018-10-17 21:21:16 +03:00
|
|
|
valid_vect el2_sync // Synchronous EL2h
|
2018-02-12 20:53:00 +03:00
|
|
|
invalid_vect el2h_irq_invalid // IRQ EL2h
|
|
|
|
invalid_vect el2h_fiq_invalid // FIQ EL2h
|
|
|
|
valid_vect el2_error // Error EL2h
|
|
|
|
|
|
|
|
valid_vect el1_sync // Synchronous 64-bit EL1
|
|
|
|
valid_vect el1_irq // IRQ 64-bit EL1
|
|
|
|
invalid_vect el1_fiq_invalid // FIQ 64-bit EL1
|
|
|
|
valid_vect el1_error // Error 64-bit EL1
|
|
|
|
|
|
|
|
valid_vect el1_sync // Synchronous 32-bit EL1
|
|
|
|
valid_vect el1_irq // IRQ 32-bit EL1
|
|
|
|
invalid_vect el1_fiq_invalid // FIQ 32-bit EL1
|
|
|
|
valid_vect el1_error // Error 32-bit EL1
|
2020-02-18 22:58:37 +03:00
|
|
|
SYM_CODE_END(__kvm_hyp_vector)
|
2018-04-10 13:36:45 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_KVM_INDIRECT_VECTORS
|
|
|
|
.macro hyp_ventry
|
|
|
|
.align 7
|
2019-06-18 18:17:36 +03:00
|
|
|
1: esb
|
|
|
|
.rept 26
|
2018-04-10 13:36:45 +03:00
|
|
|
nop
|
|
|
|
.endr
|
|
|
|
/*
|
|
|
|
* The default sequence is to directly branch to the KVM vectors,
|
|
|
|
* using the computed offset. This applies for VHE as well as
|
2019-06-18 18:17:35 +03:00
|
|
|
* !ARM64_HARDEN_EL2_VECTORS. The first vector must always run the preamble.
|
2018-04-10 13:36:45 +03:00
|
|
|
*
|
|
|
|
* For ARM64_HARDEN_EL2_VECTORS configurations, this gets replaced
|
|
|
|
* with:
|
|
|
|
*
|
|
|
|
* stp x0, x1, [sp, #-16]!
|
|
|
|
* movz x0, #(addr & 0xffff)
|
|
|
|
* movk x0, #((addr >> 16) & 0xffff), lsl #16
|
|
|
|
* movk x0, #((addr >> 32) & 0xffff), lsl #32
|
|
|
|
* br x0
|
|
|
|
*
|
2019-06-18 18:17:34 +03:00
|
|
|
* Where:
|
|
|
|
* addr = kern_hyp_va(__kvm_hyp_vector) + vector-offset + KVM_VECTOR_PREAMBLE.
|
2018-04-10 13:36:45 +03:00
|
|
|
* See kvm_patch_vector_branch for details.
|
|
|
|
*/
|
|
|
|
alternative_cb kvm_patch_vector_branch
|
2019-06-18 18:17:35 +03:00
|
|
|
stp x0, x1, [sp, #-16]!
|
|
|
|
b __kvm_hyp_vector + (1b - 0b + KVM_VECTOR_PREAMBLE)
|
2018-04-10 13:36:45 +03:00
|
|
|
nop
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
alternative_cb_end
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro generate_vectors
|
|
|
|
0:
|
|
|
|
.rept 16
|
|
|
|
hyp_ventry
|
|
|
|
.endr
|
|
|
|
.org 0b + SZ_2K // Safety measure
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.align 11
|
2020-02-18 22:58:38 +03:00
|
|
|
SYM_CODE_START(__bp_harden_hyp_vecs)
|
2018-04-10 13:36:45 +03:00
|
|
|
.rept BP_HARDEN_EL2_SLOTS
|
|
|
|
generate_vectors
|
|
|
|
.endr
|
2020-02-18 22:58:38 +03:00
|
|
|
1: .org __bp_harden_hyp_vecs + __BP_HARDEN_HYP_VECS_SZ
|
|
|
|
.org 1b
|
|
|
|
SYM_CODE_END(__bp_harden_hyp_vecs)
|
2018-04-10 13:36:45 +03:00
|
|
|
|
|
|
|
.popsection
|
|
|
|
|
2020-02-18 22:58:39 +03:00
|
|
|
SYM_CODE_START(__smccc_workaround_1_smc)
|
2019-06-18 18:17:36 +03:00
|
|
|
esb
|
2018-04-10 13:36:45 +03:00
|
|
|
sub sp, sp, #(8 * 4)
|
|
|
|
stp x2, x3, [sp, #(8 * 0)]
|
|
|
|
stp x0, x1, [sp, #(8 * 2)]
|
|
|
|
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_1
|
|
|
|
smc #0
|
|
|
|
ldp x2, x3, [sp, #(8 * 0)]
|
|
|
|
ldp x0, x1, [sp, #(8 * 2)]
|
|
|
|
add sp, sp, #(8 * 4)
|
2020-02-18 22:58:39 +03:00
|
|
|
1: .org __smccc_workaround_1_smc + __SMCCC_WORKAROUND_1_SMC_SZ
|
|
|
|
.org 1b
|
|
|
|
SYM_CODE_END(__smccc_workaround_1_smc)
|
2018-04-10 13:36:45 +03:00
|
|
|
#endif
|