#define KVM_32BIT_GAP_SIZE (512 << 20)
#define KVM_32BIT_GAP_START ((1ULL << 32) - KVM_32BIT_GAP_SIZE)
+#define SIGKVMEXIT (SIGUSR1 + 2)
+
struct kvm {
int sys_fd; /* For system ioctls(), i.e. /dev/kvm */
int vm_fd; /* For VM ioctls() */
die_perror("KVM_RUN failed");
}
+static void kvm_cpu_exit_handler(int signum)
+{
+ /* Don't do anything here */
+}
+
int kvm_cpu__start(struct kvm_cpu *cpu)
{
sigset_t sigset;
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
+ signal(SIGKVMEXIT, kvm_cpu_exit_handler);
+
kvm_cpu__setup_cpuid(cpu);
kvm_cpu__reset_vcpu(cpu);
break;
}
case KVM_EXIT_INTR:
- break;
+ /*
+ * Currently we only handle exit signal, which means
+ * we just exit if KVM_RUN exited due to a signal.
+ */
+ goto exit_kvm;
case KVM_EXIT_SHUTDOWN:
goto exit_kvm;
default:
int max_cpus;
char *hi;
int i;
+ void *ret;
signal(SIGALRM, handle_sigalrm);
signal(SIGQUIT, handle_sigquit);
die("unable to create KVM VCPU thread");
}
- for (i = 0; i < nrcpus; i++) {
- void *ret;
+ /* Only VCPU #0 is going to exit by itself when shutting down */
+ if (pthread_join(kvm_cpus[0]->thread, &ret) != 0)
+ exit_code = 1;
+ for (i = 1; i < nrcpus; i++) {
+ pthread_kill(kvm_cpus[i]->thread, SIGKVMEXIT);
if (pthread_join(kvm_cpus[i]->thread, &ret) != 0)
die("pthread_join");
if (ret != NULL)
- exit_code = 1;
+ exit_code = 1;
}
kvm__delete(kvm);