lkml.org 
[lkml]   [2020]   [Feb]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 4/8] x86/fpu/xstate: Define new functions for clearing fpregs and xstates
On Tue, Jan 21, 2020 at 12:18:39PM -0800, Yu-cheng Yu wrote:
> @@ -318,9 +313,29 @@ static inline void copy_init_fpstate_to_fpregs(void)
> * Called by sys_execve(), by the signal handler code and by various
> * error paths.
> */
> -void fpu__clear(struct fpu *fpu)
> +void fpu__clear_user_states(struct fpu *fpu)
> +{
> + WARN_ON_FPU(fpu != &current->thread.fpu);
> +
> + if (static_cpu_has(X86_FEATURE_FPU)) {
> + fpregs_lock();
> + if (!fpregs_state_valid(fpu, smp_processor_id()) &&
> + xfeatures_mask_supervisor())
> + copy_kernel_to_xregs(&fpu->state.xsave,
> + xfeatures_mask_supervisor());
> + copy_init_fpstate_to_fpregs(xfeatures_mask_user());
> + fpregs_mark_activate();
> + fpregs_unlock();
> + return;
> + } else {
> + fpu__drop(fpu);
> + fpu__initialize(fpu);
> + }
> +}
> +
> +void fpu__clear_all(struct fpu *fpu)
> {
> - WARN_ON_FPU(fpu != &current->thread.fpu); /* Almost certainly an anomaly */
> + WARN_ON_FPU(fpu != &current->thread.fpu);
>
> fpu__drop(fpu);
>
> @@ -328,8 +343,12 @@ void fpu__clear(struct fpu *fpu)
> * Make sure fpstate is cleared and initialized.
> */
> fpu__initialize(fpu);
> - if (static_cpu_has(X86_FEATURE_FPU))
> - copy_init_fpstate_to_fpregs();
> + if (static_cpu_has(X86_FEATURE_FPU)) {
> + fpregs_lock();
> + copy_init_fpstate_to_fpregs(xfeatures_mask_all);
> + fpregs_mark_activate();
> + fpregs_unlock();
> + }
> }

Why do you need two different functions which are pretty similar if you
can do

fpu__clear(struct fpu *fpu, bool user_only)
{
...

and query that user_only variable in the fpu__clear() body to do the
respective work dependent on the its setting?

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

\
 
 \ /
  Last update: 2020-02-21 15:05    [W:0.180 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site