linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: james.morse@arm.com (James Morse)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v9 05/14] arm64: hyp/kvm: Make hyp-stub reject kvm_call_hyp()
Date: Wed, 27 Apr 2016 17:47:04 +0100	[thread overview]
Message-ID: <1461775633-29715-6-git-send-email-james.morse@arm.com> (raw)
In-Reply-To: <1461775633-29715-1-git-send-email-james.morse@arm.com>

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>
---
Changes since v8:
 * This patch broken out from 'arm64: kvm: allows cpu hotplug'

 arch/arm64/include/asm/kvm_asm.h | 2 ++
 arch/arm64/kernel/hyp-stub.S     | 5 +++--
 arch/arm64/kvm/handle_exit.c     | 7 +++++++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index eb7490d232a0..dbfbc5fb5d35 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -22,6 +22,8 @@
 
 #define ARM_EXCEPTION_IRQ	  0
 #define ARM_EXCEPTION_TRAP	  1
+/* The hyp-stub will return this for any kvm_call_hyp() call */
+#define ARM_EXCEPTION_HYP_GONE	  2
 
 #define KVM_ARM64_DEBUG_DIRTY_SHIFT	0
 #define KVM_ARM64_DEBUG_DIRTY		(1 << KVM_ARM64_DEBUG_DIRTY_SHIFT)
diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S
index 894fb40fb378..8727f4490772 100644
--- a/arch/arm64/kernel/hyp-stub.S
+++ b/arch/arm64/kernel/hyp-stub.S
@@ -23,6 +23,7 @@
 
 #include <asm/assembler.h>
 #include <asm/kvm_arm.h>
+#include <asm/kvm_asm.h>
 #include <asm/ptrace.h>
 #include <asm/virt.h>
 
@@ -70,8 +71,8 @@ el1_sync:
 	msr	vbar_el2, x1
 	b	9f
 
-	/* Unrecognised call type */
-2:	mov     x0, xzr
+	/* Someone called kvm_call_hyp() against the hyp-stub... */
+2:	mov     x0, #ARM_EXCEPTION_HYP_GONE
 
 9:	eret
 ENDPROC(el1_sync)
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index eba89e42f0ed..3246c4aba5b1 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -186,6 +186,13 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		exit_handler = kvm_get_exit_handler(vcpu);
 
 		return exit_handler(vcpu, run);
+	case ARM_EXCEPTION_HYP_GONE:
+		/*
+		 * EL2 has been reset to the hyp-stub. This happens when a guest
+		 * is pre-empted by kvm_reboot()'s shutdown call.
+		 */
+		run->exit_reason = KVM_EXIT_FAIL_ENTRY;
+		return 0;
 	default:
 		kvm_pr_unimpl("Unsupported exception type: %d",
 			      exception_index);
-- 
2.8.0.rc3

  parent reply	other threads:[~2016-04-27 16:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-27 16:46 [PATCH v9 00/14] arm64: kernel: Add support for hibernate/suspend-to-disk James Morse
2016-04-27 16:47 ` [PATCH v9 01/14] arm64: Fold proc-macros.S into assembler.h James Morse
2016-04-27 16:47 ` [PATCH v9 02/14] arm64: Cleanup SCTLR flags James Morse
2016-04-27 16:47 ` [PATCH v9 03/14] arm64: kvm: Move lr save/restore from do_el2_call into EL1 James Morse
2016-04-27 16:47 ` [PATCH v9 04/14] arm64: hyp/kvm: Make hyp-stub extensible James Morse
2016-04-27 16:47 ` James Morse [this message]
2016-04-27 16:47 ` [PATCH v9 06/14] arm64: kvm: allows kvm cpu hotplug James Morse
2016-04-27 16:47 ` [PATCH v9 07/14] arm64: kernel: Rework finisher callback out of __cpu_suspend_enter() James Morse
2016-04-27 16:47 ` [PATCH v9 08/14] arm64: Change cpu_resume() to enable mmu early then access sleep_sp by va James Morse
2016-04-27 16:47 ` [PATCH v9 09/14] arm64: kernel: Include _AC definition in page.h James Morse
2016-04-27 16:47 ` [PATCH v9 10/14] arm64: Promote KERNEL_START/KERNEL_END definitions to a header file James Morse
2016-04-27 16:47 ` [PATCH v9 11/14] arm64: Add new asm macro copy_page James Morse
2016-04-27 16:47 ` [PATCH v9 12/14] PM / Hibernate: Call flush_icache_range() on pages restored in-place James Morse
2016-04-28 12:15   ` Will Deacon
2016-04-28 12:23     ` James Morse
2016-04-28 12:27       ` Will Deacon
2016-04-27 16:47 ` [PATCH v9 13/14] arm64: kernel: Add support for hibernate/suspend-to-disk James Morse
2016-04-28  9:26   ` Catalin Marinas
2016-04-27 16:47 ` [PATCH v9 14/14] arm64: hibernate: Refuse to hibernate if the boot cpu is offline James Morse
2016-04-28 12:40 ` [PATCH v9 00/14] arm64: kernel: Add support for hibernate/suspend-to-disk Will Deacon
2016-04-28 17:31   ` James Morse
2016-04-28 18:37     ` Will Deacon
2016-04-29 17:27 ` [PATCH] arm64: kvm: Fix kvm teardown for systems using the extended idmap James Morse
2016-05-02 12:05   ` Marc Zyngier
2016-05-03  8:36     ` Christoffer Dall
2016-05-03  8:41       ` Marc Zyngier
2016-05-03  8:57         ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461775633-29715-6-git-send-email-james.morse@arm.com \
    --to=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).