KVM: x86 emulator: Some cleanups and conversion to opcode::execute
cover KVM: x86 emulator: Some cleanups and conversion to opcode::execute
The patch set does not change anything functionally.
Once the code becomes a bit tidier, I will try more performance related changes.
Takuya
PATCH 1/10 KVM: x86 emulator: Use the pointers ctxt and c consistently
From: Takuya Yoshikawa <[email protected]>
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.
--- arch/x86/kvm/emulate.c | 6 ++-- arch/x86/kvm/x86.c | 59 +++++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 33 deletions(-)
arch/x86/kvm/emulate.c +3 -3
@@ -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 */
arch/x86/kvm/x86.c +29 -30
137 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 2/10 KVM: x86 emulator: Rename emulate_xxx() to em_xxx()
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
The next patch will change these to be called by opcode::execute.
--- arch/x86/kvm/emulate.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/kvm/emulate.c +10 -10
@@ -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;
Signature · 1 line
1.7.4.1
PATCH 3/10 KVM: x86 emulator: Use opcode::execute for some instructions
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
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
--- arch/x86/kvm/emulate.c | 37 ++++++++----------------------------- 1 files changed, 8 insertions(+), 29 deletions(-)
arch/x86/kvm/emulate.c +8 -29
@@ -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))
Signature · 1 line
1.7.4.1
PATCH 4/10 KVM: x86 emulator: Use opcode::execute for TEST(84/85, A8/A9)
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
--- arch/x86/kvm/emulate.c | 19 +++++++++++-------- 1 files changed, 11 insertions(+), 8 deletions(-)
arch/x86/kvm/emulate.c +11 -8
@@ -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 ;
Signature · 1 line
1.7.4.1
PATCH 5/10 KVM: x86 emulator: Use opcode::execute for XCHG(86/87)
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
In addition, replace one "goto xchg" with an em_xchg() call.
--- arch/x86/kvm/emulate.c | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-)
arch/x86/kvm/emulate.c +17 -14
@@ -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 ;
Signature · 1 line
1.7.4.1
PATCH 6/10 KVM: x86 emulator: Use opcode::execute for RET(C3)
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
--- arch/x86/kvm/emulate.c | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-)
arch/x86/kvm/emulate.c +11 -7
@@ -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 ;
Signature · 1 line
1.7.4.1
PATCH 7/10 KVM: x86 emulator: Use opcode::execute for MOV(8C/8E)
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
Different functions for those which take segment register operands.
--- arch/x86/kvm/emulate.c | 59 +++++++++++++++++++++++++---------------------- 1 files changed, 31 insertions(+), 28 deletions(-)
arch/x86/kvm/emulate.c +31 -28
@@ -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 ;
Signature · 1 line
1.7.4.1
PATCH 8/10 KVM: x86 emulator: Clean up INT n/INTO/INT 3(CC/CD/CE)
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
Call emulate_int() directly to avoid spaghetti goto's.
--- arch/x86/kvm/emulate.c | 15 +++++---------- 1 files changed, 5 insertions(+), 10 deletions(-)
arch/x86/kvm/emulate.c +5 -10
@@ -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);
Signature · 1 line
1.7.4.1
PATCH 9/10 KVM: x86 emulator: Use opcode::execute for LOOP/JCXZ
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
LOOP/LOOPcc : E0-E2
JCXZ/JECXZ/JRCXZ : E3
--- arch/x86/kvm/emulate.c | 35 ++++++++++++++++++++++++----------- 1 files changed, 24 insertions(+), 11 deletions(-)
arch/x86/kvm/emulate.c +24 -11
@@ -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;
Signature · 1 line
1.7.4.1
PATCH 10/10 KVM: x86 emulator: Use opcode::execute for CLI/STI(FA/FB)
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
--- arch/x86/kvm/emulate.c | 38 +++++++++++++++++++++----------------- 1 files changed, 21 insertions(+), 17 deletions(-)
arch/x86/kvm/emulate.c +21 -17
@@ -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 ;
Signature · 1 line
1.7.4.1
Marcelo Tosatti
AppliedQuoted 6 lines · Takuya Yoshikawa
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.