Patchwork [1/2] unlock iothread mutex before running kvm ioctl

login
register
mail settings
Submitter Glauber Costa
Date Sept. 28, 2009, 6:27 p.m.
Message ID <1254162464-20089-2-git-send-email-glommer@redhat.com>
Download mbox | patch
Permalink /patch/34384/
State Superseded
Headers show

Comments

Glauber Costa - Sept. 28, 2009, 6:27 p.m.
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          |    4 ++--
 3 files changed, 7 insertions(+), 2 deletions(-)
Anthony Liguori - Sept. 30, 2009, 8:02 p.m.
Glauber Costa wrote:
> 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>
>   

Breaks the build when !CONFIG_IOTHREAD and needs a new SoB.

> ---
>  kvm-all.c     |    2 ++
>  qemu-common.h |    3 +++
>  vl.c          |    4 ++--
>  3 files changed, 7 insertions(+), 2 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..f24a260 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -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);
>  }
>

Patch

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..f24a260 100644
--- a/vl.c
+++ b/vl.c
@@ -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);
 }