linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: marc.zyngier@arm.com (Marc Zyngier)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 14/29] ARM: KVM: move kvm_condition_valid to emulate.c
Date: Tue,  5 Mar 2013 02:43:08 +0000	[thread overview]
Message-ID: <1362451403-23460-15-git-send-email-marc.zyngier@arm.com> (raw)
In-Reply-To: <1362451403-23460-1-git-send-email-marc.zyngier@arm.com>

This is really hardware emulation, and as such it better be with
its little friends.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 arch/arm/include/asm/kvm_emulate.h |  1 +
 arch/arm/kvm/arm.c                 | 45 --------------------------------------
 arch/arm/kvm/emulate.c             | 45 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/arch/arm/include/asm/kvm_emulate.h b/arch/arm/include/asm/kvm_emulate.h
index 2f5cc48..88c43df 100644
--- a/arch/arm/include/asm/kvm_emulate.h
+++ b/arch/arm/include/asm/kvm_emulate.h
@@ -28,6 +28,7 @@ unsigned long *vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num);
 unsigned long *vcpu_spsr(struct kvm_vcpu *vcpu);
 
 int kvm_handle_wfi(struct kvm_vcpu *vcpu, struct kvm_run *run);
+bool kvm_condition_valid(struct kvm_vcpu *vcpu);
 void kvm_skip_instr(struct kvm_vcpu *vcpu, bool is_wide_instr);
 void kvm_inject_undefined(struct kvm_vcpu *vcpu);
 void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 4e83d57..93aaba6 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -44,7 +44,6 @@
 #include <asm/kvm_emulate.h>
 #include <asm/kvm_coproc.h>
 #include <asm/kvm_psci.h>
-#include <asm/opcodes.h>
 
 #ifdef REQUIRES_VIRT
 __asm__(".arch_extension	virt");
@@ -546,50 +545,6 @@ static exit_handle_fn arm_exit_handlers[] = {
 };
 
 /*
- * A conditional instruction is allowed to trap, even though it
- * wouldn't be executed.  So let's re-implement the hardware, in
- * software!
- */
-static bool kvm_condition_valid(struct kvm_vcpu *vcpu)
-{
-	unsigned long cpsr, cond, insn;
-
-	/*
-	 * Exception Code 0 can only happen if we set HCR.TGE to 1, to
-	 * catch undefined instructions, and then we won't get past
-	 * the arm_exit_handlers test anyway.
-	 */
-	BUG_ON(!kvm_vcpu_trap_get_class(vcpu));
-
-	/* Top two bits non-zero?  Unconditional. */
-	if (kvm_vcpu_get_hsr(vcpu) >> 30)
-		return true;
-
-	cpsr = *vcpu_cpsr(vcpu);
-
-	/* Is condition field valid? */
-	if ((kvm_vcpu_get_hsr(vcpu) & HSR_CV) >> HSR_CV_SHIFT)
-		cond = (kvm_vcpu_get_hsr(vcpu) & HSR_COND) >> HSR_COND_SHIFT;
-	else {
-		/* This can happen in Thumb mode: examine IT state. */
-		unsigned long it;
-
-		it = ((cpsr >> 8) & 0xFC) | ((cpsr >> 25) & 0x3);
-
-		/* it == 0 => unconditional. */
-		if (it == 0)
-			return true;
-
-		/* The cond for this insn works out as the top 4 bits. */
-		cond = (it >> 4);
-	}
-
-	/* Shift makes it look like an ARM-mode instruction */
-	insn = cond << 28;
-	return arm_check_condition(insn, cpsr) != ARM_OPCODE_CONDTEST_FAIL;
-}
-
-/*
  * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on
  * proper exit to QEMU.
  */
diff --git a/arch/arm/kvm/emulate.c b/arch/arm/kvm/emulate.c
index d3094eb..04dbac6 100644
--- a/arch/arm/kvm/emulate.c
+++ b/arch/arm/kvm/emulate.c
@@ -20,6 +20,7 @@
 #include <linux/kvm_host.h>
 #include <asm/kvm_arm.h>
 #include <asm/kvm_emulate.h>
+#include <asm/opcodes.h>
 #include <trace/events/kvm.h>
 
 #include "trace.h"
@@ -176,6 +177,50 @@ int kvm_handle_wfi(struct kvm_vcpu *vcpu, struct kvm_run *run)
 	return 1;
 }
 
+/*
+ * A conditional instruction is allowed to trap, even though it
+ * wouldn't be executed.  So let's re-implement the hardware, in
+ * software!
+ */
+bool kvm_condition_valid(struct kvm_vcpu *vcpu)
+{
+	unsigned long cpsr, cond, insn;
+
+	/*
+	 * Exception Code 0 can only happen if we set HCR.TGE to 1, to
+	 * catch undefined instructions, and then we won't get past
+	 * the arm_exit_handlers test anyway.
+	 */
+	BUG_ON(!kvm_vcpu_trap_get_class(vcpu));
+
+	/* Top two bits non-zero?  Unconditional. */
+	if (kvm_vcpu_get_hsr(vcpu) >> 30)
+		return true;
+
+	cpsr = *vcpu_cpsr(vcpu);
+
+	/* Is condition field valid? */
+	if ((kvm_vcpu_get_hsr(vcpu) & HSR_CV) >> HSR_CV_SHIFT)
+		cond = (kvm_vcpu_get_hsr(vcpu) & HSR_COND) >> HSR_COND_SHIFT;
+	else {
+		/* This can happen in Thumb mode: examine IT state. */
+		unsigned long it;
+
+		it = ((cpsr >> 8) & 0xFC) | ((cpsr >> 25) & 0x3);
+
+		/* it == 0 => unconditional. */
+		if (it == 0)
+			return true;
+
+		/* The cond for this insn works out as the top 4 bits. */
+		cond = (it >> 4);
+	}
+
+	/* Shift makes it look like an ARM-mode instruction */
+	insn = cond << 28;
+	return arm_check_condition(insn, cpsr) != ARM_OPCODE_CONDTEST_FAIL;
+}
+
 /**
  * adjust_itstate - adjust ITSTATE when emulating instructions in IT-block
  * @vcpu:	The VCPU pointer
-- 
1.7.12.4

  parent reply	other threads:[~2013-03-05  2:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-05  2:42 [PATCH 00/29] ARM: KVM: pre-arm64 KVM/arm rework Marc Zyngier
2013-03-05  2:42 ` [PATCH 01/29] ARM: KVM: convert GP registers from u32 to unsigned long Marc Zyngier
2013-03-05  2:42 ` [PATCH 02/29] ARM: KVM: abstract fault register accesses Marc Zyngier
2013-03-05  2:42 ` [PATCH 03/29] ARM: KVM: abstract HSR_ISV away Marc Zyngier
2013-03-05  2:42 ` [PATCH 04/29] ARM: KVM: abstract HSR_WNR away Marc Zyngier
2013-03-05  2:42 ` [PATCH 05/29] ARM: KVM: abstract HSR_SSE away Marc Zyngier
2013-03-05  2:43 ` [PATCH 06/29] ARM: KVM: abstract HSR_SRT_{MASK,SHIFT} away Marc Zyngier
2013-03-05  2:43 ` [PATCH 07/29] ARM: KVM: abstract external abort detection away Marc Zyngier
2013-03-05  2:43 ` [PATCH 08/29] ARM: KVM: abstract S1TW " Marc Zyngier
2013-03-05  2:43 ` [PATCH 09/29] ARM: KVM: abstract SAS decoding away Marc Zyngier
2013-03-05  2:43 ` [PATCH 10/29] ARM: KVM: abstract IL " Marc Zyngier
2013-03-05  2:43 ` [PATCH 11/29] ARM: KVM: abstract exception class " Marc Zyngier
2013-03-05  2:43 ` [PATCH 12/29] ARM: KVM: abstract fault " Marc Zyngier
2013-03-05  2:43 ` [PATCH 13/29] ARM: KVM: abstract HSR_EC_IABT away Marc Zyngier
2013-03-05  2:43 ` Marc Zyngier [this message]
2013-03-05  2:43 ` [PATCH 15/29] ARM: KVM: move exit handler selection to a separate file Marc Zyngier
2013-03-05  2:43 ` [PATCH 16/29] ARM: KVM: move kvm_handle_wfi to handle_exit.c Marc Zyngier
2013-03-05  2:43 ` [PATCH 17/29] ARM: KVM: abstract most MMU operations Marc Zyngier
2013-03-05  2:43 ` [PATCH 18/29] ARM: KVM: remove superfluous include from kvm_vgic.h Marc Zyngier
2013-03-05  2:43 ` [PATCH 19/29] ARM: KVM: move hyp init to kvm_host.h Marc Zyngier
2013-03-05  2:43 ` [PATCH 20/29] ARM: KVM: use kvm_kernel_vfp_t as an abstract type for VFP containers Marc Zyngier
2013-03-05  2:43 ` [PATCH 21/29] ARM: KVM: allow HYP mappings to be at an offset from kernel mappings Marc Zyngier
2013-03-05  2:43 ` [PATCH 22/29] ARM: KVM: fix address validation for HYP mappings Marc Zyngier
2013-03-05  2:43 ` [PATCH 23/29] ARM: KVM: sanitize freeing of HYP page tables Marc Zyngier
2013-03-05  2:43 ` [PATCH 24/29] ARM: KVM: move kvm_target_cpu to guest.c Marc Zyngier
2013-03-05  2:43 ` [PATCH 25/29] ARM: KVM: fix fault_ipa computing Marc Zyngier
2013-03-05  2:43 ` [PATCH 26/29] ARM: KVM: vgic: decouple alignment restriction from page size Marc Zyngier
2013-03-05  2:43 ` [PATCH 27/29] ARM: KVM: move include of asm/idmap.h to kvm_mmu.h Marc Zyngier
2013-03-05  2:43 ` [PATCH 28/29] ARM: KVM: change kvm_tlb_flush_vmid to kvm_tlb_flush_vmid_ipa Marc Zyngier
2013-03-05  2:43 ` [PATCH 29/29] ARM: KVM: Fix length of mmio access Marc Zyngier
2013-03-07  0:11 ` [kvmarm] [PATCH 00/29] ARM: KVM: pre-arm64 KVM/arm rework Christoffer Dall

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=1362451403-23460-15-git-send-email-marc.zyngier@arm.com \
    --to=marc.zyngier@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).