public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien-rXXEIb44qovR7s880joybQ@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: [PATCH] KVM: Access registers for instructions with ModR/M byte and Mod = 3
Date: Wed, 17 Oct 2007 19:30:41 +0200	[thread overview]
Message-ID: <20071017173041.GA8545@hall.aurel32.net> (raw)

On Wed, Oct 17, 2007 at 06:23:41PM +0200, Aurelien Jarno wrote:
> >> The 0F 01 instruction is then correctly emulated, but another of this
> > Oops s/0F 01/invlpg/
> >> group is probably not, as the patch clearly fix the problem on AMD.
> > 
> 
> I confirm the problem. SVM does not virtualize smsw and lmsw that have
> to be emulated. And it looks like the decoding or/and emulation of those
> instructions is currently broken in KVM.
>

Ok, next try. This time I have opened the IA32 manual (I should have
done that before), so I hope it is correct.


KVM: Access registers for instructions with ModR/M byte and Mod = 3

The patch belows changes the access type to register from memory for 
instructions that are declared as SrcMem or DstMem, but have a 
ModR/M byte with Mod = 3.

It fixes (at least) the lmsw and smsw instructions on an AMD64 CPU,
which are needed for FreeBSD.

Signed-off-by: Aurelien Jarno <aurelien-rXXEIb44qovR7s880joybQ@public.gmane.org>

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index e974ace..005e57c 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -831,6 +831,12 @@ modrm_done:
 		if (c->twobyte && c->b == 0x01
 				    && c->modrm_reg == 7)
 			break;
+		/* For instructions with a ModR/M byte, switch to register
+		   access if Mod = 3. */
+		if ((c->d & ModRM) && c->modrm_mod == 3) {
+			c->src.type = OP_REG;
+			break;
+		}
 srcmem_common:
 		c->src.type = OP_MEM;
 		break;
@@ -893,7 +899,12 @@ srcmem_common:
 		}
 		break;
 	case DstMem:
-		c->dst.type = OP_MEM;
+		/* For instructions with a ModR/M byte, switch to register
+		   access if Mod = 3. */
+		if ((c->d & ModRM) && c->modrm_mod == 3)
+			c->dst.type = OP_REG;
+		else
+			c->dst.type = OP_MEM;
 		break;
 	}
 

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   aurel32-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org         | aurelien-rXXEIb44qovR7s880joybQ@public.gmane.org
   `-    people.debian.org/~aurel32 | www.aurel32.net

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

             reply	other threads:[~2007-10-17 17:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-17 17:30 Aurelien Jarno [this message]
     [not found] ` <20071017173041.GA8545-OqXK5JiLQY5aJl8KAwiEcA@public.gmane.org>
2007-10-18  9:19   ` [PATCH] KVM: Access registers for instructions with ModR/M byte and Mod = 3 Avi Kivity

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=20071017173041.GA8545@hall.aurel32.net \
    --to=aurelien-rxxeib44qovr7s880joybq@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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