From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=47805 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8enp-0006XF-Am for qemu-devel@nongnu.org; Wed, 20 Oct 2010 15:58:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8enn-0003D5-Vh for qemu-devel@nongnu.org; Wed, 20 Oct 2010 15:58:25 -0400 Received: from e4.ny.us.ibm.com ([32.97.182.144]:47602) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8enn-0003Cw-S3 for qemu-devel@nongnu.org; Wed, 20 Oct 2010 15:58:23 -0400 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by e4.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o9KJg5Kf000425 for ; Wed, 20 Oct 2010 15:42:05 -0400 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9KJw9cr444528 for ; Wed, 20 Oct 2010 15:58:10 -0400 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9KJw9n2013149 for ; Wed, 20 Oct 2010 13:58:09 -0600 Message-ID: <4CBF49D2.3030808@linux.vnet.ibm.com> Date: Wed, 20 Oct 2010 14:58:10 -0500 From: Anthony Liguori MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 05/10] kvm: x86: add mce support List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcelo Tosatti Cc: Anthony Liguori , qemu-devel@nongnu.org, kvm@vger.kernel.org, Avi Kivity On 10/20/2010 12:43 PM, Marcelo Tosatti wrote: > Port qemu-kvm's MCE support > > commit c68b2374c9048812f488e00ffb95db66c0bc07a7 > Author: Huang Ying > Date: Mon Jul 20 10:00:53 2009 +0800 > > Add MCE simulation support to qemu/kvm > > KVM ioctls are used to initialize MCE simulation and inject MCE. The > real MCE simulation is implemented in Linux kernel. The Kernel part > has been merged. > > Signed-off-by: Marcelo Tosatti > Signed-off-by: Avi Kivity > --- > target-i386/helper.c | 6 +++ > target-i386/kvm.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ > target-i386/kvm_x86.h | 21 ++++++++++++ > 3 files changed, 111 insertions(+), 0 deletions(-) > create mode 100644 target-i386/kvm_x86.h > > diff --git a/target-i386/helper.c b/target-i386/helper.c > index e134340..4b430dd 100644 > --- a/target-i386/helper.c > +++ b/target-i386/helper.c > @@ -27,6 +27,7 @@ > #include "exec-all.h" > #include "qemu-common.h" > #include "kvm.h" > +#include "kvm_x86.h" > > //#define DEBUG_MMU > > @@ -1030,6 +1031,11 @@ void cpu_inject_x86_mce(CPUState *cenv, int bank, uint64_t status, > if (bank>= bank_num || !(status& MCI_STATUS_VAL)) > return; > > + if (kvm_enabled()) { > + kvm_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc); > + return; > + } > + > /* > * if MSR_MCG_CTL is not all 1s, the uncorrected error > * reporting is disabled > diff --git a/target-i386/kvm.c b/target-i386/kvm.c > index 74e7b4f..343fb02 100644 > --- a/target-i386/kvm.c > +++ b/target-i386/kvm.c > @@ -27,6 +27,7 @@ > #include "hw/pc.h" > #include "hw/apic.h" > #include "ioport.h" > +#include "kvm_x86.h" > > #ifdef CONFIG_KVM_PARA > #include > @@ -167,6 +168,67 @@ static int get_para_features(CPUState *env) > } > #endif > > +#ifdef KVM_CAP_MCE > +static int kvm_get_mce_cap_supported(KVMState *s, uint64_t *mce_cap, > + int *max_banks) > +{ > + int r; > + > + r = kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_MCE); > + if (r> 0) { > + *max_banks = r; > + return kvm_ioctl(s, KVM_X86_GET_MCE_CAP_SUPPORTED, mce_cap); > + } > + return -ENOSYS; > +} > + > +static int kvm_setup_mce(CPUState *env, uint64_t *mcg_cap) > +{ > + return kvm_vcpu_ioctl(env, KVM_X86_SETUP_MCE, mcg_cap); > +} > + > +static int kvm_set_mce(CPUState *env, struct kvm_x86_mce *m) > +{ > + return kvm_vcpu_ioctl(env, KVM_X86_SET_MCE, m); > +} > + > +struct kvm_x86_mce_data > +{ > + CPUState *env; > + struct kvm_x86_mce *mce; > +}; > CODING_STYLE. > +static void kvm_do_inject_x86_mce(void *_data) > +{ > + struct kvm_x86_mce_data *data = _data; > + int r; > + > + r = kvm_set_mce(data->env, data->mce); > + if (r< 0) > + perror("kvm_set_mce FAILED"); > CODING_STYLE. > +} > +#endif > + > +void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status, > + uint64_t mcg_status, uint64_t addr, uint64_t misc) > +{ > +#ifdef KVM_CAP_MCE > + struct kvm_x86_mce mce = { > + .bank = bank, > + .status = status, > + .mcg_status = mcg_status, > + .addr = addr, > + .misc = misc, > + }; > + struct kvm_x86_mce_data data = { > + .env = cenv, > + .mce =&mce, > + }; > + > + run_on_cpu(cenv, kvm_do_inject_x86_mce,&data); > +#endif > +} > + > int kvm_arch_init_vcpu(CPUState *env) > { > struct { > @@ -277,6 +339,28 @@ int kvm_arch_init_vcpu(CPUState *env) > > cpuid_data.cpuid.nent = cpuid_i; > > +#ifdef KVM_CAP_MCE > + if (((env->cpuid_version>> 8)&0xF)>= 6 > +&& (env->cpuid_features&(CPUID_MCE|CPUID_MCA)) == (CPUID_MCE|CPUID_MCA) > +&& kvm_check_extension(env->kvm_state, KVM_CAP_MCE)> 0) { > + uint64_t mcg_cap; > + int banks; > + > + if (kvm_get_mce_cap_supported(env->kvm_state,&mcg_cap,&banks)) > + perror("kvm_get_mce_cap_supported FAILED"); > + else { > + if (banks> MCE_BANKS_DEF) > + banks = MCE_BANKS_DEF; > + mcg_cap&= MCE_CAP_DEF; > + mcg_cap |= banks; > + if (kvm_setup_mce(env,&mcg_cap)) > + perror("kvm_setup_mce FAILED"); > + else > + env->mcg_cap = mcg_cap; > CODING_STYLE. > + } > + } > +#endif > + > return kvm_vcpu_ioctl(env, KVM_SET_CPUID2,&cpuid_data); > } > > diff --git a/target-i386/kvm_x86.h b/target-i386/kvm_x86.h > new file mode 100644 > index 0000000..c1ebd24 > --- /dev/null > +++ b/target-i386/kvm_x86.h > @@ -0,0 +1,21 @@ > +/* > + * QEMU KVM support > + * > + * Copyright (C) 2009 Red Hat Inc. > + * Copyright IBM, Corp. 2008 > + * > + * Authors: > + * Anthony Liguori > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + * > + */ > + > +#ifndef __KVM_X86_H__ > +#define __KVM_X86_H__ > + > +void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status, > + uint64_t mcg_status, uint64_t addr, uint64_t misc); > + > +#endif >