Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/fpu: Move math_state_restore() to fpu/core.c

It's another piece of FPU internals that is better off close to
the other FPU internals.

Reviewed-by: Borislav 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: Ingo Molnar <mingo@kernel.org>

+42 -42
+42
arch/x86/kernel/fpu/core.c
··· 227 227 return 0; 228 228 } 229 229 230 + /* 231 + * 'math_state_restore()' saves the current math information in the 232 + * old math state array, and gets the new ones from the current task 233 + * 234 + * Careful.. There are problems with IBM-designed IRQ13 behaviour. 235 + * Don't touch unless you *really* know how it works. 236 + * 237 + * Must be called with kernel preemption disabled (eg with local 238 + * local interrupts as in the case of do_device_not_available). 239 + */ 240 + void math_state_restore(void) 241 + { 242 + struct task_struct *tsk = current; 243 + 244 + if (!tsk_used_math(tsk)) { 245 + local_irq_enable(); 246 + /* 247 + * does a slab alloc which can sleep 248 + */ 249 + if (fpstate_alloc_init(tsk)) { 250 + /* 251 + * ran out of memory! 252 + */ 253 + do_group_exit(SIGKILL); 254 + return; 255 + } 256 + local_irq_disable(); 257 + } 258 + 259 + /* Avoid __kernel_fpu_begin() right after __thread_fpu_begin() */ 260 + kernel_fpu_disable(); 261 + __thread_fpu_begin(tsk); 262 + if (unlikely(restore_fpu_checking(tsk))) { 263 + fpu_reset_state(tsk); 264 + force_sig_info(SIGSEGV, SEND_SIG_PRIV, tsk); 265 + } else { 266 + tsk->thread.fpu.counter++; 267 + } 268 + kernel_fpu_enable(); 269 + } 270 + EXPORT_SYMBOL_GPL(math_state_restore); 271 + 230 272 void fpu__flush_thread(struct task_struct *tsk) 231 273 { 232 274 if (!use_eager_fpu()) {
-42
arch/x86/kernel/traps.c
··· 826 826 { 827 827 } 828 828 829 - /* 830 - * 'math_state_restore()' saves the current math information in the 831 - * old math state array, and gets the new ones from the current task 832 - * 833 - * Careful.. There are problems with IBM-designed IRQ13 behaviour. 834 - * Don't touch unless you *really* know how it works. 835 - * 836 - * Must be called with kernel preemption disabled (eg with local 837 - * local interrupts as in the case of do_device_not_available). 838 - */ 839 - void math_state_restore(void) 840 - { 841 - struct task_struct *tsk = current; 842 - 843 - if (!tsk_used_math(tsk)) { 844 - local_irq_enable(); 845 - /* 846 - * does a slab alloc which can sleep 847 - */ 848 - if (fpstate_alloc_init(tsk)) { 849 - /* 850 - * ran out of memory! 851 - */ 852 - do_group_exit(SIGKILL); 853 - return; 854 - } 855 - local_irq_disable(); 856 - } 857 - 858 - /* Avoid __kernel_fpu_begin() right after __thread_fpu_begin() */ 859 - kernel_fpu_disable(); 860 - __thread_fpu_begin(tsk); 861 - if (unlikely(restore_fpu_checking(tsk))) { 862 - fpu_reset_state(tsk); 863 - force_sig_info(SIGSEGV, SEND_SIG_PRIV, tsk); 864 - } else { 865 - tsk->thread.fpu.counter++; 866 - } 867 - kernel_fpu_enable(); 868 - } 869 - EXPORT_SYMBOL_GPL(math_state_restore); 870 - 871 829 dotraplinkage void 872 830 do_device_not_available(struct pt_regs *regs, long error_code) 873 831 {