From patchwork Thu Oct 14 08:52:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jin Dongming X-Patchwork-Id: 67801 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 344761007D3 for ; Thu, 14 Oct 2010 20:01:39 +1100 (EST) Received: from localhost ([127.0.0.1]:46341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6Jgu-0000Fx-AF for incoming@patchwork.ozlabs.org; Thu, 14 Oct 2010 05:01:36 -0400 Received: from [140.186.70.92] (port=45386 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6JX9-0003Pn-DY for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:51:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6JX5-0004Gp-9D for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:51:28 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:44288) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6JX4-0004GX-PX for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:51:27 -0400 Received: from m4.gw.fujitsu.co.jp ([10.0.50.74]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id o9E8pPRm024056 for (envelope-from jin.dongming@np.css.fujitsu.com); Thu, 14 Oct 2010 17:51:25 +0900 Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 3465C45DE60 for ; Thu, 14 Oct 2010 17:51:25 +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 01D7245DE6E for ; Thu, 14 Oct 2010 17:51:25 +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 DBB74EF8005 for ; Thu, 14 Oct 2010 17:51:24 +0900 (JST) Received: from m004.s.css.fujitsu.com (m004.s.css.fujitsu.com [10.23.4.34]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 7937BEF8003 for ; Thu, 14 Oct 2010 17:51:24 +0900 (JST) Received: from m004.css.fujitsu.com (m004 [127.0.0.1]) by m004.s.css.fujitsu.com (Postfix) with ESMTP id 613AB2E0108; Thu, 14 Oct 2010 17:51:24 +0900 (JST) Received: from [127.0.0.1] (unknown [10.124.101.76]) by m004.s.css.fujitsu.com (Postfix) with ESMTP id 29EC12E0105; Thu, 14 Oct 2010 17:51:24 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v1.5.1 Message-ID: <4CB6C4E3.9000001@np.css.fujitsu.com> Date: Thu, 14 Oct 2010 17:52:51 +0900 From: Jin Dongming User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; ja; rv:1.9.2.7) Gecko/20100713 Thunderbird/3.1.1 MIME-Version: 1.0 To: KVM list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Hidetoshi Seto , Dean Nelson , Marcelo Tosatti , "qemu-devel@nongnu.org" , Avi Kivity , Huang Ying Subject: [Qemu-devel] [PATCH 09/11] kvm, x86: unify sigbus handling, post1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Explicitly duplicate blocks for next cleanup. Signed-off-by: Hidetoshi Seto Tested-by: Jin Dongming --- qemu-kvm.c | 56 +++++++++++++++++++++++++++++++++----------------------- 1 files changed, 33 insertions(+), 23 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index 16bc006..d96394b 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -1223,12 +1223,20 @@ 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 && (first_cpu->mcg_cap & MCG_SER_P) && vaddr - && code == BUS_MCEERR_AO) { + if (!env && vaddr && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) { ram_addr_t ram_addr; target_phys_addr_t paddr; - /* Hope we are lucky for AO MCE */ + /* Give up MCE forwarding if immediate action required on main thread */ + if (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 " @@ -1236,19 +1244,22 @@ static void kvm_handle_sigbus(CPUState *env, int code, void *vaddr) (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 && (env->mcg_cap & MCG_SER_P) && vaddr - && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) { + if (env && 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 - */ + /* Check if recoverable MCE support is enabled */ + if (!(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)) { return; } @@ -1256,13 +1267,9 @@ static void kvm_handle_sigbus(CPUState *env, int code, void *vaddr) 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(); - } + "QEMU itself instead of guest system!: %llx\n", + (unsigned long long)vaddr); + goto out; } if (code == BUS_MCEERR_AR) { /* Fake an Intel architectural Data Load SRAR UCR */ @@ -1273,15 +1280,18 @@ static void kvm_handle_sigbus(CPUState *env, int code, void *vaddr) } return; } +out: #endif - { - if (code == BUS_MCEERR_AO) { - return; - } else if (code == BUS_MCEERR_AR) { - hardware_memory_error(); - } else { - sigbus_reraise(); - } + /* Hope we are lucky for AO MCE */ + if (code == BUS_MCEERR_AO) { + return; + } + + /* Abort in either way */ + if (code == BUS_MCEERR_AR) { + hardware_memory_error(); + } else { + sigbus_reraise(); } }