Skip to contentSkip to conversation

Do not stop VM if emulation failed in userspace.

PATCH Applied Gleb Natapov 2 participants 2 messages May 10, 2010 – May 11, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Do not stop VM if emulation failed in userspace.

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.

kvm-all.c +2 -0
index 9ac35aa..db28d94 100644
@@ -786,6 +786,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.
kvm.h +1 -0
index 67c0392..79e59f5 100644
@@ -187,4 +187,5 @@ int kvm_set_irqfd(int gsi, int fd, bool assigned)
 #endif
 
 int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign);
+bool kvm_arch_stop_on_emulation_error(CPUState *env);
 #endif
target-i386/kvm.c +6 -0
index 76c1adb..c333f86 100644
@@ -1287,4 +1287,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);
+}
+
 #include "qemu-kvm-x86.c"
target-ppc/kvm.c +5 -0
index aa3d432..7b246a1 100644
@@ -321,3 +321,8 @@ uint32_t kvmppc_get_tbfreq(void)
     retval = atoi(ns);
     return retval;
 }
+
+bool kvm_arch_stop_on_emulation_error(CPUState *env)
+{
+    return true;
+}
target-s390x/kvm.c +5 -0
index 72e77b0..14f723b 100644
@@ -480,3 +480,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;
+}        

--
Gleb.

#1 lore raw
Quoted 5 lines · Gleb Natapov

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.

Applied to uq/master, thanks.