qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue
@ 2011-02-04 15:47 Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 01/23] Prevent abortion on multiple VCPU kicks Marcelo Tosatti
                   ` (23 more replies)
  0 siblings, 24 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Marcelo Tosatti, qemu-devel, kvm

The following changes since commit bfddb47a343b4718e5768aa80bce8adead0f7fca:

  Open up the 0.15 development branch (2011-02-02 08:39:28 +0100)

are available in the git repository at:
  git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master

Glauber Costa (1):
      kvm: make tsc stable over migration and machine start

Jan Kiszka (22):
      Prevent abortion on multiple VCPU kicks
      Stop current VCPU on synchronous reset requests
      Process vmstop requests in IO thread
      Trigger exit from cpu_exec_all on pending IO events
      Leave inner main_loop faster on pending requests
      Flatten the main loop
      kvm: Report proper error on GET_VCPU_MMAP_SIZE failures
      kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn
      kvm: Handle kvm_init_vcpu errors
      kvm: Provide sigbus services arch-independently
      Refactor signal setup functions in cpus.c
      kvm: Set up signal mask also for !CONFIG_IOTHREAD
      kvm: Refactor qemu_kvm_eat_signals
      kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD
      Set up signalfd under !CONFIG_IOTHREAD
      kvm: Fix race between timer signals and vcpu entry under !IOTHREAD
      kvm: Add MCE signal support for !CONFIG_IOTHREAD
      Introduce VCPU self-signaling service
      kvm: Unconditionally reenter kernel after IO exits
      kvm: Remove static return code of kvm_handle_io
      kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN
      x86: Fix MCA broadcast parameters for TCG case

 Makefile.objs        |    2 +-
 configure            |    6 +
 cpu-defs.h           |    1 +
 cpus.c               |  549 +++++++++++++++++++++++++++++++-------------------
 cpus.h               |    1 +
 kvm-all.c            |   60 ++++---
 kvm-stub.c           |    5 +
 kvm.h                |    7 +-
 qemu-common.h        |    1 +
 target-i386/cpu.h    |    1 +
 target-i386/helper.c |    4 +-
 target-i386/kvm.c    |   27 +++-
 target-ppc/kvm.c     |   10 +
 target-s390x/kvm.c   |   10 +
 vl.c                 |   40 ++--
 15 files changed, 466 insertions(+), 258 deletions(-)

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

* [Qemu-devel] [PATCH 01/23] Prevent abortion on multiple VCPU kicks
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 02/23] Stop current VCPU on synchronous reset requests Marcelo Tosatti
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

If we call qemu_cpu_kick more than once before the target was able to
process the signal, pthread_kill will fail, and qemu will abort. Prevent
this by avoiding the redundant signal.

This logic can be found in qemu-kvm as well.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpu-defs.h |    1 +
 cpus.c     |    6 +++++-
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/cpu-defs.h b/cpu-defs.h
index 8d4bf86..db809ed 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -205,6 +205,7 @@ typedef struct CPUWatchpoint {
     uint32_t stopped; /* Artificially stopped */                        \
     struct QemuThread *thread;                                          \
     struct QemuCond *halt_cond;                                         \
+    int thread_kicked;                                                  \
     struct qemu_work_item *queued_work_first, *queued_work_last;        \
     const char *cpu_model_str;                                          \
     struct KVMState *kvm_state;                                         \
diff --git a/cpus.c b/cpus.c
index 4c9928e..ab6e40e 100644
--- a/cpus.c
+++ b/cpus.c
@@ -481,6 +481,7 @@ static void qemu_wait_io_event_common(CPUState *env)
         qemu_cond_signal(&qemu_pause_cond);
     }
     flush_queued_work(env);
+    env->thread_kicked = false;
 }
 
 static void qemu_tcg_wait_io_event(void)
@@ -648,7 +649,10 @@ void qemu_cpu_kick(void *_env)
 {
     CPUState *env = _env;
     qemu_cond_broadcast(env->halt_cond);
-    qemu_thread_signal(env->thread, SIG_IPI);
+    if (!env->thread_kicked) {
+        qemu_thread_signal(env->thread, SIG_IPI);
+        env->thread_kicked = true;
+    }
 }
 
 int qemu_cpu_self(void *_env)
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 02/23] Stop current VCPU on synchronous reset requests
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 01/23] Prevent abortion on multiple VCPU kicks Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 03/23] Process vmstop requests in IO thread Marcelo Tosatti
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

If some I/O operation ends up calling qemu_system_reset_request in VCPU
context, we record this and inform the io-thread, but we do not
terminate the VCPU loop. This can lead to fairly unexpected behavior if
the triggering reset operation is supposed to work synchronously.

Fix this for TCG (when run in deterministic I/O mode) by setting the
VCPU on stop and issuing a cpu_exit. KVM requires some more work on its
VCPU loop.

[ ported from qemu-kvm ]

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c |   13 +++++++++----
 cpus.h |    1 +
 vl.c   |    1 +
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/cpus.c b/cpus.c
index ab6e40e..ceb3a83 100644
--- a/cpus.c
+++ b/cpus.c
@@ -99,6 +99,14 @@ void cpu_synchronize_all_post_init(void)
     }
 }
 
+void cpu_stop_current(void)
+{
+    if (cpu_single_env) {
+        cpu_single_env->stopped = 1;
+        cpu_exit(cpu_single_env);
+    }
+}
+
 int cpu_is_stopped(CPUState *env)
 {
     return !vm_running || env->stopped;
@@ -863,10 +871,7 @@ void vm_stop(int reason)
          * FIXME: should not return to device code in case
          * vm_stop() has been requested.
          */
-        if (cpu_single_env) {
-            cpu_exit(cpu_single_env);
-            cpu_single_env->stop = 1;
-        }
+        cpu_stop_current();
         return;
     }
     do_vm_stop(reason);
diff --git a/cpus.h b/cpus.h
index bf4d9bb..4cadb64 100644
--- a/cpus.h
+++ b/cpus.h
@@ -6,6 +6,7 @@ int qemu_init_main_loop(void);
 void qemu_main_loop_start(void);
 void resume_all_vcpus(void);
 void pause_all_vcpus(void);
+void cpu_stop_current(void);
 
 /* vl.c */
 extern int smp_cores;
diff --git a/vl.c b/vl.c
index 655617f..b1dc3ff 100644
--- a/vl.c
+++ b/vl.c
@@ -1296,6 +1296,7 @@ void qemu_system_reset_request(void)
     } else {
         reset_requested = 1;
     }
+    cpu_stop_current();
     qemu_notify_event();
 }
 
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 03/23] Process vmstop requests in IO thread
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 01/23] Prevent abortion on multiple VCPU kicks Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 02/23] Stop current VCPU on synchronous reset requests Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 04/23] Trigger exit from cpu_exec_all on pending IO events Marcelo Tosatti
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

A pending vmstop request is also a reason to leave the inner main loop.
So far we ignored it, and pending stop requests issued over VCPU threads
were simply ignored.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 vl.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/vl.c b/vl.c
index b1dc3ff..57b4c9f 100644
--- a/vl.c
+++ b/vl.c
@@ -1391,15 +1391,11 @@ void main_loop_wait(int nonblocking)
 
 static int vm_can_run(void)
 {
-    if (powerdown_requested)
-        return 0;
-    if (reset_requested)
-        return 0;
-    if (shutdown_requested)
-        return 0;
-    if (debug_requested)
-        return 0;
-    return 1;
+    return !(powerdown_requested ||
+             reset_requested ||
+             shutdown_requested ||
+             debug_requested ||
+             vmstop_requested);
 }
 
 qemu_irq qemu_system_powerdown;
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 04/23] Trigger exit from cpu_exec_all on pending IO events
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (2 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 03/23] Process vmstop requests in IO thread Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 05/23] Leave inner main_loop faster on pending requests Marcelo Tosatti
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Except for timer events, we currently do not leave the loop over all
VCPUs if an IO event was filed. That may cause unexpected IO latencies
under !CONFIG_IOTHREAD in SMP scenarios. Fix it by setting the global
exit_request which breaks the loop.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/cpus.c b/cpus.c
index ceb3a83..5dfc54e 100644
--- a/cpus.c
+++ b/cpus.c
@@ -315,6 +315,7 @@ void qemu_notify_event(void)
     if (next_cpu && env != next_cpu) {
         cpu_exit(next_cpu);
     }
+    exit_request = 1;
 }
 
 void qemu_mutex_lock_iothread(void) {}
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 05/23] Leave inner main_loop faster on pending requests
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (3 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 04/23] Trigger exit from cpu_exec_all on pending IO events Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 06/23] Flatten the main loop Marcelo Tosatti
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

If there is any pending request that requires us to leave the inner loop
if main_loop, makes sure we do this as soon as possible by enforcing
non-blocking IO processing.

At this change, move variable definitions out of the inner loop to
improve readability.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 vl.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/vl.c b/vl.c
index 57b4c9f..6aa896c 100644
--- a/vl.c
+++ b/vl.c
@@ -1402,18 +1402,21 @@ qemu_irq qemu_system_powerdown;
 
 static void main_loop(void)
 {
+    bool nonblocking = false;
+#ifdef CONFIG_PROFILER
+    int64_t ti;
+#endif
     int r;
 
     qemu_main_loop_start();
 
     for (;;) {
         do {
-            bool nonblocking = false;
-#ifdef CONFIG_PROFILER
-            int64_t ti;
-#endif
 #ifndef CONFIG_IOTHREAD
             nonblocking = cpu_exec_all();
+            if (!vm_can_run()) {
+                nonblocking = true;
+            }
 #endif
 #ifdef CONFIG_PROFILER
             ti = profile_getclock();
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 06/23] Flatten the main loop
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (4 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 05/23] Leave inner main_loop faster on pending requests Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 07/23] kvm: Report proper error on GET_VCPU_MMAP_SIZE failures Marcelo Tosatti
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

First of all, vm_can_run is a misnomer, it actually means "no request
pending". Moreover, there is no need to check all pending requests
twice, the first time via the inner loop check and then again when
actually processing the requests. We can simply remove the inner loop
and do the checks directly.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 vl.c |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/vl.c b/vl.c
index 6aa896c..837be97 100644
--- a/vl.c
+++ b/vl.c
@@ -1389,14 +1389,16 @@ void main_loop_wait(int nonblocking)
 
 }
 
-static int vm_can_run(void)
+#ifndef CONFIG_IOTHREAD
+static int vm_request_pending(void)
 {
-    return !(powerdown_requested ||
-             reset_requested ||
-             shutdown_requested ||
-             debug_requested ||
-             vmstop_requested);
+    return powerdown_requested ||
+           reset_requested ||
+           shutdown_requested ||
+           debug_requested ||
+           vmstop_requested;
 }
+#endif
 
 qemu_irq qemu_system_powerdown;
 
@@ -1411,21 +1413,19 @@ static void main_loop(void)
     qemu_main_loop_start();
 
     for (;;) {
-        do {
 #ifndef CONFIG_IOTHREAD
-            nonblocking = cpu_exec_all();
-            if (!vm_can_run()) {
-                nonblocking = true;
-            }
+        nonblocking = cpu_exec_all();
+        if (vm_request_pending()) {
+            nonblocking = true;
+        }
 #endif
 #ifdef CONFIG_PROFILER
-            ti = profile_getclock();
+        ti = profile_getclock();
 #endif
-            main_loop_wait(nonblocking);
+        main_loop_wait(nonblocking);
 #ifdef CONFIG_PROFILER
-            dev_time += profile_getclock() - ti;
+        dev_time += profile_getclock() - ti;
 #endif
-        } while (vm_can_run());
 
         if ((r = qemu_debug_requested())) {
             vm_stop(r);
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 07/23] kvm: Report proper error on GET_VCPU_MMAP_SIZE failures
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (5 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 06/23] Flatten the main loop Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 08/23] kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn Marcelo Tosatti
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 kvm-all.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 2ec9e09..55f6ac3 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -219,6 +219,7 @@ int kvm_init_vcpu(CPUState *env)
 
     mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
     if (mmap_size < 0) {
+        ret = mmap_size;
         DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n");
         goto err;
     }
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 08/23] kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (6 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 07/23] kvm: Report proper error on GET_VCPU_MMAP_SIZE failures Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 09/23] kvm: Handle kvm_init_vcpu errors Marcelo Tosatti
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 5dfc54e..312c7a2 100644
--- a/cpus.c
+++ b/cpus.c
@@ -607,8 +607,8 @@ static void *kvm_cpu_thread_fn(void *arg)
 
     qemu_mutex_lock(&qemu_global_mutex);
     qemu_thread_self(env->thread);
-    if (kvm_enabled())
-        kvm_init_vcpu(env);
+
+    kvm_init_vcpu(env);
 
     kvm_init_ipi(env);
 
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 09/23] kvm: Handle kvm_init_vcpu errors
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (7 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 08/23] kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 10/23] kvm: Provide sigbus services arch-independently Marcelo Tosatti
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Do not ignore errors of kvm_init_vcpu, they are fatal.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/cpus.c b/cpus.c
index 312c7a2..8475757 100644
--- a/cpus.c
+++ b/cpus.c
@@ -273,12 +273,18 @@ void qemu_main_loop_start(void)
 void qemu_init_vcpu(void *_env)
 {
     CPUState *env = _env;
+    int r;
 
     env->nr_cores = smp_cores;
     env->nr_threads = smp_threads;
-    if (kvm_enabled())
-        kvm_init_vcpu(env);
-    return;
+
+    if (kvm_enabled()) {
+        r = kvm_init_vcpu(env);
+        if (r < 0) {
+            fprintf(stderr, "kvm_init_vcpu failed: %s\n", strerror(-r));
+            exit(1);
+        }
+    }
 }
 
 int qemu_cpu_self(void *env)
@@ -604,11 +610,16 @@ static int qemu_cpu_exec(CPUState *env);
 static void *kvm_cpu_thread_fn(void *arg)
 {
     CPUState *env = arg;
+    int r;
 
     qemu_mutex_lock(&qemu_global_mutex);
     qemu_thread_self(env->thread);
 
-    kvm_init_vcpu(env);
+    r = kvm_init_vcpu(env);
+    if (r < 0) {
+        fprintf(stderr, "kvm_init_vcpu failed: %s\n", strerror(-r));
+        exit(1);
+    }
 
     kvm_init_ipi(env);
 
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 10/23] kvm: Provide sigbus services arch-independently
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (8 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 09/23] kvm: Handle kvm_init_vcpu errors Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 11/23] Refactor signal setup functions in cpus.c Marcelo Tosatti
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Provide arch-independent kvm_on_sigbus* stubs to remove the #ifdef'ery
from cpus.c. This patch also fixes --disable-kvm build by providing the
missing kvm_on_sigbus_vcpu kvm-stub.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c             |   10 ++++------
 kvm-all.c          |   10 ++++++++++
 kvm-stub.c         |    5 +++++
 kvm.h              |    7 +++++--
 target-i386/kvm.c  |    4 ++--
 target-ppc/kvm.c   |   10 ++++++++++
 target-s390x/kvm.c |   10 ++++++++++
 7 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/cpus.c b/cpus.c
index 8475757..3a32828 100644
--- a/cpus.c
+++ b/cpus.c
@@ -543,10 +543,9 @@ static void sigbus_reraise(void)
 static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
                            void *ctx)
 {
-#if defined(TARGET_I386)
-    if (kvm_on_sigbus(siginfo->ssi_code, (void *)(intptr_t)siginfo->ssi_addr))
-#endif
+    if (kvm_on_sigbus(siginfo->ssi_code, (void *)(intptr_t)siginfo->ssi_addr)) {
         sigbus_reraise();
+    }
 }
 
 static void qemu_kvm_eat_signal(CPUState *env, int timeout)
@@ -579,10 +578,9 @@ static void qemu_kvm_eat_signal(CPUState *env, int timeout)
 
         switch (r) {
         case SIGBUS:
-#ifdef TARGET_I386
-            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr))
-#endif
+            if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
                 sigbus_reraise();
+            }
             break;
         default:
             break;
diff --git a/kvm-all.c b/kvm-all.c
index 55f6ac3..a83aff2 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1366,3 +1366,13 @@ int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign)
     return -ENOSYS;
 #endif
 }
+
+int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr)
+{
+    return kvm_arch_on_sigbus_vcpu(env, code, addr);
+}
+
+int kvm_on_sigbus(int code, void *addr)
+{
+    return kvm_arch_on_sigbus(code, addr);
+}
diff --git a/kvm-stub.c b/kvm-stub.c
index 88682f2..d6b6c8e 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -147,6 +147,11 @@ int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign)
     return -ENOSYS;
 }
 
+int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr)
+{
+    return 1;
+}
+
 int kvm_on_sigbus(int code, void *addr)
 {
     return 1;
diff --git a/kvm.h b/kvm.h
index ca57517..b2fb5c6 100644
--- a/kvm.h
+++ b/kvm.h
@@ -81,6 +81,9 @@ int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset);
 int kvm_pit_in_kernel(void);
 int kvm_irqchip_in_kernel(void);
 
+int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr);
+int kvm_on_sigbus(int code, void *addr);
+
 /* internal API */
 
 struct KVMState;
@@ -121,8 +124,8 @@ int kvm_arch_init_vcpu(CPUState *env);
 
 void kvm_arch_reset_vcpu(CPUState *env);
 
-int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr);
-int kvm_on_sigbus(int code, void *addr);
+int kvm_arch_on_sigbus_vcpu(CPUState *env, int code, void *addr);
+int kvm_arch_on_sigbus(int code, void *addr);
 
 struct kvm_guest_debug;
 struct kvm_debug_exit_arch;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 05010bb..9df8ff8 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1839,7 +1839,7 @@ static void kvm_mce_inj_srao_memscrub2(CPUState *env, target_phys_addr_t paddr)
 
 #endif
 
-int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr)
+int kvm_arch_on_sigbus_vcpu(CPUState *env, int code, void *addr)
 {
 #if defined(KVM_CAP_MCE)
     void *vaddr;
@@ -1889,7 +1889,7 @@ int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr)
     return 0;
 }
 
-int kvm_on_sigbus(int code, void *addr)
+int kvm_arch_on_sigbus(int code, void *addr)
 {
 #if defined(KVM_CAP_MCE)
     if ((first_cpu->mcg_cap & MCG_SER_P) && addr && code == BUS_MCEERR_AO) {
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 710eca1..93ecc57 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -404,3 +404,13 @@ bool kvm_arch_stop_on_emulation_error(CPUState *env)
 {
     return true;
 }
+
+int kvm_arch_on_sigbus_vcpu(CPUState *env, int code, void *addr)
+{
+    return 1;
+}
+
+int kvm_arch_on_sigbus(int code, void *addr)
+{
+    return 1;
+}
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 38823f5..1702c46 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -505,3 +505,13 @@ bool kvm_arch_stop_on_emulation_error(CPUState *env)
 {
     return true;
 }
+
+int kvm_arch_on_sigbus_vcpu(CPUState *env, int code, void *addr)
+{
+    return 1;
+}
+
+int kvm_arch_on_sigbus(int code, void *addr)
+{
+    return 1;
+}
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 11/23] Refactor signal setup functions in cpus.c
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (9 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 10/23] kvm: Provide sigbus services arch-independently Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 12/23] kvm: Set up signal mask also for !CONFIG_IOTHREAD Marcelo Tosatti
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Move {tcg,kvm}_init_ipi and block_io_signals to avoid prototypes, rename
the former two to clarify that they deal with more than SIG_IPI. No
functional changes - except for the tiny fixup of strerror usage.

The forward declaration of sigbus_handler is just temporarily, it will
be moved in a succeeding patch. dummy_signal is moved into the !_WIN32
block as we will soon need it also for !CONFIG_IOTHREAD.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c |  162 +++++++++++++++++++++++++++++++++-------------------------------
 1 files changed, 83 insertions(+), 79 deletions(-)

diff --git a/cpus.c b/cpus.c
index 3a32828..42717ba 100644
--- a/cpus.c
+++ b/cpus.c
@@ -230,7 +230,15 @@ fail:
     close(fds[1]);
     return err;
 }
-#else
+
+#ifdef CONFIG_IOTHREAD
+static void dummy_signal(int sig)
+{
+}
+#endif
+
+#else /* _WIN32 */
+
 HANDLE qemu_event_handle;
 
 static void dummy_event_handler(void *opaque)
@@ -256,7 +264,7 @@ static void qemu_event_increment(void)
         exit (1);
     }
 }
-#endif
+#endif /* _WIN32 */
 
 #ifndef CONFIG_IOTHREAD
 int qemu_init_main_loop(void)
@@ -352,10 +360,6 @@ static QemuCond qemu_system_cond;
 static QemuCond qemu_pause_cond;
 static QemuCond qemu_work_cond;
 
-static void tcg_init_ipi(void);
-static void kvm_init_ipi(CPUState *env);
-static sigset_t block_io_signals(void);
-
 /* If we have signalfd, we mask out the signals we want to handle and then
  * use signalfd to listen for them.  We rely on whatever the current signal
  * handler is to dispatch the signals when we receive them.
@@ -391,6 +395,77 @@ static void sigfd_handler(void *opaque)
     }
 }
 
+static void cpu_signal(int sig)
+{
+    if (cpu_single_env) {
+        cpu_exit(cpu_single_env);
+    }
+    exit_request = 1;
+}
+
+static void qemu_kvm_init_cpu_signals(CPUState *env)
+{
+    int r;
+    sigset_t set;
+    struct sigaction sigact;
+
+    memset(&sigact, 0, sizeof(sigact));
+    sigact.sa_handler = dummy_signal;
+    sigaction(SIG_IPI, &sigact, NULL);
+
+    pthread_sigmask(SIG_BLOCK, NULL, &set);
+    sigdelset(&set, SIG_IPI);
+    sigdelset(&set, SIGBUS);
+    r = kvm_set_signal_mask(env, &set);
+    if (r) {
+        fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r));
+        exit(1);
+    }
+}
+
+static void qemu_tcg_init_cpu_signals(void)
+{
+    sigset_t set;
+    struct sigaction sigact;
+
+    memset(&sigact, 0, sizeof(sigact));
+    sigact.sa_handler = cpu_signal;
+    sigaction(SIG_IPI, &sigact, NULL);
+
+    sigemptyset(&set);
+    sigaddset(&set, SIG_IPI);
+    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
+}
+
+static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
+                           void *ctx);
+
+static sigset_t block_io_signals(void)
+{
+    sigset_t set;
+    struct sigaction action;
+
+    /* SIGUSR2 used by posix-aio-compat.c */
+    sigemptyset(&set);
+    sigaddset(&set, SIGUSR2);
+    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
+
+    sigemptyset(&set);
+    sigaddset(&set, SIGIO);
+    sigaddset(&set, SIGALRM);
+    sigaddset(&set, SIG_IPI);
+    sigaddset(&set, SIGBUS);
+    pthread_sigmask(SIG_BLOCK, &set, NULL);
+
+    memset(&action, 0, sizeof(action));
+    action.sa_flags = SA_SIGINFO;
+    action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler;
+    sigaction(SIGBUS, &action, NULL);
+    prctl(PR_MCE_KILL, 1, 1, 0, 0);
+
+    return set;
+}
+
 static int qemu_signalfd_init(sigset_t mask)
 {
     int sigfd;
@@ -619,7 +694,7 @@ static void *kvm_cpu_thread_fn(void *arg)
         exit(1);
     }
 
-    kvm_init_ipi(env);
+    qemu_kvm_init_cpu_signals(env);
 
     /* signal CPU creation */
     env->created = 1;
@@ -642,7 +717,7 @@ static void *tcg_cpu_thread_fn(void *arg)
 {
     CPUState *env = arg;
 
-    tcg_init_ipi();
+    qemu_tcg_init_cpu_signals();
     qemu_thread_self(env->thread);
 
     /* signal CPU creation */
@@ -683,77 +758,6 @@ int qemu_cpu_self(void *_env)
     return qemu_thread_equal(&this, env->thread);
 }
 
-static void cpu_signal(int sig)
-{
-    if (cpu_single_env)
-        cpu_exit(cpu_single_env);
-    exit_request = 1;
-}
-
-static void tcg_init_ipi(void)
-{
-    sigset_t set;
-    struct sigaction sigact;
-
-    memset(&sigact, 0, sizeof(sigact));
-    sigact.sa_handler = cpu_signal;
-    sigaction(SIG_IPI, &sigact, NULL);
-
-    sigemptyset(&set);
-    sigaddset(&set, SIG_IPI);
-    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
-}
-
-static void dummy_signal(int sig)
-{
-}
-
-static void kvm_init_ipi(CPUState *env)
-{
-    int r;
-    sigset_t set;
-    struct sigaction sigact;
-
-    memset(&sigact, 0, sizeof(sigact));
-    sigact.sa_handler = dummy_signal;
-    sigaction(SIG_IPI, &sigact, NULL);
-
-    pthread_sigmask(SIG_BLOCK, NULL, &set);
-    sigdelset(&set, SIG_IPI);
-    sigdelset(&set, SIGBUS);
-    r = kvm_set_signal_mask(env, &set);
-    if (r) {
-        fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(r));
-        exit(1);
-    }
-}
-
-static sigset_t block_io_signals(void)
-{
-    sigset_t set;
-    struct sigaction action;
-
-    /* SIGUSR2 used by posix-aio-compat.c */
-    sigemptyset(&set);
-    sigaddset(&set, SIGUSR2);
-    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
-
-    sigemptyset(&set);
-    sigaddset(&set, SIGIO);
-    sigaddset(&set, SIGALRM);
-    sigaddset(&set, SIG_IPI);
-    sigaddset(&set, SIGBUS);
-    pthread_sigmask(SIG_BLOCK, &set, NULL);
-
-    memset(&action, 0, sizeof(action));
-    action.sa_flags = SA_SIGINFO;
-    action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler;
-    sigaction(SIGBUS, &action, NULL);
-    prctl(PR_MCE_KILL, 1, 1, 0, 0);
-
-    return set;
-}
-
 void qemu_mutex_lock_iothread(void)
 {
     if (kvm_enabled()) {
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 12/23] kvm: Set up signal mask also for !CONFIG_IOTHREAD
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (10 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 11/23] Refactor signal setup functions in cpus.c Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 13/23] kvm: Refactor qemu_kvm_eat_signals Marcelo Tosatti
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Block SIG_IPI, unblock it during KVM_RUN, just like in io-thread mode.
It's unused so far, but this infrastructure will be required for
self-IPIs and to process SIGBUS plus, in KVM mode, SIGIO and SIGALRM. As
Windows doesn't support signal services, we need to provide a stub for
the init function.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 42717ba..a33e470 100644
--- a/cpus.c
+++ b/cpus.c
@@ -231,11 +231,9 @@ fail:
     return err;
 }
 
-#ifdef CONFIG_IOTHREAD
 static void dummy_signal(int sig)
 {
 }
-#endif
 
 #else /* _WIN32 */
 
@@ -267,6 +265,32 @@ static void qemu_event_increment(void)
 #endif /* _WIN32 */
 
 #ifndef CONFIG_IOTHREAD
+static void qemu_kvm_init_cpu_signals(CPUState *env)
+{
+#ifndef _WIN32
+    int r;
+    sigset_t set;
+    struct sigaction sigact;
+
+    memset(&sigact, 0, sizeof(sigact));
+    sigact.sa_handler = dummy_signal;
+    sigaction(SIG_IPI, &sigact, NULL);
+
+    sigemptyset(&set);
+    sigaddset(&set, SIG_IPI);
+    pthread_sigmask(SIG_BLOCK, &set, NULL);
+
+    pthread_sigmask(SIG_BLOCK, NULL, &set);
+    sigdelset(&set, SIG_IPI);
+    sigdelset(&set, SIGBUS);
+    r = kvm_set_signal_mask(env, &set);
+    if (r) {
+        fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r));
+        exit(1);
+    }
+#endif
+}
+
 int qemu_init_main_loop(void)
 {
     cpu_set_debug_excp_handler(cpu_debug_handler);
@@ -292,6 +316,7 @@ void qemu_init_vcpu(void *_env)
             fprintf(stderr, "kvm_init_vcpu failed: %s\n", strerror(-r));
             exit(1);
         }
+        qemu_kvm_init_cpu_signals(env);
     }
 }
 
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 13/23] kvm: Refactor qemu_kvm_eat_signals
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (11 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 12/23] kvm: Set up signal mask also for !CONFIG_IOTHREAD Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 14/23] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD Marcelo Tosatti
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

We do not use the timeout, so drop its logic. As we always poll our
signals, we do not need to drop the global lock. Removing those calls
allows some further simplifications. Also fix the error processing of
sigpending at this chance.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c |   23 +++++++----------------
 1 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/cpus.c b/cpus.c
index a33e470..04138ba 100644
--- a/cpus.c
+++ b/cpus.c
@@ -648,31 +648,22 @@ static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
     }
 }
 
-static void qemu_kvm_eat_signal(CPUState *env, int timeout)
+static void qemu_kvm_eat_signals(CPUState *env)
 {
-    struct timespec ts;
-    int r, e;
+    struct timespec ts = { 0, 0 };
     siginfo_t siginfo;
     sigset_t waitset;
     sigset_t chkset;
-
-    ts.tv_sec = timeout / 1000;
-    ts.tv_nsec = (timeout % 1000) * 1000000;
+    int r;
 
     sigemptyset(&waitset);
     sigaddset(&waitset, SIG_IPI);
     sigaddset(&waitset, SIGBUS);
 
     do {
-        qemu_mutex_unlock(&qemu_global_mutex);
-
         r = sigtimedwait(&waitset, &siginfo, &ts);
-        e = errno;
-
-        qemu_mutex_lock(&qemu_global_mutex);
-
-        if (r == -1 && !(e == EAGAIN || e == EINTR)) {
-            fprintf(stderr, "sigtimedwait: %s\n", strerror(e));
+        if (r == -1 && !(errno == EAGAIN || errno == EINTR)) {
+            perror("sigtimedwait");
             exit(1);
         }
 
@@ -688,7 +679,7 @@ static void qemu_kvm_eat_signal(CPUState *env, int timeout)
 
         r = sigpending(&chkset);
         if (r == -1) {
-            fprintf(stderr, "sigpending: %s\n", strerror(e));
+            perror("sigpending");
             exit(1);
         }
     } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
@@ -699,7 +690,7 @@ static void qemu_kvm_wait_io_event(CPUState *env)
     while (!cpu_has_work(env))
         qemu_cond_timedwait(env->halt_cond, &qemu_global_mutex, 1000);
 
-    qemu_kvm_eat_signal(env, 0);
+    qemu_kvm_eat_signals(env);
     qemu_wait_io_event_common(env);
 }
 
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 14/23] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (12 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 13/23] kvm: Refactor qemu_kvm_eat_signals Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 15/23] Set up signalfd " Marcelo Tosatti
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

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>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c |   90 +++++++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/cpus.c b/cpus.c
index 04138ba..861e270 100644
--- a/cpus.c
+++ b/cpus.c
@@ -235,6 +235,47 @@ static void dummy_signal(int sig)
 {
 }
 
+static void sigbus_reraise(void);
+
+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;
@@ -262,6 +303,10 @@ static void qemu_event_increment(void)
         exit (1);
     }
 }
+
+static void qemu_kvm_eat_signals(CPUState *env)
+{
+}
 #endif /* _WIN32 */
 
 #ifndef CONFIG_IOTHREAD
@@ -648,43 +693,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))
@@ -949,6 +957,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) {
@@ -960,7 +970,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) {
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 15/23] Set up signalfd under !CONFIG_IOTHREAD
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (13 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 14/23] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 16/23] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD Marcelo Tosatti
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Will be required for SIGBUS handling. For obvious reasons, this will
remain a nop on Windows hosts.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 Makefile.objs |    2 +-
 cpus.c        |  117 +++++++++++++++++++++++++++++++--------------------------
 2 files changed, 65 insertions(+), 54 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index f1c7bfe..05014e9 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -141,7 +141,7 @@ common-obj-y += $(addprefix ui/, $(ui-obj-y))
 
 common-obj-y += iov.o acl.o
 common-obj-$(CONFIG_THREAD) += qemu-thread.o
-common-obj-$(CONFIG_IOTHREAD) += compatfd.o
+common-obj-$(CONFIG_POSIX) += compatfd.o
 common-obj-y += notify.o event_notifier.o
 common-obj-y += qemu-timer.o qemu-timer-common.o
 
diff --git a/cpus.c b/cpus.c
index 861e270..359361f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -235,6 +235,59 @@ static void dummy_signal(int sig)
 {
 }
 
+/* If we have signalfd, we mask out the signals we want to handle and then
+ * use signalfd to listen for them.  We rely on whatever the current signal
+ * handler is to dispatch the signals when we receive them.
+ */
+static void sigfd_handler(void *opaque)
+{
+    int fd = (unsigned long) opaque;
+    struct qemu_signalfd_siginfo info;
+    struct sigaction action;
+    ssize_t len;
+
+    while (1) {
+        do {
+            len = read(fd, &info, sizeof(info));
+        } while (len == -1 && errno == EINTR);
+
+        if (len == -1 && errno == EAGAIN) {
+            break;
+        }
+
+        if (len != sizeof(info)) {
+            printf("read from sigfd returned %zd: %m\n", len);
+            return;
+        }
+
+        sigaction(info.ssi_signo, NULL, &action);
+        if ((action.sa_flags & SA_SIGINFO) && action.sa_sigaction) {
+            action.sa_sigaction(info.ssi_signo,
+                                (siginfo_t *)&info, NULL);
+        } else if (action.sa_handler) {
+            action.sa_handler(info.ssi_signo);
+        }
+    }
+}
+
+static int qemu_signalfd_init(sigset_t mask)
+{
+    int sigfd;
+
+    sigfd = qemu_signalfd(&mask);
+    if (sigfd == -1) {
+        fprintf(stderr, "failed to create signalfd\n");
+        return -errno;
+    }
+
+    fcntl_setfl(sigfd, O_NONBLOCK);
+
+    qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL,
+                         (void *)(unsigned long) sigfd);
+
+    return 0;
+}
+
 static void sigbus_reraise(void);
 
 static void qemu_kvm_eat_signals(CPUState *env)
@@ -338,6 +391,17 @@ static void qemu_kvm_init_cpu_signals(CPUState *env)
 
 int qemu_init_main_loop(void)
 {
+#ifndef _WIN32
+    sigset_t blocked_signals;
+    int ret;
+
+    sigemptyset(&blocked_signals);
+
+    ret = qemu_signalfd_init(blocked_signals);
+    if (ret) {
+        return ret;
+    }
+#endif
     cpu_set_debug_excp_handler(cpu_debug_handler);
 
     return qemu_event_init();
@@ -430,41 +494,6 @@ static QemuCond qemu_system_cond;
 static QemuCond qemu_pause_cond;
 static QemuCond qemu_work_cond;
 
-/* If we have signalfd, we mask out the signals we want to handle and then
- * use signalfd to listen for them.  We rely on whatever the current signal
- * handler is to dispatch the signals when we receive them.
- */
-static void sigfd_handler(void *opaque)
-{
-    int fd = (unsigned long) opaque;
-    struct qemu_signalfd_siginfo info;
-    struct sigaction action;
-    ssize_t len;
-
-    while (1) {
-        do {
-            len = read(fd, &info, sizeof(info));
-        } while (len == -1 && errno == EINTR);
-
-        if (len == -1 && errno == EAGAIN) {
-            break;
-        }
-
-        if (len != sizeof(info)) {
-            printf("read from sigfd returned %zd: %m\n", len);
-            return;
-        }
-
-        sigaction(info.ssi_signo, NULL, &action);
-        if ((action.sa_flags & SA_SIGINFO) && action.sa_sigaction) {
-            action.sa_sigaction(info.ssi_signo,
-                                (siginfo_t *)&info, NULL);
-        } else if (action.sa_handler) {
-            action.sa_handler(info.ssi_signo);
-        }
-    }
-}
-
 static void cpu_signal(int sig)
 {
     if (cpu_single_env) {
@@ -536,24 +565,6 @@ static sigset_t block_io_signals(void)
     return set;
 }
 
-static int qemu_signalfd_init(sigset_t mask)
-{
-    int sigfd;
-
-    sigfd = qemu_signalfd(&mask);
-    if (sigfd == -1) {
-        fprintf(stderr, "failed to create signalfd\n");
-        return -errno;
-    }
-
-    fcntl_setfl(sigfd, O_NONBLOCK);
-
-    qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL,
-                         (void *)(unsigned long) sigfd);
-
-    return 0;
-}
-
 int qemu_init_main_loop(void)
 {
     int ret;
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 16/23] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (14 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 15/23] Set up signalfd " Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 17/23] kvm: Add MCE signal support for !CONFIG_IOTHREAD Marcelo Tosatti
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm, Stefan Hajnoczi

From: Jan Kiszka <jan.kiszka@siemens.com>

Found by Stefan Hajnoczi: There is a race in kvm_cpu_exec between
checking for exit_request on vcpu entry and timer signals arriving
before KVM starts to catch them. Plug it by blocking both timer related
signals also on !CONFIG_IOTHREAD and process those via signalfd.

As this fix depends on real signalfd support (otherwise the timer
signals only kick the compat helper thread, and the main thread hangs),
we need to detect the invalid constellation and abort configure.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
CC: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 configure |    6 ++++++
 cpus.c    |   31 ++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index 598e8e1..a3f5345 100755
--- a/configure
+++ b/configure
@@ -2057,6 +2057,12 @@ EOF
 
 if compile_prog "" "" ; then
   signalfd=yes
+elif test "$kvm" = "yes" -a "$io_thread" != "yes"; then
+  echo
+  echo "ERROR: Host kernel lacks signalfd() support,"
+  echo "but KVM depends on it when the IO thread is disabled."
+  echo
+  exit 1
 fi
 
 # check if eventfd is supported
diff --git a/cpus.c b/cpus.c
index 359361f..18caf47 100644
--- a/cpus.c
+++ b/cpus.c
@@ -327,6 +327,12 @@ static void qemu_kvm_eat_signals(CPUState *env)
             exit(1);
         }
     } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
+
+#ifndef CONFIG_IOTHREAD
+    if (sigismember(&chkset, SIGIO) || sigismember(&chkset, SIGALRM)) {
+        qemu_notify_event();
+    }
+#endif
 }
 
 #else /* _WIN32 */
@@ -376,11 +382,15 @@ static void qemu_kvm_init_cpu_signals(CPUState *env)
 
     sigemptyset(&set);
     sigaddset(&set, SIG_IPI);
+    sigaddset(&set, SIGIO);
+    sigaddset(&set, SIGALRM);
     pthread_sigmask(SIG_BLOCK, &set, NULL);
 
     pthread_sigmask(SIG_BLOCK, NULL, &set);
     sigdelset(&set, SIG_IPI);
     sigdelset(&set, SIGBUS);
+    sigdelset(&set, SIGIO);
+    sigdelset(&set, SIGALRM);
     r = kvm_set_signal_mask(env, &set);
     if (r) {
         fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r));
@@ -389,13 +399,32 @@ static void qemu_kvm_init_cpu_signals(CPUState *env)
 #endif
 }
 
+#ifndef _WIN32
+static sigset_t block_synchronous_signals(void)
+{
+    sigset_t set;
+
+    sigemptyset(&set);
+    if (kvm_enabled()) {
+        /*
+         * We need to process timer signals synchronously to avoid a race
+         * between exit_request check and KVM vcpu entry.
+         */
+        sigaddset(&set, SIGIO);
+        sigaddset(&set, SIGALRM);
+    }
+
+    return set;
+}
+#endif
+
 int qemu_init_main_loop(void)
 {
 #ifndef _WIN32
     sigset_t blocked_signals;
     int ret;
 
-    sigemptyset(&blocked_signals);
+    blocked_signals = block_synchronous_signals();
 
     ret = qemu_signalfd_init(blocked_signals);
     if (ret) {
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 17/23] kvm: Add MCE signal support for !CONFIG_IOTHREAD
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (15 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 16/23] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 18/23] Introduce VCPU self-signaling service Marcelo Tosatti
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: Hidetoshi Seto, kvm, Jan Kiszka, Marcelo Tosatti, qemu-devel,
	Huang Ying, Jin Dongming

From: Jan Kiszka <jan.kiszka@siemens.com>

Currently, we only configure and process MCE-related SIGBUS events if
CONFIG_IOTHREAD is enabled. The groundwork is laid, we just need to
factor out the required handler registration and system configuration.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
CC: Huang Ying <ying.huang@intel.com>
CC: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
CC: Jin Dongming <jin.dongming@np.css.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c |  107 +++++++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 65 insertions(+), 42 deletions(-)

diff --git a/cpus.c b/cpus.c
index 18caf47..c4c5914 100644
--- a/cpus.c
+++ b/cpus.c
@@ -34,9 +34,6 @@
 
 #include "cpus.h"
 #include "compatfd.h"
-#ifdef CONFIG_LINUX
-#include <sys/prctl.h>
-#endif
 
 #ifdef SIGRTMIN
 #define SIG_IPI (SIGRTMIN+4)
@@ -44,10 +41,24 @@
 #define SIG_IPI SIGUSR1
 #endif
 
+#ifdef CONFIG_LINUX
+
+#include <sys/prctl.h>
+
 #ifndef PR_MCE_KILL
 #define PR_MCE_KILL 33
 #endif
 
+#ifndef PR_MCE_KILL_SET
+#define PR_MCE_KILL_SET 1
+#endif
+
+#ifndef PR_MCE_KILL_EARLY
+#define PR_MCE_KILL_EARLY 1
+#endif
+
+#endif /* CONFIG_LINUX */
+
 static CPUState *next_cpu;
 
 /***********************************************************/
@@ -166,6 +177,52 @@ static void cpu_debug_handler(CPUState *env)
     vm_stop(EXCP_DEBUG);
 }
 
+#ifdef CONFIG_LINUX
+static void sigbus_reraise(void)
+{
+    sigset_t set;
+    struct sigaction action;
+
+    memset(&action, 0, sizeof(action));
+    action.sa_handler = SIG_DFL;
+    if (!sigaction(SIGBUS, &action, NULL)) {
+        raise(SIGBUS);
+        sigemptyset(&set);
+        sigaddset(&set, SIGBUS);
+        sigprocmask(SIG_UNBLOCK, &set, NULL);
+    }
+    perror("Failed to re-raise SIGBUS!\n");
+    abort();
+}
+
+static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
+                           void *ctx)
+{
+    if (kvm_on_sigbus(siginfo->ssi_code,
+                      (void *)(intptr_t)siginfo->ssi_addr)) {
+        sigbus_reraise();
+    }
+}
+
+static void qemu_init_sigbus(void)
+{
+    struct sigaction action;
+
+    memset(&action, 0, sizeof(action));
+    action.sa_flags = SA_SIGINFO;
+    action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler;
+    sigaction(SIGBUS, &action, NULL);
+
+    prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0);
+}
+
+#else /* !CONFIG_LINUX */
+
+static void qemu_init_sigbus(void)
+{
+}
+#endif /* !CONFIG_LINUX */
+
 #ifndef _WIN32
 static int io_thread_fd = -1;
 
@@ -288,8 +345,6 @@ static int qemu_signalfd_init(sigset_t mask)
     return 0;
 }
 
-static void sigbus_reraise(void);
-
 static void qemu_kvm_eat_signals(CPUState *env)
 {
     struct timespec ts = { 0, 0 };
@@ -310,13 +365,11 @@ static void qemu_kvm_eat_signals(CPUState *env)
         }
 
         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;
         }
@@ -405,6 +458,7 @@ static sigset_t block_synchronous_signals(void)
     sigset_t set;
 
     sigemptyset(&set);
+    sigaddset(&set, SIGBUS);
     if (kvm_enabled()) {
         /*
          * We need to process timer signals synchronously to avoid a race
@@ -433,6 +487,8 @@ int qemu_init_main_loop(void)
 #endif
     cpu_set_debug_excp_handler(cpu_debug_handler);
 
+    qemu_init_sigbus();
+
     return qemu_event_init();
 }
 
@@ -565,13 +621,9 @@ static void qemu_tcg_init_cpu_signals(void)
     pthread_sigmask(SIG_UNBLOCK, &set, NULL);
 }
 
-static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
-                           void *ctx);
-
 static sigset_t block_io_signals(void)
 {
     sigset_t set;
-    struct sigaction action;
 
     /* SIGUSR2 used by posix-aio-compat.c */
     sigemptyset(&set);
@@ -585,12 +637,6 @@ static sigset_t block_io_signals(void)
     sigaddset(&set, SIGBUS);
     pthread_sigmask(SIG_BLOCK, &set, NULL);
 
-    memset(&action, 0, sizeof(action));
-    action.sa_flags = SA_SIGINFO;
-    action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler;
-    sigaction(SIGBUS, &action, NULL);
-    prctl(PR_MCE_KILL, 1, 1, 0, 0);
-
     return set;
 }
 
@@ -601,6 +647,8 @@ int qemu_init_main_loop(void)
 
     cpu_set_debug_excp_handler(cpu_debug_handler);
 
+    qemu_init_sigbus();
+
     blocked_signals = block_io_signals();
 
     ret = qemu_signalfd_init(blocked_signals);
@@ -708,31 +756,6 @@ static void qemu_tcg_wait_io_event(void)
     }
 }
 
-static void sigbus_reraise(void)
-{
-    sigset_t set;
-    struct sigaction action;
-
-    memset(&action, 0, sizeof(action));
-    action.sa_handler = SIG_DFL;
-    if (!sigaction(SIGBUS, &action, NULL)) {
-        raise(SIGBUS);
-        sigemptyset(&set);
-        sigaddset(&set, SIGBUS);
-        sigprocmask(SIG_UNBLOCK, &set, NULL);
-    }
-    perror("Failed to re-raise SIGBUS!\n");
-    abort();
-}
-
-static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
-                           void *ctx)
-{
-    if (kvm_on_sigbus(siginfo->ssi_code, (void *)(intptr_t)siginfo->ssi_addr)) {
-        sigbus_reraise();
-    }
-}
-
 static void qemu_kvm_wait_io_event(CPUState *env)
 {
     while (!cpu_has_work(env))
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 18/23] Introduce VCPU self-signaling service
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (16 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 17/23] kvm: Add MCE signal support for !CONFIG_IOTHREAD Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 19/23] kvm: Unconditionally reenter kernel after IO exits Marcelo Tosatti
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Introduce qemu_cpu_kick_self to send SIG_IPI to the calling VCPU
context. First user will be kvm.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 cpus.c        |   21 +++++++++++++++++++++
 qemu-common.h |    1 +
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/cpus.c b/cpus.c
index c4c5914..9c50a34 100644
--- a/cpus.c
+++ b/cpus.c
@@ -537,6 +537,17 @@ void qemu_cpu_kick(void *env)
     return;
 }
 
+void qemu_cpu_kick_self(void)
+{
+#ifndef _WIN32
+    assert(cpu_single_env);
+
+    raise(SIG_IPI);
+#else
+    abort();
+#endif
+}
+
 void qemu_notify_event(void)
 {
     CPUState *env = cpu_single_env;
@@ -835,6 +846,16 @@ void qemu_cpu_kick(void *_env)
     }
 }
 
+void qemu_cpu_kick_self(void)
+{
+    assert(cpu_single_env);
+
+    if (!cpu_single_env->thread_kicked) {
+        qemu_thread_signal(cpu_single_env->thread, SIG_IPI);
+        cpu_single_env->thread_kicked = true;
+    }
+}
+
 int qemu_cpu_self(void *_env)
 {
     CPUState *env = _env;
diff --git a/qemu-common.h b/qemu-common.h
index c7ff280..a4d9c21 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -288,6 +288,7 @@ void qemu_notify_event(void);
 
 /* Unblock cpu */
 void qemu_cpu_kick(void *env);
+void qemu_cpu_kick_self(void);
 int qemu_cpu_self(void *env);
 
 /* work queue */
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 19/23] kvm: Unconditionally reenter kernel after IO exits
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (17 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 18/23] Introduce VCPU self-signaling service Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 20/23] kvm: Remove static return code of kvm_handle_io Marcelo Tosatti
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: Jan Kiszka, Gleb Natapov, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

KVM requires to reenter the kernel after IO exits in order to complete
instruction emulation. Failing to do so will leave the kernel state
inconsistently behind. To ensure that we will get back ASAP, we issue a
self-signal that will cause KVM_RUN to return once the pending
operations are completed.

We can move kvm_arch_process_irqchip_events out of the inner VCPU loop.
The only state that mattered at its old place was a pending INIT
request. Catch it in kvm_arch_pre_run and also trigger a self-signal to
process the request on next kvm_cpu_exec.

This patch also fixes the missing exit_request check in kvm_cpu_exec in
the CONFIG_IOTHREAD case.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
CC: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 kvm-all.c         |   31 +++++++++++++++++--------------
 target-i386/kvm.c |    5 +++++
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index a83aff2..0c20f9e 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -199,7 +199,6 @@ int kvm_pit_in_kernel(void)
     return kvm_state->pit_in_kernel;
 }
 
-
 int kvm_init_vcpu(CPUState *env)
 {
     KVMState *s = kvm_state;
@@ -896,29 +895,33 @@ int kvm_cpu_exec(CPUState *env)
 
     DPRINTF("kvm_cpu_exec()\n");
 
-    do {
-#ifndef CONFIG_IOTHREAD
-        if (env->exit_request) {
-            DPRINTF("interrupt exit requested\n");
-            ret = 0;
-            break;
-        }
-#endif
-
-        if (kvm_arch_process_irqchip_events(env)) {
-            ret = 0;
-            break;
-        }
+    if (kvm_arch_process_irqchip_events(env)) {
+        env->exit_request = 0;
+        env->exception_index = EXCP_HLT;
+        return 0;
+    }
 
+    do {
         if (env->kvm_vcpu_dirty) {
             kvm_arch_put_registers(env, KVM_PUT_RUNTIME_STATE);
             env->kvm_vcpu_dirty = 0;
         }
 
         kvm_arch_pre_run(env, run);
+        if (env->exit_request) {
+            DPRINTF("interrupt exit requested\n");
+            /*
+             * KVM requires us to reenter the kernel after IO exits to complete
+             * instruction emulation. This self-signal will ensure that we
+             * leave ASAP again.
+             */
+            qemu_cpu_kick_self();
+        }
         cpu_single_env = NULL;
         qemu_mutex_unlock_iothread();
+
         ret = kvm_vcpu_ioctl(env, KVM_RUN, 0);
+
         qemu_mutex_lock_iothread();
         cpu_single_env = env;
         kvm_arch_post_run(env, run);
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 9df8ff8..8a87244 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1426,6 +1426,11 @@ int kvm_arch_get_registers(CPUState *env)
 
 int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
 {
+    /* Force the VCPU out of its inner loop to process the INIT request */
+    if (env->interrupt_request & CPU_INTERRUPT_INIT) {
+        env->exit_request = 1;
+    }
+
     /* Inject NMI */
     if (env->interrupt_request & CPU_INTERRUPT_NMI) {
         env->interrupt_request &= ~CPU_INTERRUPT_NMI;
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 20/23] kvm: Remove static return code of kvm_handle_io
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (18 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 19/23] kvm: Unconditionally reenter kernel after IO exits Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 21/23] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN Marcelo Tosatti
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

Improve the readability of the exit dispatcher by moving the static
return value of kvm_handle_io to its caller.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 kvm-all.c |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 0c20f9e..4729ec5 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -774,8 +774,8 @@ err:
     return ret;
 }
 
-static int kvm_handle_io(uint16_t port, void *data, int direction, int size,
-                         uint32_t count)
+static void kvm_handle_io(uint16_t port, void *data, int direction, int size,
+                          uint32_t count)
 {
     int i;
     uint8_t *ptr = data;
@@ -809,8 +809,6 @@ static int kvm_handle_io(uint16_t port, void *data, int direction, int size,
 
         ptr += size;
     }
-
-    return 1;
 }
 
 #ifdef KVM_CAP_INTERNAL_ERROR_DATA
@@ -944,11 +942,12 @@ int kvm_cpu_exec(CPUState *env)
         switch (run->exit_reason) {
         case KVM_EXIT_IO:
             DPRINTF("handle_io\n");
-            ret = kvm_handle_io(run->io.port,
-                                (uint8_t *)run + run->io.data_offset,
-                                run->io.direction,
-                                run->io.size,
-                                run->io.count);
+            kvm_handle_io(run->io.port,
+                          (uint8_t *)run + run->io.data_offset,
+                          run->io.direction,
+                          run->io.size,
+                          run->io.count);
+            ret = 1;
             break;
         case KVM_EXIT_MMIO:
             DPRINTF("handle_mmio\n");
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 21/23] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (19 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 20/23] kvm: Remove static return code of kvm_handle_io Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 22/23] x86: Fix MCA broadcast parameters for TCG case Marcelo Tosatti
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@siemens.com>

The reset we issue on KVM_EXIT_SHUTDOWN implies that we should also
leave the VCPU loop. As we now check for exit_request which is set by
qemu_system_reset_request, this bug is no longer critical. Still it's an
unneeded extra turn.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 kvm-all.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 4729ec5..42dfed8 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -963,7 +963,6 @@ int kvm_cpu_exec(CPUState *env)
         case KVM_EXIT_SHUTDOWN:
             DPRINTF("shutdown\n");
             qemu_system_reset_request();
-            ret = 1;
             break;
         case KVM_EXIT_UNKNOWN:
             fprintf(stderr, "KVM: unknown exit, hardware reason %" PRIx64 "\n",
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 22/23] x86: Fix MCA broadcast parameters for TCG case
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (20 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 21/23] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-08 11:39   ` Aurelien Jarno
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 23/23] kvm: make tsc stable over migration and machine start Marcelo Tosatti
  2011-02-04 17:34 ` [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Anthony Liguori
  23 siblings, 1 reply; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Jan Kiszka, Marcelo Tosatti, Jan Kiszka, qemu-devel, kvm

From: Jan Kiszka <jan.kiszka@web.de>

When broadcasting MCEs, we need to set MCIP and RIPV in mcg_status like
it is done for KVM. Use the symbolic constants at this chance.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 target-i386/helper.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/helper.c b/target-i386/helper.c
index 1217452..f0c546d 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1147,8 +1147,8 @@ void cpu_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
                 if (cenv == env) {
                     continue;
                 }
-
-                qemu_inject_x86_mce(env, 1, 0xa000000000000000, 0, 0, 0);
+                qemu_inject_x86_mce(env, 1, MCI_STATUS_VAL | MCI_STATUS_UC,
+                                    MCG_STATUS_MCIP | MCG_STATUS_RIPV, 0, 0);
             }
         }
     }
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 23/23] kvm: make tsc stable over migration and machine start
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (21 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 22/23] x86: Fix MCA broadcast parameters for TCG case Marcelo Tosatti
@ 2011-02-04 15:47 ` Marcelo Tosatti
  2011-02-04 17:34 ` [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Anthony Liguori
  23 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 15:47 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: Glauber Costa, Marcelo Tosatti, Jan Kiszka, qemu-devel, kvm

From: Glauber Costa <glommer@redhat.com>

If the machine is stopped, we should not record two different tsc values
upon a save operation. The same problem happens with kvmclock.

But kvmclock is taking a different diretion, being now seen as a separate
device. Since this is unlikely to happen with the tsc, I am taking the
approach here of simply registering a handler for state change, and
using a per-CPUState variable that prevents double updates for the TSC.

Signed-off-by: Glauber Costa <glommer@redhat.com>
CC: Jan Kiszka <jan.kiszka@web.de>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 target-i386/cpu.h |    1 +
 target-i386/kvm.c |   18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index af701a4..5f1df8b 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -734,6 +734,7 @@ typedef struct CPUX86State {
     uint32_t sipi_vector;
     uint32_t cpuid_kvm_features;
     uint32_t cpuid_svm_features;
+    bool tsc_valid;
     
     /* in order to simplify APIC support, we leave this pointer to the
        user */
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 8a87244..ba183c4 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -301,6 +301,15 @@ void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
 #endif
 }
 
+static void cpu_update_state(void *opaque, int running, int reason)
+{
+    CPUState *env = opaque;
+
+    if (running) {
+        env->tsc_valid = false;
+    }
+}
+
 int kvm_arch_init_vcpu(CPUState *env)
 {
     struct {
@@ -434,6 +443,8 @@ int kvm_arch_init_vcpu(CPUState *env)
     }
 #endif
 
+    qemu_add_vm_change_state_handler(cpu_update_state, env);
+
     return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data);
 }
 
@@ -1061,7 +1072,12 @@ static int kvm_get_msrs(CPUState *env)
     if (has_msr_hsave_pa) {
         msrs[n++].index = MSR_VM_HSAVE_PA;
     }
-    msrs[n++].index = MSR_IA32_TSC;
+
+    if (!env->tsc_valid) {
+        msrs[n++].index = MSR_IA32_TSC;
+        env->tsc_valid = !vm_running;
+    }
+
 #ifdef TARGET_X86_64
     if (lm_capable_kernel) {
         msrs[n++].index = MSR_CSTAR;
-- 
1.7.2.3

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

* Re: [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue
  2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
                   ` (22 preceding siblings ...)
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 23/23] kvm: make tsc stable over migration and machine start Marcelo Tosatti
@ 2011-02-04 17:34 ` Anthony Liguori
  2011-02-04 17:52   ` Jan Kiszka
  23 siblings, 1 reply; 30+ messages in thread
From: Anthony Liguori @ 2011-02-04 17:34 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: Jan Kiszka, qemu-devel, kvm

On 02/04/2011 09:47 AM, Marcelo Tosatti wrote:
> The following changes since commit bfddb47a343b4718e5768aa80bce8adead0f7fca:
>
>    Open up the 0.15 development branch (2011-02-02 08:39:28 +0100)
>    

This series breaks reboot of a Linux guest both with TCG and KVM.

Perhaps it's a conflict with the ioapic changes from Jan?  I can post a 
tree but if you just rebase to the latest master there shouldn't be any 
conflicts.

Regards,

Anthony Liguori

> are available in the git repository at:
>    git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master
>
> Glauber Costa (1):
>        kvm: make tsc stable over migration and machine start
>
> Jan Kiszka (22):
>        Prevent abortion on multiple VCPU kicks
>        Stop current VCPU on synchronous reset requests
>        Process vmstop requests in IO thread
>        Trigger exit from cpu_exec_all on pending IO events
>        Leave inner main_loop faster on pending requests
>        Flatten the main loop
>        kvm: Report proper error on GET_VCPU_MMAP_SIZE failures
>        kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn
>        kvm: Handle kvm_init_vcpu errors
>        kvm: Provide sigbus services arch-independently
>        Refactor signal setup functions in cpus.c
>        kvm: Set up signal mask also for !CONFIG_IOTHREAD
>        kvm: Refactor qemu_kvm_eat_signals
>        kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD
>        Set up signalfd under !CONFIG_IOTHREAD
>        kvm: Fix race between timer signals and vcpu entry under !IOTHREAD
>        kvm: Add MCE signal support for !CONFIG_IOTHREAD
>        Introduce VCPU self-signaling service
>        kvm: Unconditionally reenter kernel after IO exits
>        kvm: Remove static return code of kvm_handle_io
>        kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN
>        x86: Fix MCA broadcast parameters for TCG case
>
>   Makefile.objs        |    2 +-
>   configure            |    6 +
>   cpu-defs.h           |    1 +
>   cpus.c               |  549 +++++++++++++++++++++++++++++++-------------------
>   cpus.h               |    1 +
>   kvm-all.c            |   60 ++++---
>   kvm-stub.c           |    5 +
>   kvm.h                |    7 +-
>   qemu-common.h        |    1 +
>   target-i386/cpu.h    |    1 +
>   target-i386/helper.c |    4 +-
>   target-i386/kvm.c    |   27 +++-
>   target-ppc/kvm.c     |   10 +
>   target-s390x/kvm.c   |   10 +
>   vl.c                 |   40 ++--
>   15 files changed, 466 insertions(+), 258 deletions(-)
>
>
>    

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

* Re: [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue
  2011-02-04 17:34 ` [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Anthony Liguori
@ 2011-02-04 17:52   ` Jan Kiszka
  2011-02-04 18:21     ` [Qemu-devel] [PATCH v3 02/23] Stop current VCPU on synchronous reset requests Jan Kiszka
  0 siblings, 1 reply; 30+ messages in thread
From: Jan Kiszka @ 2011-02-04 17:52 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: Marcelo Tosatti, qemu-devel@nongnu.org, kvm@vger.kernel.org

On 2011-02-04 18:34, Anthony Liguori wrote:
> On 02/04/2011 09:47 AM, Marcelo Tosatti wrote:
>> The following changes since commit bfddb47a343b4718e5768aa80bce8adead0f7fca:
>>
>>    Open up the 0.15 development branch (2011-02-02 08:39:28 +0100)
>>    
> 
> This series breaks reboot of a Linux guest both with TCG and KVM.
> 
> Perhaps it's a conflict with the ioapic changes from Jan?  I can post a 
> tree but if you just rebase to the latest master there shouldn't be any 
> conflicts.
> 

The problem is some patch in the queue itself. I obviously missed that
case. Will have a look.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

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

* [Qemu-devel] [PATCH v3 02/23] Stop current VCPU on synchronous reset requests
  2011-02-04 17:52   ` Jan Kiszka
@ 2011-02-04 18:21     ` Jan Kiszka
  2011-02-04 21:22       ` [Qemu-devel] " Marcelo Tosatti
  0 siblings, 1 reply; 30+ messages in thread
From: Jan Kiszka @ 2011-02-04 18:21 UTC (permalink / raw)
  To: Anthony Liguori
  Cc: Marcelo Tosatti, qemu-devel@nongnu.org, kvm@vger.kernel.org

On 2011-02-04 18:52, Jan Kiszka wrote:
> On 2011-02-04 18:34, Anthony Liguori wrote:
>> On 02/04/2011 09:47 AM, Marcelo Tosatti wrote:
>>> The following changes since commit bfddb47a343b4718e5768aa80bce8adead0f7fca:
>>>
>>>    Open up the 0.15 development branch (2011-02-02 08:39:28 +0100)
>>>    
>>
>> This series breaks reboot of a Linux guest both with TCG and KVM.
>>
>> Perhaps it's a conflict with the ioapic changes from Jan?  I can post a 
>> tree but if you just rebase to the latest master there shouldn't be any 
>> conflicts.
>>
> 
> The problem is some patch in the queue itself. I obviously missed that
> case. Will have a look.
> 

Yet another IOTHREAD vs. !IOTHREAD case: We don't need to do anything in
cpu_stop_current in the single-thread setup as qemu_notify_event already
kicks us out. Specifically, we must not set the current cpu on
stop as reset happens without stop/start.

This replaces patch 2 in the series.

Jan

--------8<----------

Subject: [PATCH] Stop current VCPU on synchronous reset requests

If some I/O operation ends up calling qemu_system_reset_request in VCPU
context, we record this and inform the io-thread, but we do not
terminate the VCPU loop. This can lead to fairly unexpected behavior if
the triggering reset operation is supposed to work synchronously.

Fix this for TCG (when run in deterministic I/O mode) by setting the
VCPU on stop and issuing a cpu_exit. KVM requires some more work on its
VCPU loop.

[ ported from qemu-kvm ]

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 cpus.c |   17 +++++++++++++----
 cpus.h |    1 +
 vl.c   |    1 +
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/cpus.c b/cpus.c
index ab6e40e..f8a88e3 100644
--- a/cpus.c
+++ b/cpus.c
@@ -312,6 +312,10 @@ void qemu_notify_event(void)
 void qemu_mutex_lock_iothread(void) {}
 void qemu_mutex_unlock_iothread(void) {}
 
+void cpu_stop_current(void)
+{
+}
+
 void vm_stop(int reason)
 {
     do_vm_stop(reason);
@@ -852,6 +856,14 @@ static void qemu_system_vmstop_request(int reason)
     qemu_notify_event();
 }
 
+void cpu_stop_current(void)
+{
+    if (cpu_single_env) {
+        cpu_single_env->stopped = 1;
+        cpu_exit(cpu_single_env);
+    }
+}
+
 void vm_stop(int reason)
 {
     QemuThread me;
@@ -863,10 +875,7 @@ void vm_stop(int reason)
          * FIXME: should not return to device code in case
          * vm_stop() has been requested.
          */
-        if (cpu_single_env) {
-            cpu_exit(cpu_single_env);
-            cpu_single_env->stop = 1;
-        }
+        cpu_stop_current();
         return;
     }
     do_vm_stop(reason);
diff --git a/cpus.h b/cpus.h
index bf4d9bb..4cadb64 100644
--- a/cpus.h
+++ b/cpus.h
@@ -6,6 +6,7 @@ int qemu_init_main_loop(void);
 void qemu_main_loop_start(void);
 void resume_all_vcpus(void);
 void pause_all_vcpus(void);
+void cpu_stop_current(void);
 
 /* vl.c */
 extern int smp_cores;
diff --git a/vl.c b/vl.c
index 655617f..b1dc3ff 100644
--- a/vl.c
+++ b/vl.c
@@ -1296,6 +1296,7 @@ void qemu_system_reset_request(void)
     } else {
         reset_requested = 1;
     }
+    cpu_stop_current();
     qemu_notify_event();
 }
 
-- 
1.7.1

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

* [Qemu-devel] Re: [PATCH v3 02/23] Stop current VCPU on synchronous reset requests
  2011-02-04 18:21     ` [Qemu-devel] [PATCH v3 02/23] Stop current VCPU on synchronous reset requests Jan Kiszka
@ 2011-02-04 21:22       ` Marcelo Tosatti
  0 siblings, 0 replies; 30+ messages in thread
From: Marcelo Tosatti @ 2011-02-04 21:22 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org

On Fri, Feb 04, 2011 at 07:21:25PM +0100, Jan Kiszka wrote:
> On 2011-02-04 18:52, Jan Kiszka wrote:
> > On 2011-02-04 18:34, Anthony Liguori wrote:
> >> On 02/04/2011 09:47 AM, Marcelo Tosatti wrote:
> >>> The following changes since commit bfddb47a343b4718e5768aa80bce8adead0f7fca:
> >>>
> >>>    Open up the 0.15 development branch (2011-02-02 08:39:28 +0100)
> >>>    
> >>
> >> This series breaks reboot of a Linux guest both with TCG and KVM.
> >>
> >> Perhaps it's a conflict with the ioapic changes from Jan?  I can post a 
> >> tree but if you just rebase to the latest master there shouldn't be any 
> >> conflicts.
> >>
> > 
> > The problem is some patch in the queue itself. I obviously missed that
> > case. Will have a look.
> > 
> 
> Yet another IOTHREAD vs. !IOTHREAD case: We don't need to do anything in
> cpu_stop_current in the single-thread setup as qemu_notify_event already
> kicks us out. Specifically, we must not set the current cpu on
> stop as reset happens without stop/start.
> 
> This replaces patch 2 in the series.
> 
> Jan

Ugh, will check about autotesting !CONFIG_IOTHREAD.

Anthony, queue updated.

git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master

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

* Re: [Qemu-devel] [PATCH 22/23] x86: Fix MCA broadcast parameters for TCG case
  2011-02-04 15:47 ` [Qemu-devel] [PATCH 22/23] x86: Fix MCA broadcast parameters for TCG case Marcelo Tosatti
@ 2011-02-08 11:39   ` Aurelien Jarno
  2011-02-08 11:42     ` Jan Kiszka
  0 siblings, 1 reply; 30+ messages in thread
From: Aurelien Jarno @ 2011-02-08 11:39 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: Jan Kiszka, Anthony Liguori, Jan Kiszka, qemu-devel, kvm

On Fri, Feb 04, 2011 at 01:47:25PM -0200, Marcelo Tosatti wrote:
> From: Jan Kiszka <jan.kiszka@web.de>
> 
> When broadcasting MCEs, we need to set MCIP and RIPV in mcg_status like
> it is done for KVM. Use the symbolic constants at this chance.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> ---
>  target-i386/helper.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)

I don't feel very comfortable about this whole series (not in my
knowledge area), but as nobody else seems to care about 32-bit support,
I have committed this patch to master and the stable-0.14 tree.

> diff --git a/target-i386/helper.c b/target-i386/helper.c
> index 1217452..f0c546d 100644
> --- a/target-i386/helper.c
> +++ b/target-i386/helper.c
> @@ -1147,8 +1147,8 @@ void cpu_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
>                  if (cenv == env) {
>                      continue;
>                  }
> -
> -                qemu_inject_x86_mce(env, 1, 0xa000000000000000, 0, 0, 0);
> +                qemu_inject_x86_mce(env, 1, MCI_STATUS_VAL | MCI_STATUS_UC,
> +                                    MCG_STATUS_MCIP | MCG_STATUS_RIPV, 0, 0);
>              }
>          }
>      }
> -- 
> 1.7.2.3
> 
> 
> 

-- 
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
aurelien@aurel32.net                 http://www.aurel32.net

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

* Re: [Qemu-devel] [PATCH 22/23] x86: Fix MCA broadcast parameters for TCG case
  2011-02-08 11:39   ` Aurelien Jarno
@ 2011-02-08 11:42     ` Jan Kiszka
  0 siblings, 0 replies; 30+ messages in thread
From: Jan Kiszka @ 2011-02-08 11:42 UTC (permalink / raw)
  To: Aurelien Jarno
  Cc: Anthony Liguori, Marcelo Tosatti, Jan Kiszka,
	qemu-devel@nongnu.org, kvm@vger.kernel.org

On 2011-02-08 12:39, Aurelien Jarno wrote:
> On Fri, Feb 04, 2011 at 01:47:25PM -0200, Marcelo Tosatti wrote:
>> From: Jan Kiszka <jan.kiszka@web.de>
>>
>> When broadcasting MCEs, we need to set MCIP and RIPV in mcg_status like
>> it is done for KVM. Use the symbolic constants at this chance.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>> ---
>>  target-i386/helper.c |    4 ++--
>>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> I don't feel very comfortable about this whole series (not in my
> knowledge area), but as nobody else seems to care about 32-bit support,
> I have committed this patch to master and the stable-0.14 tree.

Don't worry too much. MCE support in QEMU, emulated or virtualized, is
still fairly "experimental", not much to break here. And this is truly a
fix.

Thanks!
Jan

> 
>> diff --git a/target-i386/helper.c b/target-i386/helper.c
>> index 1217452..f0c546d 100644
>> --- a/target-i386/helper.c
>> +++ b/target-i386/helper.c
>> @@ -1147,8 +1147,8 @@ void cpu_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
>>                  if (cenv == env) {
>>                      continue;
>>                  }
>> -
>> -                qemu_inject_x86_mce(env, 1, 0xa000000000000000, 0, 0, 0);
>> +                qemu_inject_x86_mce(env, 1, MCI_STATUS_VAL | MCI_STATUS_UC,
>> +                                    MCG_STATUS_MCIP | MCG_STATUS_RIPV, 0, 0);
>>              }
>>          }
>>      }
>> -- 
>> 1.7.2.3
>>
>>
>>
> 

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

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

end of thread, other threads:[~2011-02-08 11:42 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-04 15:47 [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 01/23] Prevent abortion on multiple VCPU kicks Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 02/23] Stop current VCPU on synchronous reset requests Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 03/23] Process vmstop requests in IO thread Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 04/23] Trigger exit from cpu_exec_all on pending IO events Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 05/23] Leave inner main_loop faster on pending requests Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 06/23] Flatten the main loop Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 07/23] kvm: Report proper error on GET_VCPU_MMAP_SIZE failures Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 08/23] kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 09/23] kvm: Handle kvm_init_vcpu errors Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 10/23] kvm: Provide sigbus services arch-independently Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 11/23] Refactor signal setup functions in cpus.c Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 12/23] kvm: Set up signal mask also for !CONFIG_IOTHREAD Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 13/23] kvm: Refactor qemu_kvm_eat_signals Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 14/23] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 15/23] Set up signalfd " Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 16/23] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 17/23] kvm: Add MCE signal support for !CONFIG_IOTHREAD Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 18/23] Introduce VCPU self-signaling service Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 19/23] kvm: Unconditionally reenter kernel after IO exits Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 20/23] kvm: Remove static return code of kvm_handle_io Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 21/23] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN Marcelo Tosatti
2011-02-04 15:47 ` [Qemu-devel] [PATCH 22/23] x86: Fix MCA broadcast parameters for TCG case Marcelo Tosatti
2011-02-08 11:39   ` Aurelien Jarno
2011-02-08 11:42     ` Jan Kiszka
2011-02-04 15:47 ` [Qemu-devel] [PATCH 23/23] kvm: make tsc stable over migration and machine start Marcelo Tosatti
2011-02-04 17:34 ` [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue Anthony Liguori
2011-02-04 17:52   ` Jan Kiszka
2011-02-04 18:21     ` [Qemu-devel] [PATCH v3 02/23] Stop current VCPU on synchronous reset requests Jan Kiszka
2011-02-04 21:22       ` [Qemu-devel] " Marcelo Tosatti

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