Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Nov 2017 10:32:44 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325270 - in head/sys: amd64/amd64 i386/i386 i386/isa
Message-ID:  <201711011032.vA1AWi8A051327@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed Nov  1 10:32:44 2017
New Revision: 325270
URL: https://svnweb.freebsd.org/changeset/base/325270

Log:
  Consistently ensure that we do not load MXCSR with reserved bits set.
  
  Some callers of fpusetregs()/npxsetregs(), most importantly
  set_fpcontext(), clear reserved bits.  But some did not.  Do the
  clearing in fpusetregs() and remove now redundand operation from
  set_fpcontext().
  
  Reported by:	Maxime Villard <max@m00nbsd.net>
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Modified:
  head/sys/amd64/amd64/fpu.c
  head/sys/amd64/amd64/machdep.c
  head/sys/i386/i386/machdep.c
  head/sys/i386/isa/npx.c

Modified: head/sys/amd64/amd64/fpu.c
==============================================================================
--- head/sys/amd64/amd64/fpu.c	Wed Nov  1 09:18:41 2017	(r325269)
+++ head/sys/amd64/amd64/fpu.c	Wed Nov  1 10:32:44 2017	(r325270)
@@ -806,6 +806,7 @@ fpusetregs(struct thread *td, struct savefpu *addr, ch
 	struct pcb *pcb;
 	int error;
 
+	addr->sv_env.en_mxcsr &= cpu_mxcsr_mask;
 	pcb = td->td_pcb;
 	critical_enter();
 	if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) {

Modified: head/sys/amd64/amd64/machdep.c
==============================================================================
--- head/sys/amd64/amd64/machdep.c	Wed Nov  1 09:18:41 2017	(r325269)
+++ head/sys/amd64/amd64/machdep.c	Wed Nov  1 10:32:44 2017	(r325270)
@@ -2238,7 +2238,6 @@ static int
 set_fpcontext(struct thread *td, mcontext_t *mcp, char *xfpustate,
     size_t xfpustate_len)
 {
-	struct savefpu *fpstate;
 	int error;
 
 	if (mcp->mc_fpformat == _MC_FPFMT_NODEV)
@@ -2251,9 +2250,8 @@ set_fpcontext(struct thread *td, mcontext_t *mcp, char
 		error = 0;
 	} else if (mcp->mc_ownedfp == _MC_FPOWNED_FPU ||
 	    mcp->mc_ownedfp == _MC_FPOWNED_PCB) {
-		fpstate = (struct savefpu *)&mcp->mc_fpstate;
-		fpstate->sv_env.en_mxcsr &= cpu_mxcsr_mask;
-		error = fpusetregs(td, fpstate, xfpustate, xfpustate_len);
+		error = fpusetregs(td, (struct savefpu *)&mcp->mc_fpstate,
+		    xfpustate, xfpustate_len);
 	} else
 		return (EINVAL);
 	return (error);

Modified: head/sys/i386/i386/machdep.c
==============================================================================
--- head/sys/i386/i386/machdep.c	Wed Nov  1 09:18:41 2017	(r325269)
+++ head/sys/i386/i386/machdep.c	Wed Nov  1 10:32:44 2017	(r325270)
@@ -2851,7 +2851,6 @@ static int
 set_fpcontext(struct thread *td, mcontext_t *mcp, char *xfpustate,
     size_t xfpustate_len)
 {
-	union savefpu *fpstate;
 	int error;
 
 	if (mcp->mc_fpformat == _MC_FPFMT_NODEV)
@@ -2865,10 +2864,8 @@ set_fpcontext(struct thread *td, mcontext_t *mcp, char
 		error = 0;
 	} else if (mcp->mc_ownedfp == _MC_FPOWNED_FPU ||
 	    mcp->mc_ownedfp == _MC_FPOWNED_PCB) {
-		fpstate = (union savefpu *)&mcp->mc_fpstate;
-		if (cpu_fxsr)
-			fpstate->sv_xmm.sv_env.en_mxcsr &= cpu_mxcsr_mask;
-		error = npxsetregs(td, fpstate, xfpustate, xfpustate_len);
+		error = npxsetregs(td, (union savefpu *)&mcp->mc_fpstate,
+		    xfpustate, xfpustate_len);
 	} else
 		return (EINVAL);
 	return (error);

Modified: head/sys/i386/isa/npx.c
==============================================================================
--- head/sys/i386/isa/npx.c	Wed Nov  1 09:18:41 2017	(r325269)
+++ head/sys/i386/isa/npx.c	Wed Nov  1 10:32:44 2017	(r325270)
@@ -1045,6 +1045,8 @@ npxsetregs(struct thread *td, union savefpu *addr, cha
 	if (!hw_float)
 		return (ENXIO);
 
+	if (cpu_fxsr)
+		addr->sv_xmm.sv_env.en_mxcsr &= cpu_mxcsr_mask;
 	pcb = td->td_pcb;
 	critical_enter();
 	if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711011032.vA1AWi8A051327>