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

x86/fpu: Fold fpu_copy() into fpu__copy()

Splitting it into two functions needlessly obfuscated the code.
While we're at it, improve the comment slightly.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
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: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: yu-cheng yu <yu-cheng.yu@intel.com>
Link: http://lkml.kernel.org/r/3eb5a63a9c5c84077b2677a7dfe684eef96fe59e.1453675014.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
a20d7297 5ed73f40

+11 -21
+11 -21
arch/x86/kernel/fpu/core.c
··· 231 231 } 232 232 EXPORT_SYMBOL_GPL(fpstate_init); 233 233 234 - /* 235 - * Copy the current task's FPU state to a new task's FPU context. 236 - * 237 - * In both the 'eager' and the 'lazy' case we save hardware registers 238 - * directly to the destination buffer. 239 - */ 240 - static void fpu_copy(struct fpu *dst_fpu, struct fpu *src_fpu) 234 + int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) 241 235 { 236 + dst_fpu->counter = 0; 237 + dst_fpu->fpregs_active = 0; 238 + dst_fpu->last_cpu = -1; 239 + 240 + if (!src_fpu->fpstate_active || !cpu_has_fpu) 241 + return 0; 242 + 242 243 WARN_ON_FPU(src_fpu != &current->thread.fpu); 243 244 244 245 /* ··· 252 251 /* 253 252 * Save current FPU registers directly into the child 254 253 * FPU context, without any memory-to-memory copying. 255 - * 256 - * If the FPU context got destroyed in the process (FNSAVE 257 - * done on old CPUs) then copy it back into the source 258 - * context and mark the current task for lazy restore. 254 + * In lazy mode, if the FPU context isn't loaded into 255 + * fpregs, CR0.TS will be set and do_device_not_available 256 + * will load the FPU context. 259 257 * 260 258 * We have to do all this with preemption disabled, 261 259 * mostly because of the FNSAVE case, because in that ··· 274 274 fpregs_deactivate(src_fpu); 275 275 } 276 276 preempt_enable(); 277 - } 278 - 279 - int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) 280 - { 281 - dst_fpu->counter = 0; 282 - dst_fpu->fpregs_active = 0; 283 - dst_fpu->last_cpu = -1; 284 - 285 - if (src_fpu->fpstate_active && cpu_has_fpu) 286 - fpu_copy(dst_fpu, src_fpu); 287 277 288 278 return 0; 289 279 }