KVM: emulator: Do not fail on emulation of undefined opcode
authorGleb Natapov <gleb@redhat.com>
Thu, 11 Apr 2013 09:30:01 +0000 (12:30 +0300)
committerGleb Natapov <gleb@redhat.com>
Sun, 14 Apr 2013 06:44:17 +0000 (09:44 +0300)
Emulation of undefined opcode should inject #UD instead of causing
emulation failure. Do that by moving Undefined flag check to emulation
stage and injection #UD there.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
arch/x86/kvm/emulate.c

index ab6fda4eb98f4453c9f26ca9e43bf66d7d571fc2..77b56d5be3e146a5fc149971d5a57e20dfc69925 100644 (file)
@@ -4383,7 +4383,7 @@ done_prefixes:
        ctxt->intercept = opcode.intercept;
 
        /* Unrecognised? */
-       if (ctxt->d == 0 || (ctxt->d & NotImpl) || (ctxt->d & Undefined))
+       if (ctxt->d == 0 || (ctxt->d & NotImpl))
                return EMULATION_FAILED;
 
        if (!(ctxt->d & VendorSpecific) && ctxt->only_vendor_specific_insn)
@@ -4521,7 +4521,8 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
 
        ctxt->mem_read.pos = 0;
 
-       if (ctxt->mode == X86EMUL_MODE_PROT64 && (ctxt->d & No64)) {
+       if ((ctxt->mode == X86EMUL_MODE_PROT64 && (ctxt->d & No64)) ||
+                       (ctxt->d & Undefined)) {
                rc = emulate_ud(ctxt);
                goto done;
        }