KVM: x86 emulator: Unused opt removal and some cleanups
cover KVM: x86 emulator: Unused opt removal and some cleanups
Patches 0-4: Just remove unused opt
Patch 5: grpX emulation cleanup
Patch 6: jmp far emulation cleanup
Some functions introduced in patch 5/6 will be called by opcode::execute later.
Takuya
PATCH 1/6 KVM: x86 emulator: Remove unused opt from seg_override()
From: Takuya Yoshikawa <[email protected]>
In addition, one comma at the end of a statement is replaced with a semicolon.
--- arch/x86/kvm/emulate.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/kvm/emulate.c +3 -4
@@ -500,7 +500,6 @@ static unsigned long seg_base(struct x86_emulate_ctxt *ctxt, }static unsigned seg_override (struct x86_emulate_ctxt *ctxt, -struct x86_emulate_ops *ops,struct decode_cache *c) {if (!c->has_seg_override)
@@ -3527,7 +3526,7 @@ done_prefixes:if (!c->has_seg_override)set_seg_override (c,VCPU_SREG_DS ); - memop.addr.mem.seg =seg_override (ctxt, ops, c); + memop.addr.mem.seg =seg_override (ctxt, c);if (memop.type ==OP_MEM && c->ad_bytes !=8 ) memop.addr.mem.ea = (u32 )memop.addr.mem.ea;
@@ -3587,7 +3586,7 @@ done_prefixes: c->src.bytes = (c->d & ByteOp) ?1 : c->op_bytes; c->src.addr.mem.ea =register_address (c, c->regs[VCPU_REGS_RSI ]); - c->src.addr.mem.seg =seg_override (ctxt, ops, c), + c->src.addr.mem.seg =seg_override (ctxt, c); c->src.val =0 ;break ;case SrcImmFAddr:
@@ -4103,7 +4102,7 @@ writeback: c->dst.type = saved_dst_type;if ((c->d & SrcMask) == SrcSI) -string_addr_inc (ctxt,seg_override (ctxt, ops, c), +string_addr_inc (ctxt,seg_override (ctxt, c),VCPU_REGS_RSI , &c->src);if ((c->d & DstMask) == DstDI)
Signature · 1 line
1.7.1
PATCH 2/6 KVM: x86 emulator: Remove unused opt from read_descriptor()
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
--- arch/x86/kvm/emulate.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
arch/x86/kvm/emulate.c +3 -5
@@ -729,7 +729,6 @@ static void *decode_register(u8 modrm_reg, unsigned long *regs, }static int read_descriptor (struct x86_emulate_ctxt *ctxt, -struct x86_emulate_ops *ops,struct segmented_address addr,u16 *size,unsigned long *address,int op_bytes) {
@@ -2720,7 +2719,7 @@ static int em_lgdt(struct x86_emulate_ctxt *ctxt)struct desc_ptr desc_ptr;int rc; - rc =read_descriptor (ctxt, ctxt->ops, c->src.addr.mem, + rc =read_descriptor (ctxt, c->src.addr.mem, &desc_ptr.size, &desc_ptr.address, c->op_bytes);if (rc !=X86EMUL_CONTINUE )
@@ -2749,9 +2748,8 @@ static int em_lidt(struct x86_emulate_ctxt *ctxt)struct desc_ptr desc_ptr;int rc; - rc =read_descriptor (ctxt, ctxt->ops, c->src.addr.mem, - &desc_ptr.size, - &desc_ptr.address, + rc =read_descriptor (ctxt, c->src.addr.mem, + &desc_ptr.size, &desc_ptr.address, c->op_bytes);if (rc !=X86EMUL_CONTINUE )return rc;
Signature · 1 line
1.7.1
PATCH 3/6 KVM: x86 emulator: Remove unused opt from writeback()
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
Remove inline at this chance.
--- arch/x86/kvm/emulate.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
arch/x86/kvm/emulate.c +2 -3
@@ -1351,8 +1351,7 @@ static void write_register_operand(struct operand *op) } } -static inline int writeback (struct x86_emulate_ctxt *ctxt, -struct x86_emulate_ops *ops) +static int writeback (struct x86_emulate_ctxt *ctxt) {int rc;struct decode_cache *c = &ctxt->decode;
@@ -4089,7 +4088,7 @@ special_insn: goto done; writeback: - rc =writeback (ctxt, ops); + rc =writeback (ctxt);if (rc !=X86EMUL_CONTINUE ) goto done;
Signature · 1 line
1.7.1
PATCH 4/6 KVM: x86 emulator: Remove unused opt from emulate_pop()
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
The opt of emulate_grp1a() is also removed.
--- arch/x86/kvm/emulate.c | 28 +++++++++++++--------------- 1 files changed, 13 insertions(+), 15 deletions(-)
arch/x86/kvm/emulate.c +13 -15
@@ -1402,7 +1402,6 @@ static int em_push(struct x86_emulate_ctxt *ctxt) }static int emulate_pop (struct x86_emulate_ctxt *ctxt, -struct x86_emulate_ops *ops,void *dest,int len) {struct decode_cache *c = &ctxt->decode;
@@ -1423,7 +1422,7 @@ static int em_pop(struct x86_emulate_ctxt *ctxt) {struct decode_cache *c = &ctxt->decode; -return emulate_pop (ctxt, ctxt->ops, &c->dst.val, c->op_bytes); +return emulate_pop (ctxt, &c->dst.val, c->op_bytes); } static int emulate_popf(struct x86_emulate_ctxt *ctxt,
@@ -1435,7 +1434,7 @@ static int emulate_popf(struct x86_emulate_ctxt *ctxt,int iopl = (ctxt->eflags &X86_EFLAGS_IOPL ) >>IOPL_SHIFT ;int cpl = ops->cpl (ctxt); - rc =emulate_pop (ctxt, ops, &val, len); + rc =emulate_pop (ctxt, &val, len);if (rc !=X86EMUL_CONTINUE )return rc;
@@ -1494,7 +1493,7 @@ static int emulate_pop_sreg(struct x86_emulate_ctxt *ctxt,unsigned long selector;int rc; - rc =emulate_pop (ctxt, ops, &selector, c->op_bytes); + rc =emulate_pop (ctxt, &selector, c->op_bytes);if (rc !=X86EMUL_CONTINUE )return rc;
@@ -1544,7 +1543,7 @@ static int em_popa(struct x86_emulate_ctxt *ctxt) --reg; } - rc =emulate_pop (ctxt, ctxt->ops, &c->regs[reg], c->op_bytes); + rc =emulate_pop (ctxt, &c->regs[reg], c->op_bytes);if (rc !=X86EMUL_CONTINUE )break ; --reg;
@@ -1633,7 +1632,7 @@ static int emulate_iret_real(struct x86_emulate_ctxt *ctxt,/* TODO: Add stack limit check */ - rc =emulate_pop (ctxt, ops, &temp_eip, c->op_bytes); + rc =emulate_pop (ctxt, &temp_eip, c->op_bytes);if (rc !=X86EMUL_CONTINUE )return rc;
@@ -1641,12 +1640,12 @@ static int emulate_iret_real(struct x86_emulate_ctxt *ctxt,if (temp_eip & ~0xffff )return emulate_gp (ctxt,0 ); - rc =emulate_pop (ctxt, ops, &cs, c->op_bytes); + rc =emulate_pop (ctxt, &cs, c->op_bytes);if (rc !=X86EMUL_CONTINUE )return rc; - rc =emulate_pop (ctxt, ops, &temp_eflags, c->op_bytes); + rc =emulate_pop (ctxt, &temp_eflags, c->op_bytes);if (rc !=X86EMUL_CONTINUE )return rc;
@@ -1688,12 +1687,11 @@ static inline int emulate_iret(struct x86_emulate_ctxt *ctxt, } } -static inline int emulate_grp1a (struct x86_emulate_ctxt *ctxt, -struct x86_emulate_ops *ops) +static inline int emulate_grp1a (struct x86_emulate_ctxt *ctxt) {struct decode_cache *c = &ctxt->decode; -return emulate_pop (ctxt, ops, &c->dst.val, c->dst.bytes); +return emulate_pop (ctxt, &c->dst.val, c->dst.bytes); }static inline void emulate_grp2 (struct x86_emulate_ctxt *ctxt)
@@ -1822,12 +1820,12 @@ static int emulate_ret_far(struct x86_emulate_ctxt *ctxt,int rc;unsigned long cs; - rc =emulate_pop (ctxt, ops, &c->eip, c->op_bytes); + rc =emulate_pop (ctxt, &c->eip, c->op_bytes);if (rc !=X86EMUL_CONTINUE )return rc;if (c->op_bytes ==4 ) c->eip = (u32 )c->eip; - rc =emulate_pop (ctxt, ops, &cs, c->op_bytes); + rc =emulate_pop (ctxt, &cs, c->op_bytes);if (rc !=X86EMUL_CONTINUE )return rc; rc =load_segment_descriptor (ctxt, ops, (u16 )cs,VCPU_SREG_CS );
@@ -2543,7 +2541,7 @@ static int em_ret_near_imm(struct x86_emulate_ctxt *ctxt) c->dst.type =OP_REG ; c->dst.addr.reg = &c->eip; c->dst.bytes = c->op_bytes; - rc =emulate_pop (ctxt, ctxt->ops, &c->dst.val, c->op_bytes); + rc =emulate_pop (ctxt, &c->dst.val, c->op_bytes);if (rc !=X86EMUL_CONTINUE )return rc;register_address_increment (c, &c->regs[VCPU_REGS_RSP ], c->src.val);
@@ -3918,7 +3916,7 @@ special_insn:break ; }case 0x8f :/* pop (sole member of Grp1a) */ - rc =emulate_grp1a (ctxt, ops); + rc =emulate_grp1a (ctxt);break ; case 0x90 ... 0x97: /* nop / xchg reg, rax */if (c->dst.addr.reg == &c->regs[VCPU_REGS_RAX ])
Signature · 1 line
1.7.1
PATCH 5/6 KVM: x86 emulator: Rename emulate_grpX() to em_grpX()
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
The prototypes are changed appropriately.
We also replaces "goto grp45;" with simple em_grp45() call.
--- arch/x86/kvm/emulate.c | 31 +++++++++++++++---------------- 1 files changed, 15 insertions(+), 16 deletions(-)
arch/x86/kvm/emulate.c +15 -16
@@ -1687,14 +1687,14 @@ static inline int emulate_iret(struct x86_emulate_ctxt *ctxt, } } -static inline int emulate_grp1a (struct x86_emulate_ctxt *ctxt) +static int em_grp1a (struct x86_emulate_ctxt *ctxt) {struct decode_cache *c = &ctxt->decode;return emulate_pop (ctxt, &c->dst.val, c->dst.bytes); } -static inline void emulate_grp2 (struct x86_emulate_ctxt *ctxt) +static int em_grp2 (struct x86_emulate_ctxt *ctxt) {struct decode_cache *c = &ctxt->decode;switch (c->modrm_reg) {
@@ -1721,10 +1721,10 @@ static inline void emulate_grp2(struct x86_emulate_ctxt *ctxt)emulate_2op_SrcB ("sar" , c->src, c->dst, ctxt->eflags);break ; } +return X86EMUL_CONTINUE ; } -static inline int emulate_grp3 (struct x86_emulate_ctxt *ctxt, -struct x86_emulate_ops *ops) +static int em_grp3 (struct x86_emulate_ctxt *ctxt) {struct decode_cache *c = &ctxt->decode;unsigned long *rax = &c->regs[VCPU_REGS_RAX ];
@@ -1763,7 +1763,7 @@ static inline int emulate_grp3(struct x86_emulate_ctxt *ctxt,return X86EMUL_CONTINUE ; } -static int emulate_grp45 (struct x86_emulate_ctxt *ctxt) +static int em_grp45 (struct x86_emulate_ctxt *ctxt) {struct decode_cache *c = &ctxt->decode;int rc =X86EMUL_CONTINUE ;
@@ -1793,8 +1793,7 @@ static int emulate_grp45(struct x86_emulate_ctxt *ctxt)return rc; } -static inline int emulate_grp9 (struct x86_emulate_ctxt *ctxt, -struct x86_emulate_ops *ops) +static int em_grp9 (struct x86_emulate_ctxt *ctxt) {struct decode_cache *c = &ctxt->decode;u64 old = c->dst.orig_val64;
@@ -3916,7 +3915,7 @@ special_insn:break ; }case 0x8f :/* pop (sole member of Grp1a) */ - rc =emulate_grp1a (ctxt); + rc =em_grp1a (ctxt);break ; case 0x90 ... 0x97: /* nop / xchg reg, rax */if (c->dst.addr.reg == &c->regs[VCPU_REGS_RAX ])
@@ -3932,7 +3931,7 @@ special_insn: case 0xa8 ... 0xa9: /* test ax, imm */ goto test; case 0xc0 ... 0xc1: -emulate_grp2 (ctxt); + rc =em_grp2 (ctxt);break ;case 0xc3 :/* ret */ c->dst.type =OP_REG ;
@@ -3967,11 +3966,11 @@ special_insn: rc =emulate_iret (ctxt, ops);break ; case 0xd0 ... 0xd1: /* Grp2 */ -emulate_grp2 (ctxt); + rc =em_grp2 (ctxt);break ; case 0xd2 ... 0xd3: /* Grp2 */ c->src.val = c->regs[VCPU_REGS_RCX ]; -emulate_grp2 (ctxt); + rc =em_grp2 (ctxt);break ; case 0xe0 ... 0xe2: /* loop/loopz/loopnz */register_address_increment (c, &c->regs[VCPU_REGS_RCX ],-1 );
@@ -4040,7 +4039,7 @@ special_insn: ctxt->eflags ^=EFLG_CF ;break ; case 0xf6 ... 0xf7: /* Grp3 */ - rc =emulate_grp3 (ctxt, ops); + rc =em_grp3 (ctxt);break ;case 0xf8 :/* clc */ ctxt->eflags &= ~EFLG_CF ;
@@ -4071,13 +4070,13 @@ special_insn: ctxt->eflags |=EFLG_DF ;break ;case 0xfe :/* Grp4 */ - grp45: - rc =emulate_grp45 (ctxt); + rc =em_grp45 (ctxt);break ;case 0xff :/* Grp5 */ if (c->modrm_reg ==5 ) goto jump_far; - goto grp45; + rc =em_grp45 (ctxt); +break ;default : goto cannot_emulate; }
@@ -4344,7 +4343,7 @@ twobyte_insn: (u64 ) c->src.val;break ;case 0xc7 :/* Grp9 (cmpxchg8b) */ - rc =emulate_grp9 (ctxt, ops); + rc =em_grp9 (ctxt);break ;default : goto cannot_emulate;
Signature · 1 line
1.7.1
PATCH 6/6 KVM: x86 emulator: Make jmp far emulation into a separate function
In reply to Takuya YoshikawaFrom: Takuya Yoshikawa <[email protected]>
We introduce em_jmp_far().
We also call this from em_grp45() to stop treating modrm_reg == 5 case separately in the group 5 emulation.
--- arch/x86/kvm/emulate.c | 36 ++++++++++++++++++++++-------------- 1 files changed, 22 insertions(+), 14 deletions(-)
arch/x86/kvm/emulate.c +22 -14
@@ -1687,6 +1687,23 @@ static inline int emulate_iret(struct x86_emulate_ctxt *ctxt, } } +static int em_jmp_far (struct x86_emulate_ctxt *ctxt) +{ +struct decode_cache *c = &ctxt->decode; +int rc; +unsigned short sel; + +memcpy (&sel, c->src.valptr + c->op_bytes,2 ); + + rc =load_segment_descriptor (ctxt, ctxt->ops, sel,VCPU_SREG_CS ); +if (rc !=X86EMUL_CONTINUE ) +return rc; + + c->eip =0 ; +memcpy (&c->eip, c->src.valptr, c->op_bytes); +return X86EMUL_CONTINUE ; +} +static int em_grp1a (struct x86_emulate_ctxt *ctxt) {struct decode_cache *c = &ctxt->decode;
@@ -1786,6 +1803,9 @@ static int em_grp45(struct x86_emulate_ctxt *ctxt)case 4 :/* jmp abs */ c->eip = c->src.val;break ; +case 5 :/* jmp far */ + rc =em_jmp_far (ctxt); +break ;case 6 :/* push */ rc =em_push (ctxt);break ;
@@ -3997,19 +4017,9 @@ special_insn: }case 0xe9 :/* jmp rel */ goto jmp; -case 0xea : {/* jmp far */ -unsigned short sel; - jump_far: -memcpy (&sel, c->src.valptr + c->op_bytes,2 ); - - rc =load_segment_descriptor (ctxt, ops, sel,VCPU_SREG_CS ); -if (rc !=X86EMUL_CONTINUE ) - goto done; - - c->eip =0 ; -memcpy (&c->eip, c->src.valptr, c->op_bytes); +case 0xea :/* jmp far */ + rc =em_jmp_far (ctxt);break ; - }case 0xeb : jmp:/* jmp rel short */ jmp_rel (c, c->src.val);
@@ -4073,8 +4083,6 @@ special_insn: rc =em_grp45 (ctxt);break ;case 0xff :/* Grp5 */ -if (c->modrm_reg ==5 ) - goto jump_far; rc =em_grp45 (ctxt);break ;default :
Signature · 1 line
1.7.1
Avi Kivity
AppliedQuoted 6 lines · Takuya Yoshikawa
Patches 0-4: Just remove unused opt
Patch 5: grpX emulation cleanup
Patch 6: jmp far emulation cleanupSome functions introduced in patch 5/6 will be called by
opcode::executelater.
Applied, thanks.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.