public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@amd.com>
To: avi@redhat.com
Cc: kvm@vger.kernel.org, Andre Przywara <andre.przywara@amd.com>,
	Christoph Egger <christoph.egger@amd.com>,
	Amit Shah <amit.shah@redhat.com>
Subject: [PATCH 1/6] allow emulation of syscalls instructions on #UD
Date: Wed, 17 Jun 2009 15:50:31 +0200	[thread overview]
Message-ID: <1245246636-30760-2-git-send-email-andre.przywara@amd.com> (raw)
In-Reply-To: <1245246636-30760-1-git-send-email-andre.przywara@amd.com>

Add the opcodes for syscall, sysenter and sysexit to the list of instructions
handled by the undefined opcode handler.

Signed-off-by: Christoph Egger <christoph.egger@amd.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Andre Przywara <andre.przywara@amd.com>
---
 arch/x86/kvm/x86.c |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 6025e5b..88e159c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2632,14 +2632,33 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
 
 		r = x86_decode_insn(&vcpu->arch.emulate_ctxt, &emulate_ops);
 
-		/* Reject the instructions other than VMCALL/VMMCALL when
-		 * try to emulate invalid opcode */
+		/* Only allow emulation of specific instructions on #UD
+		 * (namely VMMCALL, sysenter, sysexit, syscall)*/
 		c = &vcpu->arch.emulate_ctxt.decode;
-		if ((emulation_type & EMULTYPE_TRAP_UD) &&
-		    (!(c->twobyte && c->b == 0x01 &&
-		      (c->modrm_reg == 0 || c->modrm_reg == 3) &&
-		       c->modrm_mod == 3 && c->modrm_rm == 1)))
-			return EMULATE_FAIL;
+		if (emulation_type & EMULTYPE_TRAP_UD) {
+			if (!c->twobyte)
+				return EMULATE_FAIL;
+			switch (c->b) {
+			case 0x01: /* VMMCALL */
+				if (c->modrm_mod != 3 || c->modrm_rm != 1)
+					return EMULATE_FAIL;
+				break;
+			case 0x34: /* sysenter */
+			case 0x35: /* sysexit */
+				if (c->modrm_mod != 0 || c->modrm_rm != 0)
+					return EMULATE_FAIL;
+				break;
+			case 0x05: /* syscall */
+				if (c->modrm_mod != 0 || c->modrm_rm != 0)
+					return EMULATE_FAIL;
+				break;
+			default:
+				return EMULATE_FAIL;
+			}
+
+			if (!(c->modrm_reg == 0 || c->modrm_reg == 3))
+				return EMULATE_FAIL;
+		}
 
 		++vcpu->stat.insn_emulation;
 		if (r)  {
-- 
1.6.1.3



  reply	other threads:[~2009-06-17 13:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-17 13:50 [PATCH 0/6] add sysenter/syscall emulation for 32bit compat mode Andre Przywara
2009-06-17 13:50 ` Andre Przywara [this message]
2009-06-17 13:50 ` [PATCH 2/6] add missing EFLAGS bit definitions Andre Przywara
2009-06-17 13:50 ` [PATCH 3/6] prepare for emulation of syscall instructions Andre Przywara
2009-06-17 13:50 ` [PATCH 4/6] add syscall emulation Andre Przywara
2009-06-18  8:47   ` Avi Kivity
2009-06-18 10:27     ` Andre Przywara
2009-06-22  8:43       ` Avi Kivity
2009-06-17 13:50 ` [PATCH 5/6] add sysenter emulation Andre Przywara
2009-06-17 13:50 ` [PATCH 6/6] add sysexit emulation Andre Przywara
2009-06-18  8:48 ` [PATCH 0/6] add sysenter/syscall emulation for 32bit compat mode Avi Kivity
2009-06-18 10:56   ` [PATCH 4/6 v2] add syscall emulation Andre Przywara
2009-06-18 10:56     ` [PATCH 5/6 v2] add sysenter emulation Andre Przywara
2009-06-18 10:56       ` [PATCH 6/6 v2] add sysexit emulation Andre Przywara

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=1245246636-30760-2-git-send-email-andre.przywara@amd.com \
    --to=andre.przywara@amd.com \
    --cc=amit.shah@redhat.com \
    --cc=avi@redhat.com \
    --cc=christoph.egger@amd.com \
    --cc=kvm@vger.kernel.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