aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm
diff options
context:
space:
mode:
authorTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>2011-07-30 05:03:34 -0400
committerAvi Kivity <avi@redhat.com>2011-09-25 12:18:01 -0400
commit1d2887e2d849969f58ce79203f9785ebe065d494 (patch)
tree9ca6e1bfdf14e646b9816aa45a18230e1880784d /arch/x86/kvm
parent7d88bb4803d62f6056b079ade6333a026fd11684 (diff)
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: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r--arch/x86/kvm/emulate.c12
-rw-r--r--arch/x86/kvm/x86.c2
2 files changed, 7 insertions, 7 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 191bc9be4946..fe5eb6d9b3e1 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -3373,7 +3373,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
3373 break; 3373 break;
3374#endif 3374#endif
3375 default: 3375 default:
3376 return -1; 3376 return EMULATION_FAILED;
3377 } 3377 }
3378 3378
3379 ctxt->op_bytes = def_op_bytes; 3379 ctxt->op_bytes = def_op_bytes;
@@ -3465,7 +3465,7 @@ done_prefixes:
3465 break; 3465 break;
3466 case Prefix: 3466 case Prefix:
3467 if (ctxt->rep_prefix && op_prefix) 3467 if (ctxt->rep_prefix && op_prefix)
3468 return X86EMUL_UNHANDLEABLE; 3468 return EMULATION_FAILED;
3469 simd_prefix = op_prefix ? 0x66 : ctxt->rep_prefix; 3469 simd_prefix = op_prefix ? 0x66 : ctxt->rep_prefix;
3470 switch (simd_prefix) { 3470 switch (simd_prefix) {
3471 case 0x00: opcode = opcode.u.gprefix->pfx_no; break; 3471 case 0x00: opcode = opcode.u.gprefix->pfx_no; break;
@@ -3475,7 +3475,7 @@ done_prefixes:
3475 } 3475 }
3476 break; 3476 break;
3477 default: 3477 default:
3478 return X86EMUL_UNHANDLEABLE; 3478 return EMULATION_FAILED;
3479 } 3479 }
3480 3480
3481 ctxt->d &= ~GroupMask; 3481 ctxt->d &= ~GroupMask;
@@ -3488,10 +3488,10 @@ done_prefixes:
3488 3488
3489 /* Unrecognised? */ 3489 /* Unrecognised? */
3490 if (ctxt->d == 0 || (ctxt->d & Undefined)) 3490 if (ctxt->d == 0 || (ctxt->d & Undefined))
3491 return -1; 3491 return EMULATION_FAILED;
3492 3492
3493 if (!(ctxt->d & VendorSpecific) && ctxt->only_vendor_specific_insn) 3493 if (!(ctxt->d & VendorSpecific) && ctxt->only_vendor_specific_insn)
3494 return -1; 3494 return EMULATION_FAILED;
3495 3495
3496 if (mode == X86EMUL_MODE_PROT64 && (ctxt->d & Stack)) 3496 if (mode == X86EMUL_MODE_PROT64 && (ctxt->d & Stack))
3497 ctxt->op_bytes = 8; 3497 ctxt->op_bytes = 8;
@@ -3683,7 +3683,7 @@ done:
3683 if (memopp && memopp->type == OP_MEM && ctxt->rip_relative) 3683 if (memopp && memopp->type == OP_MEM && ctxt->rip_relative)
3684 memopp->addr.mem.ea += ctxt->_eip; 3684 memopp->addr.mem.ea += ctxt->_eip;
3685 3685
3686 return (rc == X86EMUL_UNHANDLEABLE) ? EMULATION_FAILED : EMULATION_OK; 3686 return (rc != X86EMUL_CONTINUE) ? EMULATION_FAILED : EMULATION_OK;
3687} 3687}
3688 3688
3689static bool string_insn_completed(struct x86_emulate_ctxt *ctxt) 3689static bool string_insn_completed(struct x86_emulate_ctxt *ctxt)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d28dff749dfd..1fe9637ff153 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4837,7 +4837,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
4837 4837
4838 trace_kvm_emulate_insn_start(vcpu); 4838 trace_kvm_emulate_insn_start(vcpu);
4839 ++vcpu->stat.insn_emulation; 4839 ++vcpu->stat.insn_emulation;
4840 if (r) { 4840 if (r != EMULATION_OK) {
4841 if (emulation_type & EMULTYPE_TRAP_UD) 4841 if (emulation_type & EMULTYPE_TRAP_UD)
4842 return EMULATE_FAIL; 4842 return EMULATE_FAIL;
4843 if (reexecute_instruction(vcpu, cr2)) 4843 if (reexecute_instruction(vcpu, cr2))