KVM: x86 emulator: Don't write-back cpu-state on X86EMUL_INTERCEPTED
authorJoerg Roedel <joerg.roedel@amd.com>
Mon, 4 Apr 2011 10:39:24 +0000 (12:39 +0200)
committerAvi Kivity <avi@redhat.com>
Wed, 11 May 2011 11:57:00 +0000 (07:57 -0400)
This patch prevents the changed CPU state to be written back
when the emulator detected that the instruction was
intercepted by the guest.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/include/asm/kvm_emulate.h
arch/x86/kvm/emulate.c
arch/x86/kvm/x86.c

index 470ac54ca38db416fe3f8742eb69bc4edef1cc60..1dbd0c736cd1d1d254ec24302a7c0b88496f3a40 100644 (file)
@@ -331,6 +331,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len);
 #define EMULATION_FAILED -1
 #define EMULATION_OK 0
 #define EMULATION_RESTART 1
+#define EMULATION_INTERCEPTED 2
 int x86_emulate_insn(struct x86_emulate_ctxt *ctxt);
 int emulator_task_switch(struct x86_emulate_ctxt *ctxt,
                         u16 tss_selector, int reason,
index c2260e57450afd37adf53897385d115aacd50182..a2c31e527a99183abfb904225e343e148482fd2b 100644 (file)
@@ -3592,6 +3592,9 @@ writeback:
 done:
        if (rc == X86EMUL_PROPAGATE_FAULT)
                ctxt->have_exception = true;
+       if (rc == X86EMUL_INTERCEPTED)
+               return EMULATION_INTERCEPTED;
+
        return (rc == X86EMUL_UNHANDLEABLE) ? EMULATION_FAILED : EMULATION_OK;
 
 twobyte_insn:
index 36786bbb4c095f0a8a253c05ae38d1623295fbe1..99bed74779d246653afa846f011d24fef6601fe0 100644 (file)
@@ -4516,6 +4516,9 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
 restart:
        r = x86_emulate_insn(&vcpu->arch.emulate_ctxt);
 
+       if (r == EMULATION_INTERCEPTED)
+               return EMULATE_DONE;
+
        if (r == EMULATION_FAILED) {
                if (reexecute_instruction(vcpu, cr2))
                        return EMULATE_DONE;