From patchwork Mon Feb 27 05:09:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9592699 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 C856160578 for ; Mon, 27 Feb 2017 05:12:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA37B27FB1 for ; Mon, 27 Feb 2017 05:12:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF26228375; Mon, 27 Feb 2017 05:12:37 +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 347D427FB1 for ; Mon, 27 Feb 2017 05:12:37 +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 1ciDZR-00068R-FD; Mon, 27 Feb 2017 05:10:01 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ciDZQ-00066b-9x for xen-devel@lists.xen.org; Mon, 27 Feb 2017 05:10:00 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id 38/67-04991-7A4B3B85; Mon, 27 Feb 2017 05:09:59 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsXS1taRortsy+Y Ig31dFhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8ajlgXMBXeMK55t/sfYwPhVpYuRk0NIoFLi cvchNhBbQoBX4siyGawQdoDEjTdP2LsYuYBqehklZu9+wgKSYBPQl1jx+CBYkYiAtMS1z5cZQ YqYBRYySuz81Q6U4OAQFoiUWNbABFLDIqAqcfnoZnYQm1fAVuLE+VtQC+QlLlw9BTaTU8BO4t aZVmaQViGgmtXfRSYw8i5gZFjFqFGcWlSWWqRrZKKXVJSZnlGSm5iZo2toYKyXm1pcnJiempO YVKyXnJ+7iREYDPUMDIw7GF8d9zvEKMnBpCTKu8h4Y4QQX1J+SmVGYnFGfFFpTmrxIUYZDg4l Cd7+zZsjhASLUtNTK9Iyc4BhCZOW4OBREuHdvwkozVtckJhbnJkOkTrFqMtxq2HPGyYhlrz8v FQpcd5qkBkCIEUZpXlwI2AxcolRVkqYl5GBgUGIpyC1KDezBFX+FaM4B6OSMG8FyBSezLwSuE 2vgI5gAjpiNsj9vMUliQgpqQbG4qKtvGKvt63aYbtVq09JYU1K/mf3PMf3hS6Oz5YuClR8Hbj A807VFREeJ855Mn2fuj9lzbef9f6CEhvTZbsz2RZMBr4SmisCcoumnntkp9jlszs603Pz/YDH T1WsxRv2Mv2fqlP40IN182LvD8uSZJZ/uc5Tvv3lC/5d7s9XdwkHNbCssFZXYinOSDTUYi4qT gQAhPC65YwCAAA= X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1488172192!29448017!4 X-Originating-IP: [134.134.136.100] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24785 invoked from network); 27 Feb 2017 05:09:58 -0000 Received: from mga07.intel.com (HELO mga07.intel.com) (134.134.136.100) by server-4.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 27 Feb 2017 05:09:58 -0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP; 26 Feb 2017 21:09:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.35,212,1484035200"; d="scan'208"; a="1115945473" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.133]) by fmsmga001.fm.intel.com with ESMTP; 26 Feb 2017 21:09:56 -0800 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 27 Feb 2017 13:09:09 +0800 Message-Id: <20170227050912.28824-5-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170227050912.28824-1-haozhong.zhang@intel.com> References: <20170227050912.28824-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Christoph Egger , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH v2 4/7] x86/vmce: fill MSR_IA32_MCG_STATUS on all vcpus in broadcast case 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 The current implementation only fills MC MSRs on vcpu0 and leaves MC MSRs on other vcpus empty in the broadcast case. When guest reads 0 from MSR_IA32_MCG_STATUS on vcpuN (N > 0), it may think it's not possible to recover the execution on that vcpu and then get panic, although MSR_IA32_MCG_STATUS filled on vcpu0 may imply the injected vMCE is actually recoverable. To avoid such unnecessary guest panic, set MSR_IA32_MCG_STATUS on vcpuN (N > 0) to MCG_STATUS_MCIP|MCG_STATUS_RIPV. In addition, fill_vmsr_data(mc_bank, ...) is changed to return -EINVAL rather than 0, if an invalid domain ID is contained in mc_bank. Signed-off-by: Haozhong Zhang Reviewed-by: Jan Beulich --- Cc: Christoph Egger Cc: Jan Beulich Cc: Andrew Cooper --- xen/arch/x86/cpu/mcheck/mcaction.c | 16 ++++----- xen/arch/x86/cpu/mcheck/vmce.c | 74 ++++++++++++++++++++++++++------------ xen/arch/x86/cpu/mcheck/vmce.h | 2 +- 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/xen/arch/x86/cpu/mcheck/mcaction.c b/xen/arch/x86/cpu/mcheck/mcaction.c index 32056f2..dab9eac 100644 --- a/xen/arch/x86/cpu/mcheck/mcaction.c +++ b/xen/arch/x86/cpu/mcheck/mcaction.c @@ -88,22 +88,22 @@ 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) + vmce_vcpuid = VMCE_INJECT_BROADCAST; + else + vmce_vcpuid = global->mc_vcpuid; + bank->mc_addr = gfn << PAGE_SHIFT | (bank->mc_addr & (PAGE_SIZE -1 )); - if ( fill_vmsr_data(bank, d, - global->mc_gstatus) == -1 ) + if (fill_vmsr_data(bank, d, global->mc_gstatus, + vmce_vcpuid == VMCE_INJECT_BROADCAST)) { mce_printk(MCE_QUIET, "Fill vMCE# data for DOM%d " "failed\n", bank->mc_domid); goto vmce_failed; } - if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL || - global->mc_vcpuid == XEN_MC_VCPUID_INVALID) - vmce_vcpuid = VMCE_INJECT_BROADCAST; - else - vmce_vcpuid = global->mc_vcpuid; - /* We will inject vMCE to DOMU*/ if ( inject_vmce(d, vmce_vcpuid) < 0 ) { diff --git a/xen/arch/x86/cpu/mcheck/vmce.c b/xen/arch/x86/cpu/mcheck/vmce.c index 13b692c..2caccae 100644 --- a/xen/arch/x86/cpu/mcheck/vmce.c +++ b/xen/arch/x86/cpu/mcheck/vmce.c @@ -381,38 +381,66 @@ int inject_vmce(struct domain *d, int vcpu) return ret; } -int fill_vmsr_data(struct mcinfo_bank *mc_bank, struct domain *d, - uint64_t gstatus) +static int vcpu_fill_mc_msrs(struct vcpu *v, uint64_t mcg_status, + uint64_t mci_status, uint64_t mci_addr, + uint64_t mci_misc) { - struct vcpu *v = d->vcpu[0]; - - if ( mc_bank->mc_domid != DOMID_INVALID ) + if ( v->arch.vmce.mcg_status & MCG_STATUS_MCIP ) { - if ( v->arch.vmce.mcg_status & MCG_STATUS_MCIP ) - { - mce_printk(MCE_QUIET, "MCE: guest has not handled previous" - " vMCE yet!\n"); - return -1; - } + mce_printk(MCE_QUIET, "MCE: %pv: guest has not handled previous" + " vMCE yet!\n", v); + return -EBUSY; + } - spin_lock(&v->arch.vmce.lock); + spin_lock(&v->arch.vmce.lock); - v->arch.vmce.mcg_status = gstatus; - /* - * 1. Skip bank 0 to avoid 'bank 0 quirk' of old processors - * 2. Filter MCi_STATUS MSCOD model specific error code to guest - */ - v->arch.vmce.bank[1].mci_status = mc_bank->mc_status & - MCi_STATUS_MSCOD_MASK; - v->arch.vmce.bank[1].mci_addr = mc_bank->mc_addr; - v->arch.vmce.bank[1].mci_misc = mc_bank->mc_misc; + v->arch.vmce.mcg_status = mcg_status; + /* + * 1. Skip bank 0 to avoid 'bank 0 quirk' of old processors + * 2. Filter MCi_STATUS MSCOD model specific error code to guest + */ + v->arch.vmce.bank[1].mci_status = mci_status & MCi_STATUS_MSCOD_MASK; + v->arch.vmce.bank[1].mci_addr = mci_addr; + v->arch.vmce.bank[1].mci_misc = mci_misc; - spin_unlock(&v->arch.vmce.lock); - } + spin_unlock(&v->arch.vmce.lock); return 0; } +int fill_vmsr_data(struct mcinfo_bank *mc_bank, struct domain *d, + uint64_t gstatus, bool broadcast) +{ + struct vcpu *v = d->vcpu[0]; + int ret, err; + + if ( mc_bank->mc_domid == DOMID_INVALID ) + return -EINVAL; + + /* + * vMCE with the actual error information is injected to vCPU0, + * and, if broadcast is required, we choose to inject less severe + * vMCEs to other vCPUs. Thus guest can always get the severest + * error (i.e. the actual one) on vCPU0. If guest can recover from + * the severest error on vCPU0, the less severe errors on other + * vCPUs will not prevent guest from recovering on those vCPUs. + */ + ret = vcpu_fill_mc_msrs(v, gstatus, mc_bank->mc_status, + mc_bank->mc_addr, mc_bank->mc_misc); + if ( broadcast ) + for_each_vcpu ( d, v ) + { + if ( !v->vcpu_id ) + continue; + err = vcpu_fill_mc_msrs(v, MCG_STATUS_MCIP | MCG_STATUS_RIPV, + 0, 0, 0); + if ( err ) + ret = err; + } + + return ret; +} + /* It's said some ram is setup as mmio_direct for UC cache attribute */ #define P2M_UNMAP_TYPES (p2m_to_mask(p2m_ram_rw) \ | p2m_to_mask(p2m_ram_logdirty) \ diff --git a/xen/arch/x86/cpu/mcheck/vmce.h b/xen/arch/x86/cpu/mcheck/vmce.h index 163ce3c..74f6381 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); + uint64_t gstatus, bool broadcast); #define VMCE_INJECT_BROADCAST (-1) int inject_vmce(struct domain *d, int vcpu);