KVM: x86 emulator: access GPRs on demand
PATCH v2 1/1 KVM: x86 emulator: access GPRs on demand
Instead of populating the the entire register file, read in registers as they are accessed, and write back only the modified ones. This saves a VMREAD and VMWRITE on Intel (for rsp, since it is not usually used during emulation), and a two 128-byte copies for the registers.
---
v2:
add APIs for managing the register cache. This reduces the potential for confusion
between ctxt->regs_dirty and vcpu->arch.regs_dirty.
move cache management to the entry points
add missing writebacks to int and task switch emulation
arch/x86/include/asm/kvm_emulate.h | 20 ++- arch/x86/kvm/emulate.c | 305 ++++++++++++++++++++++--------------- arch/x86/kvm/x86.c | 45 +++--- 3 files changed, 223 insertions(+), 147 deletions(-)
arch/x86/include/asm/kvm_emulate.h +19 -1
@@ -86,6 +86,19 @@ struct x86_instruction_info {struct x86_emulate_ops {/* +* read_gpr: read a general purpose register (rax - r15) +* +* @reg: gpr number. +*/ +ulong (*read_gpr)(struct x86_emulate_ctxt *ctxt,unsigned reg); +/* +* write_gpr: write a general purpose register (rax - r15) +* +* @reg: gpr number. +* @val: value to write. +*/ +void (*write_gpr)(struct x86_emulate_ctxt *ctxt,unsigned reg,ulong val); +/* * read_std: Read bytes of standard (non-emulated/special) memory. * Used for descriptor reading. * @addr: [IN ] Linear address from which to read.
@@ -281,8 +294,10 @@ struct x86_emulate_ctxt {bool rip_relative;unsigned long _eip;struct operand memop; +u32 regs_valid;/* bitmaps of registers in _regs[] that can be read */ +u32 regs_dirty;/* bitmaps of registers in _regs[] that have been written */ /* Fields above regs are cleared together. */ -unsigned long regs[NR_VCPU_REGS ]; +unsigned long _regs[NR_VCPU_REGS ];struct operand *memopp;struct fetch_cache fetch;struct read_cache io_read;
@@ -394,4 +409,7 @@ int emulator_task_switch(struct x86_emulate_ctxt *ctxt, u16 tss_selector, int idt_index, int reason, bool has_error_code, u32 error_code);int emulate_int_real (struct x86_emulate_ctxt *ctxt,int irq); +void emulator_invalidate_register_cache (struct x86_emulate_ctxt *ctxt); +void emulator_writeback_register_cache (struct x86_emulate_ctxt *ctxt); +#endif /* _ASM_X86_KVM_X86_EMULATE_H */
arch/x86/kvm/emulate.c +186 -119
680 lines not on this page · raw message
arch/x86/kvm/x86.c +18 -27
114 lines not on this page · raw message
Signature · 1 line
1.7.11.3
Quoted 5 lines · Avi Kivity
Instead of populating the the entire register file, read in registers as they are accessed, and write back only the modified ones. This saves a VMREAD and VMWRITE on Intel (for rsp, since it is not usually used during emulation), and a two 128-byte copies for the registers.
Seeing a problem on Windows XP 64-bit, so please don't apply.
Signature · 1 line
error compiling committee.c: too many arguments to function