qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] IO-thread fixes again
@ 2009-10-07 18:49 Glauber Costa
  2009-10-07 18:49 ` [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl Glauber Costa
  2009-10-07 19:36 ` [Qemu-devel] [PATCH 0/2] IO-thread fixes again Glauber Costa
  0 siblings, 2 replies; 4+ messages in thread
From: Glauber Costa @ 2009-10-07 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori

Since the last one broke the build for !IO_THREAD, here it goes
a version that (at least in my boxes) does not.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl
  2009-10-07 18:49 [Qemu-devel] [PATCH 0/2] IO-thread fixes again Glauber Costa
@ 2009-10-07 18:49 ` Glauber Costa
  2009-10-07 18:49   ` [Qemu-devel] [PATCH 2/2] do proper cpu_self check Glauber Costa
  2009-10-07 19:36 ` [Qemu-devel] [PATCH 0/2] IO-thread fixes again Glauber Costa
  1 sibling, 1 reply; 4+ messages in thread
From: Glauber Costa @ 2009-10-07 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Glauber Costa, aliguori

From: Glauber Costa <glommer@mothafucka.localdomain>

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 <glommer@mothafucka.localdomain>
---
 kvm-all.c     |    2 ++
 qemu-common.h |    3 +++
 vl.c          |    8 ++++----
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 7dcc553..11f4414 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -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) {
diff --git a/qemu-common.h b/qemu-common.h
index 12e7dd0..820dd37 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -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, ...)
diff --git a/vl.c b/vl.c
index eb01da7..3012141 100644
--- a/vl.c
+++ b/vl.c
@@ -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);
 }
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 2/2] do proper cpu_self check
  2009-10-07 18:49 ` [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl Glauber Costa
@ 2009-10-07 18:49   ` Glauber Costa
  0 siblings, 0 replies; 4+ messages in thread
From: Glauber Costa @ 2009-10-07 18:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Glauber Costa, aliguori

From: Glauber Costa <glommer@mothafucka.localdomain>

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.

Signed-off-by: Glauber Costa <glommer@mothafucka.localdomain>
---
 vl.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/vl.c b/vl.c
index 3012141..e141bd1 100644
--- a/vl.c
+++ b/vl.c
@@ -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)
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] IO-thread fixes again
  2009-10-07 18:49 [Qemu-devel] [PATCH 0/2] IO-thread fixes again Glauber Costa
  2009-10-07 18:49 ` [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl Glauber Costa
@ 2009-10-07 19:36 ` Glauber Costa
  1 sibling, 0 replies; 4+ messages in thread
From: Glauber Costa @ 2009-10-07 19:36 UTC (permalink / raw)
  To: Glauber Costa; +Cc: aliguori, qemu-devel

And I forgot to fix the SoB AGAIN!

sorry dudes

On Wed, Oct 7, 2009 at 3:49 PM, Glauber Costa <glommer@redhat.com> wrote:
> Since the last one broke the build for !IO_THREAD, here it goes
> a version that (at least in my boxes) does not.
>
>
>
>



-- 
Glauber  Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-07 19:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-07 18:49 [Qemu-devel] [PATCH 0/2] IO-thread fixes again Glauber Costa
2009-10-07 18:49 ` [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl Glauber Costa
2009-10-07 18:49   ` [Qemu-devel] [PATCH 2/2] do proper cpu_self check Glauber Costa
2009-10-07 19:36 ` [Qemu-devel] [PATCH 0/2] IO-thread fixes again Glauber Costa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).