From patchwork Mon Jun 26 09:16:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9808917 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 A107C60209 for ; Mon, 26 Jun 2017 09:19:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA7F228161 for ; Mon, 26 Jun 2017 09:19:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EAFD28487; Mon, 26 Jun 2017 09:19:44 +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 045E228161 for ; Mon, 26 Jun 2017 09:19:44 +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 1dPQ8l-0002kV-Ns; Mon, 26 Jun 2017 09:17:03 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPQ8k-0002kJ-DL for xen-devel@lists.xen.org; Mon, 26 Jun 2017 09:17:02 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 2E/60-02956-D01D0595; Mon, 26 Jun 2017 09:17:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsVywNwkVpf3YkC kwZ7Z0hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bzB/oFS1UqutZPY2lg7JXqYuTiEBKYxihx /8Aypi5GTg4JAV6JI8tmsELY/hJbntxghyjqZZQ4tecGI0iCTUBfYsXjg2BFIgLSEtc+XwaLM wtUS0ycPgfMFhYIkDjVewuomYODRUBV4tFnU5Awr4CtRMP7j8wQ8+UldrVdBBvDKWAn8eLvAX YQWwioZsKvFYwTGHkXMDKsYtQoTi0qSy3SNbTQSyrKTM8oyU3MzNE1NDDTy00tLk5MT81JTCr WS87P3cQIDAYGINjBeHNjwCFGSQ4mJVHeRn//SCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvOfO B0QKCRalpqdWpGXmAMMSJi3BwaMkwnvhLFCat7ggMbc4Mx0idYpRUUqcdxZInwBIIqM0D64NF guXGGWlhHkZgQ4R4ilILcrNLEGVf8UozsGoJMzbDjKFJzOvBG76K6DFTECLWeaBLS5JREhJNT BKL2n5+M+S/2AA/362tS90l5l97fo6Mbr4zCknF8HW/ULZfaZ7VMMMpHS3bBQ+ocN//OEy/sM r5cXMrM1Sn1qtnmU6lZ2Tl7F1H7/MqRf5AtXp/d7TFbT2ByyufRItYP3EbZ6/XPakxa+e+l9e cHR3fOTfqPIppY1LqlOk7k9KPfL6Qrvbhl9KLMUZiYZazEXFiQDBqkiJgAIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-9.tower-21.messagelabs.com!1498468609!75505562!7 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 401 invoked from network); 26 Jun 2017 09:17:00 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-9.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Jun 2017 09:17:00 -0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2017 02:17:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,395,1493708400"; d="scan'208";a="985229990" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by orsmga003.jf.intel.com with ESMTP; 26 Jun 2017 02:16:59 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 26 Jun 2017 17:16:21 +0800 Message-Id: <20170626091625.19655-8-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170626091625.19655-1-haozhong.zhang@intel.com> References: <20170626091625.19655-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH v4 07/11] x86/vmce: enable injecting LMCE to guest 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 Inject LMCE to guest if the host MCE is LMCE and the affected vcpu is known. Otherwise, broadcast MCE to all vcpus on Intel host. Signed-off-by: Haozhong Zhang Reviewed-by: Jan Beulich --- Cc: Jan Beulich Cc: Andrew Cooper Changes in v4: (Take Jan's R-b with following changes.) * Change type of mc_vcpuid in mc_memerr_dhandler() from uint16_t to unsigned int. * Add a missing space in ASSERT() in fill_vmsr_data(). --- xen/arch/x86/cpu/mcheck/mcaction.c | 23 ++++++++++++++++------- xen/arch/x86/cpu/mcheck/vmce.c | 11 ++++++++++- xen/arch/x86/cpu/mcheck/vmce.h | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/cpu/mcheck/mcaction.c b/xen/arch/x86/cpu/mcheck/mcaction.c index ca17d22bd8..f959bed2cb 100644 --- a/xen/arch/x86/cpu/mcheck/mcaction.c +++ b/xen/arch/x86/cpu/mcheck/mcaction.c @@ -44,6 +44,7 @@ mc_memerr_dhandler(struct mca_binfo *binfo, unsigned long mfn, gfn; uint32_t status; int vmce_vcpuid; + unsigned int mc_vcpuid; if (!mc_check_addr(bank->mc_status, bank->mc_misc, MC_ADDR_PHYSICAL)) { dprintk(XENLOG_WARNING, @@ -88,18 +89,26 @@ mc_memerr_dhandler(struct mca_binfo *binfo, goto vmce_failed; } - if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL || - global->mc_vcpuid == XEN_MC_VCPUID_INVALID) + mc_vcpuid = global->mc_vcpuid; + if (mc_vcpuid == XEN_MC_VCPUID_INVALID || + /* + * Because MC# may happen asynchronously with the actual + * operation that triggers the error, the domain ID as + * well as the vCPU ID collected in 'global' at MC# are + * not always precise. In that case, fallback to broadcast. + */ + global->mc_domid != bank->mc_domid || + (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && + (!(global->mc_gstatus & MCG_STATUS_LMCE) || + !(d->vcpu[mc_vcpuid]->arch.vmce.mcg_ext_ctl & + MCG_EXT_CTL_LMCE_EN)))) vmce_vcpuid = VMCE_INJECT_BROADCAST; else - vmce_vcpuid = global->mc_vcpuid; + vmce_vcpuid = mc_vcpuid; bank->mc_addr = gfn << PAGE_SHIFT | (bank->mc_addr & (PAGE_SIZE -1 )); - /* TODO: support injecting LMCE */ - if (fill_vmsr_data(bank, d, - global->mc_gstatus & ~MCG_STATUS_LMCE, - vmce_vcpuid == VMCE_INJECT_BROADCAST)) + if (fill_vmsr_data(bank, d, global->mc_gstatus, vmce_vcpuid)) { mce_printk(MCE_QUIET, "Fill vMCE# data for DOM%d " "failed\n", bank->mc_domid); diff --git a/xen/arch/x86/cpu/mcheck/vmce.c b/xen/arch/x86/cpu/mcheck/vmce.c index 210670638f..9830835c5a 100644 --- a/xen/arch/x86/cpu/mcheck/vmce.c +++ b/xen/arch/x86/cpu/mcheck/vmce.c @@ -464,14 +464,23 @@ static int vcpu_fill_mc_msrs(struct vcpu *v, uint64_t mcg_status, } int fill_vmsr_data(struct mcinfo_bank *mc_bank, struct domain *d, - uint64_t gstatus, bool broadcast) + uint64_t gstatus, int vmce_vcpuid) { struct vcpu *v = d->vcpu[0]; + bool broadcast = (vmce_vcpuid == VMCE_INJECT_BROADCAST); int ret, err; if ( mc_bank->mc_domid == DOMID_INVALID ) return -EINVAL; + if ( broadcast ) + gstatus &= ~MCG_STATUS_LMCE; + else if ( gstatus & MCG_STATUS_LMCE ) + { + ASSERT(vmce_vcpuid >= 0 && vmce_vcpuid < d->max_vcpus); + v = d->vcpu[vmce_vcpuid]; + } + /* * vMCE with the actual error information is injected to vCPU0, * and, if broadcast is required, we choose to inject less severe diff --git a/xen/arch/x86/cpu/mcheck/vmce.h b/xen/arch/x86/cpu/mcheck/vmce.h index 74f6381460..2797e00275 100644 --- a/xen/arch/x86/cpu/mcheck/vmce.h +++ b/xen/arch/x86/cpu/mcheck/vmce.h @@ -17,7 +17,7 @@ int vmce_amd_rdmsr(const struct vcpu *, uint32_t msr, uint64_t *val); int vmce_amd_wrmsr(struct vcpu *, uint32_t msr, uint64_t val); int fill_vmsr_data(struct mcinfo_bank *mc_bank, struct domain *d, - uint64_t gstatus, bool broadcast); + uint64_t gstatus, int vmce_vcpuid); #define VMCE_INJECT_BROADCAST (-1) int inject_vmce(struct domain *d, int vcpu);