Skip to content

Commit 9544369

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/fpu: Remove PKRU handling from switch_fpu_finish()
PKRU is already updated and the xstate is not longer the proper source of information. [ bp: Use cpu_feature_enabled() ] 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 30a304a commit 9544369

File tree

1 file changed

+4
-30
lines changed

1 file changed

+4
-30
lines changed

arch/x86/include/asm/fpu/internal.h

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -523,39 +523,13 @@ static inline void switch_fpu_prepare(struct fpu *old_fpu, int cpu)
523523
*/
524524

525525
/*
526-
* Load PKRU from the FPU context if available. Delay loading of the
527-
* complete FPU state until the return to userland.
526+
* Delay loading of the complete FPU state until the return to userland.
527+
* PKRU is handled separately.
528528
*/
529529
static inline void switch_fpu_finish(struct fpu *new_fpu)
530530
{
531-
u32 pkru_val = init_pkru_value;
532-
struct pkru_state *pk;
533-
534-
if (!static_cpu_has(X86_FEATURE_FPU))
535-
return;
536-
537-
set_thread_flag(TIF_NEED_FPU_LOAD);
538-
539-
if (!cpu_feature_enabled(X86_FEATURE_OSPKE))
540-
return;
541-
542-
/*
543-
* PKRU state is switched eagerly because it needs to be valid before we
544-
* return to userland e.g. for a copy_to_user() operation.
545-
*/
546-
if (!(current->flags & PF_KTHREAD)) {
547-
/*
548-
* If the PKRU bit in xsave.header.xfeatures is not set,
549-
* then the PKRU component was in init state, which means
550-
* XRSTOR will set PKRU to 0. If the bit is not set then
551-
* get_xsave_addr() will return NULL because the PKRU value
552-
* in memory is not valid. This means pkru_val has to be
553-
* set to 0 and not to init_pkru_value.
554-
*/
555-
pk = get_xsave_addr(&new_fpu->state.xsave, XFEATURE_PKRU);
556-
pkru_val = pk ? pk->pkru : 0;
557-
}
558-
__write_pkru(pkru_val);
531+
if (cpu_feature_enabled(X86_FEATURE_FPU))
532+
set_thread_flag(TIF_NEED_FPU_LOAD);
559533
}
560534

561535
#endif /* _ASM_X86_FPU_INTERNAL_H */

0 commit comments

Comments
 (0)