From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jin Dongming Subject: [PATCH 08/11] kvm, x86: unify sigbus handling Date: Thu, 14 Oct 2010 17:51:06 +0900 Message-ID: <4CB6C47A.6050703@np.css.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Cc: Dean Nelson , Marcelo Tosatti , Avi Kivity , Huang Ying , Hidetoshi Seto , "qemu-devel@nongnu.org" To: KVM list Return-path: Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:48791 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755017Ab0JNItn (ORCPT ); Thu, 14 Oct 2010 04:49:43 -0400 Received: from m4.gw.fujitsu.co.jp ([10.0.50.74]) by fgwmail5.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id o9E8ngFW021109 for (envelope-from jin.dongming@np.css.fujitsu.com); Thu, 14 Oct 2010 17:49:42 +0900 Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 452A045DE6E for ; Thu, 14 Oct 2010 17:49:42 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 2469E45DE60 for ; Thu, 14 Oct 2010 17:49:42 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 0B7D8EF8001 for ; Thu, 14 Oct 2010 17:49:42 +0900 (JST) Received: from m001.s.css.fujitsu.com (m001.s.css.fujitsu.com [10.23.4.39]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id B81651DB803B for ; Thu, 14 Oct 2010 17:49:38 +0900 (JST) Sender: kvm-owner@vger.kernel.org List-ID: 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 Tested-by: Jin Dongming --- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=44491 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6JVQ-0002JJ-U2 for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:49:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6JVP-0003s2-MP for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:49:44 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:44198) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6JVP-0003rc-5R for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:49:43 -0400 Received: from m6.gw.fujitsu.co.jp ([10.0.50.76]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id o9E8ne70023079 for (envelope-from jin.dongming@np.css.fujitsu.com); Thu, 14 Oct 2010 17:49:40 +0900 Received: from smail (m6 [127.0.0.1]) by outgoing.m6.gw.fujitsu.co.jp (Postfix) with ESMTP id 5441045DE4E for ; Thu, 14 Oct 2010 17:49:40 +0900 (JST) Received: from s6.gw.fujitsu.co.jp (s6.gw.fujitsu.co.jp [10.0.50.96]) by m6.gw.fujitsu.co.jp (Postfix) with ESMTP id EB9D745DE52 for ; Thu, 14 Oct 2010 17:49:39 +0900 (JST) Received: from s6.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s6.gw.fujitsu.co.jp (Postfix) with ESMTP id 8947B1DB801D for ; Thu, 14 Oct 2010 17:49:39 +0900 (JST) Received: from m001.s.css.fujitsu.com (m001.s.css.fujitsu.com [10.23.4.39]) by s6.gw.fujitsu.co.jp (Postfix) with ESMTP id C19781DB803A for ; Thu, 14 Oct 2010 17:49:38 +0900 (JST) Message-ID: <4CB6C47A.6050703@np.css.fujitsu.com> Date: Thu, 14 Oct 2010 17:51:06 +0900 From: Jin Dongming MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 08/11] kvm, x86: unify sigbus handling List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: KVM list Cc: Hidetoshi Seto , Dean Nelson , Marcelo Tosatti , "qemu-devel@nongnu.org" , Avi Kivity , Huang Ying 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 Tested-by: Jin Dongming --- 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