qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 08/17] cpus: reorganize signal handling code
Date: Fri, 24 Feb 2017 18:40:21 +0100	[thread overview]
Message-ID: <1487958030-51417-9-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1487958030-51417-1-git-send-email-pbonzini@redhat.com>

Move the KVM "eat signals" code under CONFIG_LINUX, in preparation
for moving it to kvm-all.c; reraise non-MCE SIGBUS immediately,
without passing it to KVM.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpus.c               | 63 ++++++++++++++++++++++++++--------------------------
 include/qemu/osdep.h |  9 ++++++++
 target/i386/kvm.c    | 15 ++-----------
 3 files changed, 43 insertions(+), 44 deletions(-)

diff --git a/cpus.c b/cpus.c
index 50cae13..e50284f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -792,6 +792,10 @@ static void sigbus_reraise(void)
 
 static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx)
 {
+    if (siginfo->si_code != BUS_MCEERR_AO && siginfo->si_code != BUS_MCEERR_AR) {
+        sigbus_reraise();
+    }
+
     if (kvm_on_sigbus(siginfo->si_code, siginfo->si_addr)) {
         sigbus_reraise();
     }
@@ -809,6 +813,30 @@ static void qemu_init_sigbus(void)
     prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0);
 }
 
+static void dummy_signal(int sig)
+{
+}
+
+static void qemu_kvm_init_cpu_signals(CPUState *cpu)
+{
+    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(cpu, &set);
+    if (r) {
+        fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r));
+        exit(1);
+    }
+}
+
 static void qemu_kvm_eat_signals(CPUState *cpu)
 {
     struct timespec ts = { 0, 0 };
@@ -830,6 +858,9 @@ static void qemu_kvm_eat_signals(CPUState *cpu)
 
         switch (r) {
         case SIGBUS:
+            if (siginfo.si_code != BUS_MCEERR_AO && siginfo.si_code != BUS_MCEERR_AR) {
+                sigbus_reraise();
+            }
             if (kvm_on_sigbus_vcpu(cpu, siginfo.si_code, siginfo.si_addr)) {
                 sigbus_reraise();
             }
@@ -845,9 +876,7 @@ static void qemu_kvm_eat_signals(CPUState *cpu)
         }
     } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
 }
-
 #else /* !CONFIG_LINUX */
-
 static void qemu_init_sigbus(void)
 {
 }
@@ -855,39 +884,11 @@ static void qemu_init_sigbus(void)
 static void qemu_kvm_eat_signals(CPUState *cpu)
 {
 }
-#endif /* !CONFIG_LINUX */
-
-#ifndef _WIN32
-static void dummy_signal(int sig)
-{
-}
-
-static void qemu_kvm_init_cpu_signals(CPUState *cpu)
-{
-    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(cpu, &set);
-    if (r) {
-        fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r));
-        exit(1);
-    }
-}
 
-#else /* _WIN32 */
 static void qemu_kvm_init_cpu_signals(CPUState *cpu)
 {
-    abort();
 }
-#endif /* _WIN32 */
+#endif /* !CONFIG_LINUX */
 
 static QemuMutex qemu_global_mutex;
 static QemuCond qemu_io_proceeded_cond;
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 6932709..af37195 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -284,6 +284,15 @@ void qemu_anon_ram_free(void *ptr, size_t size);
 
 #endif
 
+#if defined(CONFIG_LINUX)
+#ifndef BUS_MCEERR_AR
+#define BUS_MCEERR_AR 4
+#endif
+#ifndef BUS_MCEERR_AO
+#define BUS_MCEERR_AO 5
+#endif
+#endif
+
 #if defined(__linux__) && \
     (defined(__x86_64__) || defined(__arm__) || defined(__aarch64__))
    /* Use 2 MiB alignment so transparent hugepages can be used by KVM.
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 0c48dfd..f49a786 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -64,13 +64,6 @@
  * 255 kvm_msr_entry structs */
 #define MSR_BUF_SIZE 4096
 
-#ifndef BUS_MCEERR_AR
-#define BUS_MCEERR_AR 4
-#endif
-#ifndef BUS_MCEERR_AO
-#define BUS_MCEERR_AO 5
-#endif
-
 const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
     KVM_CAP_INFO(SET_TSS_ADDR),
     KVM_CAP_INFO(EXT_CPUID),
@@ -469,9 +462,7 @@ int kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr)
     ram_addr_t ram_addr;
     hwaddr paddr;
 
-    if (code != BUS_MCEERR_AR && code != BUS_MCEERR_AO) {
-        return 1;
-    }
+    assert(code == BUS_MCEERR_AR || code == BUS_MCEERR_AO);
 
     /* Because the MCE happened while running the VCPU, KVM could have
      * injected action required MCEs too.  Action optional MCEs should
@@ -504,9 +495,7 @@ int kvm_arch_on_sigbus(int code, void *addr)
 {
     X86CPU *cpu = X86_CPU(first_cpu);
 
-    if (code != BUS_MCEERR_AR && code != BUS_MCEERR_AO) {
-        return 1;
-    }
+    assert(code == BUS_MCEERR_AR || code == BUS_MCEERR_AO);
 
     if (code == BUS_MCEERR_AR) {
         hardware_memory_error();
-- 
1.8.3.1

  parent reply	other threads:[~2017-02-24 17:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24 17:40 [Qemu-devel] [PULL 00/17] KVM and cpu-exec patches for 2.9 soft freeze Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 01/17] cpu-exec: unify icount_decr and tcg_exit_req Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 02/17] replay: check icount in cpu exec loop Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 03/17] cpu-exec: remove unnecessary check of cpu->exit_request Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 04/17] update-linux-headers: update for 4.11 Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 05/17] update Linux headers to 4.11 Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 06/17] cpus: remove ugly cast on sigbus_handler Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 07/17] KVM: x86: cleanup SIGBUS handlers Paolo Bonzini
2017-02-24 17:40 ` Paolo Bonzini [this message]
2017-02-24 17:40 ` [Qemu-devel] [PULL 09/17] KVM: remove kvm_arch_on_sigbus Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 10/17] KVM: do not use sigtimedwait to catch SIGBUS Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 11/17] KVM: move SIG_IPI handling to kvm-all.c Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 12/17] kvm: use atomic_read/atomic_set to access cpu->exit_request Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 13/17] KVM: use KVM_CAP_IMMEDIATE_EXIT Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 14/17] vmxcap: port to Python 3 Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 15/17] vmxcap: update for September 2016 SDM Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 16/17] qapi: flatten GuestPanicInformation union Paolo Bonzini
2017-02-24 17:40 ` [Qemu-devel] [PULL 17/17] qmp-events: fix GUEST_PANICKED description formatting Paolo Bonzini
2017-02-24 18:27 ` [Qemu-devel] [PULL 00/17] KVM and cpu-exec patches for 2.9 soft freeze no-reply
2017-02-25 21:32 ` Peter Maydell

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=1487958030-51417-9-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).