Skip to content

Commit c94b0cf

Browse files
James Morsewildea01
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>
1 parent ad72e59 commit c94b0cf

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

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
@@ -186,6 +186,13 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
186186
exit_handler = kvm_get_exit_handler(vcpu);
187187

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

0 commit comments

Comments
 (0)