KVM: emulate: warn on invalid or uninitialized exception numbers
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 20 Aug 2014 08:08:23 +0000 (10:08 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 20 Aug 2014 11:01:26 +0000 (13:01 +0200)
These were reported when running Jailhouse on AMD processors.

Initialize ctxt->exception.vector with an invalid exception number,
and warn if it remained invalid even though the emulator got
an X86EMUL_PROPAGATE_FAULT return code.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/emulate.c
arch/x86/kvm/x86.c

index 4fbf4b598f92c603a385a4d41fa94d6ad76e307c..e5bf13003cd215def5ae6973480878b1352c09f3 100644 (file)
@@ -527,6 +527,7 @@ static unsigned long seg_base(struct x86_emulate_ctxt *ctxt, int seg)
 static int emulate_exception(struct x86_emulate_ctxt *ctxt, int vec,
                             u32 error, bool valid)
 {
+       WARN_ON(vec > 0x1f);
        ctxt->exception.vector = vec;
        ctxt->exception.error_code = error;
        ctxt->exception.error_code_valid = valid;
@@ -4827,8 +4828,10 @@ writeback:
        ctxt->eip = ctxt->_eip;
 
 done:
-       if (rc == X86EMUL_PROPAGATE_FAULT)
+       if (rc == X86EMUL_PROPAGATE_FAULT) {
+               WARN_ON(ctxt->exception.vector > 0x1f);
                ctxt->have_exception = true;
+       }
        if (rc == X86EMUL_INTERCEPTED)
                return EMULATION_INTERCEPTED;
 
index 737b4bdac41c0010c9470aba72678e6175207b5b..cd718c01cdf1b1a9af35f9fd975ed30dbc29387f 100644 (file)
@@ -5248,6 +5248,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
 
                ctxt->interruptibility = 0;
                ctxt->have_exception = false;
+               ctxt->exception.vector = -1;
                ctxt->perm_ok = false;
 
                ctxt->ud = emulation_type & EMULTYPE_TRAP_UD;