From: Shuai Ruan <shuai.ruan@linux.intel.com>
To: xen-devel@lists.xen.org
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: [PATCH 3/3] x86/xsaves: ebx may return wrong value using CPUID eax=0xdh, ecx =1
Date: Mon, 22 Feb 2016 13:35:21 +0800 [thread overview]
Message-ID: <1456119321-10384-4-git-send-email-shuai.ruan@linux.intel.com> (raw)
In-Reply-To: <1456119321-10384-1-git-send-email-shuai.ruan@linux.intel.com>
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 <shuai.ruan@linux.intel.com>
---
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;
--
1.9.1
next prev parent reply other threads:[~2016-02-22 5:35 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-22 5:35 [PATCH 0/3] x86/xsaves: bugs fix Shuai Ruan
2016-02-22 5:35 ` [PATCH 1/3] x86/xsaves: caculate the xstate_comp_offsets base on xcomp_bv Shuai Ruan
2016-02-22 14:48 ` Jan Beulich
2016-02-22 5:35 ` [PATCH 2/3] x86/xsaves: fix overwriting between non-lazy/lazy xsave[sc] Shuai Ruan
2016-02-22 17:08 ` Jan Beulich
2016-02-24 7:05 ` Shuai Ruan
[not found] ` <20160224070521.GB19785@shuai.ruan@linux.intel.com>
2016-02-24 9:16 ` Jan Beulich
2016-02-26 7:41 ` Shuai Ruan
[not found] ` <20160226074133.GA3825@shuai.ruan@linux.intel.com>
2016-02-26 8:42 ` Jan Beulich
2016-02-29 9:06 ` Shuai Ruan
[not found] ` <20160229090637.GB3825@shuai.ruan@linux.intel.com>
2016-02-29 9:33 ` Jan Beulich
2016-03-02 10:31 ` Shuai Ruan
2016-02-22 5:35 ` Shuai Ruan [this message]
2016-02-22 17:18 ` [PATCH 3/3] x86/xsaves: ebx may return wrong value using CPUID eax=0xdh, ecx =1 Jan Beulich
2016-02-24 5:42 ` Shuai Ruan
2016-02-24 6:51 ` Shuai Ruan
[not found] ` <20160224054209.GA24976@shuai.ruan@linux.intel.com>
2016-02-24 9:18 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456119321-10384-4-git-send-email-shuai.ruan@linux.intel.com \
--to=shuai.ruan@linux.intel.com \
--cc=Ian.Campbell@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=keir@xen.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).