From patchwork Thu Mar 30 06:19:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9652973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 818D5602BD for ; Thu, 30 Mar 2017 06:22:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7140B28571 for ; Thu, 30 Mar 2017 06:22:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 652AF28576; Thu, 30 Mar 2017 06:22:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EC13728571 for ; Thu, 30 Mar 2017 06:22:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ctTRT-0000sn-Sl; Thu, 30 Mar 2017 06:20:19 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ctTRR-0000rf-Py for xen-devel@lists.xen.org; Thu, 30 Mar 2017 06:20:17 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id C6/F6-04270-1A3ACD85; Thu, 30 Mar 2017 06:20:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNLMWRWlGSWpSXmKPExsXS1tYhr7tg8Z0 IgyeTtSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oxLKyULlmtXrNryna2B8YNCFyMnh5BApUTb ksvsILaEAK/EkWUzWLsYOYBsf4knjapdjFxAJb2MEqcbfoPVsAnoS6x4fJAVxBYRkJa49vkyI 4jNLFAtMXH6HDBbWMBb4seXrWA2i4CqxOVfW5lBbF4BG4npR14zQ+ySl7hw9RQLiM0pYCux+m s7C8Q9NhJnrx1im8DIu4CRYRWjenFqUVlqka6lXlJRZnpGSW5iZo6uoYGxXm5qcXFiempOYlK xXnJ+7iZGYCDUMzAw7mB8/dPpEKMkB5OSKO/muXcihPiS8lMqMxKLM+KLSnNSiw8xynBwKEnw +iwCygkWpaanVqRl5gBDEiYtwcGjJMJ7EiTNW1yQmFucmQ6ROsWoKCXO6w6SEABJZJTmwbXB4 uASo6yUMC8jAwODEE9BalFuZgmq/CtGcQ5GJWFeSZApPJl5JXDTXwEtZgJaLG5zC2RxSSJCSq qBkX9fzorPsZl3vy/IvyGjyPZQRqhlz74/O+YtXTR5Z2SHa9i2G7cXLbxZnFXAGV5efkxS8Nu aPQtOp9p28ybv6tnwdMukmUsMMqZ7uDsEbIpe2+jC+5yvf90L4W3WEy3O+V8xW37hssOcix76 S1qiO//kyb0PMFqxYmOW/k6eI7u2ZpxZG1/Q76fEUpyRaKjFXFScCADM6swRfgIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-16.tower-31.messagelabs.com!1490854812!85204125!3 X-Originating-IP: [134.134.136.31] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 25177 invoked from network); 30 Mar 2017 06:20:16 -0000 Received: from mga06.intel.com (HELO mga06.intel.com) (134.134.136.31) by server-16.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 30 Mar 2017 06:20:16 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP; 29 Mar 2017 23:20:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,245,1486454400"; d="scan'208";a="241919462" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.153]) by fmsmga004.fm.intel.com with ESMTP; 29 Mar 2017 23:20:14 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Thu, 30 Mar 2017 14:19:56 +0800 Message-Id: <20170330062003.9119-3-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170330062003.9119-1-haozhong.zhang@intel.com> References: <20170330062003.9119-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH v3 2/9] x86/mce_intel: detect and enable LMCE on Intel host X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Enable LMCE if it's supported by the host CPU. If Xen boot parameter "mce_fb = 1" is present, LMCE will be disabled forcibly. Signed-off-by: Haozhong Zhang Reviewed-by: Jan Beulich --- Cc: Jan Beulich Cc: Andrew Cooper Changes in v3: * Make lmce_support static. --- xen/arch/x86/cpu/mcheck/mce_intel.c | 46 ++++++++++++++++++++++++++++++++----- xen/arch/x86/cpu/mcheck/x86_mca.h | 5 ++++ xen/include/asm-x86/msr-index.h | 2 ++ 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/cpu/mcheck/mce_intel.c b/xen/arch/x86/cpu/mcheck/mce_intel.c index fdf57ce..3c57052 100644 --- a/xen/arch/x86/cpu/mcheck/mce_intel.c +++ b/xen/arch/x86/cpu/mcheck/mce_intel.c @@ -29,6 +29,9 @@ boolean_param("mce_fb", mce_force_broadcast); static int __read_mostly nr_intel_ext_msrs; +/* If mce_force_broadcast == 1, lmce_support will be disabled forcibly. */ +static bool __read_mostly lmce_support; + /* Intel SDM define bit15~bit0 of IA32_MCi_STATUS as the MC error code */ #define INTEL_MCCOD_MASK 0xFFFF @@ -698,10 +701,34 @@ static bool mce_is_broadcast(struct cpuinfo_x86 *c) return false; } +static bool intel_enable_lmce(void) +{ + uint64_t msr_content; + + /* + * Section "Enabling Local Machine Check" in Intel SDM Vol 3 + * requires software must ensure the LOCK bit and LMCE_ON bit + * of MSR_IA32_FEATURE_CONTROL are set before setting + * MSR_IA32_MCG_EXT_CTL.LMCE_EN. + */ + + if ( rdmsr_safe(MSR_IA32_FEATURE_CONTROL, msr_content) ) + return false; + + if ( (msr_content & IA32_FEATURE_CONTROL_LOCK) && + (msr_content & IA32_FEATURE_CONTROL_LMCE_ON) ) + { + wrmsrl(MSR_IA32_MCG_EXT_CTL, MCG_EXT_CTL_LMCE_EN); + return true; + } + + return false; +} + /* Check and init MCA */ static void intel_init_mca(struct cpuinfo_x86 *c) { - bool broadcast, cmci = false, ser = false; + bool broadcast, cmci = false, ser = false, lmce = false; int ext_num = 0, first; uint64_t msr_content; @@ -721,33 +748,40 @@ static void intel_init_mca(struct cpuinfo_x86 *c) first = mce_firstbank(c); + if (!mce_force_broadcast && (msr_content & MCG_LMCE_P)) + lmce = intel_enable_lmce(); + #define CAP(enabled, name) ((enabled) ? ", " name : "") if (smp_processor_id() == 0) { dprintk(XENLOG_INFO, - "MCA capability: firstbank %d, %d ext MSRs%s%s%s\n", + "MCA Capability: firstbank %d, extended MCE MSR %d%s%s%s%s\n", first, ext_num, CAP(broadcast, "BCAST"), CAP(ser, "SER"), - CAP(cmci, "CMCI")); + CAP(cmci, "CMCI"), + CAP(lmce, "LMCE")); mce_broadcast = broadcast; cmci_support = cmci; ser_support = ser; + lmce_support = lmce; nr_intel_ext_msrs = ext_num; firstbank = first; } else if (cmci != cmci_support || ser != ser_support || broadcast != mce_broadcast || - first != firstbank || ext_num != nr_intel_ext_msrs) + first != firstbank || ext_num != nr_intel_ext_msrs || + lmce != lmce_support) dprintk(XENLOG_WARNING, "CPU%u has different MCA capability " - "(firstbank %d, %d ext MSRs%s%s%s)" + "(firstbank %d, extended MCE MSR %d%s%s%s%s)" " than BSP, may cause undetermined result!!!\n", smp_processor_id(), first, ext_num, CAP(broadcast, "BCAST"), CAP(ser, "SER"), - CAP(cmci, "CMCI")); + CAP(cmci, "CMCI"), + CAP(lmce, "LMCE")); #undef CAP } diff --git a/xen/arch/x86/cpu/mcheck/x86_mca.h b/xen/arch/x86/cpu/mcheck/x86_mca.h index de03f82..0f87bcf 100644 --- a/xen/arch/x86/cpu/mcheck/x86_mca.h +++ b/xen/arch/x86/cpu/mcheck/x86_mca.h @@ -36,6 +36,7 @@ #define MCG_TES_P (1ULL<<11) /* Intel specific */ #define MCG_EXT_CNT 16 /* Intel specific */ #define MCG_SER_P (1ULL<<24) /* Intel specific */ +#define MCG_LMCE_P (1ULL<<27) /* Intel specific */ /* Other bits are reserved */ /* Bitfield of the MSR_IA32_MCG_STATUS register */ @@ -46,6 +47,10 @@ /* Bits 3-63 are reserved on CPU not supporting LMCE */ /* Bits 4-63 are reserved on CPU supporting LMCE */ +/* Bitfield of MSR_IA32_MCG_EXT_CTL register (Intel Specific) */ +#define MCG_EXT_CTL_LMCE_EN (1ULL<<0) +/* Other bits are reserved */ + /* Bitfield of MSR_K8_MCi_STATUS registers */ /* MCA error code */ #define MCi_STATUS_MCA 0x000000000000ffffULL diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h index 771e750..756b23d 100644 --- a/xen/include/asm-x86/msr-index.h +++ b/xen/include/asm-x86/msr-index.h @@ -51,6 +51,7 @@ #define MSR_IA32_MCG_CAP 0x00000179 #define MSR_IA32_MCG_STATUS 0x0000017a #define MSR_IA32_MCG_CTL 0x0000017b +#define MSR_IA32_MCG_EXT_CTL 0x000004d0 #define MSR_IA32_PEBS_ENABLE 0x000003f1 #define MSR_IA32_DS_AREA 0x00000600 @@ -296,6 +297,7 @@ #define IA32_FEATURE_CONTROL_SENTER_PARAM_CTL 0x7f00 #define IA32_FEATURE_CONTROL_ENABLE_SENTER 0x8000 #define IA32_FEATURE_CONTROL_SGX_ENABLE 0x40000 +#define IA32_FEATURE_CONTROL_LMCE_ON 0x100000 #define MSR_IA32_TSC_ADJUST 0x0000003b