All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jin Dongming <jin.dongming@np.css.fujitsu.com>
To: KVM list <kvm@vger.kernel.org>
Cc: Dean Nelson <dnelson@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Avi Kivity <avi@redhat.com>, Huang Ying <ying.huang@intel.com>,
	Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: [PATCH 08/11] kvm, x86: unify sigbus handling
Date: Thu, 14 Oct 2010 17:51:06 +0900	[thread overview]
Message-ID: <4CB6C47A.6050703@np.css.fujitsu.com> (raw)

Now kvm_handle_sigbus can handle both cases of SIGBUS.

Note that env is NULL when main thread receives SIGBUS via
signalfd, otherwise env points vcpu thread that receives SIGBUS.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Tested-by: Jin Dongming <jin.dongming@np.css.fujitsu.com>
---
 qemu-kvm.c |   94 +++++++++++++++++++++++++++---------------------------------
 1 files changed, 42 insertions(+), 52 deletions(-)

diff --git a/qemu-kvm.c b/qemu-kvm.c
index b58181a..16bc006 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1219,10 +1219,12 @@ static void kvm_mce_inj_srao_broadcast(target_phys_addr_t paddr)
 }
 #endif
 
-static void kvm_handle_sigbus(int code, void *vaddr)
+static void kvm_handle_sigbus(CPUState *env, int code, void *vaddr)
 {
 #if defined(KVM_CAP_MCE) && defined(TARGET_I386)
-    if ((first_cpu->mcg_cap & MCG_SER_P) && vaddr && code == BUS_MCEERR_AO) {
+    /* env == NULL: when main thread received a SIGBUS */
+    if (!env && (first_cpu->mcg_cap & MCG_SER_P) && vaddr
+        && code == BUS_MCEERR_AO) {
         ram_addr_t ram_addr;
         target_phys_addr_t paddr;
 
@@ -1235,7 +1237,42 @@ static void kvm_handle_sigbus(int code, void *vaddr)
             return;
         }
         kvm_mce_inj_srao_broadcast(paddr);
-    } else
+        return;
+    }
+
+    /* env != NULL: when vcpu thread received a SIGBUS */
+    if (env && (env->mcg_cap & MCG_SER_P) && vaddr
+        && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) {
+        ram_addr_t ram_addr;
+        unsigned long paddr;
+
+        /*
+         * If there is an MCE excpetion being processed, ignore this SRAO MCE
+         */
+        if (code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) {
+            return;
+        }
+
+        if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) ||
+            !kvm_physical_memory_addr_from_ram(kvm_state, ram_addr, &paddr)) {
+            fprintf(stderr, "Hardware memory error for memory used by "
+                    "QEMU itself instaed of guest system!\n");
+            /* Hope we are lucky for AO MCE */
+            if (code == BUS_MCEERR_AO) {
+                return;
+            } else {
+                hardware_memory_error();
+            }
+        }
+        if (code == BUS_MCEERR_AR) {
+            /* Fake an Intel architectural Data Load SRAR UCR */
+            kvm_mce_inj_srar_dataload(env, paddr);
+        } else {
+            /* Fake an Intel architectural Memory scrubbing UCR */
+            kvm_mce_inj_srao_memscrub(env, paddr);
+        }
+        return;
+    }
 #endif
     {
         if (code == BUS_MCEERR_AO) {
@@ -1250,7 +1287,7 @@ static void kvm_handle_sigbus(int code, void *vaddr)
 
 static void sigbus_handler(int n, struct qemu_signalfd_siginfo *ssi, void *ctx)
 {
-    kvm_handle_sigbus(ssi->ssi_code, (void *)(intptr_t)ssi->ssi_addr);
+    kvm_handle_sigbus(NULL, ssi->ssi_code, (void *)(intptr_t)ssi->ssi_addr);
 }
 
 static void on_vcpu(CPUState *env, void (*func)(void *data), void *data)
@@ -1378,53 +1415,6 @@ static void flush_queued_work(CPUState *env)
     pthread_cond_broadcast(&qemu_work_cond);
 }
 
-static void kvm_on_sigbus(CPUState *env, int code, void *vaddr)
-{
-#if defined(KVM_CAP_MCE) && defined(TARGET_I386)
-    ram_addr_t ram_addr;
-    target_phys_addr_t paddr;
-
-    if ((env->mcg_cap & MCG_SER_P) && vaddr
-        && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) {
-
-        /*
-         * If there is an MCE excpetion being processed, ignore this SRAO MCE
-         */
-        if (code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) }
-            return;
-        }
-
-        if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) ||
-            !kvm_physical_memory_addr_from_ram(kvm_state, ram_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;
-            } else {
-                hardware_memory_error();
-            }
-        }
-        if (code == BUS_MCEERR_AR) {
-            /* Fake an Intel architectural Data Load SRAR UCR */
-            kvm_mce_inj_srar_dataload(env, paddr);
-        } else {
-            /* Fake an Intel architectural Memory scrubbing UCR */
-            kvm_mce_inj_srao_memscrub(env, paddr);
-        }
-    } else
-#endif
-    {
-        if (code == BUS_MCEERR_AO) {
-            return;
-        } else if (code == BUS_MCEERR_AR) {
-            hardware_memory_error();
-        } else {
-            sigbus_reraise();
-        }
-    }
-}
-
 static void kvm_main_loop_wait(CPUState *env, int timeout)
 {
     struct timespec ts;
@@ -1454,7 +1444,7 @@ static void kvm_main_loop_wait(CPUState *env, int timeout)
 
         switch (r) {
         case SIGBUS:
-            kvm_on_sigbus(env, siginfo.si_code, (void *)siginfo.si_addr);
+            kvm_handle_sigbus(env, siginfo.si_code, (void *)siginfo.si_addr);
             break;
         default:
             break;
-- 
1.7.1.1



WARNING: multiple messages have this Message-ID (diff)
From: Jin Dongming <jin.dongming@np.css.fujitsu.com>
To: KVM list <kvm@vger.kernel.org>
Cc: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
	Dean Nelson <dnelson@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	Avi Kivity <avi@redhat.com>, Huang Ying <ying.huang@intel.com>
Subject: [Qemu-devel] [PATCH 08/11] kvm, x86: unify sigbus handling
Date: Thu, 14 Oct 2010 17:51:06 +0900	[thread overview]
Message-ID: <4CB6C47A.6050703@np.css.fujitsu.com> (raw)

Now kvm_handle_sigbus can handle both cases of SIGBUS.

Note that env is NULL when main thread receives SIGBUS via
signalfd, otherwise env points vcpu thread that receives SIGBUS.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Tested-by: Jin Dongming <jin.dongming@np.css.fujitsu.com>
---
 qemu-kvm.c |   94 +++++++++++++++++++++++++++---------------------------------
 1 files changed, 42 insertions(+), 52 deletions(-)

diff --git a/qemu-kvm.c b/qemu-kvm.c
index b58181a..16bc006 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1219,10 +1219,12 @@ static void kvm_mce_inj_srao_broadcast(target_phys_addr_t paddr)
 }
 #endif
 
-static void kvm_handle_sigbus(int code, void *vaddr)
+static void kvm_handle_sigbus(CPUState *env, int code, void *vaddr)
 {
 #if defined(KVM_CAP_MCE) && defined(TARGET_I386)
-    if ((first_cpu->mcg_cap & MCG_SER_P) && vaddr && code == BUS_MCEERR_AO) {
+    /* env == NULL: when main thread received a SIGBUS */
+    if (!env && (first_cpu->mcg_cap & MCG_SER_P) && vaddr
+        && code == BUS_MCEERR_AO) {
         ram_addr_t ram_addr;
         target_phys_addr_t paddr;
 
@@ -1235,7 +1237,42 @@ static void kvm_handle_sigbus(int code, void *vaddr)
             return;
         }
         kvm_mce_inj_srao_broadcast(paddr);
-    } else
+        return;
+    }
+
+    /* env != NULL: when vcpu thread received a SIGBUS */
+    if (env && (env->mcg_cap & MCG_SER_P) && vaddr
+        && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) {
+        ram_addr_t ram_addr;
+        unsigned long paddr;
+
+        /*
+         * If there is an MCE excpetion being processed, ignore this SRAO MCE
+         */
+        if (code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) {
+            return;
+        }
+
+        if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) ||
+            !kvm_physical_memory_addr_from_ram(kvm_state, ram_addr, &paddr)) {
+            fprintf(stderr, "Hardware memory error for memory used by "
+                    "QEMU itself instaed of guest system!\n");
+            /* Hope we are lucky for AO MCE */
+            if (code == BUS_MCEERR_AO) {
+                return;
+            } else {
+                hardware_memory_error();
+            }
+        }
+        if (code == BUS_MCEERR_AR) {
+            /* Fake an Intel architectural Data Load SRAR UCR */
+            kvm_mce_inj_srar_dataload(env, paddr);
+        } else {
+            /* Fake an Intel architectural Memory scrubbing UCR */
+            kvm_mce_inj_srao_memscrub(env, paddr);
+        }
+        return;
+    }
 #endif
     {
         if (code == BUS_MCEERR_AO) {
@@ -1250,7 +1287,7 @@ static void kvm_handle_sigbus(int code, void *vaddr)
 
 static void sigbus_handler(int n, struct qemu_signalfd_siginfo *ssi, void *ctx)
 {
-    kvm_handle_sigbus(ssi->ssi_code, (void *)(intptr_t)ssi->ssi_addr);
+    kvm_handle_sigbus(NULL, ssi->ssi_code, (void *)(intptr_t)ssi->ssi_addr);
 }
 
 static void on_vcpu(CPUState *env, void (*func)(void *data), void *data)
@@ -1378,53 +1415,6 @@ static void flush_queued_work(CPUState *env)
     pthread_cond_broadcast(&qemu_work_cond);
 }
 
-static void kvm_on_sigbus(CPUState *env, int code, void *vaddr)
-{
-#if defined(KVM_CAP_MCE) && defined(TARGET_I386)
-    ram_addr_t ram_addr;
-    target_phys_addr_t paddr;
-
-    if ((env->mcg_cap & MCG_SER_P) && vaddr
-        && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) {
-
-        /*
-         * If there is an MCE excpetion being processed, ignore this SRAO MCE
-         */
-        if (code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) }
-            return;
-        }
-
-        if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) ||
-            !kvm_physical_memory_addr_from_ram(kvm_state, ram_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;
-            } else {
-                hardware_memory_error();
-            }
-        }
-        if (code == BUS_MCEERR_AR) {
-            /* Fake an Intel architectural Data Load SRAR UCR */
-            kvm_mce_inj_srar_dataload(env, paddr);
-        } else {
-            /* Fake an Intel architectural Memory scrubbing UCR */
-            kvm_mce_inj_srao_memscrub(env, paddr);
-        }
-    } else
-#endif
-    {
-        if (code == BUS_MCEERR_AO) {
-            return;
-        } else if (code == BUS_MCEERR_AR) {
-            hardware_memory_error();
-        } else {
-            sigbus_reraise();
-        }
-    }
-}
-
 static void kvm_main_loop_wait(CPUState *env, int timeout)
 {
     struct timespec ts;
@@ -1454,7 +1444,7 @@ static void kvm_main_loop_wait(CPUState *env, int timeout)
 
         switch (r) {
         case SIGBUS:
-            kvm_on_sigbus(env, siginfo.si_code, (void *)siginfo.si_addr);
+            kvm_handle_sigbus(env, siginfo.si_code, (void *)siginfo.si_addr);
             break;
         default:
             break;
-- 
1.7.1.1

             reply	other threads:[~2010-10-14  8:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-14  8:51 Jin Dongming [this message]
2010-10-14  8:51 ` [Qemu-devel] [PATCH 08/11] kvm, x86: unify sigbus handling Jin Dongming

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=4CB6C47A.6050703@np.css.fujitsu.com \
    --to=jin.dongming@np.css.fujitsu.com \
    --cc=avi@redhat.com \
    --cc=dnelson@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.