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>
 #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,
 
 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:
 
 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;