Skip to content

Commit b81125c

Browse files
author
Marc Zyngier
committed
arm64: KVM: VHE: Patch out use of HVC
With VHE, the host never issues an HVC instruction to get into the KVM code, as we can simply branch there. Use runtime code patching to simplify things a bit. Reviewed-by: Christoffer Dall <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 1e947ba commit b81125c

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

arch/arm64/kvm/hyp.S

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
#include <linux/linkage.h>
1919

20+
#include <asm/alternative.h>
2021
#include <asm/assembler.h>
22+
#include <asm/cpufeature.h>
2123

2224
/*
2325
* u64 kvm_call_hyp(void *hypfn, ...);
@@ -38,6 +40,11 @@
3840
* arch/arm64/kernel/hyp_stub.S.
3941
*/
4042
ENTRY(kvm_call_hyp)
43+
alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
4144
hvc #0
4245
ret
46+
alternative_else
47+
b __vhe_hyp_call
48+
nop
49+
alternative_endif
4350
ENDPROC(kvm_call_hyp)

arch/arm64/kvm/hyp/hyp-entry.S

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@
3838
ldp x0, x1, [sp], #16
3939
.endm
4040

41+
.macro do_el2_call
42+
/*
43+
* Shuffle the parameters before calling the function
44+
* pointed to in x0. Assumes parameters in x[1,2,3].
45+
*/
46+
sub sp, sp, #16
47+
str lr, [sp]
48+
mov lr, x0
49+
mov x0, x1
50+
mov x1, x2
51+
mov x2, x3
52+
blr lr
53+
ldr lr, [sp]
54+
add sp, sp, #16
55+
.endm
56+
57+
ENTRY(__vhe_hyp_call)
58+
do_el2_call
59+
/*
60+
* We used to rely on having an exception return to get
61+
* an implicit isb. In the E2H case, we don't have it anymore.
62+
* rather than changing all the leaf functions, just do it here
63+
* before returning to the rest of the kernel.
64+
*/
65+
isb
66+
ret
67+
ENDPROC(__vhe_hyp_call)
68+
4169
el1_sync: // Guest trapped into EL2
4270
save_x0_to_x3
4371

@@ -58,19 +86,13 @@ el1_sync: // Guest trapped into EL2
5886
mrs x0, vbar_el2
5987
b 2f
6088

61-
1: stp lr, xzr, [sp, #-16]!
62-
89+
1:
6390
/*
64-
* Compute the function address in EL2, and shuffle the parameters.
91+
* Perform the EL2 call
6592
*/
6693
kern_hyp_va x0
67-
mov lr, x0
68-
mov x0, x1
69-
mov x1, x2
70-
mov x2, x3
71-
blr lr
94+
do_el2_call
7295

73-
ldp lr, xzr, [sp], #16
7496
2: eret
7597

7698
el1_trap:

0 commit comments

Comments
 (0)