diff mbox series

[11/29] x86/fpu: Always init the `state' in fpu__clear()

Message ID 20181128222035.2996-12-bigeasy@linutronix.de (mailing list archive)
State New, archived
Headers show
Series [01/29] x86/fpu: Use ULL for shift in xfeature_uncompacted_offset() | expand

Commit Message

Sebastian Andrzej Siewior Nov. 28, 2018, 10:20 p.m. UTC
fpu__clear() only initializes the `state' if the FPU is present. This
initialisation is also required for the FPU-less system and takes place
math_emulate(). Since fpu__initialize() only performs the initialization
if ->initialized is zero it does not matter that it is invoked each time
an opcode is emulated. It makes the removal of ->initialized easier if
the struct is also initialized in FPU-less case at the same time.

Move fpu__initialize() before the FPU check so it is also performed in
FPU-less case.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/x86/include/asm/fpu/internal.h | 1 -
 arch/x86/kernel/fpu/core.c          | 5 ++---
 arch/x86/math-emu/fpu_entry.c       | 3 ---
 3 files changed, 2 insertions(+), 7 deletions(-)

Comments

Borislav Petkov Dec. 12, 2018, 5:11 p.m. UTC | #1
On Wed, Nov 28, 2018 at 11:20:17PM +0100, Sebastian Andrzej Siewior wrote:
> fpu__clear() only initializes the `state' if the FPU is present. This
> initialisation is also required for the FPU-less system and takes place
> math_emulate(). Since fpu__initialize() only performs the initialization
> if ->initialized is zero it does not matter that it is invoked each time
> an opcode is emulated. It makes the removal of ->initialized easier if
> the struct is also initialized in FPU-less case at the same time.
> 
> Move fpu__initialize() before the FPU check so it is also performed in
> FPU-less case.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  arch/x86/include/asm/fpu/internal.h | 1 -
>  arch/x86/kernel/fpu/core.c          | 5 ++---
>  arch/x86/math-emu/fpu_entry.c       | 3 ---
>  3 files changed, 2 insertions(+), 7 deletions(-)

...

> diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
> index 9e2ba7e667f61..a873da6b46d6b 100644
> --- a/arch/x86/math-emu/fpu_entry.c
> +++ b/arch/x86/math-emu/fpu_entry.c
> @@ -113,9 +113,6 @@ void math_emulate(struct math_emu_info *info)
>  	unsigned long code_base = 0;
>  	unsigned long code_limit = 0;	/* Initialized to stop compiler warnings */
>  	struct desc_struct code_descriptor;
> -	struct fpu *fpu = &current->thread.fpu;
> -
> -	fpu__initialize(fpu);

Ok, you're removing it here but where is the FPU going to be initialized
now in the FPU-less case?

IOW, it is not clear to me where fpu__clear() get called for the FPU
emulation case now...
Sebastian Andrzej Siewior Dec. 13, 2018, 2:35 p.m. UTC | #2
On 2018-12-12 18:11:29 [+0100], Borislav Petkov wrote:
> > diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
> > index 9e2ba7e667f61..a873da6b46d6b 100644
> > --- a/arch/x86/math-emu/fpu_entry.c
> > +++ b/arch/x86/math-emu/fpu_entry.c
> > @@ -113,9 +113,6 @@ void math_emulate(struct math_emu_info *info)
> >  	unsigned long code_base = 0;
> >  	unsigned long code_limit = 0;	/* Initialized to stop compiler warnings */
> >  	struct desc_struct code_descriptor;
> > -	struct fpu *fpu = &current->thread.fpu;
> > -
> > -	fpu__initialize(fpu);
> 
> Ok, you're removing it here but where is the FPU going to be initialized
> now in the FPU-less case?
> 
> IOW, it is not clear to me where fpu__clear() get called for the FPU
> emulation case now...

During fork() fpu__initialize() is called for both (with and without
FPU) systems. The difference is made in fpu__clear() where the init is
avoided in the FPU-less case. With this hunk:

--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -365,8 +364,8 @@ void fpu__clear(struct fpu *fpu)
        /*
         * Make sure fpstate is cleared and initialized.
         */
+       fpu__initialize(fpu);
        if (static_cpu_has(X86_FEATURE_FPU)) {
-               fpu__initialize(fpu);
                user_fpu_begin();
                copy_init_fpstate_to_fpregs();
        }                                                                                                                                                                                 
we have the initialization in both cases.
The only "negative" thing might be that we now have a memset(, 0, 684)
(fpstate_init_soft()) during fork which would be avoided in case the
FPU-less system has a userland which is compiled with a soft-FPU toolchain.

I would worry about it once someone complains (and I doubt someone
complains even if we remove soft FPU support).

Sebastian
diff mbox series

Patch

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index 415d43bdaaa76..1d0e043bfc447 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -24,7 +24,6 @@ 
 /*
  * High level FPU state handling functions:
  */
-extern void fpu__initialize(struct fpu *fpu);
 extern void fpu__prepare_read(struct fpu *fpu);
 extern void fpu__prepare_write(struct fpu *fpu);
 extern void fpu__save(struct fpu *fpu);
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 1940319268aef..e43296854e379 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -223,7 +223,7 @@  int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu)
  * Activate the current task's in-memory FPU context,
  * if it has not been used before:
  */
-void fpu__initialize(struct fpu *fpu)
+static void fpu__initialize(struct fpu *fpu)
 {
 	WARN_ON_FPU(fpu != &current->thread.fpu);
 
@@ -236,7 +236,6 @@  void fpu__initialize(struct fpu *fpu)
 		fpu->initialized = 1;
 	}
 }
-EXPORT_SYMBOL_GPL(fpu__initialize);
 
 /*
  * This function must be called before we read a task's fpstate.
@@ -365,8 +364,8 @@  void fpu__clear(struct fpu *fpu)
 	/*
 	 * Make sure fpstate is cleared and initialized.
 	 */
+	fpu__initialize(fpu);
 	if (static_cpu_has(X86_FEATURE_FPU)) {
-		fpu__initialize(fpu);
 		user_fpu_begin();
 		copy_init_fpstate_to_fpregs();
 	}
diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 9e2ba7e667f61..a873da6b46d6b 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -113,9 +113,6 @@  void math_emulate(struct math_emu_info *info)
 	unsigned long code_base = 0;
 	unsigned long code_limit = 0;	/* Initialized to stop compiler warnings */
 	struct desc_struct code_descriptor;
-	struct fpu *fpu = &current->thread.fpu;
-
-	fpu__initialize(fpu);
 
 #ifdef RE_ENTRANT_CHECKING
 	if (emulating) {