From patchwork Thu Oct 14 08:44:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jin Dongming X-Patchwork-Id: 67792 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 EB609B70E3 for ; Thu, 14 Oct 2010 19:44:40 +1100 (EST) Received: from localhost ([127.0.0.1]:33870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6JQT-0006Ss-7W for incoming@patchwork.ozlabs.org; Thu, 14 Oct 2010 04:44:37 -0400 Received: from [140.186.70.92] (port=60565 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6JOy-0006QN-HX for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:43:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6JOw-0002ib-B7 for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:43:04 -0400 Received: from fgwmail7.fujitsu.co.jp ([192.51.44.37]:41031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6JOt-0002hd-VG for qemu-devel@nongnu.org; Thu, 14 Oct 2010 04:43:02 -0400 Received: from m3.gw.fujitsu.co.jp ([10.0.50.73]) by fgwmail7.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id o9E8gwEQ030050 for (envelope-from jin.dongming@np.css.fujitsu.com); Thu, 14 Oct 2010 17:42:58 +0900 Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 5A14245DE52 for ; Thu, 14 Oct 2010 17:42:58 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 2B0D845DE4D for ; Thu, 14 Oct 2010 17:42:58 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 0AE85E18004 for ; Thu, 14 Oct 2010 17:42:58 +0900 (JST) Received: from m005.s.css.fujitsu.com (m005.s.css.fujitsu.com [10.23.4.35]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id AF812E18003 for ; Thu, 14 Oct 2010 17:42:57 +0900 (JST) Received: from m005.css.fujitsu.com (m005 [127.0.0.1]) by m005.s.css.fujitsu.com (Postfix) with ESMTP id 8E5B453EB01; Thu, 14 Oct 2010 17:42:57 +0900 (JST) Received: from [127.0.0.1] (unknown [10.124.101.76]) by m005.s.css.fujitsu.com (Postfix) with ESMTP id 3831753EB02; Thu, 14 Oct 2010 17:42:57 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v1.5.1 Message-ID: <4CB6C2E7.7080301@np.css.fujitsu.com> Date: Thu, 14 Oct 2010 17:44:23 +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 03/11] kvm, x86: introduce kvm_mce_in_progress 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 Share same error handing, and put it in #ifdef MCE && i386. Rename this function after MCIP (Machine Check In Progress) flag. Signed-off-by: Hidetoshi Seto Tested-by: Jin Dongming --- qemu-kvm.c | 47 ++++++++++++++++++++--------------------------- 1 files changed, 20 insertions(+), 27 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index 1338e99..a71c07c 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -1131,6 +1131,21 @@ static void sigbus_reraise(void) } #if defined(KVM_CAP_MCE) && defined(TARGET_I386) +static int kvm_mce_in_progress(CPUState *env) +{ + struct kvm_msr_entry msr_mcg_status = { + .index = MSR_MCG_STATUS, + }; + int r; + + r = kvm_get_msrs(env, &msr_mcg_status, 1); + if (r == -1 || r == 0) { + perror("Failed to get MCE status"); + return 0; + } + return !!(msr_mcg_status.data & MCG_STATUS_MCIP); +} + static void kvm_do_set_mce(CPUState *env, struct kvm_x86_mce *mce, int abort_on_error) { @@ -1315,20 +1330,6 @@ static void flush_queued_work(CPUState *env) pthread_cond_broadcast(&qemu_work_cond); } -static int kvm_mce_in_exception(CPUState *env) -{ - struct kvm_msr_entry msr_mcg_status = { - .index = MSR_MCG_STATUS, - }; - int r; - - r = kvm_get_msrs(env, &msr_mcg_status, 1); - if (r == -1 || r == 0) { - return -1; - } - return !!(msr_mcg_status.data & MCG_STATUS_MCIP); -} - static void kvm_on_sigbus(CPUState *env, siginfo_t *siginfo) { #if defined(KVM_CAP_MCE) && defined(TARGET_I386) @@ -1338,7 +1339,6 @@ static void kvm_on_sigbus(CPUState *env, siginfo_t *siginfo) void *vaddr; ram_addr_t ram_addr; unsigned long paddr; - int r; if ((env->mcg_cap & MCG_SER_P) && siginfo->si_addr && (siginfo->si_code == BUS_MCEERR_AR @@ -1355,12 +1355,10 @@ static void kvm_on_sigbus(CPUState *env, siginfo_t *siginfo) * If there is an MCE excpetion being processed, ignore * this SRAO MCE */ - r = kvm_mce_in_exception(env); - if (r == -1) { - fprintf(stderr, "Failed to get MCE status\n"); - } else if (r) { + if (kvm_mce_in_progress(env)) { return; } + /* Fake an Intel architectural Memory scrubbing UCR */ mce.status = MCI_STATUS_VAL | MCI_STATUS_UC | MCI_STATUS_EN | MCI_STATUS_MISCV | MCI_STATUS_ADDRV | MCI_STATUS_S @@ -1913,17 +1911,12 @@ struct kvm_x86_mce_data { static void kvm_do_inject_x86_mce(void *_data) { struct kvm_x86_mce_data *data = _data; - int r; /* If there is an MCE exception being processed, ignore this SRAO MCE */ if ((data->env->mcg_cap & MCG_SER_P) && - !(data->mce->status & MCI_STATUS_AR)) { - r = kvm_mce_in_exception(data->env); - if (r == -1) { - fprintf(stderr, "Failed to get MCE status\n"); - } else if (r) { - return; - } + !(data->mce->status & MCI_STATUS_AR) && + kvm_mce_in_progress(data->env)) { + return; } kvm_do_set_mce(data->env, data->mce, data->abort_on_error);