aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei Huang <wei.huang2@amd.com>2011-05-09 11:38:55 +0100
committerWei Huang <wei.huang2@amd.com>2011-05-09 11:38:55 +0100
commit0217c28adbb1656e72ce68239eb6092fdc7cde0c (patch)
tree7ca88d8c8022cdcbeeae5c42a599fe1612400779
parent3eb0faa4f80653d56e0e74d68872f6d73de23937 (diff)
downloadxen-0217c28adbb1656e72ce68239eb6092fdc7cde0c.tar.gz
xen-0217c28adbb1656e72ce68239eb6092fdc7cde0c.tar.bz2
xen-0217c28adbb1656e72ce68239eb6092fdc7cde0c.zip
x86/fpu: add mask parameter to xsave and xrstor
Xen currently sets mask bits of xsave() and xrstor() to all 1's. This patch adds a mask option to xsave() and xrstor(). Signed-off-by: Wei Huang <wei.huang2@amd.com>
-rw-r--r--xen/arch/x86/i387.c12
-rw-r--r--xen/arch/x86/xstate.c15
-rw-r--r--xen/include/asm-x86/xstate.h8
3 files changed, 22 insertions, 13 deletions
diff --git a/xen/arch/x86/i387.c b/xen/arch/x86/i387.c
index fc0c1c45f4..9350f734d5 100644
--- a/xen/arch/x86/i387.c
+++ b/xen/arch/x86/i387.c
@@ -35,14 +35,14 @@ static void fpu_init(void)
/* FPU Restore Functions */
/*******************************/
/* Restore x87 extended state */
-static inline void fpu_xrstor(struct vcpu *v)
+static inline void fpu_xrstor(struct vcpu *v, uint64_t mask)
{
/*
* XCR0 normally represents what guest OS set. In case of Xen itself,
* we set all supported feature mask before doing save/restore.
*/
set_xcr0(v->arch.xcr0_accum);
- xrstor(v);
+ xrstor(v, mask);
set_xcr0(v->arch.xcr0);
}
@@ -98,13 +98,13 @@ static inline void fpu_frstor(struct vcpu *v)
/* FPU Save Functions */
/*******************************/
/* Save x87 extended state */
-static inline void fpu_xsave(struct vcpu *v)
+static inline void fpu_xsave(struct vcpu *v, uint64_t mask)
{
/* XCR0 normally represents what guest OS set. In case of Xen itself,
* we set all accumulated feature mask before doing save/restore.
*/
set_xcr0(v->arch.xcr0_accum);
- xsave(v);
+ xsave(v, mask);
set_xcr0(v->arch.xcr0);
}
@@ -174,7 +174,7 @@ void vcpu_restore_fpu(struct vcpu *v)
return;
if ( xsave_enabled(v) )
- fpu_xrstor(v);
+ fpu_xrstor(v, XSTATE_ALL);
else if ( v->fpu_initialised )
{
if ( cpu_has_fxsr )
@@ -204,7 +204,7 @@ void vcpu_save_fpu(struct vcpu *v)
clts();
if ( xsave_enabled(v) )
- fpu_xsave(v);
+ fpu_xsave(v, XSTATE_ALL);
else if ( cpu_has_fxsr )
fpu_fxsave(v);
else
diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c
index e358fd7bbd..fdb80d37ab 100644
--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -51,32 +51,37 @@ inline uint64_t get_xcr0(void)
return this_cpu(xcr0);
}
-void xsave(struct vcpu *v)
+void xsave(struct vcpu *v, uint64_t mask)
{
struct xsave_struct *ptr = v->arch.xsave_area;
+ uint32_t hmask = mask >> 32;
+ uint32_t lmask = mask;
if ( cpu_has_xsaveopt )
asm volatile (
".byte " REX_PREFIX "0x0f,0xae,0x37"
:
- : "a" (-1), "d" (-1), "D"(ptr)
+ : "a" (lmask), "d" (hmask), "D"(ptr)
: "memory" );
else
asm volatile (
".byte " REX_PREFIX "0x0f,0xae,0x27"
:
- : "a" (-1), "d" (-1), "D"(ptr)
+ : "a" (lmask), "d" (hmask), "D"(ptr)
: "memory" );
}
-void xrstor(struct vcpu *v)
+void xrstor(struct vcpu *v, uint64_t mask)
{
+ uint32_t hmask = mask >> 32;
+ uint32_t lmask = mask;
+
struct xsave_struct *ptr = v->arch.xsave_area;
asm volatile (
".byte " REX_PREFIX "0x0f,0xae,0x2f"
:
- : "m" (*ptr), "a" (-1), "d" (-1), "D"(ptr) );
+ : "m" (*ptr), "a" (lmask), "d" (hmask), "D"(ptr) );
}
bool_t xsave_enabled(const struct vcpu *v)
diff --git a/xen/include/asm-x86/xstate.h b/xen/include/asm-x86/xstate.h
index a0677173fd..2ff495b226 100644
--- a/xen/include/asm-x86/xstate.h
+++ b/xen/include/asm-x86/xstate.h
@@ -27,6 +27,10 @@
#define XSTATE_FP_SSE (XSTATE_FP | XSTATE_SSE)
#define XCNTXT_MASK (XSTATE_FP | XSTATE_SSE | XSTATE_YMM | XSTATE_LWP)
+#define XSTATE_ALL (~0)
+#define XSTATE_NONLAZY (XSTATE_LWP)
+#define XSTATE_LAZY (XSTATE_ALL & ~XSTATE_NONLAZY)
+
#ifdef CONFIG_X86_64
#define REX_PREFIX "0x48, "
#else
@@ -56,8 +60,8 @@ struct xsave_struct
/* extended state operations */
void set_xcr0(u64 xfeatures);
uint64_t get_xcr0(void);
-void xsave(struct vcpu *v);
-void xrstor(struct vcpu *v);
+void xsave(struct vcpu *v, uint64_t mask);
+void xrstor(struct vcpu *v, uint64_t mask);
bool_t xsave_enabled(const struct vcpu *v);
/* extended state init and cleanup functions */