Do not stop VM if emulation failed in userspace.
authorGleb Natapov <gleb@redhat.com>
Mon, 10 May 2010 08:21:34 +0000 (11:21 +0300)
committerMarcelo Tosatti <mtosatti@redhat.com>
Tue, 11 May 2010 17:03:44 +0000 (14:03 -0300)
Continue vcpu execution in case emulation failure happened while vcpu
was in userspace. In this case #UD will be injected into the guest
allowing guest OS to kill offending process and continue.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
kvm-all.c
kvm.h
target-i386/kvm.c
target-ppc/kvm.c
target-s390x/kvm.c

index d06980c0009730cb72ca9bbe66255d678575872f..c238f5421cded1bd5b1ba318f72f51c13d20789a 100644 (file)
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -764,6 +764,8 @@ static void kvm_handle_internal_error(CPUState *env, struct kvm_run *run)
     cpu_dump_state(env, stderr, fprintf, 0);
     if (run->internal.suberror == KVM_INTERNAL_ERROR_EMULATION) {
         fprintf(stderr, "emulation failure\n");
+        if (!kvm_arch_stop_on_emulation_error(env))
+               return;
     }
     /* FIXME: Should trigger a qmp message to let management know
      * something went wrong.
diff --git a/kvm.h b/kvm.h
index 5071a31decd7e228f17a741085b81e0f4f1f08ae..a28e7aab53df55aba7cc03ed1a50ba48674e70dd 100644 (file)
--- a/kvm.h
+++ b/kvm.h
@@ -140,6 +140,8 @@ void kvm_arch_remove_all_hw_breakpoints(void);
 
 void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg);
 
+bool kvm_arch_stop_on_emulation_error(CPUState *env);
+
 int kvm_check_extension(KVMState *s, unsigned int extension);
 
 uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function,
index bd7a1906783dc2e194d02471428aeeb1aca46a0b..676aa60791f0ba8a689354882f511147e5a9ec13 100644 (file)
@@ -1289,3 +1289,10 @@ void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg)
     }
 }
 #endif /* KVM_CAP_SET_GUEST_DEBUG */
+
+bool kvm_arch_stop_on_emulation_error(CPUState *env)
+{
+      return !(env->cr[0] & CR0_PE_MASK) ||
+              ((env->segs[R_CS].selector  & 3) != 3);
+}
+
index 91c0963f8864cd6378ef9833c521f23fcd2540bd..2625cb8bd93efb9e80c1b26a568aba2ecacef738 100644 (file)
@@ -326,3 +326,8 @@ uint32_t kvmppc_get_tbfreq(void)
     retval = atoi(ns);
     return retval;
 }
+
+bool kvm_arch_stop_on_emulation_error(CPUState *env)
+{
+    return true;
+}
index a2c00acf0fca5fd53df88f1464d21dd0afa07ee0..a2d77419bd045a97f7e36674b2420cbfb17b8dd4 100644 (file)
@@ -485,3 +485,8 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run)
 
     return ret;
 }
+
+bool kvm_arch_stop_on_emulation_error(CPUState *env)
+{
+    return true;
+}