qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
	Jin Dongming <jin.dongming@np.css.fujitsu.com>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org,
	Huang Ying <ying.huang@intel.com>
Subject: [Qemu-devel] [PATCH 15/22] kvm: Add MCE signal support for !CONFIG_IOTHREAD
Date: Thu, 27 Jan 2011 14:09:59 +0100	[thread overview]
Message-ID: <99d06c0381c7834c80b83669443e26094a3a788b.1296133797.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1296133797.git.jan.kiszka@siemens.com>
In-Reply-To: <cover.1296133797.git.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>
---
 cpus.c |  106 ++++++++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 66 insertions(+), 40 deletions(-)

diff --git a/cpus.c b/cpus.c
index 29b1070..bba59e5 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;
 
@@ -248,6 +305,7 @@ static void qemu_kvm_init_cpu_signals(CPUState *env)
 #ifndef CONFIG_IOTHREAD
     sigemptyset(&set);
     sigaddset(&set, SIG_IPI);
+    sigaddset(&set, SIGBUS);
     pthread_sigmask(SIG_BLOCK, &set, NULL);
 #endif
 
@@ -338,13 +396,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;
         }
@@ -408,6 +464,7 @@ int qemu_init_main_loop(void)
     int ret;
 
     sigemptyset(&blocked_signals);
+    sigaddset(&blocked_signals, SIGBUS);
     if (kvm_enabled()) {
         /*
          * We need to process timer signals synchronously to avoid a race
@@ -424,6 +481,8 @@ int qemu_init_main_loop(void)
 #endif
     cpu_set_debug_excp_handler(cpu_debug_handler);
 
+    qemu_init_sigbus();
+
     return qemu_event_init();
 }
 
@@ -535,13 +594,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);
@@ -555,12 +610,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;
 }
 
@@ -571,6 +620,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);
@@ -678,31 +729,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.1

  parent reply	other threads:[~2011-01-27 13:10 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27 13:09 [Qemu-devel] [PATCH 00/22] [uq/master] Patch queue, part II Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 01/22] Prevent abortion on multiple VCPU kicks Jan Kiszka
2011-01-31  9:44   ` [Qemu-devel] " Avi Kivity
2011-01-31 11:19     ` Jan Kiszka
2011-01-31 13:16       ` Avi Kivity
2011-01-27 13:09 ` [Qemu-devel] [PATCH 02/22] Stop current VCPU on synchronous reset requests Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 03/22] Process vmstop requests in IO thread Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 04/22] Leave inner main_loop faster on pending requests Jan Kiszka
2011-01-31  9:52   ` [Qemu-devel] " Avi Kivity
2011-01-31 11:22     ` Jan Kiszka
2011-01-31 13:17       ` Avi Kivity
2011-01-31 14:32         ` Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 05/22] kvm: Report proper error on GET_VCPU_MMAP_SIZE failures Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 06/22] kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 07/22] kvm: Handle kvm_init_vcpu errors Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 08/22] kvm: Provide sigbus services arch-independently Jan Kiszka
2011-01-27 16:39   ` [Qemu-devel] " Paolo Bonzini
2011-01-30 14:51   ` Alexander Graf
2011-01-27 13:09 ` [Qemu-devel] [PATCH 09/22] Refactor signal setup functions in cpus.c Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 10/22] kvm: Set up signal mask also for !CONFIG_IOTHREAD Jan Kiszka
2011-01-28  8:08   ` [Qemu-devel] " Paolo Bonzini
2011-01-27 13:09 ` [Qemu-devel] [PATCH 11/22] kvm: Refactor qemu_kvm_eat_signals Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 12/22] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD Jan Kiszka
2011-01-28  8:09   ` [Qemu-devel] " Paolo Bonzini
2011-02-01 12:38   ` Marcelo Tosatti
2011-02-01 12:49     ` Marcelo Tosatti
2011-02-01 13:21     ` Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 13/22] Set up signalfd " Jan Kiszka
2011-01-28  8:11   ` [Qemu-devel] " Paolo Bonzini
2011-01-27 13:09 ` [Qemu-devel] [PATCH 14/22] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD Jan Kiszka
2011-01-27 14:20   ` [Qemu-devel] [PATCH v2 " Jan Kiszka
2011-01-27 14:33     ` [Qemu-devel] [PATCH v3 " Jan Kiszka
2011-01-31 10:03       ` [Qemu-devel] " Avi Kivity
2011-01-31 11:27         ` Jan Kiszka
2011-01-31 12:13           ` Stefan Hajnoczi
2011-01-31 12:18             ` Jan Kiszka
2011-01-31 13:35               ` Stefan Hajnoczi
2011-01-31 13:22           ` Avi Kivity
2011-01-31 14:31             ` Jan Kiszka
2011-01-31 16:30               ` Avi Kivity
2011-02-01 12:47   ` [Qemu-devel] Re: [PATCH " Marcelo Tosatti
2011-02-01 13:32     ` Jan Kiszka
2011-02-01 13:48       ` Marcelo Tosatti
2011-02-01 13:58         ` Jan Kiszka
2011-02-01 14:10           ` Marcelo Tosatti
2011-02-01 14:21             ` Jan Kiszka
2011-02-01 14:37               ` Jan Kiszka
2011-02-01 14:45                 ` Jan Kiszka
2011-01-27 13:09 ` Jan Kiszka [this message]
2011-01-27 13:10 ` [Qemu-devel] [PATCH 16/22] Introduce VCPU self-signaling service Jan Kiszka
2011-02-01 13:14   ` [Qemu-devel] " Marcelo Tosatti
2011-02-01 13:33     ` Jan Kiszka
2011-02-01 13:50       ` Marcelo Tosatti
2011-02-01 13:59         ` Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 17/22] kvm: Move irqchip event processing out of inner loop Jan Kiszka
2011-01-31 10:08   ` [Qemu-devel] " Avi Kivity
2011-01-31 11:36     ` Jan Kiszka
2011-01-31 13:04       ` Jan Kiszka
2011-01-31 15:40         ` Jan Kiszka
2011-01-31 16:38           ` Gleb Natapov
2011-01-31 16:41             ` Jan Kiszka
2011-01-31 16:45               ` Jan Kiszka
2011-01-31 16:50               ` Gleb Natapov
2011-01-31 16:52                 ` Jan Kiszka
2011-01-31 16:56                   ` Gleb Natapov
2011-01-31 18:06                     ` [Qemu-devel] [PATCH v2 17&18/22] kvm: Unconditionally reenter kernel after IO exits Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 18/22] " Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 19/22] kvm: Remove static return code of kvm_handle_io Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 20/22] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 21/22] Refactor kvm&tcg function names in cpus.c Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 22/22] Fix a few coding style violations " Jan Kiszka
2011-01-31 10:12 ` [Qemu-devel] Re: [PATCH 00/22] [uq/master] Patch queue, part II Avi Kivity
2011-01-31 12:03   ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=99d06c0381c7834c80b83669443e26094a3a788b.1296133797.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=avi@redhat.com \
    --cc=jin.dongming@np.css.fujitsu.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    --cc=ying.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).