qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 2/2] do proper cpu_self check
  2009-09-28 18:27 ` [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl Glauber Costa
@ 2009-09-28 18:27   ` Glauber Costa
  2009-09-28 18:58     ` malc
  0 siblings, 1 reply; 6+ messages in thread
From: Glauber Costa @ 2009-09-28 18:27 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 f24a260..9448190 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] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] do proper cpu_self check
  2009-09-28 18:27   ` [Qemu-devel] [PATCH 2/2] do proper cpu_self check Glauber Costa
@ 2009-09-28 18:58     ` malc
  0 siblings, 0 replies; 6+ messages in thread
From: malc @ 2009-09-28 18:58 UTC (permalink / raw)
  To: Glauber Costa; +Cc: Glauber Costa, aliguori, qemu-devel

On Mon, 28 Sep 2009, Glauber Costa wrote:

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

Nice signoff

[..snip..]

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 6+ 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; 6+ 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] 6+ messages in thread

* [Qemu-devel] [PATCH 0/2] IO-thread fixes
@ 2009-10-07 19:38 Glauber Costa
  2009-10-07 19:38 ` [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl Glauber Costa
  0 siblings, 1 reply; 6+ messages in thread
From: Glauber Costa @ 2009-10-07 19:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori

Builds ok, and does not offend anybody this time.

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

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

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@redhat.com>
---
 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] 6+ messages in thread

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

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@redhat.com>
---
 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] 6+ messages in thread

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

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-07 19:38 [Qemu-devel] [PATCH 0/2] IO-thread fixes Glauber Costa
2009-10-07 19:38 ` [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl Glauber Costa
2009-10-07 19:38   ` [Qemu-devel] [PATCH 2/2] do proper cpu_self check Glauber Costa
  -- strict thread matches above, loose matches on Subject: below --
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-09-28 18:27 [Qemu-devel] [PATCH 0/2] Resend: fixes for io-thread Glauber Costa
2009-09-28 18:27 ` [Qemu-devel] [PATCH 1/2] unlock iothread mutex before running kvm ioctl Glauber Costa
2009-09-28 18:27   ` [Qemu-devel] [PATCH 2/2] do proper cpu_self check Glauber Costa
2009-09-28 18:58     ` malc

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