qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH 2/7] KVM: x86: cleanup SIGBUS handlers
Date: Fri, 10 Feb 2017 10:50:07 +0100	[thread overview]
Message-ID: <20170210095012.16039-3-pbonzini@redhat.com> (raw)
In-Reply-To: <20170210095012.16039-1-pbonzini@redhat.com>

This patch should have no semantic change.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/kvm.c | 81 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 42 insertions(+), 39 deletions(-)

diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 27fd050..0c48dfd 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -469,31 +469,34 @@ int kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr)
     ram_addr_t ram_addr;
     hwaddr paddr;
 
-    if ((env->mcg_cap & MCG_SER_P) && addr
-        && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) {
+    if (code != BUS_MCEERR_AR && code != BUS_MCEERR_AO) {
+        return 1;
+    }
+
+    /* Because the MCE happened while running the VCPU, KVM could have
+     * injected action required MCEs too.  Action optional MCEs should
+     * be delivered to the main thread, which qemu_init_sigbus identifies
+     * as the "early kill" thread, but if we get one for whatever reason
+     * we just handle it just like the main thread would.
+     */
+    if ((env->mcg_cap & MCG_SER_P) && addr) {
         ram_addr = qemu_ram_addr_from_host(addr);
-        if (ram_addr == RAM_ADDR_INVALID ||
-            !kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr)) {
-            fprintf(stderr, "Hardware memory error for memory used by "
-                    "QEMU itself instead of guest system!\n");
-            /* Hope we are lucky for AO MCE */
-            if (code == BUS_MCEERR_AO) {
-                return 0;
-            } else {
-                hardware_memory_error();
-            }
-        }
-        kvm_hwpoison_page_add(ram_addr);
-        kvm_mce_inject(cpu, paddr, code);
-    } else {
-        if (code == BUS_MCEERR_AO) {
+        if (ram_addr != RAM_ADDR_INVALID &&
+            kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr)) {
+            kvm_hwpoison_page_add(ram_addr);
+            kvm_mce_inject(cpu, paddr, code);
             return 0;
-        } else if (code == BUS_MCEERR_AR) {
-            hardware_memory_error();
-        } else {
-            return 1;
         }
+
+        fprintf(stderr, "Hardware memory error for memory used by "
+                "QEMU itself instead of guest system!\n");
+    }
+
+    if (code == BUS_MCEERR_AR) {
+        hardware_memory_error();
     }
+
+    /* Hope we are lucky for AO MCE */
     return 0;
 }
 
@@ -501,29 +504,29 @@ int kvm_arch_on_sigbus(int code, void *addr)
 {
     X86CPU *cpu = X86_CPU(first_cpu);
 
-    if ((cpu->env.mcg_cap & MCG_SER_P) && addr && code == BUS_MCEERR_AO) {
+    if (code != BUS_MCEERR_AR && code != BUS_MCEERR_AO) {
+        return 1;
+    }
+
+    if (code == BUS_MCEERR_AR) {
+        hardware_memory_error();
+    }
+
+    /* Hope we are lucky for AO MCE */
+    if ((cpu->env.mcg_cap & MCG_SER_P) && addr) {
         ram_addr_t ram_addr;
         hwaddr paddr;
 
-        /* Hope we are lucky for AO MCE */
         ram_addr = qemu_ram_addr_from_host(addr);
-        if (ram_addr == RAM_ADDR_INVALID ||
-            !kvm_physical_memory_addr_from_host(first_cpu->kvm_state,
-                                                addr, &paddr)) {
-            fprintf(stderr, "Hardware memory error for memory used by "
-                    "QEMU itself instead of guest system!: %p\n", addr);
-            return 0;
-        }
-        kvm_hwpoison_page_add(ram_addr);
-        kvm_mce_inject(X86_CPU(first_cpu), paddr, code);
-    } else {
-        if (code == BUS_MCEERR_AO) {
-            return 0;
-        } else if (code == BUS_MCEERR_AR) {
-            hardware_memory_error();
-        } else {
-            return 1;
+        if (ram_addr != RAM_ADDR_INVALID &&
+            kvm_physical_memory_addr_from_host(first_cpu->kvm_state,
+                                               addr, &paddr)) {
+            kvm_hwpoison_page_add(ram_addr);
+            kvm_mce_inject(X86_CPU(first_cpu), paddr, code);
         }
+
+        fprintf(stderr, "Hardware memory error for memory used by "
+                "QEMU itself instead of guest system!: %p\n", addr);
     }
     return 0;
 }
-- 
1.8.3.1

  parent reply	other threads:[~2017-02-10  9:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10  9:50 [Qemu-devel] [PATCH qemu 0/7] KVM: race-free exit from KVM_RUN without POSIX signals Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 1/7] cpus: remove ugly cast on sigbus_handler Paolo Bonzini
2017-02-10  9:50 ` Paolo Bonzini [this message]
2017-02-10  9:50 ` [Qemu-devel] [PATCH 3/7] cpus: reorganize signal handling code Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 4/7] KVM: remove kvm_arch_on_sigbus Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 5/7] KVM: do not use sigtimedwait to catch SIGBUS Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 6/7] KVM: move SIG_IPI handling to kvm-all.c Paolo Bonzini
2017-02-10  9:50 ` [Qemu-devel] [PATCH 7/7] KVM: use KVM_CAP_IMMEDIATE_EXIT Paolo Bonzini
2017-02-10 10:11 ` [Qemu-devel] [PATCH qemu 0/7] KVM: race-free exit from KVM_RUN without POSIX signals no-reply
2017-02-15 15:57 ` Paolo Bonzini

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=20170210095012.16039-3-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --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).