Commit 88f5260a authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Borislav Petkov

x86/fpu: Always init the state in fpu__clear()

fpu__clear() only initializes the state if the CPU has FPU support.
This initialisation is also required for FPU-less systems and takes
place in 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 the FPU-less
case at the same time.

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

 [ bp: Massage a bit. ]
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarDave Hansen <dave.hansen@intel.com>
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aubrey Li <aubrey.li@intel.com>
Cc: Bill Metzenthen <billm@melbpc.org.au>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jann Horn <jannh@google.com>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: kvm ML <kvm@vger.kernel.org>
Cc: Nicolai Stange <nstange@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190403164156.19645-5-bigeasy@linutronix.de
parent 60e528d6
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
/* /*
* High level FPU state handling functions: * 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_read(struct fpu *fpu);
extern void fpu__prepare_write(struct fpu *fpu); extern void fpu__prepare_write(struct fpu *fpu);
extern void fpu__save(struct fpu *fpu); extern void fpu__save(struct fpu *fpu);
......
...@@ -223,7 +223,7 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) ...@@ -223,7 +223,7 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu)
* Activate the current task's in-memory FPU context, * Activate the current task's in-memory FPU context,
* if it has not been used before: * 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); WARN_ON_FPU(fpu != &current->thread.fpu);
...@@ -236,7 +236,6 @@ void fpu__initialize(struct fpu *fpu) ...@@ -236,7 +236,6 @@ void fpu__initialize(struct fpu *fpu)
fpu->initialized = 1; fpu->initialized = 1;
} }
} }
EXPORT_SYMBOL_GPL(fpu__initialize);
/* /*
* This function must be called before we read a task's fpstate. * This function must be called before we read a task's fpstate.
...@@ -365,8 +364,8 @@ void fpu__clear(struct fpu *fpu) ...@@ -365,8 +364,8 @@ void fpu__clear(struct fpu *fpu)
/* /*
* Make sure fpstate is cleared and initialized. * Make sure fpstate is cleared and initialized.
*/ */
fpu__initialize(fpu);
if (static_cpu_has(X86_FEATURE_FPU)) { if (static_cpu_has(X86_FEATURE_FPU)) {
fpu__initialize(fpu);
user_fpu_begin(); user_fpu_begin();
copy_init_fpstate_to_fpregs(); copy_init_fpstate_to_fpregs();
} }
......
...@@ -113,9 +113,6 @@ void math_emulate(struct math_emu_info *info) ...@@ -113,9 +113,6 @@ void math_emulate(struct math_emu_info *info)
unsigned long code_base = 0; unsigned long code_base = 0;
unsigned long code_limit = 0; /* Initialized to stop compiler warnings */ unsigned long code_limit = 0; /* Initialized to stop compiler warnings */
struct desc_struct code_descriptor; struct desc_struct code_descriptor;
struct fpu *fpu = &current->thread.fpu;
fpu__initialize(fpu);
#ifdef RE_ENTRANT_CHECKING #ifdef RE_ENTRANT_CHECKING
if (emulating) { if (emulating) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment