@@ -391,8 +391,6 @@ int fpu_copy_uabi_to_guest_fpstate(struct fpu_guest *gfpu, const void *buf,
391391{
392392 struct fpstate * kstate = gfpu -> fpstate ;
393393 const union fpregs_state * ustate = buf ;
394- struct pkru_state * xpkru ;
395- int ret ;
396394
397395 if (!cpu_feature_enabled (X86_FEATURE_XSAVE )) {
398396 if (ustate -> xsave .header .xfeatures & ~XFEATURE_MASK_FPSSE )
@@ -406,19 +404,15 @@ int fpu_copy_uabi_to_guest_fpstate(struct fpu_guest *gfpu, const void *buf,
406404 if (ustate -> xsave .header .xfeatures & ~xcr0 )
407405 return - EINVAL ;
408406
409- ret = copy_uabi_from_kernel_to_xstate (kstate , ustate );
410- if (ret )
411- return ret ;
412-
413- /* Retrieve PKRU if not in init state */
414- if (kstate -> regs .xsave .header .xfeatures & XFEATURE_MASK_PKRU ) {
415- xpkru = get_xsave_addr (& kstate -> regs .xsave , XFEATURE_PKRU );
416- * vpkru = xpkru -> pkru ;
417- }
407+ /*
408+ * Nullify @vpkru to preserve its current value if PKRU's bit isn't set
409+ * in the header. KVM's odd ABI is to leave PKRU untouched in this
410+ * case (all other components are eventually re-initialized).
411+ */
412+ if (!(ustate -> xsave .header .xfeatures & XFEATURE_MASK_PKRU ))
413+ vpkru = NULL ;
418414
419- /* Ensure that XCOMP_BV is set up for XSAVES */
420- xstate_init_xcomp_bv (& kstate -> regs .xsave , kstate -> xfeatures );
421- return 0 ;
415+ return copy_uabi_from_kernel_to_xstate (kstate , ustate , vpkru );
422416}
423417EXPORT_SYMBOL_GPL (fpu_copy_uabi_to_guest_fpstate );
424418#endif /* CONFIG_KVM */
@@ -432,7 +426,7 @@ void kernel_fpu_begin_mask(unsigned int kfpu_mask)
432426
433427 this_cpu_write (in_kernel_fpu , true);
434428
435- if (!(current -> flags & PF_KTHREAD ) &&
429+ if (!(current -> flags & ( PF_KTHREAD | PF_IO_WORKER ) ) &&
436430 !test_thread_flag (TIF_NEED_FPU_LOAD )) {
437431 set_thread_flag (TIF_NEED_FPU_LOAD );
438432 save_fpregs_to_fpstate (& current -> thread .fpu );
@@ -859,12 +853,12 @@ int fpu__exception_code(struct fpu *fpu, int trap_nr)
859853 * Initialize register state that may prevent from entering low-power idle.
860854 * This function will be invoked from the cpuidle driver only when needed.
861855 */
862- void fpu_idle_fpregs (void )
856+ noinstr void fpu_idle_fpregs (void )
863857{
864858 /* Note: AMX_TILE being enabled implies XGETBV1 support */
865859 if (cpu_feature_enabled (X86_FEATURE_AMX_TILE ) &&
866860 (xfeatures_in_use () & XFEATURE_MASK_XTILE )) {
867861 tile_release ();
868- fpregs_deactivate ( & current -> thread . fpu );
862+ __this_cpu_write ( fpu_fpregs_owner_ctx , NULL );
869863 }
870864}
0 commit comments