Re: [patch V3 66/66] x86/fpu/signal: Let xrstor handle the features to init

From: Borislav Petkov
Date: Wed Jun 23 2021 - 04:57:04 EST


On Fri, Jun 18, 2021 at 04:19:29PM +0200, Thomas Gleixner wrote:
> There is no reason to do an extra XRSTOR from initfp_state for feature bits
> which have been cleared by user space in the FX magic xfeatures storage.
>
> Just clear them in the task's XSTATE header and do a full restore which
> will put these cleared features into init state.
>
> There is no real difference in performance because the current code already
> does a full restore when the xfeatures bits are preserved as the signal
> frame setup has stored them, which is the full UABI feature set.
>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> ---
> arch/x86/kernel/fpu/signal.c | 92 +++++++++++++++----------------------------
> 1 file changed, 33 insertions(+), 59 deletions(-)

...

> @@ -390,54 +362,56 @@ static int __fpu_restore_sig(void __user
> set_thread_flag(TIF_NEED_FPU_LOAD);
> }
> __fpu_invalidate_fpregs_state(fpu);
> + __cpu_invalidate_fpregs_state();
> fpregs_unlock();
>
> if (use_xsave() && !fx_only) {
> - u64 init_bv = xfeatures_mask_uabi() & ~user_xfeatures;
> -
> - ret = copy_sigframe_from_user_to_xstate(&fpu->state.xsave, buf_fx);
> + ret = copy_sigframe_from_user_to_xstate(&fpu->state.xsave,
> + buf_fx);

Why? Just let it stick out.

Regardless,

Reviewed-by: Borislav Petkov <bp@xxxxxxx>

--
Regards/Gruss,
Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg