Skip to contentSkip to conversation

Resend: fixes for io-thread

PATCH In review Glauber Costa 3 participants 5 messages Sep 28, 2009 – Sep 30, 2009

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw

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
index 7dcc553..11f4414 100644
@@ -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
index 12e7dd0..820dd37 100644
@@ -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
index eb01da7..f24a260 100644
@@ -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
#2 lore raw

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
index f24a260..9448190 100644
@@ -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
#3 lore raw

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_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.

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.

Nice signoff

[..snip..]

Signature · 1 line
mailto:[email protected]
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl

In reply to Glauber Costa
Quoted 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.

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
index 7dcc553..11f4414 100644
@@ -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
index 12e7dd0..820dd37 100644
@@ -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
index eb01da7..f24a260 100644
@@ -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);
 }