From: "Jan Beulich" Subject: [PATCH] x86: consistently mask floating point exceptions Date: Wed, 16 Jan 2013 10:51:38 +0000 Message-ID: <50F6944A02000078000B623C@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part6253C92A.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel 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. --=__Part6253C92A.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline c/s 23142:f5e8d152a565 resulted in v->arch.fpu_ctxt to point into the save area allocated for xsave/xrstor (when they're available). The way vcpu_restore_fpu_lazy() works (using fpu_init() for an uninitialized vCPU only when there's no xsave support) causes this to load whatever arch_set_info_guest() put there, irrespective of whether the i387 state was specified to be valid in the respective input structure. Consequently, with a cleared (al zeroes) incoming FPU context, and with xsave available, one gets all exceptions unmasked (as opposed to to the legacy case, where FINIT and LDMXCSR get used, masking all exceptions). This causes e.g. para-virtualized NetWare to crash. The behavior of arch_set_info_guest() is thus being made more hardware- like for the FPU portion of it: Considering it to be similar to INIT, it will leave untouched all floating point state now. An alternative would be to make the behavior RESET-like, forcing all state to known values, albeit - taking into account legacy behavior - not to precisely the values RESET would enforce (which masks only SSE exceptions, but not x87 ones); that would come closest to mimicing FINIT behavior in the xsave case. Another option would be to continue copying whatever was provided, but override (at least) FCW and MXCSR if VGCF_I387_VALID isn't set. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -748,7 +748,9 @@ int arch_set_info_guest( =20 v->arch.vgc_flags =3D flags; =20 - memcpy(v->arch.fpu_ctxt, &c.nat->fpu_ctxt, sizeof(c.nat->fpu_ctxt)); + if ( flags & VGCF_I387_VALID ) + memcpy(v->arch.fpu_ctxt, &c.nat->fpu_ctxt, sizeof(c.nat->fpu_ctxt)= ); + if ( !compat ) { memcpy(&v->arch.user_regs, &c.nat->user_regs, sizeof(c.nat->user_r= egs)); --=__Part6253C92A.0__= Content-Type: text/plain; name="x86-fpu-context-conditional.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-fpu-context-conditional.patch" x86: consistently mask floating point exceptions=0A=0Ac/s 23142:f5e8d152a56= 5 resulted in v->arch.fpu_ctxt to point into the=0Asave area allocated for = xsave/xrstor (when they're available). The way=0Avcpu_restore_fpu_lazy() = works (using fpu_init() for an uninitialized=0AvCPU only when there's no = xsave support) causes this to load whatever=0Aarch_set_info_guest() put = there, irrespective of whether the i387 state=0Awas specified to be valid = in the respective input structure.=0A=0AConsequently, with a cleared (al = zeroes) incoming FPU context, and with=0Axsave available, one gets all = exceptions unmasked (as opposed to to the=0Alegacy case, where FINIT and = LDMXCSR get used, masking all exceptions).=0AThis causes e.g. para-virtuali= zed NetWare to crash.=0A=0AThe behavior of arch_set_info_guest() is thus = being made more hardware-=0Alike for the FPU portion of it: Considering it = to be similar to INIT,=0Ait will leave untouched all floating point state = now. An alternative=0Awould be to make the behavior RESET-like, forcing = all state to known=0Avalues, albeit - taking into account legacy behavior = - not to precisely=0Athe values RESET would enforce (which masks only SSE = exceptions, but=0Anot x87 ones); that would come closest to mimicing FINIT = behavior in=0Athe xsave case. Another option would be to continue copying = whatever=0Awas provided, but override (at least) FCW and MXCSR if = VGCF_I387_VALID=0Aisn't set.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/domain.c=0A+++ b/xen/arch/x86/domain.c=0A@@ = -748,7 +748,9 @@ int arch_set_info_guest(=0A =0A v->arch.vgc_flags =3D = flags;=0A =0A- memcpy(v->arch.fpu_ctxt, &c.nat->fpu_ctxt, sizeof(c.nat->= fpu_ctxt));=0A+ if ( flags & VGCF_I387_VALID )=0A+ memcpy(v->arch= .fpu_ctxt, &c.nat->fpu_ctxt, sizeof(c.nat->fpu_ctxt));=0A+=0A if ( = !compat )=0A {=0A memcpy(&v->arch.user_regs, &c.nat->user_regs,= sizeof(c.nat->user_regs));=0A --=__Part6253C92A.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.xen.org http://lists.xen.org/xen-devel --=__Part6253C92A.0__=--