Skip to content

Commit c44b4c6

Browse files
whitebrandybonzini
authored andcommitted
KVM: emulate: clean up initializations in init_decode_cache
A lot of initializations are unnecessary as they get set to appropriate values before actually being used. Optimize placement of fields in x86_emulate_ctxt Signed-off-by: Bandan Das <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 02357bd commit c44b4c6

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

arch/x86/include/asm/kvm_emulate.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,30 +288,32 @@ struct x86_emulate_ctxt {
288288
u8 opcode_len;
289289
u8 b;
290290
u8 intercept;
291-
u8 lock_prefix;
292-
u8 rep_prefix;
293291
u8 op_bytes;
294292
u8 ad_bytes;
295-
u8 rex_prefix;
296293
struct operand src;
297294
struct operand src2;
298295
struct operand dst;
299-
bool has_seg_override;
300-
u8 seg_override;
301-
u64 d;
302296
int (*execute)(struct x86_emulate_ctxt *ctxt);
303297
int (*check_perm)(struct x86_emulate_ctxt *ctxt);
298+
bool has_seg_override;
299+
bool rip_relative;
300+
u8 rex_prefix;
301+
u8 lock_prefix;
302+
u8 rep_prefix;
303+
u8 seg_override;
304+
/* bitmaps of registers in _regs[] that can be read */
305+
u32 regs_valid;
306+
/* bitmaps of registers in _regs[] that have been written */
307+
u32 regs_dirty;
304308
/* modrm */
305309
u8 modrm;
306310
u8 modrm_mod;
307311
u8 modrm_reg;
308312
u8 modrm_rm;
309313
u8 modrm_seg;
310-
bool rip_relative;
314+
u64 d;
311315
unsigned long _eip;
312316
struct operand memop;
313-
u32 regs_valid; /* bitmaps of registers in _regs[] that can be read */
314-
u32 regs_dirty; /* bitmaps of registers in _regs[] that have been written */
315317
/* Fields above regs are cleared together. */
316318
unsigned long _regs[NR_VCPU_REGS];
317319
struct operand *memopp;

arch/x86/kvm/emulate.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4534,14 +4534,11 @@ static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *))
45344534

45354535
void init_decode_cache(struct x86_emulate_ctxt *ctxt)
45364536
{
4537-
memset(&ctxt->opcode_len, 0,
4538-
(void *)&ctxt->_regs - (void *)&ctxt->opcode_len);
4537+
memset(&ctxt->has_seg_override, 0,
4538+
(void *)&ctxt->modrm - (void *)&ctxt->has_seg_override);
45394539

4540-
ctxt->fetch.start = 0;
4541-
ctxt->fetch.end = 0;
45424540
ctxt->io_read.pos = 0;
45434541
ctxt->io_read.end = 0;
4544-
ctxt->mem_read.pos = 0;
45454542
ctxt->mem_read.end = 0;
45464543
}
45474544

0 commit comments

Comments
 (0)