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 <[email protected]> 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)) { _______________________________________________ [email protected] mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "[email protected]"
