diff options
-rw-r--r-- | qemu/qemu-kvm-x86.c | 3 | ||||
-rw-r--r-- | qemu/qemu-kvm.c | 23 | ||||
-rw-r--r-- | qemu/qemu-kvm.h | 2 |
3 files changed, 19 insertions, 9 deletions
diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c index c79ca369..d1838f1d 100644 --- a/qemu/qemu-kvm-x86.c +++ b/qemu/qemu-kvm-x86.c @@ -23,7 +23,6 @@ extern kvm_context_t kvm_context; static int kvm_has_msr_star; static int lm_capable_kernel; -extern __thread CPUState *vcpu_env; int kvm_arch_qemu_create_context(void) { @@ -576,7 +575,7 @@ void kvm_arch_pre_kvm_run(void *opaque, int vcpu) void kvm_arch_post_kvm_run(void *opaque, int vcpu) { - CPUState *env = vcpu_env; + CPUState *env = qemu_kvm_cpu_env(vcpu); cpu_single_env = env; env->eflags = kvm_get_interrupt_flag(kvm_context, vcpu) diff --git a/qemu/qemu-kvm.c b/qemu/qemu-kvm.c index 43b52f39..ec05027c 100644 --- a/qemu/qemu-kvm.c +++ b/qemu/qemu-kvm.c @@ -30,7 +30,7 @@ extern int smp_cpus; pthread_mutex_t qemu_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t qemu_aio_cond = PTHREAD_COND_INITIALIZER; -__thread CPUState *vcpu_env; +__thread struct vcpu_info *vcpu; struct qemu_kvm_signal_table { sigset_t sigset; @@ -42,6 +42,7 @@ static struct qemu_kvm_signal_table io_signal_table; #define SIG_IPI (SIGRTMIN+4) struct vcpu_info { + CPUState *env; int sipi_needed; int init; pthread_t thread; @@ -50,13 +51,18 @@ struct vcpu_info { int stopped; } vcpu_info[4]; +CPUState *qemu_kvm_cpu_env(int index) +{ + return vcpu_info[index].env; +} + static void sig_ipi_handler(int n) { } void kvm_update_interrupt_request(CPUState *env) { - if (env && env != vcpu_env) { + if (env && vcpu && env != vcpu->env) { if (vcpu_info[env->cpu_index].signalled) return; vcpu_info[env->cpu_index].signalled = 1; @@ -154,7 +160,8 @@ static int kvm_eat_signal(CPUState *env, int timeout) return 0; e = errno; pthread_mutex_lock(&qemu_mutex); - cpu_single_env = vcpu_env; + if (vcpu) + cpu_single_env = vcpu->env; if (r == -1 && !(errno == EAGAIN || errno == EINTR)) { printf("sigtimedwait: %s\n", strerror(e)); exit(1); @@ -189,7 +196,7 @@ static void kvm_eat_signals(CPUState *env, int timeout) * for which there is no signal handler installed. */ pthread_mutex_lock(&qemu_mutex); - cpu_single_env = vcpu_env; + cpu_single_env = vcpu->env; main_loop_wait(0); pthread_mutex_unlock(&qemu_mutex); } @@ -251,7 +258,7 @@ static void pause_other_threads(void) pthread_kill(vcpu_info[i].thread, SIG_IPI); } while (!all_threads_paused()) - kvm_eat_signals(vcpu_env, 0); + kvm_eat_signals(vcpu->env, 0); } static void resume_other_threads(void) @@ -344,7 +351,8 @@ static void *ap_main_loop(void *_env) CPUState *env = _env; sigset_t signals; - vcpu_env = env; + vcpu = &vcpu_info[env->cpu_index]; + vcpu->env = env; sigfillset(&signals); //sigdelset(&signals, SIG_IPI); sigprocmask(SIG_BLOCK, &signals, NULL); @@ -381,7 +389,8 @@ int kvm_init_ap(void) kvm_add_signal(&io_signal_table, SIG_IPI); sigprocmask(SIG_BLOCK, &io_signal_table.sigset, NULL); - vcpu_env = first_cpu; + vcpu = &vcpu_info[0]; + vcpu->env = first_cpu; signal(SIG_IPI, sig_ipi_handler); for (i = 1; i < smp_cpus; ++i) { pthread_create(&vcpu_info[i].thread, NULL, ap_main_loop, env); diff --git a/qemu/qemu-kvm.h b/qemu/qemu-kvm.h index bda1c0b1..4df8cd44 100644 --- a/qemu/qemu-kvm.h +++ b/qemu/qemu-kvm.h @@ -40,6 +40,8 @@ int kvm_arch_has_work(CPUState *env); int kvm_arch_try_push_interrupts(void *opaque); void kvm_arch_update_regs_for_sipi(CPUState *env); +CPUState *qemu_kvm_cpu_env(int index); + void qemu_kvm_aio_wait_start(void); void qemu_kvm_aio_wait(void); void qemu_kvm_aio_wait_end(void); |