diff options
author | Gleb Natapov <gleb@redhat.com> | 2010-04-28 12:15:43 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-08-01 03:35:36 -0400 |
commit | 95cb229530f329ec8002274891793be9c91385f7 (patch) | |
tree | 0bc4aabbc07bbf06222d68e5fcef5db8cd285385 /arch/x86/kvm/x86.c | |
parent | 4d2179e1e9cb74b25a8181a506600d96e15504fb (diff) |
KVM: x86 emulator: move interruptibility state tracking out of emulator
Emulator shouldn't access vcpu directly.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 21d36081a9d9..91bfe7771f50 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -3838,12 +3838,26 @@ static void cache_all_regs(struct kvm_vcpu *vcpu) | |||
3838 | vcpu->arch.regs_dirty = ~0; | 3838 | vcpu->arch.regs_dirty = ~0; |
3839 | } | 3839 | } |
3840 | 3840 | ||
3841 | static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask) | ||
3842 | { | ||
3843 | u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(vcpu, mask); | ||
3844 | /* | ||
3845 | * an sti; sti; sequence only disable interrupts for the first | ||
3846 | * instruction. So, if the last instruction, be it emulated or | ||
3847 | * not, left the system with the INT_STI flag enabled, it | ||
3848 | * means that the last instruction is an sti. We should not | ||
3849 | * leave the flag on in this case. The same goes for mov ss | ||
3850 | */ | ||
3851 | if (!(int_shadow & mask)) | ||
3852 | kvm_x86_ops->set_interrupt_shadow(vcpu, mask); | ||
3853 | } | ||
3854 | |||
3841 | int emulate_instruction(struct kvm_vcpu *vcpu, | 3855 | int emulate_instruction(struct kvm_vcpu *vcpu, |
3842 | unsigned long cr2, | 3856 | unsigned long cr2, |
3843 | u16 error_code, | 3857 | u16 error_code, |
3844 | int emulation_type) | 3858 | int emulation_type) |
3845 | { | 3859 | { |
3846 | int r, shadow_mask; | 3860 | int r; |
3847 | struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode; | 3861 | struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode; |
3848 | 3862 | ||
3849 | kvm_clear_exception_queue(vcpu); | 3863 | kvm_clear_exception_queue(vcpu); |
@@ -3871,6 +3885,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu, | |||
3871 | ? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16; | 3885 | ? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16; |
3872 | memset(c, 0, sizeof(struct decode_cache)); | 3886 | memset(c, 0, sizeof(struct decode_cache)); |
3873 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); | 3887 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); |
3888 | vcpu->arch.emulate_ctxt.interruptibility = 0; | ||
3874 | 3889 | ||
3875 | r = x86_decode_insn(&vcpu->arch.emulate_ctxt, &emulate_ops); | 3890 | r = x86_decode_insn(&vcpu->arch.emulate_ctxt, &emulate_ops); |
3876 | trace_kvm_emulate_insn_start(vcpu); | 3891 | trace_kvm_emulate_insn_start(vcpu); |
@@ -3938,8 +3953,7 @@ restart: | |||
3938 | return EMULATE_FAIL; | 3953 | return EMULATE_FAIL; |
3939 | } | 3954 | } |
3940 | 3955 | ||
3941 | shadow_mask = vcpu->arch.emulate_ctxt.interruptibility; | 3956 | toggle_interruptibility(vcpu, vcpu->arch.emulate_ctxt.interruptibility); |
3942 | kvm_x86_ops->set_interrupt_shadow(vcpu, shadow_mask); | ||
3943 | kvm_x86_ops->set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags); | 3957 | kvm_x86_ops->set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags); |
3944 | memcpy(vcpu->arch.regs, c->regs, sizeof c->regs); | 3958 | memcpy(vcpu->arch.regs, c->regs, sizeof c->regs); |
3945 | kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip); | 3959 | kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip); |