From patchwork Mon Jul 3 03:46:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9821901 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 485306035F for ; Mon, 3 Jul 2017 03:49:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31BB9283C7 for ; Mon, 3 Jul 2017 03:49:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2693D2851E; Mon, 3 Jul 2017 03:49:55 +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 B2D95283C7 for ; Mon, 3 Jul 2017 03:49:54 +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 1dRsKq-0006Z7-Fg; Mon, 03 Jul 2017 03:47:40 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dRsKo-0006XC-Mn for xen-devel@lists.xen.org; Mon, 03 Jul 2017 03:47:38 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id 95/01-01731-95EB9595; Mon, 03 Jul 2017 03:47:37 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsVywNykWDdyX2S kwbHn/BZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bHPa1MBXeVKo4tmM3awPhKoouRk0NIYDqj xPsuVRBbQoBX4siyGaxdjBxAdoBEVwNPFyMXUEkvo8ST2w/ZQWrYBPQlVjw+yApiiwhIS1z7f JkRxGYWqJaYOH0OmC0M1Nu4chIziM0ioCpxo+8BE4jNK2Aj8WzNKSaIXfISu9ougs3hFLCVuD l1JxPEPTYSeyb9Y5zAyLuAkWEVo0ZxalFZapGukYVeUlFmekZJbmJmjq6hgalebmpxcWJ6ak5 iUrFecn7uJkZgMNQzMDDuYOxb5XeIUZKDSUmUd+W10EghvqT8lMqMxOKM+KLSnNTiQ4wyHBxK Ery8eyMjhQSLUtNTK9Iyc4BhCZOW4OBREuG95gOU5i0uSMwtzkyHSJ1i1OV4NeH/NyYhlrz8v FQpcV4xkBkCIEUZpXlwI2AxcolRVkqYl5GBgUGIpyC1KDezBFX+FaM4B6OSMK/OHqApPJl5JX CbXgEdwQR0RENPBMgRJYkIKakGxlmcZidD5r6ZfPmnzsP08xO7V0S94DCYvvb6hM4jNyr18yz 6bI4s+so9QVhLXyK53fhBge3Z7h920zwflxzVWnIutOfQV45O1m+aWv7PHPr7JovunPH63iZL vkLnlsrT2aqR9Qae3y4//ll4KIr9x5y4glNH0x5fkDr6n+XJxhfTxPfKvXu1jF2JpTgj0VCLu ag4EQC2E0nwjAIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1499053645!100869672!7 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26733 invoked from network); 3 Jul 2017 03:47:36 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-6.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 3 Jul 2017 03:47:36 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jul 2017 20:47:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,301,1496127600"; d="scan'208"; a="1189835662" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 02 Jul 2017 20:47:35 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 3 Jul 2017 11:46:22 +0800 Message-Id: <20170703034626.9429-8-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170703034626.9429-1-haozhong.zhang@intel.com> References: <20170703034626.9429-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH v5 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 --- 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);