aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGleb Natapov <gleb@redhat.com>2010-04-28 12:15:43 -0400
committerAvi Kivity <avi@redhat.com>2010-08-01 03:35:36 -0400
commit95cb229530f329ec8002274891793be9c91385f7 (patch)
tree0bc4aabbc07bbf06222d68e5fcef5db8cd285385
parent4d2179e1e9cb74b25a8181a506600d96e15504fb (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>
-rw-r--r--arch/x86/kvm/emulate.c19
-rw-r--r--arch/x86/kvm/x86.c20
2 files changed, 19 insertions, 20 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 97a42e8c00d0..c40b40561dff 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1843,20 +1843,6 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
1843 return X86EMUL_CONTINUE; 1843 return X86EMUL_CONTINUE;
1844} 1844}
1845 1845
1846static void toggle_interruptibility(struct x86_emulate_ctxt *ctxt, u32 mask)
1847{
1848 u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(ctxt->vcpu, mask);
1849 /*
1850 * an sti; sti; sequence only disable interrupts for the first
1851 * instruction. So, if the last instruction, be it emulated or
1852 * not, left the system with the INT_STI flag enabled, it
1853 * means that the last instruction is an sti. We should not
1854 * leave the flag on in this case. The same goes for mov ss
1855 */
1856 if (!(int_shadow & mask))
1857 ctxt->interruptibility = mask;
1858}
1859
1860static inline void 1846static inline void
1861setup_syscalls_segments(struct x86_emulate_ctxt *ctxt, 1847setup_syscalls_segments(struct x86_emulate_ctxt *ctxt,
1862 struct x86_emulate_ops *ops, struct desc_struct *cs, 1848 struct x86_emulate_ops *ops, struct desc_struct *cs,
@@ -2516,7 +2502,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
2516 int rc = X86EMUL_CONTINUE; 2502 int rc = X86EMUL_CONTINUE;
2517 int saved_dst_type = c->dst.type; 2503 int saved_dst_type = c->dst.type;
2518 2504
2519 ctxt->interruptibility = 0;
2520 ctxt->decode.mem_read.pos = 0; 2505 ctxt->decode.mem_read.pos = 0;
2521 2506
2522 if (ctxt->mode == X86EMUL_MODE_PROT64 && (c->d & No64)) { 2507 if (ctxt->mode == X86EMUL_MODE_PROT64 && (c->d & No64)) {
@@ -2789,7 +2774,7 @@ special_insn:
2789 } 2774 }
2790 2775
2791 if (c->modrm_reg == VCPU_SREG_SS) 2776 if (c->modrm_reg == VCPU_SREG_SS)
2792 toggle_interruptibility(ctxt, KVM_X86_SHADOW_INT_MOV_SS); 2777 ctxt->interruptibility = KVM_X86_SHADOW_INT_MOV_SS;
2793 2778
2794 rc = load_segment_descriptor(ctxt, ops, sel, c->modrm_reg); 2779 rc = load_segment_descriptor(ctxt, ops, sel, c->modrm_reg);
2795 2780
@@ -2958,7 +2943,7 @@ special_insn:
2958 if (emulator_bad_iopl(ctxt, ops)) 2943 if (emulator_bad_iopl(ctxt, ops))
2959 kvm_inject_gp(ctxt->vcpu, 0); 2944 kvm_inject_gp(ctxt->vcpu, 0);
2960 else { 2945 else {
2961 toggle_interruptibility(ctxt, KVM_X86_SHADOW_INT_STI); 2946 ctxt->interruptibility = KVM_X86_SHADOW_INT_STI;
2962 ctxt->eflags |= X86_EFLAGS_IF; 2947 ctxt->eflags |= X86_EFLAGS_IF;
2963 c->dst.type = OP_NONE; /* Disable writeback. */ 2948 c->dst.type = OP_NONE; /* Disable writeback. */
2964 } 2949 }
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
3841static 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
3841int emulate_instruction(struct kvm_vcpu *vcpu, 3855int 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);