Commit ad72e59f authored by Geoff Levand's avatar Geoff Levand Committed by Will Deacon

arm64: hyp/kvm: Make hyp-stub extensible

The existing arm64 hcall implementations are limited in that they only
allow for two distinct hcalls; with the x0 register either zero or not
zero.  Also, the API of the hyp-stub exception vector routines and the
KVM exception vector routines differ; hyp-stub uses a non-zero value in
x0 to implement __hyp_set_vectors, whereas KVM uses it to implement
kvm_call_hyp.

To allow for additional hcalls to be defined and to make the arm64 hcall
API more consistent across exception vector routines, change the hcall
implementations to reserve all x0 values below 0xfff for hcalls such
as {s,g}et_vectors().

Define two new preprocessor macros HVC_GET_VECTORS, and HVC_SET_VECTORS
to be used as hcall type specifiers and convert the existing
__hyp_get_vectors() and __hyp_set_vectors() routines to use these new
macros when executing an HVC call.  Also, change the corresponding
hyp-stub and KVM el1_sync exception vector routines to use these new
macros.
Signed-off-by: default avatarGeoff Levand <geoff@infradead.org>
[Merged two hcall patches, moved immediate value from esr to x0, use lr
 as a scratch register, changed limit to 0xfff]
Signed-off-by: default avatarJames Morse <james.morse@arm.com>
Acked-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent 00a44cda
...@@ -18,6 +18,22 @@ ...@@ -18,6 +18,22 @@
#ifndef __ASM__VIRT_H #ifndef __ASM__VIRT_H
#define __ASM__VIRT_H #define __ASM__VIRT_H
/*
* The arm64 hcall implementation uses x0 to specify the hcall type. A value
* less than 0xfff indicates a special hcall, such as get/set vector.
* Any other value is used as a pointer to the function to call.
*/
/* HVC_GET_VECTORS - Return the value of the vbar_el2 register. */
#define HVC_GET_VECTORS 0
/*
* HVC_SET_VECTORS - Set the value of the vbar_el2 register.
*
* @x1: Physical address of the new vector table.
*/
#define HVC_SET_VECTORS 1
#define BOOT_CPU_MODE_EL1 (0xe11) #define BOOT_CPU_MODE_EL1 (0xe11)
#define BOOT_CPU_MODE_EL2 (0xe12) #define BOOT_CPU_MODE_EL2 (0xe12)
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/irqchip/arm-gic-v3.h> #include <linux/irqchip/arm-gic-v3.h>
#include <asm/assembler.h> #include <asm/assembler.h>
#include <asm/kvm_arm.h>
#include <asm/ptrace.h> #include <asm/ptrace.h>
#include <asm/virt.h> #include <asm/virt.h>
...@@ -53,15 +54,26 @@ ENDPROC(__hyp_stub_vectors) ...@@ -53,15 +54,26 @@ ENDPROC(__hyp_stub_vectors)
.align 11 .align 11
el1_sync: el1_sync:
mrs x1, esr_el2 mrs x30, esr_el2
lsr x1, x1, #26 lsr x30, x30, #ESR_ELx_EC_SHIFT
cmp x1, #0x16
b.ne 2f // Not an HVC trap cmp x30, #ESR_ELx_EC_HVC64
cbz x0, 1f b.ne 9f // Not an HVC trap
msr vbar_el2, x0 // Set vbar_el2
b 2f cmp x0, #HVC_GET_VECTORS
1: mrs x0, vbar_el2 // Return vbar_el2 b.ne 1f
2: eret mrs x0, vbar_el2
b 9f
1: cmp x0, #HVC_SET_VECTORS
b.ne 2f
msr vbar_el2, x1
b 9f
/* Unrecognised call type */
2: mov x0, xzr
9: eret
ENDPROC(el1_sync) ENDPROC(el1_sync)
.macro invalid_vector label .macro invalid_vector label
...@@ -102,7 +114,7 @@ ENDPROC(\label) ...@@ -102,7 +114,7 @@ ENDPROC(\label)
ENTRY(__hyp_get_vectors) ENTRY(__hyp_get_vectors)
str lr, [sp, #-16]! str lr, [sp, #-16]!
mov x0, xzr mov x0, #HVC_GET_VECTORS
hvc #0 hvc #0
ldr lr, [sp], #16 ldr lr, [sp], #16
ret ret
...@@ -110,6 +122,8 @@ ENDPROC(__hyp_get_vectors) ...@@ -110,6 +122,8 @@ ENDPROC(__hyp_get_vectors)
ENTRY(__hyp_set_vectors) ENTRY(__hyp_set_vectors)
str lr, [sp, #-16]! str lr, [sp, #-16]!
mov x1, x0
mov x0, #HVC_SET_VECTORS
hvc #0 hvc #0
ldr lr, [sp], #16 ldr lr, [sp], #16
ret ret
......
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
* in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are
* passed in x0. * passed in x0.
* *
* A function pointer with a value of 0 has a special meaning, and is * A function pointer with a value less than 0xfff has a special meaning,
* used to implement __hyp_get_vectors in the same way as in * and is used to implement __hyp_get_vectors in the same way as in
* arch/arm64/kernel/hyp_stub.S. * arch/arm64/kernel/hyp_stub.S.
* HVC behaves as a 'bl' call and will clobber lr. * HVC behaves as a 'bl' call and will clobber lr.
*/ */
......
...@@ -82,8 +82,8 @@ alternative_endif ...@@ -82,8 +82,8 @@ alternative_endif
/* Here, we're pretty sure the host called HVC. */ /* Here, we're pretty sure the host called HVC. */
restore_x0_to_x3 restore_x0_to_x3
/* Check for __hyp_get_vectors */ cmp x0, #HVC_GET_VECTORS
cbnz x0, 1f b.ne 1f
mrs x0, vbar_el2 mrs x0, vbar_el2
b 2f b 2f
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment