From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jin Dongming Subject: [PATCH 10/11] kvm, x86: unify sigbus handling, post2 Date: Thu, 14 Oct 2010 17:54:12 +0900 Message-ID: <4CB6C534.4070303@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 fgwmail6.fujitsu.co.jp ([192.51.44.36]:44343 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755024Ab0JNIwu (ORCPT ); Thu, 14 Oct 2010 04:52:50 -0400 Received: from m2.gw.fujitsu.co.jp ([10.0.50.72]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id o9E8qm7E024575 for (envelope-from jin.dongming@np.css.fujitsu.com); Thu, 14 Oct 2010 17:52:49 +0900 Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 0902745DE51 for ; Thu, 14 Oct 2010 17:52:48 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id BCB5245DE57 for ; Thu, 14 Oct 2010 17:52:47 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 7F666E38001 for ; Thu, 14 Oct 2010 17:52:47 +0900 (JST) Received: from m004.s.css.fujitsu.com (m004.s.css.fujitsu.com [10.23.4.34]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 2A87F1DB8038 for ; Thu, 14 Oct 2010 17:52:47 +0900 (JST) Sender: kvm-owner@vger.kernel.org List-ID: Cleanup to finish unification. Signed-off-by: Hidetoshi Seto Tested-by: Jin Dongming --- qemu-kvm.c | 41 ++++++++++++----------------------------- 1 files changed, 12 insertions(+), 29 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index d96394b..d2b2459 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -1222,45 +1222,24 @@ static void kvm_mce_inj_srao_broadcast(target_phys_addr_t paddr) static void kvm_handle_sigbus(CPUState *env, int code, void *vaddr) { #if defined(KVM_CAP_MCE) && defined(TARGET_I386) - /* env == NULL: when main thread received a SIGBUS */ - if (!env && vaddr && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) { + if (vaddr && (code == BUS_MCEERR_AO || code == BUS_MCEERR_AR)) { ram_addr_t ram_addr; target_phys_addr_t paddr; + CPUState *target_env; /* Give up MCE forwarding if immediate action required on main thread */ - if (code == BUS_MCEERR_AR) { + if (!env && code == BUS_MCEERR_AR) { goto out; } /* Check if recoverable MCE support is enabled */ - if (!(first_cpu->mcg_cap & MCG_SER_P)){ - goto out; - } - - 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!: %llx\n", - (unsigned long long)vaddr); - return; - } - /* Broadcast SRAO UCR to all vcpu threads */ - kvm_mce_inj_srao_broadcast(paddr); - return; - } - - /* env != NULL: when vcpu thread received a SIGBUS */ - if (env && vaddr && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) { - ram_addr_t ram_addr; - unsigned long paddr; - - /* Check if recoverable MCE support is enabled */ - if (!(env->mcg_cap & MCG_SER_P)){ + target_env = env ? env : first_cpu; + if (!target_env || !(target_env->mcg_cap & MCG_SER_P)) { goto out; } /* If there is an MCE exception being processed, ignore this SRAO MCE */ - if (code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) { + if (env && code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) { return; } @@ -1273,10 +1252,14 @@ static void kvm_handle_sigbus(CPUState *env, int code, void *vaddr) } if (code == BUS_MCEERR_AR) { /* Fake an Intel architectural Data Load SRAR UCR */ - kvm_mce_inj_srar_dataload(env, paddr); + kvm_mce_inj_srar_dataload(target_env, paddr); } else { /* Fake an Intel architectural Memory scrubbing UCR */ - kvm_mce_inj_srao_memscrub(env, paddr); + if (env) { + kvm_mce_inj_srao_memscrub(target_env, paddr); + } else { + kvm_mce_inj_srao_broadcast(paddr); + } } return; } -- 1.7.1.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=46037 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6JYb-0004Q2-52 for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:53:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6JYT-0004T9-36 for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:52:54 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:44346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6JYS-0004So-JB for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:52:53 -0400 Received: from m5.gw.fujitsu.co.jp ([10.0.50.75]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id o9E8qp6K024587 for (envelope-from jin.dongming@np.css.fujitsu.com); Thu, 14 Oct 2010 17:52:51 +0900 Received: from smail (m5 [127.0.0.1]) by outgoing.m5.gw.fujitsu.co.jp (Postfix) with ESMTP id E4DE445DE51 for ; Thu, 14 Oct 2010 17:52:50 +0900 (JST) Received: from s5.gw.fujitsu.co.jp (s5.gw.fujitsu.co.jp [10.0.50.95]) by m5.gw.fujitsu.co.jp (Postfix) with ESMTP id BC4F245DE4E for ; Thu, 14 Oct 2010 17:52:50 +0900 (JST) Received: from s5.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s5.gw.fujitsu.co.jp (Postfix) with ESMTP id 7E270E08001 for ; Thu, 14 Oct 2010 17:52:50 +0900 (JST) Received: from m004.s.css.fujitsu.com (m004.s.css.fujitsu.com [10.23.4.34]) by s5.gw.fujitsu.co.jp (Postfix) with ESMTP id 2BCCA1DB803F for ; Thu, 14 Oct 2010 17:52:47 +0900 (JST) Message-ID: <4CB6C534.4070303@np.css.fujitsu.com> Date: Thu, 14 Oct 2010 17:54:12 +0900 From: Jin Dongming MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 10/11] kvm, x86: unify sigbus handling, post2 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 Cleanup to finish unification. Signed-off-by: Hidetoshi Seto Tested-by: Jin Dongming --- qemu-kvm.c | 41 ++++++++++++----------------------------- 1 files changed, 12 insertions(+), 29 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index d96394b..d2b2459 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -1222,45 +1222,24 @@ static void kvm_mce_inj_srao_broadcast(target_phys_addr_t paddr) static void kvm_handle_sigbus(CPUState *env, int code, void *vaddr) { #if defined(KVM_CAP_MCE) && defined(TARGET_I386) - /* env == NULL: when main thread received a SIGBUS */ - if (!env && vaddr && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) { + if (vaddr && (code == BUS_MCEERR_AO || code == BUS_MCEERR_AR)) { ram_addr_t ram_addr; target_phys_addr_t paddr; + CPUState *target_env; /* Give up MCE forwarding if immediate action required on main thread */ - if (code == BUS_MCEERR_AR) { + if (!env && code == BUS_MCEERR_AR) { goto out; } /* Check if recoverable MCE support is enabled */ - if (!(first_cpu->mcg_cap & MCG_SER_P)){ - goto out; - } - - 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!: %llx\n", - (unsigned long long)vaddr); - return; - } - /* Broadcast SRAO UCR to all vcpu threads */ - kvm_mce_inj_srao_broadcast(paddr); - return; - } - - /* env != NULL: when vcpu thread received a SIGBUS */ - if (env && vaddr && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) { - ram_addr_t ram_addr; - unsigned long paddr; - - /* Check if recoverable MCE support is enabled */ - if (!(env->mcg_cap & MCG_SER_P)){ + target_env = env ? env : first_cpu; + if (!target_env || !(target_env->mcg_cap & MCG_SER_P)) { goto out; } /* If there is an MCE exception being processed, ignore this SRAO MCE */ - if (code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) { + if (env && code == BUS_MCEERR_AO && kvm_mce_in_progress(env)) { return; } @@ -1273,10 +1252,14 @@ static void kvm_handle_sigbus(CPUState *env, int code, void *vaddr) } if (code == BUS_MCEERR_AR) { /* Fake an Intel architectural Data Load SRAR UCR */ - kvm_mce_inj_srar_dataload(env, paddr); + kvm_mce_inj_srar_dataload(target_env, paddr); } else { /* Fake an Intel architectural Memory scrubbing UCR */ - kvm_mce_inj_srao_memscrub(env, paddr); + if (env) { + kvm_mce_inj_srao_memscrub(target_env, paddr); + } else { + kvm_mce_inj_srao_broadcast(paddr); + } } return; } -- 1.7.1.1