From: "Jan Beulich" Subject: [PATCH] x86/xsave: provide guests with finit-like environment Date: Thu, 17 Nov 2011 14:43:25 +0000 Message-ID: <4EC52B9D020000780006199E@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part634CE59D.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" Cc: Charles Arnold , Bruce Rogers List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part634CE59D.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Without the use of xsave, guests get their initial floating point environment set up with finit. At least NetWare actually depends on this (in particular on all exceptions being masked), so to be consistent set the same environment also when using xsave. This is also in line with all SSE exceptions getting masked initially. To avoid further fragile casts in xstate_alloc_save_area() the patch also changes xsave_struct's fpu_see member to have actually usable fields. The patch was tested in its technically identical, but modified-file- wise different 4.1.2 version. Signed-off-by: Jan Beulich Tested-by: Charles Arnold --- a/xen/arch/x86/i387.c +++ b/xen/arch/x86/i387.c @@ -17,7 +17,6 @@ #include #include =20 -#define MXCSR_DEFAULT 0x1f80 static void fpu_init(void) { unsigned long val; --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -97,7 +97,7 @@ bool_t xsave_enabled(const struct vcpu * =20 int xstate_alloc_save_area(struct vcpu *v) { - void *save_area; + struct xsave_struct *save_area; =20 if ( !cpu_has_xsave || is_idle_vcpu(v) ) return 0; @@ -109,8 +109,9 @@ int xstate_alloc_save_area(struct vcpu * if ( save_area =3D=3D NULL ) return -ENOMEM; =20 - ((u32 *)save_area)[6] =3D 0x1f80; /* MXCSR */ - *(uint64_t *)(save_area + 512) =3D XSTATE_FP_SSE; /* XSETBV */ + save_area->fpu_sse.fcw =3D FCW_DEFAULT; + save_area->fpu_sse.mxcsr =3D MXCSR_DEFAULT; + save_area->xsave_hdr.xstate_bv =3D XSTATE_FP_SSE; =20 v->arch.xsave_area =3D save_area; v->arch.xcr0 =3D XSTATE_FP_SSE; --- a/xen/include/asm-x86/xstate.h +++ b/xen/include/asm-x86/xstate.h @@ -11,6 +11,9 @@ #include #include =20 +#define FCW_DEFAULT 0x037f +#define MXCSR_DEFAULT 0x1f80 + #define XSTATE_CPUID 0x0000000d #define XSTATE_FEATURE_XSAVEOPT (1 << 0) /* sub-leaf 1, eax[bit 0] = */ =20 @@ -46,7 +49,29 @@ extern u64 xfeature_mask; /* extended state save area */ struct xsave_struct { - struct { char x[512]; } fpu_sse; /* FPU/MMX, SSE */ + union { /* FPU/MMX, SSE */ + char x[512]; + struct { + uint16_t fcw; + uint16_t fsw; + uint8_t ftw; + uint8_t rsvd1; + uint16_t fop; + union { +#ifdef __x86_64__ + uint64_t addr; +#endif + struct { + uint32_t offs; + uint16_t sel; + uint16_t rsvd; + }; + } fip, fdp; + uint32_t mxcsr; + uint32_t mxcsr_mask; + /* data registers follow here */ + }; + } fpu_sse; =20 struct { u64 xstate_bv; --=__Part634CE59D.0__= Content-Type: text/plain; name="x86-xstate-init.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-xstate-init.patch" x86/xsave: provide guests with finit-like environment=0A=0AWithout the use = of xsave, guests get their initial floating point=0Aenvironment set up = with finit. At least NetWare actually depends on=0Athis (in particular on = all exceptions being masked), so to be=0Aconsistent set the same environmen= t also when using xsave. This is=0Aalso in line with all SSE exceptions = getting masked initially.=0A=0ATo avoid further fragile casts in xstate_all= oc_save_area() the patch=0Aalso changes xsave_struct's fpu_see member to = have actually usable=0Afields.=0A=0AThe patch was tested in its technically= identical, but modified-file-=0Awise different 4.1.2 version.=0A=0ASigned-= off-by: Jan Beulich =0ATested-by: Charles Arnold = =0A=0A--- a/xen/arch/x86/i387.c=0A+++ b/xen/arch/x86/i387= .c=0A@@ -17,7 +17,6 @@=0A #include =0A #include =0A =0A-#define MXCSR_DEFAULT 0x1f80=0A static void fpu_init(void)=0A = {=0A unsigned long val;=0A--- a/xen/arch/x86/xstate.c=0A+++ b/xen/arch/= x86/xstate.c=0A@@ -97,7 +97,7 @@ bool_t xsave_enabled(const struct vcpu = *=0A =0A int xstate_alloc_save_area(struct vcpu *v)=0A {=0A- void = *save_area;=0A+ struct xsave_struct *save_area;=0A =0A if ( = !cpu_has_xsave || is_idle_vcpu(v) )=0A return 0;=0A@@ -109,8 = +109,9 @@ int xstate_alloc_save_area(struct vcpu *=0A if ( save_area = =3D=3D NULL )=0A return -ENOMEM;=0A =0A- ((u32 *)save_area)[6] = =3D 0x1f80; /* MXCSR */=0A- *(uint64_t *)(save_area + 512) =3D = XSTATE_FP_SSE; /* XSETBV */=0A+ save_area->fpu_sse.fcw =3D FCW_DEFAULT;= =0A+ save_area->fpu_sse.mxcsr =3D MXCSR_DEFAULT;=0A+ save_area->xsave= _hdr.xstate_bv =3D XSTATE_FP_SSE;=0A =0A v->arch.xsave_area =3D = save_area;=0A v->arch.xcr0 =3D XSTATE_FP_SSE;=0A--- a/xen/include/asm-x= 86/xstate.h=0A+++ b/xen/include/asm-x86/xstate.h=0A@@ -11,6 +11,9 @@=0A = #include =0A #include =0A =0A+#define FCW_DEFAUL= T 0x037f=0A+#define MXCSR_DEFAULT 0x1f80=0A+=0A = #define XSTATE_CPUID 0x0000000d=0A #define XSTATE_FEATURE_XSAV= EOPT (1 << 0) /* sub-leaf 1, eax[bit 0] */=0A =0A@@ -46,7 +49,29 @@ = extern u64 xfeature_mask;=0A /* extended state save area */=0A struct = xsave_struct=0A {=0A- struct { char x[512]; } fpu_sse; /* = FPU/MMX, SSE */=0A+ union { /* = FPU/MMX, SSE */=0A+ char x[512];=0A+ struct {=0A+ = uint16_t fcw;=0A+ uint16_t fsw;=0A+ uint8_t ftw;=0A+ = uint8_t rsvd1;=0A+ uint16_t fop;=0A+ = union {=0A+#ifdef __x86_64__=0A+ uint64_t addr;=0A+#endif=0A= + struct {=0A+ uint32_t offs;=0A+ = uint16_t sel;=0A+ uint16_t rsvd;=0A+ = };=0A+ } fip, fdp;=0A+ uint32_t mxcsr;=0A+ = uint32_t mxcsr_mask;=0A+ /* data registers follow here = */=0A+ };=0A+ } fpu_sse;=0A =0A struct {=0A u64 = xstate_bv;=0A --=__Part634CE59D.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part634CE59D.0__=--