diff options
author | Gleb Natapov <gleb@redhat.com> | 2010-03-18 09:20:06 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-05-17 05:15:59 -0400 |
commit | 063db061b9b3472c925f09ae3a0a8359b80c2295 (patch) | |
tree | b38642f43f436c88ab67c5cadd618596d6e9130a /arch | |
parent | 9c5372445c1ad4fcdb4128957ec89334223b8113 (diff) |
KVM: Provide current eip as part of emulator context.
Eliminate the need to call back into KVM to get it from emulator.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/include/asm/kvm_emulate.h | 3 | ||||
-rw-r--r-- | arch/x86/kvm/emulate.c | 12 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 1 |
3 files changed, 9 insertions, 7 deletions
diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h index b048fd21c54e..07657258af8f 100644 --- a/arch/x86/include/asm/kvm_emulate.h +++ b/arch/x86/include/asm/kvm_emulate.h | |||
@@ -141,7 +141,7 @@ struct decode_cache { | |||
141 | u8 seg_override; | 141 | u8 seg_override; |
142 | unsigned int d; | 142 | unsigned int d; |
143 | unsigned long regs[NR_VCPU_REGS]; | 143 | unsigned long regs[NR_VCPU_REGS]; |
144 | unsigned long eip, eip_orig; | 144 | unsigned long eip; |
145 | /* modrm */ | 145 | /* modrm */ |
146 | u8 modrm; | 146 | u8 modrm; |
147 | u8 modrm_mod; | 147 | u8 modrm_mod; |
@@ -160,6 +160,7 @@ struct x86_emulate_ctxt { | |||
160 | struct kvm_vcpu *vcpu; | 160 | struct kvm_vcpu *vcpu; |
161 | 161 | ||
162 | unsigned long eflags; | 162 | unsigned long eflags; |
163 | unsigned long eip; /* eip before instruction emulation */ | ||
163 | /* Emulated execution mode, represented by an X86EMUL_MODE value. */ | 164 | /* Emulated execution mode, represented by an X86EMUL_MODE value. */ |
164 | int mode; | 165 | int mode; |
165 | u32 cs_base; | 166 | u32 cs_base; |
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 8bd05571672c..2c27aa466cf4 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c | |||
@@ -667,7 +667,7 @@ static int do_insn_fetch(struct x86_emulate_ctxt *ctxt, | |||
667 | int rc; | 667 | int rc; |
668 | 668 | ||
669 | /* x86 instructions are limited to 15 bytes. */ | 669 | /* x86 instructions are limited to 15 bytes. */ |
670 | if (eip + size - ctxt->decode.eip_orig > 15) | 670 | if (eip + size - ctxt->eip > 15) |
671 | return X86EMUL_UNHANDLEABLE; | 671 | return X86EMUL_UNHANDLEABLE; |
672 | eip += ctxt->cs_base; | 672 | eip += ctxt->cs_base; |
673 | while (size--) { | 673 | while (size--) { |
@@ -927,7 +927,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) | |||
927 | /* Shadow copy of register state. Committed on successful emulation. */ | 927 | /* Shadow copy of register state. Committed on successful emulation. */ |
928 | 928 | ||
929 | memset(c, 0, sizeof(struct decode_cache)); | 929 | memset(c, 0, sizeof(struct decode_cache)); |
930 | c->eip = c->eip_orig = kvm_rip_read(ctxt->vcpu); | 930 | c->eip = ctxt->eip; |
931 | ctxt->cs_base = seg_base(ctxt, VCPU_SREG_CS); | 931 | ctxt->cs_base = seg_base(ctxt, VCPU_SREG_CS); |
932 | memcpy(c->regs, ctxt->vcpu->arch.regs, sizeof c->regs); | 932 | memcpy(c->regs, ctxt->vcpu->arch.regs, sizeof c->regs); |
933 | 933 | ||
@@ -1878,7 +1878,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) | |||
1878 | } | 1878 | } |
1879 | } | 1879 | } |
1880 | register_address_increment(c, &c->regs[VCPU_REGS_RCX], -1); | 1880 | register_address_increment(c, &c->regs[VCPU_REGS_RCX], -1); |
1881 | c->eip = kvm_rip_read(ctxt->vcpu); | 1881 | c->eip = ctxt->eip; |
1882 | } | 1882 | } |
1883 | 1883 | ||
1884 | if (c->src.type == OP_MEM) { | 1884 | if (c->src.type == OP_MEM) { |
@@ -2447,7 +2447,7 @@ twobyte_insn: | |||
2447 | goto done; | 2447 | goto done; |
2448 | 2448 | ||
2449 | /* Let the processor re-execute the fixed hypercall */ | 2449 | /* Let the processor re-execute the fixed hypercall */ |
2450 | c->eip = kvm_rip_read(ctxt->vcpu); | 2450 | c->eip = ctxt->eip; |
2451 | /* Disable writeback. */ | 2451 | /* Disable writeback. */ |
2452 | c->dst.type = OP_NONE; | 2452 | c->dst.type = OP_NONE; |
2453 | break; | 2453 | break; |
@@ -2551,7 +2551,7 @@ twobyte_insn: | |||
2551 | | ((u64)c->regs[VCPU_REGS_RDX] << 32); | 2551 | | ((u64)c->regs[VCPU_REGS_RDX] << 32); |
2552 | if (kvm_set_msr(ctxt->vcpu, c->regs[VCPU_REGS_RCX], msr_data)) { | 2552 | if (kvm_set_msr(ctxt->vcpu, c->regs[VCPU_REGS_RCX], msr_data)) { |
2553 | kvm_inject_gp(ctxt->vcpu, 0); | 2553 | kvm_inject_gp(ctxt->vcpu, 0); |
2554 | c->eip = kvm_rip_read(ctxt->vcpu); | 2554 | c->eip = ctxt->eip; |
2555 | } | 2555 | } |
2556 | rc = X86EMUL_CONTINUE; | 2556 | rc = X86EMUL_CONTINUE; |
2557 | c->dst.type = OP_NONE; | 2557 | c->dst.type = OP_NONE; |
@@ -2560,7 +2560,7 @@ twobyte_insn: | |||
2560 | /* rdmsr */ | 2560 | /* rdmsr */ |
2561 | if (kvm_get_msr(ctxt->vcpu, c->regs[VCPU_REGS_RCX], &msr_data)) { | 2561 | if (kvm_get_msr(ctxt->vcpu, c->regs[VCPU_REGS_RCX], &msr_data)) { |
2562 | kvm_inject_gp(ctxt->vcpu, 0); | 2562 | kvm_inject_gp(ctxt->vcpu, 0); |
2563 | c->eip = kvm_rip_read(ctxt->vcpu); | 2563 | c->eip = ctxt->eip; |
2564 | } else { | 2564 | } else { |
2565 | c->regs[VCPU_REGS_RAX] = (u32)msr_data; | 2565 | c->regs[VCPU_REGS_RAX] = (u32)msr_data; |
2566 | c->regs[VCPU_REGS_RDX] = msr_data >> 32; | 2566 | c->regs[VCPU_REGS_RDX] = msr_data >> 32; |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9cb28a943c9a..0ecd37ac9d39 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -3531,6 +3531,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu, | |||
3531 | 3531 | ||
3532 | vcpu->arch.emulate_ctxt.vcpu = vcpu; | 3532 | vcpu->arch.emulate_ctxt.vcpu = vcpu; |
3533 | vcpu->arch.emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu); | 3533 | vcpu->arch.emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu); |
3534 | vcpu->arch.emulate_ctxt.eip = kvm_rip_read(vcpu); | ||
3534 | vcpu->arch.emulate_ctxt.mode = | 3535 | vcpu->arch.emulate_ctxt.mode = |
3535 | (!is_protmode(vcpu)) ? X86EMUL_MODE_REAL : | 3536 | (!is_protmode(vcpu)) ? X86EMUL_MODE_REAL : |
3536 | (vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM) | 3537 | (vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM) |