diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-06 19:25:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-06 19:25:13 -0400 |
commit | 4a386c3e177ca2fbc70c9283d0b46537844763a0 (patch) | |
tree | 7f3a6a6a984a988e8a6e908d93dcd57d92a82efd /arch/x86/kernel/i387.c | |
parent | e8779776afbd5f2d5315cf48c4257ca7e9b250fb (diff) | |
parent | 1cff92d8fdb27684308864d9cdb324bee43b40ab (diff) |
Merge branch 'x86-xsave-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-xsave-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
x86, xsave: Make xstate_enable_boot_cpu() __init, protect on CPU 0
x86, xsave: Add __init attribute to setup_xstate_features()
x86, xsave: Make init_xstate_buf static
x86, xsave: Check cpuid level for XSTATE_CPUID (0x0d)
x86, xsave: Introduce xstate enable functions
x86, xsave: Separate fpu and xsave initialization
x86, xsave: Move boot cpu initialization to xsave_init()
x86, xsave: 32/64 bit boot cpu check unification in initialization
x86, xsave: Do not include asm/i387.h in asm/xsave.h
x86, xsave: Use xsaveopt in context-switch path when supported
x86, xsave: Sync xsave memory layout with its header for user handling
x86, xsave: Track the offset, size of state in the xsave layout
Diffstat (limited to 'arch/x86/kernel/i387.c')
-rw-r--r-- | arch/x86/kernel/i387.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c index c4444bce8469..1f11f5ce668f 100644 --- a/arch/x86/kernel/i387.c +++ b/arch/x86/kernel/i387.c | |||
@@ -59,18 +59,18 @@ void __cpuinit mxcsr_feature_mask_init(void) | |||
59 | stts(); | 59 | stts(); |
60 | } | 60 | } |
61 | 61 | ||
62 | void __cpuinit init_thread_xstate(void) | 62 | static void __cpuinit init_thread_xstate(void) |
63 | { | 63 | { |
64 | /* | ||
65 | * Note that xstate_size might be overwriten later during | ||
66 | * xsave_init(). | ||
67 | */ | ||
68 | |||
64 | if (!HAVE_HWFP) { | 69 | if (!HAVE_HWFP) { |
65 | xstate_size = sizeof(struct i387_soft_struct); | 70 | xstate_size = sizeof(struct i387_soft_struct); |
66 | return; | 71 | return; |
67 | } | 72 | } |
68 | 73 | ||
69 | if (cpu_has_xsave) { | ||
70 | xsave_cntxt_init(); | ||
71 | return; | ||
72 | } | ||
73 | |||
74 | if (cpu_has_fxsr) | 74 | if (cpu_has_fxsr) |
75 | xstate_size = sizeof(struct i387_fxsave_struct); | 75 | xstate_size = sizeof(struct i387_fxsave_struct); |
76 | #ifdef CONFIG_X86_32 | 76 | #ifdef CONFIG_X86_32 |
@@ -84,6 +84,7 @@ void __cpuinit init_thread_xstate(void) | |||
84 | * Called at bootup to set up the initial FPU state that is later cloned | 84 | * Called at bootup to set up the initial FPU state that is later cloned |
85 | * into all processes. | 85 | * into all processes. |
86 | */ | 86 | */ |
87 | |||
87 | void __cpuinit fpu_init(void) | 88 | void __cpuinit fpu_init(void) |
88 | { | 89 | { |
89 | unsigned long oldcr0 = read_cr0(); | 90 | unsigned long oldcr0 = read_cr0(); |
@@ -93,19 +94,24 @@ void __cpuinit fpu_init(void) | |||
93 | 94 | ||
94 | write_cr0(oldcr0 & ~(X86_CR0_TS|X86_CR0_EM)); /* clear TS and EM */ | 95 | write_cr0(oldcr0 & ~(X86_CR0_TS|X86_CR0_EM)); /* clear TS and EM */ |
95 | 96 | ||
96 | /* | ||
97 | * Boot processor to setup the FP and extended state context info. | ||
98 | */ | ||
99 | if (!smp_processor_id()) | 97 | if (!smp_processor_id()) |
100 | init_thread_xstate(); | 98 | init_thread_xstate(); |
101 | xsave_init(); | ||
102 | 99 | ||
103 | mxcsr_feature_mask_init(); | 100 | mxcsr_feature_mask_init(); |
104 | /* clean state in init */ | 101 | /* clean state in init */ |
105 | current_thread_info()->status = 0; | 102 | current_thread_info()->status = 0; |
106 | clear_used_math(); | 103 | clear_used_math(); |
107 | } | 104 | } |
108 | #endif /* CONFIG_X86_64 */ | 105 | |
106 | #else /* CONFIG_X86_64 */ | ||
107 | |||
108 | void __cpuinit fpu_init(void) | ||
109 | { | ||
110 | if (!smp_processor_id()) | ||
111 | init_thread_xstate(); | ||
112 | } | ||
113 | |||
114 | #endif /* CONFIG_X86_32 */ | ||
109 | 115 | ||
110 | void fpu_finit(struct fpu *fpu) | 116 | void fpu_finit(struct fpu *fpu) |
111 | { | 117 | { |
@@ -191,6 +197,8 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset, | |||
191 | if (ret) | 197 | if (ret) |
192 | return ret; | 198 | return ret; |
193 | 199 | ||
200 | sanitize_i387_state(target); | ||
201 | |||
194 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | 202 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
195 | &target->thread.fpu.state->fxsave, 0, -1); | 203 | &target->thread.fpu.state->fxsave, 0, -1); |
196 | } | 204 | } |
@@ -208,6 +216,8 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset, | |||
208 | if (ret) | 216 | if (ret) |
209 | return ret; | 217 | return ret; |
210 | 218 | ||
219 | sanitize_i387_state(target); | ||
220 | |||
211 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | 221 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
212 | &target->thread.fpu.state->fxsave, 0, -1); | 222 | &target->thread.fpu.state->fxsave, 0, -1); |
213 | 223 | ||
@@ -447,6 +457,8 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset, | |||
447 | -1); | 457 | -1); |
448 | } | 458 | } |
449 | 459 | ||
460 | sanitize_i387_state(target); | ||
461 | |||
450 | if (kbuf && pos == 0 && count == sizeof(env)) { | 462 | if (kbuf && pos == 0 && count == sizeof(env)) { |
451 | convert_from_fxsr(kbuf, target); | 463 | convert_from_fxsr(kbuf, target); |
452 | return 0; | 464 | return 0; |
@@ -468,6 +480,8 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset, | |||
468 | if (ret) | 480 | if (ret) |
469 | return ret; | 481 | return ret; |
470 | 482 | ||
483 | sanitize_i387_state(target); | ||
484 | |||
471 | if (!HAVE_HWFP) | 485 | if (!HAVE_HWFP) |
472 | return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf); | 486 | return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf); |
473 | 487 | ||
@@ -534,6 +548,9 @@ static int save_i387_xsave(void __user *buf) | |||
534 | struct _fpstate_ia32 __user *fx = buf; | 548 | struct _fpstate_ia32 __user *fx = buf; |
535 | int err = 0; | 549 | int err = 0; |
536 | 550 | ||
551 | |||
552 | sanitize_i387_state(tsk); | ||
553 | |||
537 | /* | 554 | /* |
538 | * For legacy compatible, we always set FP/SSE bits in the bit | 555 | * For legacy compatible, we always set FP/SSE bits in the bit |
539 | * vector while saving the state to the user context. | 556 | * vector while saving the state to the user context. |