Resend: fixes for io-thread
cover Resend: fixes for io-thread
I am resending those two fixes, needed for kvm to run with our current io-thread.
Anthony, please apply them. It will lead us to a much better shape.
PATCH 1/2 unlock iothread mutex before running kvm ioctl
From: Glauber Costa <[email protected]>
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 | 4 ++-- 3 files changed, 7 insertions(+), 2 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 +2 -2
@@ -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
From: Glauber Costa <[email protected]>
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
Re: [Qemu-devel] [PATCH 2/2] do proper cpu_self check
Quoted 7 lines · Glauber Costa
From: Glauber Costa <[email protected]>
Currently, our check for
qemu_cpu_selfonly checks if there is a cpu currently in execution (represented bycpu_single_envbeing set). While this might be okay for tcg, it is certainly not okay for kvm, since multiple cpus might be executing.
Quoted 7 lines
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.
Signed-off-by Glauber Costa <[email protected]>
Nice signoff
[..snip..]
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl
In reply to Glauber CostaQuoted 7 lines · Glauber Costa
From: Glauber Costa <[email protected]>
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.
Signed-off-by Glauber Costa <[email protected]>
Breaks the build when !CONFIG_IOTHREAD and needs a new SoB.
Quoted 57 lines
--- kvm-all.c | 2 ++ qemu-common.h | 3 +++ vl.c | 4 ++-- 3 files changed, 7 insertions(+), 2 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 +2
-2@@ -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); }