diff --git a/include/kvm/kvm-cpu.h b/include/kvm/kvm-cpu.h index f241e86..b2b6fce 100644 --- a/include/kvm/kvm-cpu.h +++ b/include/kvm/kvm-cpu.h @@ -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); diff --git a/kvm-cpu.c b/kvm-cpu.c index 331e025..de0591f 100644 --- a/kvm-cpu.c +++ b/kvm-cpu.c @@ -14,6 +14,8 @@ #include #include +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; diff --git a/kvm-run.c b/kvm-run.c index 76b5782..f384ddd 100644 --- a/kvm-run.c +++ b/kvm-run.c @@ -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;