diff options
author | Gleb Natapov <gleb@redhat.com> | 2010-04-28 12:15:44 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-08-01 03:35:37 -0400 |
commit | 54b8486f469475d6c8e8aec917b91239a54eb8c8 (patch) | |
tree | a619826dc8e4915fcf308f3514a43615345e077a /arch/x86/kvm/x86.c | |
parent | 95cb229530f329ec8002274891793be9c91385f7 (diff) |
KVM: x86 emulator: do not inject exception directly into vcpu
Return exception as a result of instruction emulation and handle
injection in KVM code.
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 91bfe7771f50..63c87adcec48 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -3852,6 +3852,17 @@ static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask) | |||
3852 | kvm_x86_ops->set_interrupt_shadow(vcpu, mask); | 3852 | kvm_x86_ops->set_interrupt_shadow(vcpu, mask); |
3853 | } | 3853 | } |
3854 | 3854 | ||
3855 | static void inject_emulated_exception(struct kvm_vcpu *vcpu) | ||
3856 | { | ||
3857 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; | ||
3858 | if (ctxt->exception == PF_VECTOR) | ||
3859 | kvm_inject_page_fault(vcpu, ctxt->cr2, ctxt->error_code); | ||
3860 | else if (ctxt->error_code_valid) | ||
3861 | kvm_queue_exception_e(vcpu, ctxt->exception, ctxt->error_code); | ||
3862 | else | ||
3863 | kvm_queue_exception(vcpu, ctxt->exception); | ||
3864 | } | ||
3865 | |||
3855 | int emulate_instruction(struct kvm_vcpu *vcpu, | 3866 | int emulate_instruction(struct kvm_vcpu *vcpu, |
3856 | unsigned long cr2, | 3867 | unsigned long cr2, |
3857 | u16 error_code, | 3868 | u16 error_code, |
@@ -3886,6 +3897,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu, | |||
3886 | memset(c, 0, sizeof(struct decode_cache)); | 3897 | memset(c, 0, sizeof(struct decode_cache)); |
3887 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); | 3898 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); |
3888 | vcpu->arch.emulate_ctxt.interruptibility = 0; | 3899 | vcpu->arch.emulate_ctxt.interruptibility = 0; |
3900 | vcpu->arch.emulate_ctxt.exception = -1; | ||
3889 | 3901 | ||
3890 | r = x86_decode_insn(&vcpu->arch.emulate_ctxt, &emulate_ops); | 3902 | r = x86_decode_insn(&vcpu->arch.emulate_ctxt, &emulate_ops); |
3891 | trace_kvm_emulate_insn_start(vcpu); | 3903 | trace_kvm_emulate_insn_start(vcpu); |
@@ -3958,6 +3970,11 @@ restart: | |||
3958 | memcpy(vcpu->arch.regs, c->regs, sizeof c->regs); | 3970 | memcpy(vcpu->arch.regs, c->regs, sizeof c->regs); |
3959 | kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip); | 3971 | kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip); |
3960 | 3972 | ||
3973 | if (vcpu->arch.emulate_ctxt.exception >= 0) { | ||
3974 | inject_emulated_exception(vcpu); | ||
3975 | return EMULATE_DONE; | ||
3976 | } | ||
3977 | |||
3961 | if (vcpu->arch.pio.count) { | 3978 | if (vcpu->arch.pio.count) { |
3962 | if (!vcpu->arch.pio.in) | 3979 | if (!vcpu->arch.pio.in) |
3963 | vcpu->arch.pio.count = 0; | 3980 | vcpu->arch.pio.count = 0; |
@@ -3970,9 +3987,6 @@ restart: | |||
3970 | return EMULATE_DO_MMIO; | 3987 | return EMULATE_DO_MMIO; |
3971 | } | 3988 | } |
3972 | 3989 | ||
3973 | if (vcpu->arch.exception.pending) | ||
3974 | vcpu->arch.emulate_ctxt.restart = false; | ||
3975 | |||
3976 | if (vcpu->arch.emulate_ctxt.restart) | 3990 | if (vcpu->arch.emulate_ctxt.restart) |
3977 | goto restart; | 3991 | goto restart; |
3978 | 3992 | ||