Fix initial x87 state after r345562.
After the referenced commit, we did not set x87 and sse valid bits in the xstate_bv bitmask for initial fpu state (stored in memory), when using XSAVE. The state is loaded into FPU register file to initialize the process FPU state, and since both bits were clear, the default x87 and SSE states were loaded. By chance, FreeBSD ABI SSE2 state is same as FPU initial state, so the bug is not visible for 64bit processes. But on i386, the precision control should be set to double (53bit mantissa), instead of the default double extended (64bit mantissa). For 32bit processes on amd64, kernel reloads control word with the right mask, which only left native i386 and amd64 native but using x87 as affected. Fix it by setting minimal required xstate_bv mask. Sponsored by: The FreeBSD Foundation MFC after: 1 week
This commit is contained in:
parent
b800eb9d17
commit
fdfe249b63
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=346294
@ -370,6 +370,7 @@ fpuinit(void)
|
||||
static void
|
||||
fpuinitstate(void *arg __unused)
|
||||
{
|
||||
uint64_t *xstate_bv;
|
||||
register_t saveintr;
|
||||
int cp[4], i, max_ext_n;
|
||||
|
||||
@ -400,6 +401,10 @@ fpuinitstate(void *arg __unused)
|
||||
* Save Area.
|
||||
*/
|
||||
if (use_xsave) {
|
||||
xstate_bv = (uint64_t *)((char *)(fpu_initialstate + 1) +
|
||||
offsetof(struct xstate_hdr, xstate_bv));
|
||||
*xstate_bv = XFEATURE_ENABLED_X87 | XFEATURE_ENABLED_SSE;
|
||||
|
||||
max_ext_n = flsl(xsave_mask);
|
||||
xsave_area_desc = malloc(max_ext_n * sizeof(struct
|
||||
xsave_area_elm_descr), M_DEVBUF, M_WAITOK | M_ZERO);
|
||||
|
@ -472,6 +472,7 @@ npxinit(bool bsp)
|
||||
static void
|
||||
npxinitstate(void *arg __unused)
|
||||
{
|
||||
uint64_t *xstate_bv;
|
||||
register_t saveintr;
|
||||
int cp[4], i, max_ext_n;
|
||||
|
||||
@ -507,6 +508,7 @@ npxinitstate(void *arg __unused)
|
||||
sizeof(npx_initialstate->sv_xmm.sv_fp));
|
||||
bzero(npx_initialstate->sv_xmm.sv_xmm,
|
||||
sizeof(npx_initialstate->sv_xmm.sv_xmm));
|
||||
|
||||
} else
|
||||
bzero(npx_initialstate->sv_87.sv_ac,
|
||||
sizeof(npx_initialstate->sv_87.sv_ac));
|
||||
@ -516,6 +518,10 @@ npxinitstate(void *arg __unused)
|
||||
* Save Area.
|
||||
*/
|
||||
if (use_xsave) {
|
||||
xstate_bv = (uint64_t *)((char *)(npx_initialstate + 1) +
|
||||
offsetof(struct xstate_hdr, xstate_bv));
|
||||
*xstate_bv = XFEATURE_ENABLED_X87 | XFEATURE_ENABLED_SSE;
|
||||
|
||||
if (xsave_mask >> 32 != 0)
|
||||
max_ext_n = fls(xsave_mask >> 32) + 32;
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user