Re: [PATCH 04/13] KVM: X86: Add x86 callback for intercept check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/25/2011 11:29 AM, Joerg Roedel wrote:
This patch adds a callback into kvm_x86_ops so that svm and
vmx code can do intercept checks on emulated instructions.



+/*
+ * This struct is used to carry enough information from the instruction
+ * decoder to main KVM so that a decision can be made whether the
+ * instruction needs to be intercepted or not.
+ */
+struct x86_instruction_info {
+	u8  intercept;		/* which intercept			*/
+	u8  rep_prefix;		/* rep prefix?				*/
+	u8  modrm;		/* index of register used		*/
+	u64 src_val;		/* value of source operand		*/
+	u8  src_bytes;		/* size of source operand		*/
+	u8  dst_bytes;		/* size of destination operand		*/
+	u8  ad_bytes;		/* size of src/dst address		*/
+	u64 next_rip;		/* rip following the instruction	*/
+};

Should be in kvm_emulate.h.

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 90a41aa..bf72ec6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4245,7 +4245,25 @@ static int emulator_intercept(struct x86_emulate_ctxt *ctxt,
  			      enum x86_intercept intercept,
  			      enum x86_intercept_stage stage)
  {
-	return X86EMUL_CONTINUE;
+	struct x86_instruction_info info = {
+		.intercept  = intercept,
+		.rep_prefix = ctxt->decode.rep_prefix,
+		.modrm      = ctxt->decode.modrm,
+		.src_val    = ctxt->decode.src.val64,
+		.src_bytes  = ctxt->decode.src.bytes,
+		.dst_bytes  = ctxt->decode.dst.bytes,
+		.ad_bytes   = ctxt->decode.ad_bytes,
+		.next_rip   = ctxt->eip,
+	};

And this should be in emulate.c, so kvm code doesn't have to peek into the emulator internals.


+
+	/*
+	 * The callback only needs to be implemented if the architecture
+	 * supports emulated guest-mode. This BUG_ON reminds the
+	 * programmer that this callback needs to be implemented.
+	 */
+	BUG_ON(kvm_x86_ops->check_intercept == NULL);
+

BUG_ON()s are nasty.  I prefer a null implementation for vmx.

+	return kvm_x86_ops->check_intercept(ctxt->vcpu,&info, stage);
  }

  static struct x86_emulate_ops emulate_ops = {


--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux