IO-thread fixes
cover IO-thread fixes
Builds ok, and does not offend anybody this time.
PATCH 1/2 unlock iothread mutex before running kvm ioctl
Without this, kvm will hold the mutex while it issues its run ioctl, and never be able to step out of it, causing a deadlock.
--- kvm-all.c | 2 ++ qemu-common.h | 3 +++ vl.c | 8 ++++---- 3 files changed, 9 insertions(+), 4 deletions(-)
kvm-all.c +2 -0
@@ -605,7 +605,9 @@ int kvm_cpu_exec(CPUState *env) }kvm_arch_pre_run (env, run); +qemu_mutex_unlock_iothread (); ret =kvm_vcpu_ioctl (env,KVM_RUN ,0 ); +qemu_mutex_lock_iothread ();kvm_arch_post_run (env, run);if (ret == -EINTR || ret == -EAGAIN ) {
qemu-common.h +3 -0
@@ -146,6 +146,9 @@ char *qemu_strndup(const char *str, size_t size);void *get_mmap_addr (unsigned long size); +void qemu_mutex_lock_iothread (void ); +void qemu_mutex_unlock_iothread (void ); +/* Error handling. */ void QEMU_NORETURN hw_error(const char *fmt, ...)
vl.c +4 -4
@@ -3445,8 +3445,8 @@ void qemu_notify_event(void) } } -#define qemu_mutex_lock_iothread () do { } while (0) -#define qemu_mutex_unlock_iothread () do { } while (0) +void qemu_mutex_lock_iothread (void ) {} +void qemu_mutex_unlock_iothread (void ) {}void vm_stop (int reason) {
@@ -3640,7 +3640,7 @@ static void qemu_signal_lock(unsigned int msecs)qemu_mutex_unlock (&qemu_fair_mutex); } -static void qemu_mutex_lock_iothread (void ) +void qemu_mutex_lock_iothread (void ) {if (kvm_enabled ()) {qemu_mutex_lock (&qemu_fair_mutex);
@@ -3650,7 +3650,7 @@ static void qemu_mutex_lock_iothread(void)qemu_signal_lock (100 ); } -static void qemu_mutex_unlock_iothread (void ) +void qemu_mutex_unlock_iothread (void ) {qemu_mutex_unlock (&qemu_global_mutex); }
Signature · 1 line
1.6.2.5
PATCH 2/2 do proper cpu_self check
Currently, our check for qemu_cpu_self only checks if there is a cpu currently in execution (represented by cpu_single_env being set). While this might be okay for tcg, it is certainly not okay for kvm, since multiple cpus might be executing.
Instead, I propose we use pthread primitives to test if the caller thread is the same as env->thread.
For tcg, it will have the same semantics as before, since all CPUStates will point to the same thread, and we'll only have one in execution at a time.
--- vl.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
vl.c +7 -2
@@ -3582,9 +3582,14 @@ void qemu_cpu_kick(void *_env)qemu_thread_signal (env->thread,SIGUSR1 ); } -int qemu_cpu_self (void *env) +int qemu_cpu_self (void *_env) { -return (cpu_single_env !=NULL ); +CPUState *env = _env; +QemuThread this; + +qemu_thread_self (&this); + +return qemu_thread_equal (&this, env->thread); }static void cpu_signal (int sig)
Signature · 1 line
1.6.2.5