KVM: Purify x86_decode_insn() error case management
authorLaurent Vivier <Laurent.Vivier@bull.net>
Mon, 24 Sep 2007 15:00:58 +0000 (17:00 +0200)
committerAvi Kivity <avi@qumranet.com>
Wed, 30 Jan 2008 15:52:49 +0000 (17:52 +0200)
The only valid case is on protected page access, other cases are errors.

Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
Signed-off-by: Avi Kivity <avi@qumranet.com>
drivers/kvm/kvm_main.c

index 2d55bab41634b089dd3cdc517aa2a2af1d9319fa..888b0924c17b36d68c37ebe6fb1d83dec9bcd564 100644 (file)
@@ -1251,7 +1251,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
                        u16 error_code,
                        int no_decode)
 {
-       int r = 0;
+       int r;
 
        vcpu->mmio_fault_cr2 = cr2;
        kvm_x86_ops->cache_regs(vcpu);
@@ -1294,10 +1294,14 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
                                        get_segment_base(vcpu, VCPU_SREG_FS);
 
                r = x86_decode_insn(&vcpu->emulate_ctxt, &emulate_ops);
+               if (r)  {
+                       if (kvm_mmu_unprotect_page_virt(vcpu, cr2))
+                               return EMULATE_DONE;
+                       return EMULATE_FAIL;
+               }
        }
 
-       if (r == 0)
-               r = x86_emulate_insn(&vcpu->emulate_ctxt, &emulate_ops);
+       r = x86_emulate_insn(&vcpu->emulate_ctxt, &emulate_ops);
 
        if (vcpu->pio.string)
                return EMULATE_DO_MMIO;