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