From patchwork Fri Jan 29 10:26:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 8162111 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B861A9F96D for ; Fri, 29 Jan 2016 10:29:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B252E2037E for ; Fri, 29 Jan 2016 10:29:39 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6CA2020253 for ; Fri, 29 Jan 2016 10:29:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aP6GT-0000Tm-U6; Fri, 29 Jan 2016 10:26:53 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aP6GS-0000TW-5V for xen-devel@lists.xenproject.org; Fri, 29 Jan 2016 10:26:52 +0000 Received: from [193.109.254.147] by server-1.bemta-14.messagelabs.com id BC/74-28791-B6E3BA65; Fri, 29 Jan 2016 10:26:51 +0000 X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1454063208!19698822!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48154 invoked from network); 29 Jan 2016 10:26:49 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-3.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 29 Jan 2016 10:26:49 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Fri, 29 Jan 2016 03:26:47 -0700 Message-Id: <56AB4C7902000078000CC53B@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Fri, 29 Jan 2016 03:26:49 -0700 From: "Jan Beulich" To: "xen-devel" References: <56AB4B6102000078000CC51B@prv-mh.provo.novell.com> In-Reply-To: <56AB4B6102000078000CC51B@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper , Keir Fraser , Harmandeep Kaur , Shuai Ruan Subject: [Xen-devel] [PATCH 1/4] x86/xstate: fix xcomp_bv initialization X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We must not clear the compaction bit when using XSAVES/XRSTORS. And we need to guarantee that xcomp_bv never has any bits clear which are set in xstate_bv (which requires partly undoing commit 83ae0bb226 ["x86/xsave: simplify xcomp_bv initialization"]). Split initialization of xcomp_bv from the other FPU/SSE/AVX related state setup in arch_set_info_guest() and hvm_load_cpu_ctxt(). Reported-by: Harmandeep Kaur Signed-off-by: Jan Beulich x86/xstate: fix xcomp_bv initialization We must not clear the compaction bit when using XSAVES/XRSTORS. And we need to guarantee that xcomp_bv never has any bits clear which are set in xstate_bv (which requires partly undoing commit 83ae0bb226 ["x86/xsave: simplify xcomp_bv initialization"]). Split initialization of xcomp_bv from the other FPU/SSE/AVX related state setup in arch_set_info_guest() and hvm_load_cpu_ctxt(). Reported-by: Harmandeep Kaur Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -923,15 +923,13 @@ int arch_set_info_guest( { memcpy(v->arch.fpu_ctxt, &c.nat->fpu_ctxt, sizeof(c.nat->fpu_ctxt)); if ( v->arch.xsave_area ) - { v->arch.xsave_area->xsave_hdr.xstate_bv = XSTATE_FP_SSE; - v->arch.xsave_area->xsave_hdr.xcomp_bv = - cpu_has_xsaves ? XSTATE_COMPACTION_ENABLED : 0; - } } else if ( v->arch.xsave_area ) - memset(&v->arch.xsave_area->xsave_hdr, 0, - sizeof(v->arch.xsave_area->xsave_hdr)); + { + v->arch.xsave_area->xsave_hdr.xstate_bv = 0; + v->arch.xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT; + } else { typeof(v->arch.xsave_area->fpu_sse) *fpu_sse = v->arch.fpu_ctxt; @@ -940,6 +938,14 @@ int arch_set_info_guest( fpu_sse->fcw = FCW_DEFAULT; fpu_sse->mxcsr = MXCSR_DEFAULT; } + if ( cpu_has_xsaves ) + { + ASSERT(v->arch.xsave_area); + v->arch.xsave_area->xsave_hdr.xcomp_bv = XSTATE_COMPACTION_ENABLED | + v->arch.xsave_area->xsave_hdr.xstate_bv; + } + else if ( v->arch.xsave_area ) + v->arch.xsave_area->xsave_hdr.xcomp_bv = 0; if ( !compat ) { --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1971,6 +1971,7 @@ static int hvm_load_cpu_ctxt(struct doma struct hvm_hw_cpu ctxt; struct segment_register seg; const char *errstr; + struct xsave_struct *xsave_area; /* Which vcpu is this? */ vcpuid = hvm_load_instance(h); @@ -2097,20 +2098,24 @@ static int hvm_load_cpu_ctxt(struct doma seg.attr.bytes = ctxt.ldtr_arbytes; hvm_set_segment_register(v, x86_seg_ldtr, &seg); + /* Cover xsave-absent save file restoration on xsave-capable host. */ + xsave_area = xsave_enabled(v) ? NULL : v->arch.xsave_area; + v->fpu_initialised = !!(ctxt.flags & XEN_X86_FPU_INITIALISED); if ( v->fpu_initialised ) { memcpy(v->arch.fpu_ctxt, ctxt.fpu_regs, sizeof(ctxt.fpu_regs)); - /* In case xsave-absent save file is restored on a xsave-capable host */ - if ( cpu_has_xsave && !xsave_enabled(v) ) - { - struct xsave_struct *xsave_area = v->arch.xsave_area; - + if ( xsave_area ) xsave_area->xsave_hdr.xstate_bv = XSTATE_FP_SSE; - xsave_area->xsave_hdr.xcomp_bv = - cpu_has_xsaves ? XSTATE_COMPACTION_ENABLED : 0; - } } + else if ( xsave_area ) + { + xsave_area->xsave_hdr.xstate_bv = 0; + xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT; + } + if ( cpu_has_xsaves && xsave_area ) + xsave_area->xsave_hdr.xcomp_bv = XSTATE_COMPACTION_ENABLED | + xsave_area->xsave_hdr.xstate_bv; v->arch.user_regs.eax = ctxt.rax; v->arch.user_regs.ebx = ctxt.rbx; @@ -5468,8 +5473,8 @@ void hvm_vcpu_reset_state(struct vcpu *v if ( v->arch.xsave_area ) { v->arch.xsave_area->xsave_hdr.xstate_bv = XSTATE_FP; - v->arch.xsave_area->xsave_hdr.xcomp_bv = - cpu_has_xsaves ? XSTATE_COMPACTION_ENABLED : 0; + v->arch.xsave_area->xsave_hdr.xcomp_bv = cpu_has_xsaves + ? XSTATE_COMPACTION_ENABLED | XSTATE_FP : 0; } v->arch.vgc_flags = VGCF_online; Reviewed-by: Andrew Cooper --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -923,15 +923,13 @@ int arch_set_info_guest( { memcpy(v->arch.fpu_ctxt, &c.nat->fpu_ctxt, sizeof(c.nat->fpu_ctxt)); if ( v->arch.xsave_area ) - { v->arch.xsave_area->xsave_hdr.xstate_bv = XSTATE_FP_SSE; - v->arch.xsave_area->xsave_hdr.xcomp_bv = - cpu_has_xsaves ? XSTATE_COMPACTION_ENABLED : 0; - } } else if ( v->arch.xsave_area ) - memset(&v->arch.xsave_area->xsave_hdr, 0, - sizeof(v->arch.xsave_area->xsave_hdr)); + { + v->arch.xsave_area->xsave_hdr.xstate_bv = 0; + v->arch.xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT; + } else { typeof(v->arch.xsave_area->fpu_sse) *fpu_sse = v->arch.fpu_ctxt; @@ -940,6 +938,14 @@ int arch_set_info_guest( fpu_sse->fcw = FCW_DEFAULT; fpu_sse->mxcsr = MXCSR_DEFAULT; } + if ( cpu_has_xsaves ) + { + ASSERT(v->arch.xsave_area); + v->arch.xsave_area->xsave_hdr.xcomp_bv = XSTATE_COMPACTION_ENABLED | + v->arch.xsave_area->xsave_hdr.xstate_bv; + } + else if ( v->arch.xsave_area ) + v->arch.xsave_area->xsave_hdr.xcomp_bv = 0; if ( !compat ) { --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1971,6 +1971,7 @@ static int hvm_load_cpu_ctxt(struct doma struct hvm_hw_cpu ctxt; struct segment_register seg; const char *errstr; + struct xsave_struct *xsave_area; /* Which vcpu is this? */ vcpuid = hvm_load_instance(h); @@ -2097,20 +2098,24 @@ static int hvm_load_cpu_ctxt(struct doma seg.attr.bytes = ctxt.ldtr_arbytes; hvm_set_segment_register(v, x86_seg_ldtr, &seg); + /* Cover xsave-absent save file restoration on xsave-capable host. */ + xsave_area = xsave_enabled(v) ? NULL : v->arch.xsave_area; + v->fpu_initialised = !!(ctxt.flags & XEN_X86_FPU_INITIALISED); if ( v->fpu_initialised ) { memcpy(v->arch.fpu_ctxt, ctxt.fpu_regs, sizeof(ctxt.fpu_regs)); - /* In case xsave-absent save file is restored on a xsave-capable host */ - if ( cpu_has_xsave && !xsave_enabled(v) ) - { - struct xsave_struct *xsave_area = v->arch.xsave_area; - + if ( xsave_area ) xsave_area->xsave_hdr.xstate_bv = XSTATE_FP_SSE; - xsave_area->xsave_hdr.xcomp_bv = - cpu_has_xsaves ? XSTATE_COMPACTION_ENABLED : 0; - } } + else if ( xsave_area ) + { + xsave_area->xsave_hdr.xstate_bv = 0; + xsave_area->fpu_sse.mxcsr = MXCSR_DEFAULT; + } + if ( cpu_has_xsaves && xsave_area ) + xsave_area->xsave_hdr.xcomp_bv = XSTATE_COMPACTION_ENABLED | + xsave_area->xsave_hdr.xstate_bv; v->arch.user_regs.eax = ctxt.rax; v->arch.user_regs.ebx = ctxt.rbx; @@ -5468,8 +5473,8 @@ void hvm_vcpu_reset_state(struct vcpu *v if ( v->arch.xsave_area ) { v->arch.xsave_area->xsave_hdr.xstate_bv = XSTATE_FP; - v->arch.xsave_area->xsave_hdr.xcomp_bv = - cpu_has_xsaves ? XSTATE_COMPACTION_ENABLED : 0; + v->arch.xsave_area->xsave_hdr.xcomp_bv = cpu_has_xsaves + ? XSTATE_COMPACTION_ENABLED | XSTATE_FP : 0; } v->arch.vgc_flags = VGCF_online;