From patchwork Mon Dec 21 01:50:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Ruan X-Patchwork-Id: 7892961 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 609A79F349 for ; Mon, 21 Dec 2015 01:56:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7ABEE203AD for ; Mon, 21 Dec 2015 01:56:03 +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 7C77A20397 for ; Mon, 21 Dec 2015 01:56:02 +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 1aApe3-0005oR-OG; Mon, 21 Dec 2015 01:52:15 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aApe2-0005oM-Ji for xen-devel@lists.xen.org; Mon, 21 Dec 2015 01:52:14 +0000 Received: from [85.158.137.68] by server-4.bemta-3.messagelabs.com id 7F/1E-09570-D4B57765; Mon, 21 Dec 2015 01:52:13 +0000 X-Env-Sender: shuai.ruan@linux.intel.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1450662730!953117!1 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6343 invoked from network); 21 Dec 2015 01:52:11 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-9.tower-31.messagelabs.com with SMTP; 21 Dec 2015 01:52:11 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 20 Dec 2015 17:52:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,457,1444719600"; d="scan'208";a="877908681" Received: from rs-vmm.bj.intel.com ([10.238.135.211]) by fmsmga002.fm.intel.com with ESMTP; 20 Dec 2015 17:52:08 -0800 From: Shuai Ruan To: xen-devel@lists.xen.org Date: Mon, 21 Dec 2015 09:50:37 +0800 Message-Id: <1450662637-5062-1-git-send-email-shuai.ruan@linux.intel.com> X-Mailer: git-send-email 1.9.1 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] 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. 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 8882c01..480bd83 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_ALIGN (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_ALIGN; + /* Clean up EDX */ + regs[3] = 0; break; } } diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 08cef1f..c4ac677 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4619,7 +4619,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 & 0x2) + *ebx = ROUNDUP(*ebx, 64); *ebx += xstate_sizes[sub_leaf]; + } } else *ebx = *ecx = *edx = 0;