Skip to contentSkip to conversation

KVM: x86 emulator: Discard CR2 in x86 emulator

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

lore
Share & tools
lore

Sheng Yang

author
#0 lore raw

PATCH 1/1 KVM: x86 emulator: Discard CR2 in x86 emulator

From f8aca5afbc018e71dc37d2e6001bcec376499939 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Fri, 16 Nov 2007 16:29:15 +0800
Subject: [PATCH] KVM: x86 emulator: Discard CR2 in x86 emulator

For CR2 is unreliable and unavailable in many condition, this patch completely decode memory operand instead of using CR2 in x86 emulator.

---
 drivers/kvm/x86.c         |    1 -
 drivers/kvm/x86_emulate.c |   18 +++++++++---------
 drivers/kvm/x86_emulate.h |    1 -
 3 files changed, 9 insertions(+), 11 deletions(-)
drivers/kvm/x86.c +0 -1
index 6d7f384..16b32bc 100644
@@ -1352,7 +1352,6 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
 
 		vcpu->emulate_ctxt.vcpu = vcpu;
 		vcpu->emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu);
-		vcpu->emulate_ctxt.cr2 = cr2;
 		vcpu->emulate_ctxt.mode =
 			(vcpu->emulate_ctxt.eflags & X86_EFLAGS_VM)
 			? X86EMUL_MODE_REAL : cs_l
drivers/kvm/x86_emulate.c +0 -0
index b9d2781..cbd50dd 100644
@@ -1090,13 +1090,13 @@ static inline int emulate_grp45(struct 

x86_emulate_ctxt *ctxt,

static inline int emulate_grp9(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops,
- unsigned long cr2)
+ unsigned long memop)
{
struct decode_cache *c = &ctxt->decode;
u64 old, new;
int rc;

- rc = ops->read_emulated(cr2, &old, 8, ctxt->vcpu);
+ rc = ops->read_emulated(memop, &old, 8, ctxt->vcpu);
if (rc != 0)
return rc;

@@ -1111,7 +1111,7 @@ static inline int emulate_grp9(struct x86_emulate_ctxt *ctxt,
new = ((u64)c->regs[VCPU_REGS_RCX] << 32) |
(u32) c->regs[VCPU_REGS_RBX];

- rc = ops->cmpxchg_emulated(cr2, &old, &new, 8, ctxt->vcpu);
+ rc = ops->cmpxchg_emulated(memop, &old, &new, 8, ctxt->vcpu);
if (rc != 0)
return rc;
ctxt->eflags |= EFLG_ZF;
@@ -1174,7 +1174,7 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
int
x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) {
- unsigned long cr2 = ctxt->cr2;
+ unsigned long memop = 0;
u64 msr_data;
unsigned long saved_eip;
struct decode_cache *c = &ctxt->decode;
@@ -1189,10 +1189,10 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
saved_eip = c->eip;

if (((c->d & ModRM) && (c->modrm_mod != 3)) || (c->d & MemAbs))
- cr2 = c->modrm_ea;
+ memop = c->modrm_ea;

if (c->src.type == OP_MEM) {
- c->src.ptr = (unsigned long *)cr2;
+ c->src.ptr = (unsigned long *)memop;
c->src.val = 0;
rc = ops->read_emulated((unsigned long)c->src.ptr,
&c->src.val,
@@ -1208,7 +1208,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)

if (c->dst.type == OP_MEM) {
- c->dst.ptr = (unsigned long *)cr2;
+ c->dst.ptr = (unsigned long *)memop;
c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes; c->dst.val = 0;
if (c->d & BitOp) {
@@ -1647,7 +1647,7 @@ twobyte_insn:
&ctxt->eflags);
break;
case 7: /* invlpg*/
- emulate_invlpg(ctxt->vcpu, cr2);
+ emulate_invlpg(ctxt->vcpu, memop);
break;
default:
goto cannot_emulate;
@@ -1818,7 +1818,7 @@ twobyte_special_insn:
break;
}
case 0xc7: /* Grp9 (cmpxchg8b) */
- rc = emulate_grp9(ctxt, ops, cr2);
+ rc = emulate_grp9(ctxt, ops, memop);
if (rc != 0)
goto done;
break;

drivers/kvm/x86_emulate.h +0 -1
index e34868b..c0a89c9 100644
@@ -149,7 +149,6 @@ struct x86_emulate_ctxt {
 
 	/* Linear faulting address (if emulating a page-faulting instruction). */
 	unsigned long eflags;
-	unsigned long cr2;
 
 	/* Emulated execution mode, represented by an X86EMUL_MODE value. */
 	int mode;
Signature · 1 line
1.5.3.4

From f8aca5afbc018e71dc37d2e6001bcec376499939 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Fri, 16 Nov 2007 16:29:15 +0800
Subject: [PATCH] KVM: x86 emulator: Discard CR2 in x86 emulator

For CR2 is unreliable and unavailable in many condition, this patch completely decode memory operand instead of using CR2 in x86 emulator.

---
 drivers/kvm/x86.c         |    1 -
 drivers/kvm/x86_emulate.c |   18 +++++++++---------
 drivers/kvm/x86_emulate.h |    1 -
 3 files changed, 9 insertions(+), 11 deletions(-)
drivers/kvm/x86.c +0 -1
index 6d7f384..16b32bc 100644
@@ -1352,7 +1352,6 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
 
 		vcpu->emulate_ctxt.vcpu = vcpu;
 		vcpu->emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu);
-		vcpu->emulate_ctxt.cr2 = cr2;
 		vcpu->emulate_ctxt.mode =
 			(vcpu->emulate_ctxt.eflags & X86_EFLAGS_VM)
 			? X86EMUL_MODE_REAL : cs_l
drivers/kvm/x86_emulate.c +9 -9
index b9d2781..cbd50dd 100644
@@ -1090,13 +1090,13 @@ static inline int emulate_grp45(struct x86_emulate_ctxt *ctxt,
 
 static inline int emulate_grp9(struct x86_emulate_ctxt *ctxt,
 			       struct x86_emulate_ops *ops,
-			       unsigned long cr2)
+			       unsigned long memop)
 {
 	struct decode_cache *c = &ctxt->decode;
 	u64 old, new;
 	int rc;
 
-	rc = ops->read_emulated(cr2, &old, 8, ctxt->vcpu);
+	rc = ops->read_emulated(memop, &old, 8, ctxt->vcpu);
 	if (rc != 0)
 		return rc;
 
@@ -1111,7 +1111,7 @@ static inline int emulate_grp9(struct x86_emulate_ctxt *ctxt,
 		new = ((u64)c->regs[VCPU_REGS_RCX] << 32) |
 		       (u32) c->regs[VCPU_REGS_RBX];
 
-		rc = ops->cmpxchg_emulated(cr2, &old, &new, 8, ctxt->vcpu);
+		rc = ops->cmpxchg_emulated(memop, &old, &new, 8, ctxt->vcpu);
 		if (rc != 0)
 			return rc;
 		ctxt->eflags |= EFLG_ZF;
@@ -1174,7 +1174,7 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
 int
 x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 {
-	unsigned long cr2 = ctxt->cr2;
+	unsigned long memop = 0;
 	u64 msr_data;
 	unsigned long saved_eip;
 	struct decode_cache *c = &ctxt->decode;
@@ -1189,10 +1189,10 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 	saved_eip = c->eip;
 
 	if (((c->d & ModRM) && (c->modrm_mod != 3)) || (c->d & MemAbs))
-		cr2 = c->modrm_ea;
+		memop = c->modrm_ea;
 
 	if (c->src.type == OP_MEM) {
-		c->src.ptr = (unsigned long *)cr2;
+		c->src.ptr = (unsigned long *)memop;
 		c->src.val = 0;
 		rc = ops->read_emulated((unsigned long)c->src.ptr,
 					&c->src.val,
@@ -1208,7 +1208,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 
 
 	if (c->dst.type == OP_MEM) {
-		c->dst.ptr = (unsigned long *)cr2;
+		c->dst.ptr = (unsigned long *)memop;
 		c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
 		c->dst.val = 0;
 		if (c->d & BitOp) {
@@ -1647,7 +1647,7 @@ twobyte_insn:
 						  &ctxt->eflags);
 			break;
 		case 7: /* invlpg*/
-			emulate_invlpg(ctxt->vcpu, cr2);
+			emulate_invlpg(ctxt->vcpu, memop);
 			break;
 		default:
 			goto cannot_emulate;
@@ -1818,7 +1818,7 @@ twobyte_special_insn:
 		break;
 	}
 	case 0xc7:		/* Grp9 (cmpxchg8b) */
-		rc = emulate_grp9(ctxt, ops, cr2);
+		rc = emulate_grp9(ctxt, ops, memop);
 		if (rc != 0)
 			goto done;
 		break;
drivers/kvm/x86_emulate.h +0 -1
index e34868b..c0a89c9 100644
@@ -149,7 +149,6 @@ struct x86_emulate_ctxt {
 
 	/* Linear faulting address (if emulating a page-faulting instruction). */
 	unsigned long eflags;
-	unsigned long cr2;
 
 	/* Emulated execution mode, represented by an X86EMUL_MODE value. */
 	int mode;
Signature · 1 line
1.5.3.4

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

_______________________________________________
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): 200711161630.34137.sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

Applied
#2 lore raw
Quoted 8 lines · Sheng Yang

From f8aca5afbc018e71dc37d2e6001bcec376499939 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Fri, 16 Nov 2007 16:29:15 +0800
Subject: [PATCH] KVM: x86 emulator: Discard CR2 in x86 emulator

For CR2 is unreliable and unavailable in many condition, this patch completely decode memory operand instead of using CR2 in x86 emulator.

Applied, thanks.

This is just a rename, right? That means lods/stos was the last instance of using cr2.

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


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

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

author
#4 lore raw
Quoted 6 lines · On Sunday 18 November 2007 18:35:22 Avi Kivity wrote:
Quoted 5 lines · Sheng Yang

From f8aca5afbc018e71dc37d2e6001bcec376499939 Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Fri, 16 Nov 2007 16:29:15 +0800
Subject: [PATCH] KVM: x86 emulator: Discard CR2 in x86 emulator

Quoted 7 lines
Quoted 2 lines

For CR2 is unreliable and unavailable in many condition, this patch completely decode memory operand instead of using CR2 in x86 emulator.

Applied, thanks.

This is just a rename, right? That means lods/stos was the last instance of using cr2.

Yeah, I think so.

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/