Commit 3103ae3a authored by Ingo Molnar's avatar Ingo Molnar

x86/fpu: Add debug check to kernel_fpu_disable()

We are not supposed to call kernel_fpu_disable() if we have not
previously enabled it.

Also use kernel_fpu_disable()/enable() in the __kernel_fpu_begin/end()
primitives, instead of writing to in_kernel_fpu directly,
so that we get the debugging checks.
Reviewed-by: default avatarBorislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 416d49ac
...@@ -17,6 +17,7 @@ static void kernel_fpu_disable(void) ...@@ -17,6 +17,7 @@ static void kernel_fpu_disable(void)
static void kernel_fpu_enable(void) static void kernel_fpu_enable(void)
{ {
WARN_ON_ONCE(!this_cpu_read(in_kernel_fpu));
this_cpu_write(in_kernel_fpu, false); this_cpu_write(in_kernel_fpu, false);
} }
...@@ -77,7 +78,7 @@ void __kernel_fpu_begin(void) ...@@ -77,7 +78,7 @@ void __kernel_fpu_begin(void)
{ {
struct task_struct *me = current; struct task_struct *me = current;
this_cpu_write(in_kernel_fpu, true); kernel_fpu_disable();
if (__thread_has_fpu(me)) { if (__thread_has_fpu(me)) {
__save_init_fpu(me); __save_init_fpu(me);
...@@ -100,7 +101,7 @@ void __kernel_fpu_end(void) ...@@ -100,7 +101,7 @@ void __kernel_fpu_end(void)
stts(); stts();
} }
this_cpu_write(in_kernel_fpu, false); kernel_fpu_enable();
} }
EXPORT_SYMBOL(__kernel_fpu_end); EXPORT_SYMBOL(__kernel_fpu_end);
......
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