Skip to content

Commit 0e8c54f

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/fpu: Don't store PKRU in xstate in fpu_reset_fpstate()
PKRU for a task is stored in task->thread.pkru when the task is scheduled out. For 'current' the authoritative source of PKRU is the hardware. fpu_reset_fpstate() has two callers: 1) fpu__clear_user_states() for !FPU systems. For those PKRU is irrelevant 2) fpu_flush_thread() which is invoked from flush_thread(). flush_thread() resets the hardware to the kernel restrictive default value. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 9544369 commit 0e8c54f

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

arch/x86/kernel/fpu/core.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,6 @@ static inline unsigned int init_fpstate_copy_size(void)
337337
return sizeof(init_fpstate.xsave);
338338
}
339339

340-
/* Temporary workaround. Will be removed once PKRU and XSTATE are untangled. */
341-
static inline void pkru_set_default_in_xstate(struct xregs_state *xsave)
342-
{
343-
struct pkru_state *pk;
344-
345-
if (!cpu_feature_enabled(X86_FEATURE_OSPKE))
346-
return;
347-
/*
348-
* Force XFEATURE_PKRU to be set in the header otherwise
349-
* get_xsave_addr() does not work and it also needs to be set to
350-
* make XRSTOR(S) load it.
351-
*/
352-
xsave->header.xfeatures |= XFEATURE_MASK_PKRU;
353-
pk = get_xsave_addr(xsave, XFEATURE_PKRU);
354-
pk->pkru = pkru_get_init_value();
355-
}
356-
357340
/*
358341
* Reset current->fpu memory state to the init values.
359342
*/
@@ -371,9 +354,12 @@ static void fpu_reset_fpstate(void)
371354
*
372355
* Do not use fpstate_init() here. Just copy init_fpstate which has
373356
* the correct content already except for PKRU.
357+
*
358+
* PKRU handling does not rely on the xstate when restoring for
359+
* user space as PKRU is eagerly written in switch_to() and
360+
* flush_thread().
374361
*/
375362
memcpy(&fpu->state, &init_fpstate, init_fpstate_copy_size());
376-
pkru_set_default_in_xstate(&fpu->state.xsave);
377363
set_thread_flag(TIF_NEED_FPU_LOAD);
378364
fpregs_unlock();
379365
}

0 commit comments

Comments
 (0)