Commit 1d2887e2 authored by Takuya Yoshikawa's avatar Takuya Yoshikawa Committed by Avi Kivity

KVM: x86 emulator: Make x86_decode_insn() return proper macros

Return EMULATION_OK/FAILED consistently.  Also treat instruction fetch
errors, not restricted to X86EMUL_UNHANDLEABLE, as EMULATION_FAILED;
although this cannot happen in practice, the current logic will continue
the emulation even if the decoder fails to fetch the instruction.
Signed-off-by: default avatarTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 7d88bb48
...@@ -3373,7 +3373,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len) ...@@ -3373,7 +3373,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
break; break;
#endif #endif
default: default:
return -1; return EMULATION_FAILED;
} }
ctxt->op_bytes = def_op_bytes; ctxt->op_bytes = def_op_bytes;
...@@ -3465,7 +3465,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len) ...@@ -3465,7 +3465,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
break; break;
case Prefix: case Prefix:
if (ctxt->rep_prefix && op_prefix) if (ctxt->rep_prefix && op_prefix)
return X86EMUL_UNHANDLEABLE; return EMULATION_FAILED;
simd_prefix = op_prefix ? 0x66 : ctxt->rep_prefix; simd_prefix = op_prefix ? 0x66 : ctxt->rep_prefix;
switch (simd_prefix) { switch (simd_prefix) {
case 0x00: opcode = opcode.u.gprefix->pfx_no; break; case 0x00: opcode = opcode.u.gprefix->pfx_no; break;
...@@ -3475,7 +3475,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len) ...@@ -3475,7 +3475,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
} }
break; break;
default: default:
return X86EMUL_UNHANDLEABLE; return EMULATION_FAILED;
} }
ctxt->d &= ~GroupMask; ctxt->d &= ~GroupMask;
...@@ -3488,10 +3488,10 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len) ...@@ -3488,10 +3488,10 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
/* Unrecognised? */ /* Unrecognised? */
if (ctxt->d == 0 || (ctxt->d & Undefined)) if (ctxt->d == 0 || (ctxt->d & Undefined))
return -1; return EMULATION_FAILED;
if (!(ctxt->d & VendorSpecific) && ctxt->only_vendor_specific_insn) if (!(ctxt->d & VendorSpecific) && ctxt->only_vendor_specific_insn)
return -1; return EMULATION_FAILED;
if (mode == X86EMUL_MODE_PROT64 && (ctxt->d & Stack)) if (mode == X86EMUL_MODE_PROT64 && (ctxt->d & Stack))
ctxt->op_bytes = 8; ctxt->op_bytes = 8;
...@@ -3683,7 +3683,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len) ...@@ -3683,7 +3683,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
if (memopp && memopp->type == OP_MEM && ctxt->rip_relative) if (memopp && memopp->type == OP_MEM && ctxt->rip_relative)
memopp->addr.mem.ea += ctxt->_eip; memopp->addr.mem.ea += ctxt->_eip;
return (rc == X86EMUL_UNHANDLEABLE) ? EMULATION_FAILED : EMULATION_OK; return (rc != X86EMUL_CONTINUE) ? EMULATION_FAILED : EMULATION_OK;
} }
static bool string_insn_completed(struct x86_emulate_ctxt *ctxt) static bool string_insn_completed(struct x86_emulate_ctxt *ctxt)
......
...@@ -4837,7 +4837,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, ...@@ -4837,7 +4837,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
trace_kvm_emulate_insn_start(vcpu); trace_kvm_emulate_insn_start(vcpu);
++vcpu->stat.insn_emulation; ++vcpu->stat.insn_emulation;
if (r) { if (r != EMULATION_OK) {
if (emulation_type & EMULTYPE_TRAP_UD) if (emulation_type & EMULTYPE_TRAP_UD)
return EMULATE_FAIL; return EMULATE_FAIL;
if (reexecute_instruction(vcpu, cr2)) if (reexecute_instruction(vcpu, cr2))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment