Patchwork [12/22] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD

login
register
mail settings
Submitter Jan Kiszka
Date Jan. 27, 2011, 1:09 p.m.
Message ID <0e59ec643d0d2abfb497091672daa9e8ae7f0353.1296133797.git.jan.kiszka@siemens.com>
Download mbox | patch
Permalink /patch/80694/
State New
Headers show

Comments

Jan Kiszka - Jan. 27, 2011, 1:09 p.m.
Move qemu_kvm_eat_signals around and call it also when the IO-thread is
not used. Do not yet process SIGBUS, will be armed in a separate step.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 cpus.c |   88 ++++++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 50 insertions(+), 38 deletions(-)
Paolo Bonzini - Jan. 28, 2011, 8:09 a.m.
On 01/27/2011 02:09 PM, Jan Kiszka wrote:
> Move qemu_kvm_eat_signals around and call it also when the IO-thread is
> not used. Do not yet process SIGBUS, will be armed in a separate step.
>
> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>
> ---
>   cpus.c |   88 ++++++++++++++++++++++++++++++++++++---------------------------
>   1 files changed, 50 insertions(+), 38 deletions(-)
>
> diff --git a/cpus.c b/cpus.c
> index 9071848..558c0d3 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -261,6 +261,45 @@ static void qemu_kvm_init_cpu_signals(CPUState *env)
>       }
>   }
>
> +static void qemu_kvm_eat_signals(CPUState *env)
> +{
> +    struct timespec ts = { 0, 0 };
> +    siginfo_t siginfo;
> +    sigset_t waitset;
> +    sigset_t chkset;
> +    int r;
> +
> +    sigemptyset(&waitset);
> +    sigaddset(&waitset, SIG_IPI);
> +    sigaddset(&waitset, SIGBUS);
> +
> +    do {
> +        r = sigtimedwait(&waitset,&siginfo,&ts);
> +        if (r == -1&&  !(errno == EAGAIN || errno == EINTR)) {
> +            perror("sigtimedwait");
> +            exit(1);
> +        }
> +
> +        switch (r) {
> +#ifdef CONFIG_IOTHREAD
> +        case SIGBUS:
> +            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
> +                sigbus_reraise();
> +            }
> +            break;
> +#endif
> +        default:
> +            break;
> +        }
> +
> +        r = sigpending(&chkset);
> +        if (r == -1) {
> +            perror("sigpending");
> +            exit(1);
> +        }
> +    } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
> +}
> +
>   #else /* _WIN32 */
>
>   HANDLE qemu_event_handle;
> @@ -292,6 +331,10 @@ static void qemu_event_increment(void)
>   static void qemu_kvm_init_cpu_signals(CPUState *env)
>   {
>   }
> +
> +static void qemu_kvm_eat_signals(CPUState *env)
> +{
> +}
>   #endif /* _WIN32 */
>
>   #ifndef CONFIG_IOTHREAD
> @@ -631,43 +674,6 @@ static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
>       }
>   }
>
> -static void qemu_kvm_eat_signals(CPUState *env)
> -{
> -    struct timespec ts = { 0, 0 };
> -    siginfo_t siginfo;
> -    sigset_t waitset;
> -    sigset_t chkset;
> -    int r;
> -
> -    sigemptyset(&waitset);
> -    sigaddset(&waitset, SIG_IPI);
> -    sigaddset(&waitset, SIGBUS);
> -
> -    do {
> -        r = sigtimedwait(&waitset,&siginfo,&ts);
> -        if (r == -1&&  !(errno == EAGAIN || errno == EINTR)) {
> -            perror("sigtimedwait");
> -            exit(1);
> -        }
> -
> -        switch (r) {
> -        case SIGBUS:
> -            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
> -                sigbus_reraise();
> -            }
> -            break;
> -        default:
> -            break;
> -        }
> -
> -        r = sigpending(&chkset);
> -        if (r == -1) {
> -            perror("sigpending");
> -            exit(1);
> -        }
> -    } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
> -}
> -
>   static void qemu_kvm_wait_io_event(CPUState *env)
>   {
>       while (!cpu_has_work(env))
> @@ -932,6 +938,8 @@ static int qemu_cpu_exec(CPUState *env)
>
>   bool cpu_exec_all(void)
>   {
> +    int r;
> +
>       if (next_cpu == NULL)
>           next_cpu = first_cpu;
>       for (; next_cpu != NULL&&  !exit_request; next_cpu = next_cpu->next_cpu) {
> @@ -943,7 +951,11 @@ bool cpu_exec_all(void)
>           if (qemu_alarm_pending())
>               break;
>           if (cpu_can_run(env)) {
> -            if (qemu_cpu_exec(env) == EXCP_DEBUG) {
> +            r = qemu_cpu_exec(env);
> +            if (kvm_enabled()) {
> +                qemu_kvm_eat_signals(env);
> +            }
> +            if (r == EXCP_DEBUG) {
>                   break;
>               }
>           } else if (env->stop) {

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo
Marcelo Tosatti - Feb. 1, 2011, 12:38 p.m.
On Thu, Jan 27, 2011 at 02:09:56PM +0100, Jan Kiszka wrote:
> Move qemu_kvm_eat_signals around and call it also when the IO-thread is
> not used. Do not yet process SIGBUS, will be armed in a separate step.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  cpus.c |   88 ++++++++++++++++++++++++++++++++++++---------------------------
>  1 files changed, 50 insertions(+), 38 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index 9071848..558c0d3 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -261,6 +261,45 @@ static void qemu_kvm_init_cpu_signals(CPUState *env)
>      }
>  }
>  
> +static void qemu_kvm_eat_signals(CPUState *env)
> +{
> +    struct timespec ts = { 0, 0 };
> +    siginfo_t siginfo;
> +    sigset_t waitset;
> +    sigset_t chkset;
> +    int r;
> +
> +    sigemptyset(&waitset);
> +    sigaddset(&waitset, SIG_IPI);
> +    sigaddset(&waitset, SIGBUS);
> +
> +    do {
> +        r = sigtimedwait(&waitset, &siginfo, &ts);
> +        if (r == -1 && !(errno == EAGAIN || errno == EINTR)) {
> +            perror("sigtimedwait");
> +            exit(1);
> +        }
> +
> +        switch (r) {
> +#ifdef CONFIG_IOTHREAD
> +        case SIGBUS:
> +            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
> +                sigbus_reraise();
> +            }
> +            break;
> +#endif
> +        default:
> +            break;
> +        }
> +
> +        r = sigpending(&chkset);
> +        if (r == -1) {
> +            perror("sigpending");
> +            exit(1);
> +        }
> +    } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
> +}
> +
>  #else /* _WIN32 */
>  
>  HANDLE qemu_event_handle;
> @@ -292,6 +331,10 @@ static void qemu_event_increment(void)
>  static void qemu_kvm_init_cpu_signals(CPUState *env)
>  {
>  }
> +
> +static void qemu_kvm_eat_signals(CPUState *env)
> +{
> +}
>  #endif /* _WIN32 */
>  
>  #ifndef CONFIG_IOTHREAD
> @@ -631,43 +674,6 @@ static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
>      }
>  }
>  
> -static void qemu_kvm_eat_signals(CPUState *env)
> -{
> -    struct timespec ts = { 0, 0 };
> -    siginfo_t siginfo;
> -    sigset_t waitset;
> -    sigset_t chkset;
> -    int r;
> -
> -    sigemptyset(&waitset);
> -    sigaddset(&waitset, SIG_IPI);
> -    sigaddset(&waitset, SIGBUS);
> -
> -    do {
> -        r = sigtimedwait(&waitset, &siginfo, &ts);
> -        if (r == -1 && !(errno == EAGAIN || errno == EINTR)) {
> -            perror("sigtimedwait");
> -            exit(1);
> -        }
> -
> -        switch (r) {
> -        case SIGBUS:
> -            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
> -                sigbus_reraise();
> -            }
> -            break;
> -        default:
> -            break;
> -        }
> -
> -        r = sigpending(&chkset);
> -        if (r == -1) {
> -            perror("sigpending");
> -            exit(1);
> -        }
> -    } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
> -}
> -
>  static void qemu_kvm_wait_io_event(CPUState *env)
>  {
>      while (!cpu_has_work(env))
> @@ -932,6 +938,8 @@ static int qemu_cpu_exec(CPUState *env)
>  
>  bool cpu_exec_all(void)
>  {
> +    int r;
> +
>      if (next_cpu == NULL)
>          next_cpu = first_cpu;
>      for (; next_cpu != NULL && !exit_request; next_cpu = next_cpu->next_cpu) {
> @@ -943,7 +951,11 @@ bool cpu_exec_all(void)
>          if (qemu_alarm_pending())
>              break;
>          if (cpu_can_run(env)) {
> -            if (qemu_cpu_exec(env) == EXCP_DEBUG) {
> +            r = qemu_cpu_exec(env);
> +            if (kvm_enabled()) {
> +                qemu_kvm_eat_signals(env);
> +            }
> +            if (r == EXCP_DEBUG) {
>                  break;
>              }

As mentioned before, signal processing should be independent of
cpu_can_run (still want to process SIGALRM if vm is stopped, for
example).
Marcelo Tosatti - Feb. 1, 2011, 12:49 p.m.
On Tue, Feb 01, 2011 at 10:38:35AM -0200, Marcelo Tosatti wrote:
> > @@ -943,7 +951,11 @@ bool cpu_exec_all(void)
> >          if (qemu_alarm_pending())
> >              break;
> >          if (cpu_can_run(env)) {
> > -            if (qemu_cpu_exec(env) == EXCP_DEBUG) {
> > +            r = qemu_cpu_exec(env);
> > +            if (kvm_enabled()) {
> > +                qemu_kvm_eat_signals(env);
> > +            }
> > +            if (r == EXCP_DEBUG) {
> >                  break;
> >              }
> 
> As mentioned before, signal processing should be independent of
> cpu_can_run (still want to process SIGALRM if vm is stopped, for
> example).

Nevermind that comment.
Jan Kiszka - Feb. 1, 2011, 1:21 p.m.
On 2011-02-01 13:38, Marcelo Tosatti wrote:
> On Thu, Jan 27, 2011 at 02:09:56PM +0100, Jan Kiszka wrote:
>> Move qemu_kvm_eat_signals around and call it also when the IO-thread is
>> not used. Do not yet process SIGBUS, will be armed in a separate step.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>>  cpus.c |   88 ++++++++++++++++++++++++++++++++++++---------------------------
>>  1 files changed, 50 insertions(+), 38 deletions(-)
>>
>> diff --git a/cpus.c b/cpus.c
>> index 9071848..558c0d3 100644
>> --- a/cpus.c
>> +++ b/cpus.c
>> @@ -261,6 +261,45 @@ static void qemu_kvm_init_cpu_signals(CPUState *env)
>>      }
>>  }
>>  
>> +static void qemu_kvm_eat_signals(CPUState *env)
>> +{
>> +    struct timespec ts = { 0, 0 };
>> +    siginfo_t siginfo;
>> +    sigset_t waitset;
>> +    sigset_t chkset;
>> +    int r;
>> +
>> +    sigemptyset(&waitset);
>> +    sigaddset(&waitset, SIG_IPI);
>> +    sigaddset(&waitset, SIGBUS);
>> +
>> +    do {
>> +        r = sigtimedwait(&waitset, &siginfo, &ts);
>> +        if (r == -1 && !(errno == EAGAIN || errno == EINTR)) {
>> +            perror("sigtimedwait");
>> +            exit(1);
>> +        }
>> +
>> +        switch (r) {
>> +#ifdef CONFIG_IOTHREAD
>> +        case SIGBUS:
>> +            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
>> +                sigbus_reraise();
>> +            }
>> +            break;
>> +#endif
>> +        default:
>> +            break;
>> +        }
>> +
>> +        r = sigpending(&chkset);
>> +        if (r == -1) {
>> +            perror("sigpending");
>> +            exit(1);
>> +        }
>> +    } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
>> +}
>> +
>>  #else /* _WIN32 */
>>  
>>  HANDLE qemu_event_handle;
>> @@ -292,6 +331,10 @@ static void qemu_event_increment(void)
>>  static void qemu_kvm_init_cpu_signals(CPUState *env)
>>  {
>>  }
>> +
>> +static void qemu_kvm_eat_signals(CPUState *env)
>> +{
>> +}
>>  #endif /* _WIN32 */
>>  
>>  #ifndef CONFIG_IOTHREAD
>> @@ -631,43 +674,6 @@ static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
>>      }
>>  }
>>  
>> -static void qemu_kvm_eat_signals(CPUState *env)
>> -{
>> -    struct timespec ts = { 0, 0 };
>> -    siginfo_t siginfo;
>> -    sigset_t waitset;
>> -    sigset_t chkset;
>> -    int r;
>> -
>> -    sigemptyset(&waitset);
>> -    sigaddset(&waitset, SIG_IPI);
>> -    sigaddset(&waitset, SIGBUS);
>> -
>> -    do {
>> -        r = sigtimedwait(&waitset, &siginfo, &ts);
>> -        if (r == -1 && !(errno == EAGAIN || errno == EINTR)) {
>> -            perror("sigtimedwait");
>> -            exit(1);
>> -        }
>> -
>> -        switch (r) {
>> -        case SIGBUS:
>> -            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
>> -                sigbus_reraise();
>> -            }
>> -            break;
>> -        default:
>> -            break;
>> -        }
>> -
>> -        r = sigpending(&chkset);
>> -        if (r == -1) {
>> -            perror("sigpending");
>> -            exit(1);
>> -        }
>> -    } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
>> -}
>> -
>>  static void qemu_kvm_wait_io_event(CPUState *env)
>>  {
>>      while (!cpu_has_work(env))
>> @@ -932,6 +938,8 @@ static int qemu_cpu_exec(CPUState *env)
>>  
>>  bool cpu_exec_all(void)
>>  {
>> +    int r;
>> +
>>      if (next_cpu == NULL)
>>          next_cpu = first_cpu;
>>      for (; next_cpu != NULL && !exit_request; next_cpu = next_cpu->next_cpu) {
>> @@ -943,7 +951,11 @@ bool cpu_exec_all(void)
>>          if (qemu_alarm_pending())
>>              break;
>>          if (cpu_can_run(env)) {
>> -            if (qemu_cpu_exec(env) == EXCP_DEBUG) {
>> +            r = qemu_cpu_exec(env);
>> +            if (kvm_enabled()) {
>> +                qemu_kvm_eat_signals(env);
>> +            }
>> +            if (r == EXCP_DEBUG) {
>>                  break;
>>              }
> 
> As mentioned before, signal processing should be independent of
> cpu_can_run (still want to process SIGALRM if vm is stopped, for
> example).
> 

For those signals that matter, it is.

Jan

Patch

diff --git a/cpus.c b/cpus.c
index 9071848..558c0d3 100644
--- a/cpus.c
+++ b/cpus.c
@@ -261,6 +261,45 @@  static void qemu_kvm_init_cpu_signals(CPUState *env)
     }
 }
 
+static void qemu_kvm_eat_signals(CPUState *env)
+{
+    struct timespec ts = { 0, 0 };
+    siginfo_t siginfo;
+    sigset_t waitset;
+    sigset_t chkset;
+    int r;
+
+    sigemptyset(&waitset);
+    sigaddset(&waitset, SIG_IPI);
+    sigaddset(&waitset, SIGBUS);
+
+    do {
+        r = sigtimedwait(&waitset, &siginfo, &ts);
+        if (r == -1 && !(errno == EAGAIN || errno == EINTR)) {
+            perror("sigtimedwait");
+            exit(1);
+        }
+
+        switch (r) {
+#ifdef CONFIG_IOTHREAD
+        case SIGBUS:
+            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
+                sigbus_reraise();
+            }
+            break;
+#endif
+        default:
+            break;
+        }
+
+        r = sigpending(&chkset);
+        if (r == -1) {
+            perror("sigpending");
+            exit(1);
+        }
+    } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
+}
+
 #else /* _WIN32 */
 
 HANDLE qemu_event_handle;
@@ -292,6 +331,10 @@  static void qemu_event_increment(void)
 static void qemu_kvm_init_cpu_signals(CPUState *env)
 {
 }
+
+static void qemu_kvm_eat_signals(CPUState *env)
+{
+}
 #endif /* _WIN32 */
 
 #ifndef CONFIG_IOTHREAD
@@ -631,43 +674,6 @@  static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
     }
 }
 
-static void qemu_kvm_eat_signals(CPUState *env)
-{
-    struct timespec ts = { 0, 0 };
-    siginfo_t siginfo;
-    sigset_t waitset;
-    sigset_t chkset;
-    int r;
-
-    sigemptyset(&waitset);
-    sigaddset(&waitset, SIG_IPI);
-    sigaddset(&waitset, SIGBUS);
-
-    do {
-        r = sigtimedwait(&waitset, &siginfo, &ts);
-        if (r == -1 && !(errno == EAGAIN || errno == EINTR)) {
-            perror("sigtimedwait");
-            exit(1);
-        }
-
-        switch (r) {
-        case SIGBUS:
-            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
-                sigbus_reraise();
-            }
-            break;
-        default:
-            break;
-        }
-
-        r = sigpending(&chkset);
-        if (r == -1) {
-            perror("sigpending");
-            exit(1);
-        }
-    } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
-}
-
 static void qemu_kvm_wait_io_event(CPUState *env)
 {
     while (!cpu_has_work(env))
@@ -932,6 +938,8 @@  static int qemu_cpu_exec(CPUState *env)
 
 bool cpu_exec_all(void)
 {
+    int r;
+
     if (next_cpu == NULL)
         next_cpu = first_cpu;
     for (; next_cpu != NULL && !exit_request; next_cpu = next_cpu->next_cpu) {
@@ -943,7 +951,11 @@  bool cpu_exec_all(void)
         if (qemu_alarm_pending())
             break;
         if (cpu_can_run(env)) {
-            if (qemu_cpu_exec(env) == EXCP_DEBUG) {
+            r = qemu_cpu_exec(env);
+            if (kvm_enabled()) {
+                qemu_kvm_eat_signals(env);
+            }
+            if (r == EXCP_DEBUG) {
                 break;
             }
         } else if (env->stop) {