From patchwork Mon Feb 22 05:35:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Ruan X-Patchwork-Id: 8371921 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 8CB579F314 for ; Mon, 22 Feb 2016 05:41:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B8307203A9 for ; Mon, 22 Feb 2016 05:41:04 +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 8B90D203AB for ; Mon, 22 Feb 2016 05:41:03 +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 1aXjCA-0005vm-1K; Mon, 22 Feb 2016 05:38:06 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aXjC8-0005vQ-VY for xen-devel@lists.xen.org; Mon, 22 Feb 2016 05:38:05 +0000 Received: from [193.109.254.147] by server-6.bemta-14.messagelabs.com id DC/F7-16618-CBE9AC65; Mon, 22 Feb 2016 05:38:04 +0000 X-Env-Sender: shuai.ruan@linux.intel.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1456119478!25258078!4 X-Originating-IP: [134.134.136.65] 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 3577 invoked from network); 22 Feb 2016 05:38:03 -0000 Received: from mga03.intel.com (HELO mga03.intel.com) (134.134.136.65) by server-3.tower-27.messagelabs.com with SMTP; 22 Feb 2016 05:38:03 -0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 21 Feb 2016 21:38:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,483,1449561600"; d="scan'208";a="750713957" Received: from rs-vmm.bj.intel.com ([10.238.135.71]) by orsmga003.jf.intel.com with ESMTP; 21 Feb 2016 21:38:01 -0800 From: Shuai Ruan To: xen-devel@lists.xen.org Date: Mon, 22 Feb 2016 13:35:21 +0800 Message-Id: <1456119321-10384-4-git-send-email-shuai.ruan@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456119321-10384-1-git-send-email-shuai.ruan@linux.intel.com> References: <1456119321-10384-1-git-send-email-shuai.ruan@linux.intel.com> Cc: wei.liu2@citrix.com, Ian.Campbell@citrix.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, jbeulich@suse.com, keir@xen.org Subject: [Xen-devel] [PATCH 3/3] x86/xsaves: ebx may return wrong value using CPUID eax=0xdh, ecx =1 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: , MIME-Version: 1.0 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 Refer to SDM 13.4.3 Extended Region of an XSAVE Area. The value return by ecx[1] with cpuid function 0xdh and sub-fucntion i (i>1) indicates the alignment of the state component i when the compacted format of the extended region of an xsave area is used. So when hvm guest using CPUID eax=0xdh,ecx=1 to get the size of area used for compacted format, we need to take alignment into consideration. Signed-off-by: Shuai Ruan --- tools/libxc/xc_cpuid_x86.c | 10 ++++++++-- xen/arch/x86/hvm/hvm.c | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index c142595..d36f20b 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -285,6 +285,7 @@ static void intel_xc_cpuid_policy(xc_interface *xch, #define XSAVEC (1 << 1) #define XGETBV1 (1 << 2) #define XSAVES (1 << 3) +#define XSTATE_ALIGN64 (1 << 1) /* Configure extended state enumeration leaves (0x0000000D for xsave) */ static void xc_cpuid_config_xsave(xc_interface *xch, const struct cpuid_domain_info *info, @@ -333,8 +334,13 @@ static void xc_cpuid_config_xsave(xc_interface *xch, regs[0] = regs[1] = regs[2] = regs[3] = 0; break; } - /* Don't touch EAX, EBX. Also cleanup ECX and EDX */ - regs[2] = regs[3] = 0; + /* Don't touch EAX, EBX. + * ECX[1] indicates whether the state component + * needs alignment when compacted format is used. + */ + regs[2] &= XSTATE_ALIGN64; + /* Clean up EDX */ + regs[3] = 0; break; } } diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index fe382ce..4ccd392 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4703,7 +4703,19 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ ) if ( (v->arch.xcr0 | v->arch.hvm_vcpu.msr_xss) & (1ULL << sub_leaf) ) + { + domain_cpuid(d, input, sub_leaf, &_eax, &_ebx, + &_ecx, &_edx); + /* + * The value return by _ecx[1] indicates the + * alignment of the state component i when the + * compacted format of the extended region of + * an xsave area is used. + */ + if (_ecx & XSTATE_ALIGN64) + *ebx = ROUNDUP(*ebx, 64); *ebx += xstate_sizes[sub_leaf]; + } } else *ebx = *ecx = *edx = 0;