* [PATCH 01/10] KVM: x86 emulator: Use the pointers ctxt and c consistently
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
@ 2011-05-29 12:53 ` Takuya Yoshikawa
2011-05-29 12:55 ` [PATCH 02/10] KVM: x86 emulator: Rename emulate_xxx() to em_xxx() Takuya Yoshikawa
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 12:53 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
We should use the local variables ctxt and c when the emulate_ctxt and
decode appears many times. At least, we need to be consistent about
how we use these in a function.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 6 ++--
arch/x86/kvm/x86.c | 59 +++++++++++++++++++++++------------------------
2 files changed, 32 insertions(+), 33 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index b8b9748..c9fc539 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -3691,7 +3691,7 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
int saved_dst_type = c->dst.type;
int irq; /* Used for int 3, int, and into */
- ctxt->decode.mem_read.pos = 0;
+ c->mem_read.pos = 0;
if (ctxt->mode == X86EMUL_MODE_PROT64 && (c->d & No64)) {
rc = emulate_ud(ctxt);
@@ -4078,7 +4078,7 @@ writeback:
&c->dst);
if (c->rep_prefix && (c->d & String)) {
- struct read_cache *r = &ctxt->decode.io_read;
+ struct read_cache *r = &c->io_read;
register_address_increment(c, &c->regs[VCPU_REGS_RCX], -1);
if (!string_insn_completed(ctxt)) {
@@ -4093,7 +4093,7 @@ writeback:
* decode, but since instruction is restarted
* we have to do it here.
*/
- ctxt->decode.mem_read.end = 0;
+ c->mem_read.end = 0;
return EMULATION_RESTART;
}
goto done; /* skip rip writeback */
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index da48622..99e12ec 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4537,24 +4537,24 @@ static void init_emulate_ctxt(struct kvm_vcpu *vcpu)
int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip)
{
- struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
+ struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt;
+ struct decode_cache *c = &ctxt->decode;
int ret;
init_emulate_ctxt(vcpu);
- vcpu->arch.emulate_ctxt.decode.op_bytes = 2;
- vcpu->arch.emulate_ctxt.decode.ad_bytes = 2;
- vcpu->arch.emulate_ctxt.decode.eip = vcpu->arch.emulate_ctxt.eip +
- inc_eip;
- ret = emulate_int_real(&vcpu->arch.emulate_ctxt, irq);
+ c->op_bytes = 2;
+ c->ad_bytes = 2;
+ c->eip = ctxt->eip + inc_eip;
+ ret = emulate_int_real(ctxt, irq);
if (ret != X86EMUL_CONTINUE)
return EMULATE_FAIL;
- vcpu->arch.emulate_ctxt.eip = c->eip;
+ ctxt->eip = c->eip;
memcpy(vcpu->arch.regs, c->regs, sizeof c->regs);
- kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip);
- kvm_set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags);
+ kvm_rip_write(vcpu, ctxt->eip);
+ kvm_set_rflags(vcpu, ctxt->eflags);
if (irq == NMI_VECTOR)
vcpu->arch.nmi_pending = false;
@@ -4615,21 +4615,22 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
int insn_len)
{
int r;
- struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
+ struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt;
+ struct decode_cache *c = &ctxt->decode;
bool writeback = true;
kvm_clear_exception_queue(vcpu);
if (!(emulation_type & EMULTYPE_NO_DECODE)) {
init_emulate_ctxt(vcpu);
- vcpu->arch.emulate_ctxt.interruptibility = 0;
- vcpu->arch.emulate_ctxt.have_exception = false;
- vcpu->arch.emulate_ctxt.perm_ok = false;
+ ctxt->interruptibility = 0;
+ ctxt->have_exception = false;
+ ctxt->perm_ok = false;
- vcpu->arch.emulate_ctxt.only_vendor_specific_insn
+ ctxt->only_vendor_specific_insn
= emulation_type & EMULTYPE_TRAP_UD;
- r = x86_decode_insn(&vcpu->arch.emulate_ctxt, insn, insn_len);
+ r = x86_decode_insn(ctxt, insn, insn_len);
trace_kvm_emulate_insn_start(vcpu);
++vcpu->stat.insn_emulation;
@@ -4645,7 +4646,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
}
if (emulation_type & EMULTYPE_SKIP) {
- kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.decode.eip);
+ kvm_rip_write(vcpu, c->eip);
return EMULATE_DONE;
}
@@ -4657,7 +4658,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
}
restart:
- r = x86_emulate_insn(&vcpu->arch.emulate_ctxt);
+ r = x86_emulate_insn(ctxt);
if (r == EMULATION_INTERCEPTED)
return EMULATE_DONE;
@@ -4669,7 +4670,7 @@ restart:
return handle_emulation_failure(vcpu);
}
- if (vcpu->arch.emulate_ctxt.have_exception) {
+ if (ctxt->have_exception) {
inject_emulated_exception(vcpu);
r = EMULATE_DONE;
} else if (vcpu->arch.pio.count) {
@@ -4688,13 +4689,12 @@ restart:
r = EMULATE_DONE;
if (writeback) {
- toggle_interruptibility(vcpu,
- vcpu->arch.emulate_ctxt.interruptibility);
- kvm_set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags);
+ toggle_interruptibility(vcpu, ctxt->interruptibility);
+ kvm_set_rflags(vcpu, ctxt->eflags);
kvm_make_request(KVM_REQ_EVENT, vcpu);
memcpy(vcpu->arch.regs, c->regs, sizeof c->regs);
vcpu->arch.emulate_regs_need_sync_to_vcpu = false;
- kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip);
+ kvm_rip_write(vcpu, ctxt->eip);
} else
vcpu->arch.emulate_regs_need_sync_to_vcpu = true;
@@ -5115,8 +5115,7 @@ int emulator_fix_hypercall(struct x86_emulate_ctxt *ctxt)
kvm_x86_ops->patch_hypercall(vcpu, instruction);
- return emulator_write_emulated(&vcpu->arch.emulate_ctxt,
- rip, instruction, 3, NULL);
+ return emulator_write_emulated(ctxt, rip, instruction, 3, NULL);
}
static int move_to_next_stateful_cpuid_entry(struct kvm_vcpu *vcpu, int i)
@@ -5834,21 +5833,21 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason,
bool has_error_code, u32 error_code)
{
- struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
+ struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt;
+ struct decode_cache *c = &ctxt->decode;
int ret;
init_emulate_ctxt(vcpu);
- ret = emulator_task_switch(&vcpu->arch.emulate_ctxt,
- tss_selector, reason, has_error_code,
- error_code);
+ ret = emulator_task_switch(ctxt, tss_selector, reason,
+ has_error_code, error_code);
if (ret)
return EMULATE_FAIL;
memcpy(vcpu->arch.regs, c->regs, sizeof c->regs);
- kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip);
- kvm_set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags);
+ kvm_rip_write(vcpu, ctxt->eip);
+ kvm_set_rflags(vcpu, ctxt->eflags);
kvm_make_request(KVM_REQ_EVENT, vcpu);
return EMULATE_DONE;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 02/10] KVM: x86 emulator: Rename emulate_xxx() to em_xxx()
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
2011-05-29 12:53 ` [PATCH 01/10] KVM: x86 emulator: Use the pointers ctxt and c consistently Takuya Yoshikawa
@ 2011-05-29 12:55 ` Takuya Yoshikawa
2011-05-29 12:56 ` [PATCH 03/10] KVM: x86 emulator: Use opcode::execute for some instructions Takuya Yoshikawa
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 12:55 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
The next patch will change these to be called by opcode::execute.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index c9fc539..756cbbd 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1654,7 +1654,7 @@ static int emulate_iret_real(struct x86_emulate_ctxt *ctxt)
return rc;
}
-static int emulate_iret(struct x86_emulate_ctxt *ctxt)
+static int em_iret(struct x86_emulate_ctxt *ctxt)
{
switch(ctxt->mode) {
case X86EMUL_MODE_REAL:
@@ -1814,7 +1814,7 @@ static int em_grp9(struct x86_emulate_ctxt *ctxt)
return X86EMUL_CONTINUE;
}
-static int emulate_ret_far(struct x86_emulate_ctxt *ctxt)
+static int em_ret_far(struct x86_emulate_ctxt *ctxt)
{
struct decode_cache *c = &ctxt->decode;
int rc;
@@ -1878,7 +1878,7 @@ setup_syscalls_segments(struct x86_emulate_ctxt *ctxt,
ss->p = 1;
}
-static int emulate_syscall(struct x86_emulate_ctxt *ctxt)
+static int em_syscall(struct x86_emulate_ctxt *ctxt)
{
struct decode_cache *c = &ctxt->decode;
struct x86_emulate_ops *ops = ctxt->ops;
@@ -1931,7 +1931,7 @@ static int emulate_syscall(struct x86_emulate_ctxt *ctxt)
return X86EMUL_CONTINUE;
}
-static int emulate_sysenter(struct x86_emulate_ctxt *ctxt)
+static int em_sysenter(struct x86_emulate_ctxt *ctxt)
{
struct decode_cache *c = &ctxt->decode;
struct x86_emulate_ops *ops = ctxt->ops;
@@ -1987,7 +1987,7 @@ static int emulate_sysenter(struct x86_emulate_ctxt *ctxt)
return X86EMUL_CONTINUE;
}
-static int emulate_sysexit(struct x86_emulate_ctxt *ctxt)
+static int em_sysexit(struct x86_emulate_ctxt *ctxt)
{
struct decode_cache *c = &ctxt->decode;
struct x86_emulate_ops *ops = ctxt->ops;
@@ -3932,7 +3932,7 @@ special_insn:
rc = emulate_load_segment(ctxt, VCPU_SREG_DS);
break;
case 0xcb: /* ret far */
- rc = emulate_ret_far(ctxt);
+ rc = em_ret_far(ctxt);
break;
case 0xcc: /* int3 */
irq = 3;
@@ -3949,7 +3949,7 @@ special_insn:
}
break;
case 0xcf: /* iret */
- rc = emulate_iret(ctxt);
+ rc = em_iret(ctxt);
break;
case 0xd0 ... 0xd1: /* Grp2 */
rc = em_grp2(ctxt);
@@ -4113,7 +4113,7 @@ done:
twobyte_insn:
switch (c->b) {
case 0x05: /* syscall */
- rc = emulate_syscall(ctxt);
+ rc = em_syscall(ctxt);
break;
case 0x06:
rc = em_clts(ctxt);
@@ -4175,10 +4175,10 @@ twobyte_insn:
rc = X86EMUL_CONTINUE;
break;
case 0x34: /* sysenter */
- rc = emulate_sysenter(ctxt);
+ rc = em_sysenter(ctxt);
break;
case 0x35: /* sysexit */
- rc = emulate_sysexit(ctxt);
+ rc = em_sysexit(ctxt);
break;
case 0x40 ... 0x4f: /* cmov */
c->dst.val = c->dst.orig_val = c->src.val;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 03/10] KVM: x86 emulator: Use opcode::execute for some instructions
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
2011-05-29 12:53 ` [PATCH 01/10] KVM: x86 emulator: Use the pointers ctxt and c consistently Takuya Yoshikawa
2011-05-29 12:55 ` [PATCH 02/10] KVM: x86 emulator: Rename emulate_xxx() to em_xxx() Takuya Yoshikawa
@ 2011-05-29 12:56 ` Takuya Yoshikawa
2011-05-29 12:57 ` [PATCH 04/10] KVM: x86 emulator: Use opcode::execute for TEST(84/85, A8/A9) Takuya Yoshikawa
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 12:56 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Move the following functions to the opcode tables:
RET (Far return) : CB
IRET : CF
JMP (Jump far) : EA
SYSCALL : 0F 05
CLTS : 0F 06
SYSENTER : 0F 34
SYSEXIT : 0F 35
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 37 ++++++++-----------------------------
1 files changed, 8 insertions(+), 29 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 756cbbd..9134965 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -3167,9 +3167,9 @@ static struct opcode opcode_table[256] = {
D(DstReg | SrcMemFAddr | ModRM | No64), D(DstReg | SrcMemFAddr | ModRM | No64),
G(ByteOp, group11), G(0, group11),
/* 0xC8 - 0xCF */
- N, N, N, D(ImplicitOps | Stack),
+ N, N, N, I(ImplicitOps | Stack, em_ret_far),
D(ImplicitOps), DI(SrcImmByte, intn),
- D(ImplicitOps | No64), DI(ImplicitOps, iret),
+ D(ImplicitOps | No64), II(ImplicitOps, em_iret, iret),
/* 0xD0 - 0xD7 */
D2bv(DstMem | SrcOne | ModRM), D2bv(DstMem | ModRM),
N, N, N, N,
@@ -3181,7 +3181,7 @@ static struct opcode opcode_table[256] = {
D2bvIP(SrcAcc | DstImmUByte, out, check_perm_out),
/* 0xE8 - 0xEF */
D(SrcImm | Stack), D(SrcImm | ImplicitOps),
- D(SrcImmFAddr | No64), D(SrcImmByte | ImplicitOps),
+ I(SrcImmFAddr | No64, em_jmp_far), D(SrcImmByte | ImplicitOps),
D2bvIP(SrcNone | DstAcc, in, check_perm_in),
D2bvIP(SrcAcc | ImplicitOps, out, check_perm_out),
/* 0xF0 - 0xF7 */
@@ -3196,7 +3196,8 @@ static struct opcode opcode_table[256] = {
static struct opcode twobyte_table[256] = {
/* 0x00 - 0x0F */
G(0, group6), GD(0, &group7), N, N,
- N, D(ImplicitOps | VendorSpecific), DI(ImplicitOps | Priv, clts), N,
+ N, I(ImplicitOps | VendorSpecific, em_syscall),
+ II(ImplicitOps | Priv, em_clts, clts), N,
DI(ImplicitOps | Priv, invd), DI(ImplicitOps | Priv, wbinvd), N, N,
N, D(ImplicitOps | ModRM), N, N,
/* 0x10 - 0x1F */
@@ -3213,7 +3214,8 @@ static struct opcode twobyte_table[256] = {
IIP(ImplicitOps, em_rdtsc, rdtsc, check_rdtsc),
DI(ImplicitOps | Priv, rdmsr),
DIP(ImplicitOps | Priv, rdpmc, check_rdpmc),
- D(ImplicitOps | VendorSpecific), D(ImplicitOps | Priv | VendorSpecific),
+ I(ImplicitOps | VendorSpecific, em_sysenter),
+ I(ImplicitOps | Priv | VendorSpecific, em_sysexit),
N, N,
N, N, N, N, N, N, N, N,
/* 0x40 - 0x4F */
@@ -3931,9 +3933,6 @@ special_insn:
case 0xc5: /* lds */
rc = emulate_load_segment(ctxt, VCPU_SREG_DS);
break;
- case 0xcb: /* ret far */
- rc = em_ret_far(ctxt);
- break;
case 0xcc: /* int3 */
irq = 3;
goto do_interrupt;
@@ -3948,9 +3947,6 @@ special_insn:
goto do_interrupt;
}
break;
- case 0xcf: /* iret */
- rc = em_iret(ctxt);
- break;
case 0xd0 ... 0xd1: /* Grp2 */
rc = em_grp2(ctxt);
break;
@@ -3982,12 +3978,7 @@ special_insn:
break;
}
case 0xe9: /* jmp rel */
- goto jmp;
- case 0xea: /* jmp far */
- rc = em_jmp_far(ctxt);
- break;
- case 0xeb:
- jmp: /* jmp rel short */
+ case 0xeb: /* jmp rel short */
jmp_rel(c, c->src.val);
c->dst.type = OP_NONE; /* Disable writeback. */
break;
@@ -4112,12 +4103,6 @@ done:
twobyte_insn:
switch (c->b) {
- case 0x05: /* syscall */
- rc = em_syscall(ctxt);
- break;
- case 0x06:
- rc = em_clts(ctxt);
- break;
case 0x09: /* wbinvd */
(ctxt->ops->wbinvd)(ctxt);
break;
@@ -4174,12 +4159,6 @@ twobyte_insn:
}
rc = X86EMUL_CONTINUE;
break;
- case 0x34: /* sysenter */
- rc = em_sysenter(ctxt);
- break;
- case 0x35: /* sysexit */
- rc = em_sysexit(ctxt);
- break;
case 0x40 ... 0x4f: /* cmov */
c->dst.val = c->dst.orig_val = c->src.val;
if (!test_cc(c->b, ctxt->eflags))
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 04/10] KVM: x86 emulator: Use opcode::execute for TEST(84/85, A8/A9)
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
` (2 preceding siblings ...)
2011-05-29 12:56 ` [PATCH 03/10] KVM: x86 emulator: Use opcode::execute for some instructions Takuya Yoshikawa
@ 2011-05-29 12:57 ` Takuya Yoshikawa
2011-05-29 12:59 ` [PATCH 05/10] KVM: x86 emulator: Use opcode::execute for XCHG(86/87) Takuya Yoshikawa
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 12:57 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 9134965..2e2e87f 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2603,6 +2603,14 @@ static int em_cmp(struct x86_emulate_ctxt *ctxt)
return X86EMUL_CONTINUE;
}
+static int em_test(struct x86_emulate_ctxt *ctxt)
+{
+ struct decode_cache *c = &ctxt->decode;
+
+ emulate_2op_SrcV("test", c->src, c->dst, ctxt->eflags);
+ return X86EMUL_CONTINUE;
+}
+
static int em_imul(struct x86_emulate_ctxt *ctxt)
{
struct decode_cache *c = &ctxt->decode;
@@ -3133,7 +3141,8 @@ static struct opcode opcode_table[256] = {
G(DstMem | SrcImm | ModRM | Group, group1),
G(ByteOp | DstMem | SrcImm | ModRM | No64 | Group, group1),
G(DstMem | SrcImmByte | ModRM | Group, group1),
- D2bv(DstMem | SrcReg | ModRM), D2bv(DstMem | SrcReg | ModRM | Lock),
+ I2bv(DstMem | SrcReg | ModRM, em_test),
+ D2bv(DstMem | SrcReg | ModRM | Lock),
/* 0x88 - 0x8F */
I2bv(DstMem | SrcReg | ModRM | Mov, em_mov),
I2bv(DstReg | SrcMem | ModRM | Mov, em_mov),
@@ -3152,7 +3161,7 @@ static struct opcode opcode_table[256] = {
I2bv(SrcSI | DstDI | Mov | String, em_mov),
I2bv(SrcSI | DstDI | String, em_cmp),
/* 0xA8 - 0xAF */
- D2bv(DstAcc | SrcImm),
+ I2bv(DstAcc | SrcImm, em_test),
I2bv(SrcAcc | DstDI | Mov | String, em_mov),
I2bv(SrcSI | DstAcc | Mov | String, em_mov),
I2bv(SrcAcc | DstDI | String, em_cmp),
@@ -3857,10 +3866,6 @@ special_insn:
if (test_cc(c->b, ctxt->eflags))
jmp_rel(c, c->src.val);
break;
- case 0x84 ... 0x85:
- test:
- emulate_2op_SrcV("test", c->src, c->dst, ctxt->eflags);
- break;
case 0x86 ... 0x87: /* xchg */
xchg:
/* Write back the register source. */
@@ -3916,8 +3921,6 @@ special_insn:
case 8: c->dst.val = (s32)c->dst.val; break;
}
break;
- case 0xa8 ... 0xa9: /* test ax, imm */
- goto test;
case 0xc0 ... 0xc1:
rc = em_grp2(ctxt);
break;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 05/10] KVM: x86 emulator: Use opcode::execute for XCHG(86/87)
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
` (3 preceding siblings ...)
2011-05-29 12:57 ` [PATCH 04/10] KVM: x86 emulator: Use opcode::execute for TEST(84/85, A8/A9) Takuya Yoshikawa
@ 2011-05-29 12:59 ` Takuya Yoshikawa
2011-05-29 13:00 ` [PATCH 06/10] KVM: x86 emulator: Use opcode::execute for RET(C3) Takuya Yoshikawa
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 12:59 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
In addition, replace one "goto xchg" with an em_xchg() call.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 31 +++++++++++++++++--------------
1 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 2e2e87f..16c7507 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2611,6 +2611,20 @@ static int em_test(struct x86_emulate_ctxt *ctxt)
return X86EMUL_CONTINUE;
}
+static int em_xchg(struct x86_emulate_ctxt *ctxt)
+{
+ struct decode_cache *c = &ctxt->decode;
+
+ /* Write back the register source. */
+ c->src.val = c->dst.val;
+ write_register_operand(&c->src);
+
+ /* Write back the memory destination with implicit LOCK prefix. */
+ c->dst.val = c->src.orig_val;
+ c->lock_prefix = 1;
+ return X86EMUL_CONTINUE;
+}
+
static int em_imul(struct x86_emulate_ctxt *ctxt)
{
struct decode_cache *c = &ctxt->decode;
@@ -3142,7 +3156,7 @@ static struct opcode opcode_table[256] = {
G(ByteOp | DstMem | SrcImm | ModRM | No64 | Group, group1),
G(DstMem | SrcImmByte | ModRM | Group, group1),
I2bv(DstMem | SrcReg | ModRM, em_test),
- D2bv(DstMem | SrcReg | ModRM | Lock),
+ I2bv(DstMem | SrcReg | ModRM | Lock, em_xchg),
/* 0x88 - 0x8F */
I2bv(DstMem | SrcReg | ModRM | Mov, em_mov),
I2bv(DstReg | SrcMem | ModRM | Mov, em_mov),
@@ -3866,18 +3880,6 @@ special_insn:
if (test_cc(c->b, ctxt->eflags))
jmp_rel(c, c->src.val);
break;
- case 0x86 ... 0x87: /* xchg */
- xchg:
- /* Write back the register source. */
- c->src.val = c->dst.val;
- write_register_operand(&c->src);
- /*
- * Write back the memory destination with implicit LOCK
- * prefix.
- */
- c->dst.val = c->src.orig_val;
- c->lock_prefix = 1;
- break;
case 0x8c: /* mov r/m, sreg */
if (c->modrm_reg > VCPU_SREG_GS) {
rc = emulate_ud(ctxt);
@@ -3913,7 +3915,8 @@ special_insn:
case 0x90 ... 0x97: /* nop / xchg reg, rax */
if (c->dst.addr.reg == &c->regs[VCPU_REGS_RAX])
break;
- goto xchg;
+ rc = em_xchg(ctxt);
+ break;
case 0x98: /* cbw/cwde/cdqe */
switch (c->op_bytes) {
case 2: c->dst.val = (s8)c->dst.val; break;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 06/10] KVM: x86 emulator: Use opcode::execute for RET(C3)
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
` (4 preceding siblings ...)
2011-05-29 12:59 ` [PATCH 05/10] KVM: x86 emulator: Use opcode::execute for XCHG(86/87) Takuya Yoshikawa
@ 2011-05-29 13:00 ` Takuya Yoshikawa
2011-05-29 13:01 ` [PATCH 07/10] KVM: x86 emulator: Use opcode::execute for MOV(8C/8E) Takuya Yoshikawa
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 13:00 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 16c7507..759ec7c 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1814,6 +1814,16 @@ static int em_grp9(struct x86_emulate_ctxt *ctxt)
return X86EMUL_CONTINUE;
}
+static int em_ret(struct x86_emulate_ctxt *ctxt)
+{
+ struct decode_cache *c = &ctxt->decode;
+
+ c->dst.type = OP_REG;
+ c->dst.addr.reg = &c->eip;
+ c->dst.bytes = c->op_bytes;
+ return em_pop(ctxt);
+}
+
static int em_ret_far(struct x86_emulate_ctxt *ctxt)
{
struct decode_cache *c = &ctxt->decode;
@@ -3186,7 +3196,7 @@ static struct opcode opcode_table[256] = {
/* 0xC0 - 0xC7 */
D2bv(DstMem | SrcImmByte | ModRM),
I(ImplicitOps | Stack | SrcImmU16, em_ret_near_imm),
- D(ImplicitOps | Stack),
+ I(ImplicitOps | Stack, em_ret),
D(DstReg | SrcMemFAddr | ModRM | No64), D(DstReg | SrcMemFAddr | ModRM | No64),
G(ByteOp, group11), G(0, group11),
/* 0xC8 - 0xCF */
@@ -3927,12 +3937,6 @@ special_insn:
case 0xc0 ... 0xc1:
rc = em_grp2(ctxt);
break;
- case 0xc3: /* ret */
- c->dst.type = OP_REG;
- c->dst.addr.reg = &c->eip;
- c->dst.bytes = c->op_bytes;
- rc = em_pop(ctxt);
- break;
case 0xc4: /* les */
rc = emulate_load_segment(ctxt, VCPU_SREG_ES);
break;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 07/10] KVM: x86 emulator: Use opcode::execute for MOV(8C/8E)
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
` (5 preceding siblings ...)
2011-05-29 13:00 ` [PATCH 06/10] KVM: x86 emulator: Use opcode::execute for RET(C3) Takuya Yoshikawa
@ 2011-05-29 13:01 ` Takuya Yoshikawa
2011-05-29 13:02 ` [PATCH 08/10] KVM: x86 emulator: Clean up INT n/INTO/INT 3(CC/CD/CE) Takuya Yoshikawa
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 13:01 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Different functions for those which take segment register operands.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 59 +++++++++++++++++++++++++----------------------
1 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 759ec7c..7a06fb2 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2681,6 +2681,33 @@ static int em_mov(struct x86_emulate_ctxt *ctxt)
return X86EMUL_CONTINUE;
}
+static int em_mov_rm_sreg(struct x86_emulate_ctxt *ctxt)
+{
+ struct decode_cache *c = &ctxt->decode;
+
+ if (c->modrm_reg > VCPU_SREG_GS)
+ return emulate_ud(ctxt);
+
+ c->dst.val = get_segment_selector(ctxt, c->modrm_reg);
+ return X86EMUL_CONTINUE;
+}
+
+static int em_mov_sreg_rm(struct x86_emulate_ctxt *ctxt)
+{
+ struct decode_cache *c = &ctxt->decode;
+ u16 sel = c->src.val;
+
+ if (c->modrm_reg == VCPU_SREG_CS || c->modrm_reg > VCPU_SREG_GS)
+ return emulate_ud(ctxt);
+
+ if (c->modrm_reg == VCPU_SREG_SS)
+ ctxt->interruptibility = KVM_X86_SHADOW_INT_MOV_SS;
+
+ /* Disable writeback. */
+ c->dst.type = OP_NONE;
+ return load_segment_descriptor(ctxt, sel, c->modrm_reg);
+}
+
static int em_movdqu(struct x86_emulate_ctxt *ctxt)
{
struct decode_cache *c = &ctxt->decode;
@@ -3170,8 +3197,10 @@ static struct opcode opcode_table[256] = {
/* 0x88 - 0x8F */
I2bv(DstMem | SrcReg | ModRM | Mov, em_mov),
I2bv(DstReg | SrcMem | ModRM | Mov, em_mov),
- D(DstMem | SrcNone | ModRM | Mov), D(ModRM | SrcMem | NoAccess | DstReg),
- D(ImplicitOps | SrcMem16 | ModRM), G(0, group1A),
+ I(DstMem | SrcNone | ModRM | Mov, em_mov_rm_sreg),
+ D(ModRM | SrcMem | NoAccess | DstReg),
+ I(ImplicitOps | SrcMem16 | ModRM, em_mov_sreg_rm),
+ G(0, group1A),
/* 0x90 - 0x97 */
DI(SrcAcc | DstReg, pause), X7(D(SrcAcc | DstReg)),
/* 0x98 - 0x9F */
@@ -3890,35 +3919,9 @@ special_insn:
if (test_cc(c->b, ctxt->eflags))
jmp_rel(c, c->src.val);
break;
- case 0x8c: /* mov r/m, sreg */
- if (c->modrm_reg > VCPU_SREG_GS) {
- rc = emulate_ud(ctxt);
- goto done;
- }
- c->dst.val = get_segment_selector(ctxt, c->modrm_reg);
- break;
case 0x8d: /* lea r16/r32, m */
c->dst.val = c->src.addr.mem.ea;
break;
- case 0x8e: { /* mov seg, r/m16 */
- uint16_t sel;
-
- sel = c->src.val;
-
- if (c->modrm_reg == VCPU_SREG_CS ||
- c->modrm_reg > VCPU_SREG_GS) {
- rc = emulate_ud(ctxt);
- goto done;
- }
-
- if (c->modrm_reg == VCPU_SREG_SS)
- ctxt->interruptibility = KVM_X86_SHADOW_INT_MOV_SS;
-
- rc = load_segment_descriptor(ctxt, sel, c->modrm_reg);
-
- c->dst.type = OP_NONE; /* Disable writeback. */
- break;
- }
case 0x8f: /* pop (sole member of Grp1a) */
rc = em_grp1a(ctxt);
break;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 08/10] KVM: x86 emulator: Clean up INT n/INTO/INT 3(CC/CD/CE)
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
` (6 preceding siblings ...)
2011-05-29 13:01 ` [PATCH 07/10] KVM: x86 emulator: Use opcode::execute for MOV(8C/8E) Takuya Yoshikawa
@ 2011-05-29 13:02 ` Takuya Yoshikawa
2011-05-29 13:04 ` [PATCH 09/10] KVM: x86 emulator: Use opcode::execute for LOOP/JCXZ Takuya Yoshikawa
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 13:02 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Call emulate_int() directly to avoid spaghetti goto's.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 15 +++++----------
1 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 7a06fb2..a5d067c 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -3753,7 +3753,6 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
struct decode_cache *c = &ctxt->decode;
int rc = X86EMUL_CONTINUE;
int saved_dst_type = c->dst.type;
- int irq; /* Used for int 3, int, and into */
c->mem_read.pos = 0;
@@ -3947,18 +3946,14 @@ special_insn:
rc = emulate_load_segment(ctxt, VCPU_SREG_DS);
break;
case 0xcc: /* int3 */
- irq = 3;
- goto do_interrupt;
+ rc = emulate_int(ctxt, 3);
+ break;
case 0xcd: /* int n */
- irq = c->src.val;
- do_interrupt:
- rc = emulate_int(ctxt, irq);
+ rc = emulate_int(ctxt, c->src.val);
break;
case 0xce: /* into */
- if (ctxt->eflags & EFLG_OF) {
- irq = 4;
- goto do_interrupt;
- }
+ if (ctxt->eflags & EFLG_OF)
+ rc = emulate_int(ctxt, 4);
break;
case 0xd0 ... 0xd1: /* Grp2 */
rc = em_grp2(ctxt);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 09/10] KVM: x86 emulator: Use opcode::execute for LOOP/JCXZ
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
` (7 preceding siblings ...)
2011-05-29 13:02 ` [PATCH 08/10] KVM: x86 emulator: Clean up INT n/INTO/INT 3(CC/CD/CE) Takuya Yoshikawa
@ 2011-05-29 13:04 ` Takuya Yoshikawa
2011-05-29 13:05 ` [PATCH 10/10] KVM: x86 emulator: Use opcode::execute for CLI/STI(FA/FB) Takuya Yoshikawa
2011-05-31 18:33 ` [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Marcelo Tosatti
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 13:04 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
LOOP/LOOPcc : E0-E2
JCXZ/JECXZ/JRCXZ : E3
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 35 ++++++++++++++++++++++++-----------
1 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index a5d067c..2bf3415 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2822,6 +2822,28 @@ static int em_lmsw(struct x86_emulate_ctxt *ctxt)
return X86EMUL_CONTINUE;
}
+static int em_loop(struct x86_emulate_ctxt *ctxt)
+{
+ struct decode_cache *c = &ctxt->decode;
+
+ register_address_increment(c, &c->regs[VCPU_REGS_RCX], -1);
+ if ((address_mask(c, c->regs[VCPU_REGS_RCX]) != 0) &&
+ (c->b == 0xe2 || test_cc(c->b ^ 0x5, ctxt->eflags)))
+ jmp_rel(c, c->src.val);
+
+ return X86EMUL_CONTINUE;
+}
+
+static int em_jcxz(struct x86_emulate_ctxt *ctxt)
+{
+ struct decode_cache *c = &ctxt->decode;
+
+ if (address_mask(c, c->regs[VCPU_REGS_RCX]) == 0)
+ jmp_rel(c, c->src.val);
+
+ return X86EMUL_CONTINUE;
+}
+
static bool valid_cr(int nr)
{
switch (nr) {
@@ -3238,7 +3260,8 @@ static struct opcode opcode_table[256] = {
/* 0xD8 - 0xDF */
N, N, N, N, N, N, N, N,
/* 0xE0 - 0xE7 */
- X4(D(SrcImmByte)),
+ X3(I(SrcImmByte, em_loop)),
+ I(SrcImmByte, em_jcxz),
D2bvIP(SrcImmUByte | DstAcc, in, check_perm_in),
D2bvIP(SrcAcc | DstImmUByte, out, check_perm_out),
/* 0xE8 - 0xEF */
@@ -3962,16 +3985,6 @@ special_insn:
c->src.val = c->regs[VCPU_REGS_RCX];
rc = em_grp2(ctxt);
break;
- case 0xe0 ... 0xe2: /* loop/loopz/loopnz */
- register_address_increment(c, &c->regs[VCPU_REGS_RCX], -1);
- if (address_mask(c, c->regs[VCPU_REGS_RCX]) != 0 &&
- (c->b == 0xe2 || test_cc(c->b ^ 0x5, ctxt->eflags)))
- jmp_rel(c, c->src.val);
- break;
- case 0xe3: /* jcxz/jecxz/jrcxz */
- if (address_mask(c, c->regs[VCPU_REGS_RCX]) == 0)
- jmp_rel(c, c->src.val);
- break;
case 0xe4: /* inb */
case 0xe5: /* in */
goto do_io_in;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 10/10] KVM: x86 emulator: Use opcode::execute for CLI/STI(FA/FB)
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
` (8 preceding siblings ...)
2011-05-29 13:04 ` [PATCH 09/10] KVM: x86 emulator: Use opcode::execute for LOOP/JCXZ Takuya Yoshikawa
@ 2011-05-29 13:05 ` Takuya Yoshikawa
2011-05-31 18:33 ` [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Marcelo Tosatti
10 siblings, 0 replies; 12+ messages in thread
From: Takuya Yoshikawa @ 2011-05-29 13:05 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm, yoshikawa.takuya, gleb
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/emulate.c | 38 +++++++++++++++++++++-----------------
1 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 2bf3415..e0c83a7 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2844,6 +2844,25 @@ static int em_jcxz(struct x86_emulate_ctxt *ctxt)
return X86EMUL_CONTINUE;
}
+static int em_cli(struct x86_emulate_ctxt *ctxt)
+{
+ if (emulator_bad_iopl(ctxt))
+ return emulate_gp(ctxt, 0);
+
+ ctxt->eflags &= ~X86_EFLAGS_IF;
+ return X86EMUL_CONTINUE;
+}
+
+static int em_sti(struct x86_emulate_ctxt *ctxt)
+{
+ if (emulator_bad_iopl(ctxt))
+ return emulate_gp(ctxt, 0);
+
+ ctxt->interruptibility = KVM_X86_SHADOW_INT_STI;
+ ctxt->eflags |= X86_EFLAGS_IF;
+ return X86EMUL_CONTINUE;
+}
+
static bool valid_cr(int nr)
{
switch (nr) {
@@ -3274,7 +3293,8 @@ static struct opcode opcode_table[256] = {
DI(ImplicitOps | Priv, hlt), D(ImplicitOps),
G(ByteOp, group3), G(0, group3),
/* 0xF8 - 0xFF */
- D(ImplicitOps), D(ImplicitOps), D(ImplicitOps), D(ImplicitOps),
+ D(ImplicitOps), D(ImplicitOps),
+ I(ImplicitOps, em_cli), I(ImplicitOps, em_sti),
D(ImplicitOps), D(ImplicitOps), G(0, group4), G(0, group5),
};
@@ -4035,22 +4055,6 @@ special_insn:
case 0xf9: /* stc */
ctxt->eflags |= EFLG_CF;
break;
- case 0xfa: /* cli */
- if (emulator_bad_iopl(ctxt)) {
- rc = emulate_gp(ctxt, 0);
- goto done;
- } else
- ctxt->eflags &= ~X86_EFLAGS_IF;
- break;
- case 0xfb: /* sti */
- if (emulator_bad_iopl(ctxt)) {
- rc = emulate_gp(ctxt, 0);
- goto done;
- } else {
- ctxt->interruptibility = KVM_X86_SHADOW_INT_STI;
- ctxt->eflags |= X86_EFLAGS_IF;
- }
- break;
case 0xfc: /* cld */
ctxt->eflags &= ~EFLG_DF;
break;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute
2011-05-29 12:52 [PATCH 00/10] KVM: x86 emulator: Some cleanups and conversion to opcode::execute Takuya Yoshikawa
` (9 preceding siblings ...)
2011-05-29 13:05 ` [PATCH 10/10] KVM: x86 emulator: Use opcode::execute for CLI/STI(FA/FB) Takuya Yoshikawa
@ 2011-05-31 18:33 ` Marcelo Tosatti
10 siblings, 0 replies; 12+ messages in thread
From: Marcelo Tosatti @ 2011-05-31 18:33 UTC (permalink / raw)
To: Takuya Yoshikawa; +Cc: avi, kvm, yoshikawa.takuya, gleb
On Sun, May 29, 2011 at 09:52:00PM +0900, Takuya Yoshikawa wrote:
> The patch set does not change anything functionally.
>
> Once the code becomes a bit tidier, I will try more performance related
> changes.
>
> Takuya
Applied, thanks.
^ permalink raw reply [flat|nested] 12+ messages in thread