x86/fpu: Get rid of PF_USED_MATH usage, convert it to fpu->fpstate_active
[firefly-linux-kernel-4.4.55.git] / arch / x86 / kernel / fpu / core.c
1 /*
2  *  Copyright (C) 1994 Linus Torvalds
3  *
4  *  Pentium III FXSR, SSE support
5  *  General FPU state handling cleanups
6  *      Gareth Hughes <gareth@valinux.com>, May 2000
7  */
8 #include <asm/fpu-internal.h>
9
10 /*
11  * Track whether the kernel is using the FPU state
12  * currently.
13  *
14  * This flag is used:
15  *
16  *   - by IRQ context code to potentially use the FPU
17  *     if it's unused.
18  *
19  *   - to debug kernel_fpu_begin()/end() correctness
20  */
21 static DEFINE_PER_CPU(bool, in_kernel_fpu);
22
23 /*
24  * Track which context is using the FPU on the CPU:
25  */
26 DEFINE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
27
28 static void kernel_fpu_disable(void)
29 {
30         WARN_ON(this_cpu_read(in_kernel_fpu));
31         this_cpu_write(in_kernel_fpu, true);
32 }
33
34 static void kernel_fpu_enable(void)
35 {
36         WARN_ON_ONCE(!this_cpu_read(in_kernel_fpu));
37         this_cpu_write(in_kernel_fpu, false);
38 }
39
40 static bool kernel_fpu_disabled(void)
41 {
42         return this_cpu_read(in_kernel_fpu);
43 }
44
45 /*
46  * Were we in an interrupt that interrupted kernel mode?
47  *
48  * On others, we can do a kernel_fpu_begin/end() pair *ONLY* if that
49  * pair does nothing at all: the thread must not have fpu (so
50  * that we don't try to save the FPU state), and TS must
51  * be set (so that the clts/stts pair does nothing that is
52  * visible in the interrupted kernel thread).
53  *
54  * Except for the eagerfpu case when we return true; in the likely case
55  * the thread has FPU but we are not going to set/clear TS.
56  */
57 static bool interrupted_kernel_fpu_idle(void)
58 {
59         if (kernel_fpu_disabled())
60                 return false;
61
62         if (use_eager_fpu())
63                 return true;
64
65         return !current->thread.fpu.has_fpu && (read_cr0() & X86_CR0_TS);
66 }
67
68 /*
69  * Were we in user mode (or vm86 mode) when we were
70  * interrupted?
71  *
72  * Doing kernel_fpu_begin/end() is ok if we are running
73  * in an interrupt context from user mode - we'll just
74  * save the FPU state as required.
75  */
76 static bool interrupted_user_mode(void)
77 {
78         struct pt_regs *regs = get_irq_regs();
79         return regs && user_mode(regs);
80 }
81
82 /*
83  * Can we use the FPU in kernel mode with the
84  * whole "kernel_fpu_begin/end()" sequence?
85  *
86  * It's always ok in process context (ie "not interrupt")
87  * but it is sometimes ok even from an irq.
88  */
89 bool irq_fpu_usable(void)
90 {
91         return !in_interrupt() ||
92                 interrupted_user_mode() ||
93                 interrupted_kernel_fpu_idle();
94 }
95 EXPORT_SYMBOL(irq_fpu_usable);
96
97 void __kernel_fpu_begin(void)
98 {
99         struct fpu *fpu = &current->thread.fpu;
100
101         kernel_fpu_disable();
102
103         if (fpu->has_fpu) {
104                 fpu_save_init(fpu);
105         } else {
106                 this_cpu_write(fpu_fpregs_owner_ctx, NULL);
107                 if (!use_eager_fpu())
108                         clts();
109         }
110 }
111 EXPORT_SYMBOL(__kernel_fpu_begin);
112
113 void __kernel_fpu_end(void)
114 {
115         struct task_struct *me = current;
116         struct fpu *fpu = &me->thread.fpu;
117
118         if (fpu->has_fpu) {
119                 if (WARN_ON(restore_fpu_checking(me)))
120                         fpu_reset_state(me);
121         } else if (!use_eager_fpu()) {
122                 stts();
123         }
124
125         kernel_fpu_enable();
126 }
127 EXPORT_SYMBOL(__kernel_fpu_end);
128
129 /*
130  * Save the FPU state (initialize it if necessary):
131  *
132  * This only ever gets called for the current task.
133  */
134 void fpu__save(struct task_struct *tsk)
135 {
136         struct fpu *fpu = &tsk->thread.fpu;
137
138         WARN_ON(tsk != current);
139
140         preempt_disable();
141         if (fpu->has_fpu) {
142                 if (use_eager_fpu()) {
143                         __save_fpu(tsk);
144                 } else {
145                         fpu_save_init(fpu);
146                         __thread_fpu_end(fpu);
147                 }
148         }
149         preempt_enable();
150 }
151 EXPORT_SYMBOL_GPL(fpu__save);
152
153 void fpstate_init(struct fpu *fpu)
154 {
155         if (!cpu_has_fpu) {
156                 finit_soft_fpu(&fpu->state->soft);
157                 return;
158         }
159
160         memset(fpu->state, 0, xstate_size);
161
162         if (cpu_has_fxsr) {
163                 fx_finit(&fpu->state->fxsave);
164         } else {
165                 struct i387_fsave_struct *fp = &fpu->state->fsave;
166                 fp->cwd = 0xffff037fu;
167                 fp->swd = 0xffff0000u;
168                 fp->twd = 0xffffffffu;
169                 fp->fos = 0xffff0000u;
170         }
171 }
172 EXPORT_SYMBOL_GPL(fpstate_init);
173
174 /*
175  * FPU state allocation:
176  */
177 static struct kmem_cache *task_xstate_cachep;
178
179 void fpstate_cache_init(void)
180 {
181         task_xstate_cachep =
182                 kmem_cache_create("task_xstate", xstate_size,
183                                   __alignof__(union thread_xstate),
184                                   SLAB_PANIC | SLAB_NOTRACK, NULL);
185         setup_xstate_comp();
186 }
187
188 int fpstate_alloc(struct fpu *fpu)
189 {
190         if (fpu->state)
191                 return 0;
192
193         fpu->state = kmem_cache_alloc(task_xstate_cachep, GFP_KERNEL);
194         if (!fpu->state)
195                 return -ENOMEM;
196
197         /* The CPU requires the FPU state to be aligned to 16 byte boundaries: */
198         WARN_ON((unsigned long)fpu->state & 15);
199
200         return 0;
201 }
202 EXPORT_SYMBOL_GPL(fpstate_alloc);
203
204 void fpstate_free(struct fpu *fpu)
205 {
206         if (fpu->state) {
207                 kmem_cache_free(task_xstate_cachep, fpu->state);
208                 fpu->state = NULL;
209         }
210 }
211 EXPORT_SYMBOL_GPL(fpstate_free);
212
213 /*
214  * Copy the current task's FPU state to a new task's FPU context.
215  *
216  * In the 'eager' case we just save to the destination context.
217  *
218  * In the 'lazy' case we save to the source context, mark the FPU lazy
219  * via stts() and copy the source context into the destination context.
220  */
221 static void fpu_copy(struct task_struct *dst, struct task_struct *src)
222 {
223         WARN_ON(src != current);
224
225         if (use_eager_fpu()) {
226                 memset(&dst->thread.fpu.state->xsave, 0, xstate_size);
227                 __save_fpu(dst);
228         } else {
229                 struct fpu *dfpu = &dst->thread.fpu;
230                 struct fpu *sfpu = &src->thread.fpu;
231
232                 fpu__save(src);
233                 memcpy(dfpu->state, sfpu->state, xstate_size);
234         }
235 }
236
237 int fpu__copy(struct task_struct *dst, struct task_struct *src)
238 {
239         struct fpu *dst_fpu = &dst->thread.fpu;
240         struct fpu *src_fpu = &src->thread.fpu;
241
242         dst->thread.fpu.counter = 0;
243         dst->thread.fpu.has_fpu = 0;
244         dst->thread.fpu.state = NULL;
245
246         task_disable_lazy_fpu_restore(dst);
247
248         if (src_fpu->fpstate_active) {
249                 int err = fpstate_alloc(dst_fpu);
250
251                 if (err)
252                         return err;
253                 fpu_copy(dst, src);
254         }
255         return 0;
256 }
257
258 /*
259  * Allocate the backing store for the current task's FPU registers
260  * and initialize the registers themselves as well.
261  *
262  * Can fail.
263  */
264 int fpstate_alloc_init(struct task_struct *curr)
265 {
266         struct fpu *fpu = &curr->thread.fpu;
267         int ret;
268
269         if (WARN_ON_ONCE(curr != current))
270                 return -EINVAL;
271         if (WARN_ON_ONCE(fpu->fpstate_active))
272                 return -EINVAL;
273
274         /*
275          * Memory allocation at the first usage of the FPU and other state.
276          */
277         ret = fpstate_alloc(&curr->thread.fpu);
278         if (ret)
279                 return ret;
280
281         fpstate_init(&curr->thread.fpu);
282
283         /* Safe to do for the current task: */
284         fpu->fpstate_active = 1;
285
286         return 0;
287 }
288 EXPORT_SYMBOL_GPL(fpstate_alloc_init);
289
290 /*
291  * This function is called before we modify a stopped child's
292  * FPU state context.
293  *
294  * If the child has not used the FPU before then initialize its
295  * FPU context.
296  *
297  * If the child has used the FPU before then unlazy it.
298  *
299  * [ After this function call, after the context is modified and
300  *   the child task is woken up, the child task will restore
301  *   the modified FPU state from the modified context. If we
302  *   didn't clear its lazy status here then the lazy in-registers
303  *   state pending on its former CPU could be restored, losing
304  *   the modifications. ]
305  *
306  * This function is also called before we read a stopped child's
307  * FPU state - to make sure it's modified.
308  *
309  * TODO: A future optimization would be to skip the unlazying in
310  *       the read-only case, it's not strictly necessary for
311  *       read-only access to the context.
312  */
313 static int fpu__unlazy_stopped(struct task_struct *child)
314 {
315         struct fpu *child_fpu = &child->thread.fpu;
316         int ret;
317
318         if (WARN_ON_ONCE(child == current))
319                 return -EINVAL;
320
321         if (child_fpu->fpstate_active) {
322                 task_disable_lazy_fpu_restore(child);
323                 return 0;
324         }
325
326         /*
327          * Memory allocation at the first usage of the FPU and other state.
328          */
329         ret = fpstate_alloc(&child->thread.fpu);
330         if (ret)
331                 return ret;
332
333         fpstate_init(&child->thread.fpu);
334
335         /* Safe to do for stopped child tasks: */
336         child_fpu->fpstate_active = 1;
337
338         return 0;
339 }
340
341 /*
342  * 'fpu__restore()' saves the current math information in the
343  * old math state array, and gets the new ones from the current task
344  *
345  * Careful.. There are problems with IBM-designed IRQ13 behaviour.
346  * Don't touch unless you *really* know how it works.
347  *
348  * Must be called with kernel preemption disabled (eg with local
349  * local interrupts as in the case of do_device_not_available).
350  */
351 void fpu__restore(void)
352 {
353         struct task_struct *tsk = current;
354         struct fpu *fpu = &tsk->thread.fpu;
355
356         if (!fpu->fpstate_active) {
357                 local_irq_enable();
358                 /*
359                  * does a slab alloc which can sleep
360                  */
361                 if (fpstate_alloc_init(tsk)) {
362                         /*
363                          * ran out of memory!
364                          */
365                         do_group_exit(SIGKILL);
366                         return;
367                 }
368                 local_irq_disable();
369         }
370
371         /* Avoid __kernel_fpu_begin() right after __thread_fpu_begin() */
372         kernel_fpu_disable();
373         __thread_fpu_begin(fpu);
374         if (unlikely(restore_fpu_checking(tsk))) {
375                 fpu_reset_state(tsk);
376                 force_sig_info(SIGSEGV, SEND_SIG_PRIV, tsk);
377         } else {
378                 tsk->thread.fpu.counter++;
379         }
380         kernel_fpu_enable();
381 }
382 EXPORT_SYMBOL_GPL(fpu__restore);
383
384 void fpu__flush_thread(struct task_struct *tsk)
385 {
386         struct fpu *fpu = &tsk->thread.fpu;
387
388         WARN_ON(tsk != current);
389
390         if (!use_eager_fpu()) {
391                 /* FPU state will be reallocated lazily at the first use. */
392                 drop_fpu(tsk);
393                 fpstate_free(&tsk->thread.fpu);
394         } else {
395                 if (!fpu->fpstate_active) {
396                         /* kthread execs. TODO: cleanup this horror. */
397                 if (WARN_ON(fpstate_alloc_init(tsk)))
398                                 force_sig(SIGKILL, tsk);
399                         user_fpu_begin();
400                 }
401                 restore_init_xstate();
402         }
403 }
404
405 /*
406  * The xstateregs_active() routine is the same as the fpregs_active() routine,
407  * as the "regset->n" for the xstate regset will be updated based on the feature
408  * capabilites supported by the xsave.
409  */
410 int fpregs_active(struct task_struct *target, const struct user_regset *regset)
411 {
412         struct fpu *target_fpu = &target->thread.fpu;
413
414         return target_fpu->fpstate_active ? regset->n : 0;
415 }
416
417 int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
418 {
419         struct fpu *target_fpu = &target->thread.fpu;
420
421         return (cpu_has_fxsr && target_fpu->fpstate_active) ? regset->n : 0;
422 }
423
424 int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
425                 unsigned int pos, unsigned int count,
426                 void *kbuf, void __user *ubuf)
427 {
428         int ret;
429
430         if (!cpu_has_fxsr)
431                 return -ENODEV;
432
433         ret = fpu__unlazy_stopped(target);
434         if (ret)
435                 return ret;
436
437         sanitize_i387_state(target);
438
439         return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
440                                    &target->thread.fpu.state->fxsave, 0, -1);
441 }
442
443 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
444                 unsigned int pos, unsigned int count,
445                 const void *kbuf, const void __user *ubuf)
446 {
447         int ret;
448
449         if (!cpu_has_fxsr)
450                 return -ENODEV;
451
452         ret = fpu__unlazy_stopped(target);
453         if (ret)
454                 return ret;
455
456         sanitize_i387_state(target);
457
458         ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
459                                  &target->thread.fpu.state->fxsave, 0, -1);
460
461         /*
462          * mxcsr reserved bits must be masked to zero for security reasons.
463          */
464         target->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask;
465
466         /*
467          * update the header bits in the xsave header, indicating the
468          * presence of FP and SSE state.
469          */
470         if (cpu_has_xsave)
471                 target->thread.fpu.state->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE;
472
473         return ret;
474 }
475
476 int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
477                 unsigned int pos, unsigned int count,
478                 void *kbuf, void __user *ubuf)
479 {
480         struct xsave_struct *xsave;
481         int ret;
482
483         if (!cpu_has_xsave)
484                 return -ENODEV;
485
486         ret = fpu__unlazy_stopped(target);
487         if (ret)
488                 return ret;
489
490         xsave = &target->thread.fpu.state->xsave;
491
492         /*
493          * Copy the 48bytes defined by the software first into the xstate
494          * memory layout in the thread struct, so that we can copy the entire
495          * xstateregs to the user using one user_regset_copyout().
496          */
497         memcpy(&xsave->i387.sw_reserved,
498                 xstate_fx_sw_bytes, sizeof(xstate_fx_sw_bytes));
499         /*
500          * Copy the xstate memory layout.
501          */
502         ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, xsave, 0, -1);
503         return ret;
504 }
505
506 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
507                   unsigned int pos, unsigned int count,
508                   const void *kbuf, const void __user *ubuf)
509 {
510         struct xsave_struct *xsave;
511         int ret;
512
513         if (!cpu_has_xsave)
514                 return -ENODEV;
515
516         ret = fpu__unlazy_stopped(target);
517         if (ret)
518                 return ret;
519
520         xsave = &target->thread.fpu.state->xsave;
521
522         ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, xsave, 0, -1);
523         /*
524          * mxcsr reserved bits must be masked to zero for security reasons.
525          */
526         xsave->i387.mxcsr &= mxcsr_feature_mask;
527         xsave->xsave_hdr.xstate_bv &= pcntxt_mask;
528         /*
529          * These bits must be zero.
530          */
531         memset(&xsave->xsave_hdr.reserved, 0, 48);
532         return ret;
533 }
534
535 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
536
537 /*
538  * FPU tag word conversions.
539  */
540
541 static inline unsigned short twd_i387_to_fxsr(unsigned short twd)
542 {
543         unsigned int tmp; /* to avoid 16 bit prefixes in the code */
544
545         /* Transform each pair of bits into 01 (valid) or 00 (empty) */
546         tmp = ~twd;
547         tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */
548         /* and move the valid bits to the lower byte. */
549         tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */
550         tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */
551         tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */
552
553         return tmp;
554 }
555
556 #define FPREG_ADDR(f, n)        ((void *)&(f)->st_space + (n) * 16)
557 #define FP_EXP_TAG_VALID        0
558 #define FP_EXP_TAG_ZERO         1
559 #define FP_EXP_TAG_SPECIAL      2
560 #define FP_EXP_TAG_EMPTY        3
561
562 static inline u32 twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave)
563 {
564         struct _fpxreg *st;
565         u32 tos = (fxsave->swd >> 11) & 7;
566         u32 twd = (unsigned long) fxsave->twd;
567         u32 tag;
568         u32 ret = 0xffff0000u;
569         int i;
570
571         for (i = 0; i < 8; i++, twd >>= 1) {
572                 if (twd & 0x1) {
573                         st = FPREG_ADDR(fxsave, (i - tos) & 7);
574
575                         switch (st->exponent & 0x7fff) {
576                         case 0x7fff:
577                                 tag = FP_EXP_TAG_SPECIAL;
578                                 break;
579                         case 0x0000:
580                                 if (!st->significand[0] &&
581                                     !st->significand[1] &&
582                                     !st->significand[2] &&
583                                     !st->significand[3])
584                                         tag = FP_EXP_TAG_ZERO;
585                                 else
586                                         tag = FP_EXP_TAG_SPECIAL;
587                                 break;
588                         default:
589                                 if (st->significand[3] & 0x8000)
590                                         tag = FP_EXP_TAG_VALID;
591                                 else
592                                         tag = FP_EXP_TAG_SPECIAL;
593                                 break;
594                         }
595                 } else {
596                         tag = FP_EXP_TAG_EMPTY;
597                 }
598                 ret |= tag << (2 * i);
599         }
600         return ret;
601 }
602
603 /*
604  * FXSR floating point environment conversions.
605  */
606
607 void
608 convert_from_fxsr(struct user_i387_ia32_struct *env, struct task_struct *tsk)
609 {
610         struct i387_fxsave_struct *fxsave = &tsk->thread.fpu.state->fxsave;
611         struct _fpreg *to = (struct _fpreg *) &env->st_space[0];
612         struct _fpxreg *from = (struct _fpxreg *) &fxsave->st_space[0];
613         int i;
614
615         env->cwd = fxsave->cwd | 0xffff0000u;
616         env->swd = fxsave->swd | 0xffff0000u;
617         env->twd = twd_fxsr_to_i387(fxsave);
618
619 #ifdef CONFIG_X86_64
620         env->fip = fxsave->rip;
621         env->foo = fxsave->rdp;
622         /*
623          * should be actually ds/cs at fpu exception time, but
624          * that information is not available in 64bit mode.
625          */
626         env->fcs = task_pt_regs(tsk)->cs;
627         if (tsk == current) {
628                 savesegment(ds, env->fos);
629         } else {
630                 env->fos = tsk->thread.ds;
631         }
632         env->fos |= 0xffff0000;
633 #else
634         env->fip = fxsave->fip;
635         env->fcs = (u16) fxsave->fcs | ((u32) fxsave->fop << 16);
636         env->foo = fxsave->foo;
637         env->fos = fxsave->fos;
638 #endif
639
640         for (i = 0; i < 8; ++i)
641                 memcpy(&to[i], &from[i], sizeof(to[0]));
642 }
643
644 void convert_to_fxsr(struct task_struct *tsk,
645                      const struct user_i387_ia32_struct *env)
646
647 {
648         struct i387_fxsave_struct *fxsave = &tsk->thread.fpu.state->fxsave;
649         struct _fpreg *from = (struct _fpreg *) &env->st_space[0];
650         struct _fpxreg *to = (struct _fpxreg *) &fxsave->st_space[0];
651         int i;
652
653         fxsave->cwd = env->cwd;
654         fxsave->swd = env->swd;
655         fxsave->twd = twd_i387_to_fxsr(env->twd);
656         fxsave->fop = (u16) ((u32) env->fcs >> 16);
657 #ifdef CONFIG_X86_64
658         fxsave->rip = env->fip;
659         fxsave->rdp = env->foo;
660         /* cs and ds ignored */
661 #else
662         fxsave->fip = env->fip;
663         fxsave->fcs = (env->fcs & 0xffff);
664         fxsave->foo = env->foo;
665         fxsave->fos = env->fos;
666 #endif
667
668         for (i = 0; i < 8; ++i)
669                 memcpy(&to[i], &from[i], sizeof(from[0]));
670 }
671
672 int fpregs_get(struct task_struct *target, const struct user_regset *regset,
673                unsigned int pos, unsigned int count,
674                void *kbuf, void __user *ubuf)
675 {
676         struct user_i387_ia32_struct env;
677         int ret;
678
679         ret = fpu__unlazy_stopped(target);
680         if (ret)
681                 return ret;
682
683         if (!static_cpu_has(X86_FEATURE_FPU))
684                 return fpregs_soft_get(target, regset, pos, count, kbuf, ubuf);
685
686         if (!cpu_has_fxsr)
687                 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
688                                            &target->thread.fpu.state->fsave, 0,
689                                            -1);
690
691         sanitize_i387_state(target);
692
693         if (kbuf && pos == 0 && count == sizeof(env)) {
694                 convert_from_fxsr(kbuf, target);
695                 return 0;
696         }
697
698         convert_from_fxsr(&env, target);
699
700         return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &env, 0, -1);
701 }
702
703 int fpregs_set(struct task_struct *target, const struct user_regset *regset,
704                unsigned int pos, unsigned int count,
705                const void *kbuf, const void __user *ubuf)
706 {
707         struct user_i387_ia32_struct env;
708         int ret;
709
710         ret = fpu__unlazy_stopped(target);
711         if (ret)
712                 return ret;
713
714         sanitize_i387_state(target);
715
716         if (!static_cpu_has(X86_FEATURE_FPU))
717                 return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf);
718
719         if (!cpu_has_fxsr)
720                 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
721                                           &target->thread.fpu.state->fsave, 0,
722                                           -1);
723
724         if (pos > 0 || count < sizeof(env))
725                 convert_from_fxsr(&env, target);
726
727         ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &env, 0, -1);
728         if (!ret)
729                 convert_to_fxsr(target, &env);
730
731         /*
732          * update the header bit in the xsave header, indicating the
733          * presence of FP.
734          */
735         if (cpu_has_xsave)
736                 target->thread.fpu.state->xsave.xsave_hdr.xstate_bv |= XSTATE_FP;
737         return ret;
738 }
739
740 /*
741  * FPU state for core dumps.
742  * This is only used for a.out dumps now.
743  * It is declared generically using elf_fpregset_t (which is
744  * struct user_i387_struct) but is in fact only used for 32-bit
745  * dumps, so on 64-bit it is really struct user_i387_ia32_struct.
746  */
747 int dump_fpu(struct pt_regs *regs, struct user_i387_struct *ufpu)
748 {
749         struct task_struct *tsk = current;
750         struct fpu *fpu = &tsk->thread.fpu;
751         int fpvalid;
752
753         fpvalid = fpu->fpstate_active;
754         if (fpvalid)
755                 fpvalid = !fpregs_get(tsk, NULL,
756                                       0, sizeof(struct user_i387_ia32_struct),
757                                       ufpu, NULL);
758
759         return fpvalid;
760 }
761 EXPORT_SYMBOL(dump_fpu);
762
763 #endif  /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */