]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
KVM: x86: set ctxt->have_exception in x86_decode_insn()
authorJan Dakinevich <jan.dakinevich@virtuozzo.com>
Tue, 27 Aug 2019 13:07:08 +0000 (13:07 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 11 Sep 2019 16:01:34 +0000 (18:01 +0200)
x86_emulate_instruction() takes into account ctxt->have_exception flag
during instruction decoding, but in practice this flag is never set in
x86_decode_insn().

Fixes: 6ea6e84309ca ("KVM: x86: inject exceptions produced by x86_decode_insn")
Cc: stable@vger.kernel.org
Cc: Denis Lunev <den@virtuozzo.com>
Cc: Roman Kagan <rkagan@virtuozzo.com>
Cc: Denis Plotnikov <dplotnikov@virtuozzo.com>
Signed-off-by: Jan Dakinevich <jan.dakinevich@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/emulate.c
arch/x86/kvm/x86.c

index bef3c3c695d73c0821f6d757a529fd313765fdcb..698efb8c38971913eee17875fd84b1ea2b5d57e4 100644 (file)
@@ -5416,6 +5416,8 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
                                        ctxt->memopp->addr.mem.ea + ctxt->_eip);
 
 done:
+       if (rc == X86EMUL_PROPAGATE_FAULT)
+               ctxt->have_exception = true;
        return (rc != X86EMUL_CONTINUE) ? EMULATION_FAILED : EMULATION_OK;
 }
 
index 263fac7e9307d311cf8d69c3193bd944ca6405ad..f7cfd8e6edd175e0032bb4e25f015641fe507fb4 100644 (file)
@@ -6577,6 +6577,12 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
                                                emulation_type))
                                return EMULATE_DONE;
                        if (ctxt->have_exception) {
+                               /*
+                                * #UD should result in just EMULATION_FAILED, and trap-like
+                                * exception should not be encountered during decode.
+                                */
+                               WARN_ON_ONCE(ctxt->exception.vector == UD_VECTOR ||
+                                            exception_type(ctxt->exception.vector) == EXCPT_TRAP);
                                inject_emulated_exception(vcpu);
                                return EMULATE_DONE;
                        }