Skip to content

Commit 6f7056c

Browse files
James MorseAlex Shi
authored andcommitted
arm64: hyp/kvm: Make hyp-stub reject kvm_call_hyp()
A later patch implements kvm_arch_hardware_disable(), to remove kvm from el2, and re-instate the hyp-stub. This can happen while guests are running, particularly when kvm_reboot() calls kvm_arch_hardware_disable() on each cpu. This can interrupt a guest, remove kvm, then allow the guest to be scheduled again. This causes kvm_call_hyp() to be run against the hyp-stub. Change the hyp-stub to return a new exception type when this happens, and add code to kvm's handle_exit() to tell userspace we failed to enter the guest. Signed-off-by: James Morse <james.morse@arm.com> Acked-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com> (cherry picked from commit c94b0cf28281d483c8b43b4874fcb7ab14ade1b1) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent 1520ad1 commit 6f7056c

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

arch/arm64/include/asm/kvm_asm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#define ARM_EXCEPTION_IRQ 0
2424
#define ARM_EXCEPTION_TRAP 1
25+
/* The hyp-stub will return this for any kvm_call_hyp() call */
26+
#define ARM_EXCEPTION_HYP_GONE 2
2527

2628
#define KVM_ARM64_DEBUG_DIRTY_SHIFT 0
2729
#define KVM_ARM64_DEBUG_DIRTY (1 << KVM_ARM64_DEBUG_DIRTY_SHIFT)

arch/arm64/kernel/hyp-stub.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <asm/assembler.h>
2525
#include <asm/kvm_arm.h>
26+
#include <asm/kvm_asm.h>
2627
#include <asm/ptrace.h>
2728
#include <asm/virt.h>
2829

@@ -70,8 +71,8 @@ el1_sync:
7071
msr vbar_el2, x1
7172
b 9f
7273

73-
/* Unrecognised call type */
74-
2: mov x0, xzr
74+
/* Someone called kvm_call_hyp() against the hyp-stub... */
75+
2: mov x0, #ARM_EXCEPTION_HYP_GONE
7576

7677
9: eret
7778
ENDPROC(el1_sync)

arch/arm64/kvm/handle_exit.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
183183
exit_handler = kvm_get_exit_handler(vcpu);
184184

185185
return exit_handler(vcpu, run);
186+
case ARM_EXCEPTION_HYP_GONE:
187+
/*
188+
* EL2 has been reset to the hyp-stub. This happens when a guest
189+
* is pre-empted by kvm_reboot()'s shutdown call.
190+
*/
191+
run->exit_reason = KVM_EXIT_FAIL_ENTRY;
192+
return 0;
186193
default:
187194
kvm_pr_unimpl("Unsupported exception type: %d",
188195
exception_index);

0 commit comments

Comments
 (0)