Skip to contentSkip to conversation

KVM: x86 emulator: modify 'cmpxchg8b', 'lods', 'stos' to not depend on CR2

PATCH Applied Sheng Yang 2 participants 3 messages Nov 15, 2007 – Nov 16, 2007 2 messages not in the archive KVM

lore
Share & tools
lore

Sheng Yang

author
#0 lore raw

PATCH 1/2 KVM: x86 emulator: modify 'cmpxchg8b', 'lods', 'stos' to not depend on CR2

From c7b60a362930679e24df27e6a412cdbdf1a55f69 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Thu, 15 Nov 2007 14:52:28 +0800
Subject: [PATCH 1/2] KVM: x86 emulator: modify 'cmpxchg8b', 'lods', 'stos' to not depend on CR2

The current 'lods' and 'stos' is depending on incoming CR2 rather than decode memory address from registers.

And 'cmpxchg8b' should be decode memory address too.

---
 drivers/kvm/x86_emulate.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
drivers/kvm/x86_emulate.c +12 -5
index dfcbda5..c020010 100644
@@ -214,7 +214,8 @@ static u16 twobyte_table[256] = {
 	0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
 	    DstReg | SrcMem16 | ModRM | Mov,
 	/* 0xC0 - 0xCF */
-	0, 0, 0, DstMem | SrcReg | ModRM | Mov, 0, 0, 0, ImplicitOps | ModRM,
+	0, 0, 0, DstMem | SrcReg | ModRM | Mov,
+	0, 0, 0, ImplicitOps | ModRM | MemAbs,
 	0, 0, 0, 0, 0, 0, 0, 0,
 	/* 0xD0 - 0xDF */
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1533,7 +1534,9 @@ special_insn:
 	case 0xaa ... 0xab:	/* stos */
 		c->dst.type = OP_MEM;
 		c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
-		c->dst.ptr = (unsigned long *)cr2;
+		c->dst.ptr = (unsigned long *)register_address(
+						   ctxt->es_base,
+						   c->regs[VCPU_REGS_RDI]);
 		c->dst.val = c->regs[VCPU_REGS_RAX];
 		register_address_increment(c->regs[VCPU_REGS_RDI],
 				       (ctxt->eflags & EFLG_DF) ? -c->dst.bytes
@@ -1543,9 +1546,13 @@ special_insn:
 		c->dst.type = OP_REG;
 		c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
 		c->dst.ptr = (unsigned long *)&c->regs[VCPU_REGS_RAX];
-		if ((rc = ops->read_emulated(cr2, &c->dst.val,
-					     c->dst.bytes,
-					     ctxt->vcpu)) != 0)
+		if ((rc = ops->read_emulated(register_address(
+				c->override_base ? *c->override_base :
+						   ctxt->ds_base,
+						 c->regs[VCPU_REGS_RSI]),
+						 &c->dst.val,
+						 c->dst.bytes,
+						 ctxt->vcpu)) != 0)
 			goto done;
 
 		register_address_increment(c->regs[VCPU_REGS_RSI],
Signature · 1 line
1.5.2

From c7b60a362930679e24df27e6a412cdbdf1a55f69 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Thu, 15 Nov 2007 14:52:28 +0800
Subject: [PATCH 1/2] KVM: x86 emulator: modify 'cmpxchg8b', 'lods', 'stos' to not depend on CR2

The current 'lods' and 'stos' is depending on incoming CR2 rather than decode memory address from registers.

And 'cmpxchg8b' should be decode memory address too.

---
 drivers/kvm/x86_emulate.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
drivers/kvm/x86_emulate.c +12 -5
index dfcbda5..c020010 100644
@@ -214,7 +214,8 @@ static u16 twobyte_table[256] = {
 	0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
 	    DstReg | SrcMem16 | ModRM | Mov,
 	/* 0xC0 - 0xCF */
-	0, 0, 0, DstMem | SrcReg | ModRM | Mov, 0, 0, 0, ImplicitOps | ModRM,
+	0, 0, 0, DstMem | SrcReg | ModRM | Mov,
+	0, 0, 0, ImplicitOps | ModRM | MemAbs,
 	0, 0, 0, 0, 0, 0, 0, 0,
 	/* 0xD0 - 0xDF */
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1533,7 +1534,9 @@ special_insn:
 	case 0xaa ... 0xab:	/* stos */
 		c->dst.type = OP_MEM;
 		c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
-		c->dst.ptr = (unsigned long *)cr2;
+		c->dst.ptr = (unsigned long *)register_address(
+						   ctxt->es_base,
+						   c->regs[VCPU_REGS_RDI]);
 		c->dst.val = c->regs[VCPU_REGS_RAX];
 		register_address_increment(c->regs[VCPU_REGS_RDI],
 				       (ctxt->eflags & EFLG_DF) ? -c->dst.bytes
@@ -1543,9 +1546,13 @@ special_insn:
 		c->dst.type = OP_REG;
 		c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
 		c->dst.ptr = (unsigned long *)&c->regs[VCPU_REGS_RAX];
-		if ((rc = ops->read_emulated(cr2, &c->dst.val,
-					     c->dst.bytes,
-					     ctxt->vcpu)) != 0)
+		if ((rc = ops->read_emulated(register_address(
+				c->override_base ? *c->override_base :
+						   ctxt->ds_base,
+						 c->regs[VCPU_REGS_RSI]),
+						 &c->dst.val,
+						 c->dst.bytes,
+						 ctxt->vcpu)) != 0)
 			goto done;
 
 		register_address_increment(c->regs[VCPU_REGS_RSI],
Signature · 1 line
1.5.2

-------------------------------------------------------------------------
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/

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

A message that is not in the archive (sent off-list or not yet received): 200711151531.50461.sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

Applied
#2 lore raw
Quoted 9 lines · Sheng Yang

From c7b60a362930679e24df27e6a412cdbdf1a55f69 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Thu, 15 Nov 2007 14:52:28 +0800
Subject: [PATCH 1/2] KVM: x86 emulator: modify 'cmpxchg8b', 'lods', 'stos' to not depend on CR2

The current 'lods' and 'stos' is depending on incoming CR2 rather than decode memory address from registers.

Applied, thanks.

Quoted 6 lines
drivers/kvm/x86_emulate.c +0 -0
index dfcbda5..c020010 100644

drivers/kvm/x86_emulate.c static u16 twobyte_table[256] = { · line 221

Quoted 9 lines
drivers/kvm/x86_emulate.c +2 -1
@@ -214,7 +214,8 @@ static u16 twobyte_table[256] = {
 	0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
 	    DstReg | SrcMem16 | ModRM | Mov,
 	/* 0xC0 - 0xCF */
-	0, 0, 0, DstMem | SrcReg | ModRM | Mov, 0, 0, 0, ImplicitOps | ModRM,
+	0, 0, 0, DstMem | SrcReg | ModRM | Mov,
+	0, 0, 0, ImplicitOps | ModRM | MemAbs,
 	0, 0, 0, 0, 0, 0, 0, 0,
 	/* 0xD0 - 0xDF */
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

Dropped this part: ModRM and MemAbs are mutually exclusive. MemAbs is where you have an absolute address in the instruction that is not encoded with mod r/m.

Didn't see anything else about cmpchg{8,16}b. Is something missing?

Signature · 8 lines
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
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/

A message that is not in the archive (sent off-list or not yet received): 473C19EA.80804-atKUWr5tajBWk0Htik3J/[email protected]

author
#4 lore raw
Quoted 31 lines · On Thursday 15 November 2007 18:05:30 Avi Kivity wrote:
Quoted 8 lines · Sheng Yang

From c7b60a362930679e24df27e6a412cdbdf1a55f69 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Thu, 15 Nov 2007 14:52:28 +0800
Subject: [PATCH 1/2] KVM: x86 emulator: modify 'cmpxchg8b', 'lods', 'stos' to not depend on CR2

The current 'lods' and 'stos' is depending on incoming CR2 rather than decode memory address from registers.

Applied, thanks.

Quoted 5 lines
drivers/kvm/x86_emulate.c +0 -0
index dfcbda5..c020010 100644

drivers/kvm/x86_emulate.c static u16 twobyte_table[256] = { · line 221

Quoted 9 lines
drivers/kvm/x86_emulate.c +2 -1
@@ -214,7 +214,8 @@ static u16 twobyte_table[256] = {
 	0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
 	    DstReg | SrcMem16 | ModRM | Mov,
 	/* 0xC0 - 0xCF */
-	0, 0, 0, DstMem | SrcReg | ModRM | Mov, 0, 0, 0, ImplicitOps | ModRM,
+	0, 0, 0, DstMem | SrcReg | ModRM | Mov,
+	0, 0, 0, ImplicitOps | ModRM | MemAbs,
 	0, 0, 0, 0, 0, 0, 0, 0,
 	/* 0xD0 - 0xDF */
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

Dropped this part: ModRM and MemAbs are mutually exclusive. MemAbs is where you have an absolute address in the instruction that is not encoded with mod r/m.

Quoted 1 line

Didn't see anything else about cmpchg{8,16}b. Is something missing?

In fact, this was about cmpchg{8,16}b. And yes, you're right. I miss that. Only ModRM is needed.

Signature · 7 lines
Thanks
Yang, Sheng

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/