]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Exit VCPU thread only when SIGKVMEXIT is received
authorSasha Levin <levinsasha928@gmail.com>
Thu, 26 May 2011 14:25:46 +0000 (17:25 +0300)
committerPekka Enberg <penberg@kernel.org>
Thu, 26 May 2011 19:03:22 +0000 (22:03 +0300)
Currently the VCPU loop would exit when the thread received any signal.

Change behaviour to exit only when SIGKVMEXIT is received. This change
prevents from the guest to terminate when unrelated signals are processed
by the thread (for example, when attaching a debugger).

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/include/kvm/kvm-cpu.h
tools/kvm/kvm-cpu.c
tools/kvm/kvm-run.c

index f241e86a969299b460b6db85bdffd6c8be18e34d..b2b6fceea3ed75abbd84ccc0777dfd9ba44b183b 100644 (file)
@@ -21,6 +21,8 @@ struct kvm_cpu {
        struct kvm_fpu          fpu;
 
        struct kvm_msrs         *msrs;          /* dynamically allocated */
+
+       u8                      is_running;
 };
 
 struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id);
index 331e02517cc5d2be8500357168705133cbdd4439..de0591f88d1a60eb590d610ffd5844c5905dac2d 100644 (file)
@@ -14,6 +14,8 @@
 #include <errno.h>
 #include <stdio.h>
 
+extern __thread struct kvm_cpu *current_kvm_cpu;
+
 static inline bool is_in_protected_mode(struct kvm_cpu *vcpu)
 {
        return vcpu->sregs.cr0 & 0x01;
@@ -87,6 +89,8 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id)
        if (vcpu->kvm_run == MAP_FAILED)
                die("unable to mmap vcpu fd");
 
+       vcpu->is_running = true;
+
        return vcpu;
 }
 
@@ -381,7 +385,10 @@ void kvm_cpu__run(struct kvm_cpu *vcpu)
 
 static void kvm_cpu_exit_handler(int signum)
 {
-       /* Don't do anything here */
+       if (current_kvm_cpu->is_running) {
+               current_kvm_cpu->is_running = false;
+               pthread_kill(pthread_self(), SIGKVMEXIT);
+       }
 }
 
 int kvm_cpu__start(struct kvm_cpu *cpu)
@@ -437,10 +444,8 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
                        break;
                }
                case KVM_EXIT_INTR:
-                       /*
-                        * Currently we only handle exit signal, which means
-                        * we just exit if KVM_RUN exited due to a signal.
-                        */
+                       if (cpu->is_running)
+                               break;
                        goto exit_kvm;
                case KVM_EXIT_SHUTDOWN:
                        goto exit_kvm;
index 76b578294073b85d82572e6d99a45881a4f29a79..f384dddcc5485bb8e7e0347b3d6b899828f56a8f 100644 (file)
@@ -48,7 +48,7 @@
 
 static struct kvm *kvm;
 static struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
-static __thread struct kvm_cpu *current_kvm_cpu;
+__thread struct kvm_cpu *current_kvm_cpu;
 
 static u64 ram_size;
 static u8  image_count;