diff options
-rw-r--r-- | arch/x86/kernel/Makefile | 2 | ||||
-rw-r--r-- | arch/x86/kernel/cpu/common.c | 8 | ||||
-rw-r--r-- | arch/x86/kernel/i387.c | 12 | ||||
-rw-r--r-- | arch/x86/kernel/traps_32.c | 1 | ||||
-rw-r--r-- | arch/x86/kernel/traps_64.c | 4 | ||||
-rw-r--r-- | arch/x86/kernel/xsave.c | 87 | ||||
-rw-r--r-- | include/asm-x86/i387.h | 1 | ||||
-rw-r--r-- | include/asm-x86/processor-flags.h | 1 | ||||
-rw-r--r-- | include/asm-x86/processor.h | 12 | ||||
-rw-r--r-- | include/asm-x86/xsave.h | 26 |
10 files changed, 148 insertions, 6 deletions
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index a07ec14f3312..d6ea91abaebc 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile | |||
@@ -38,7 +38,7 @@ obj-y += tsc.o io_delay.o rtc.o | |||
38 | 38 | ||
39 | obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o | 39 | obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o |
40 | obj-y += process.o | 40 | obj-y += process.o |
41 | obj-y += i387.o | 41 | obj-y += i387.o xsave.o |
42 | obj-y += ptrace.o | 42 | obj-y += ptrace.o |
43 | obj-y += ds.o | 43 | obj-y += ds.o |
44 | obj-$(CONFIG_X86_32) += tls.o | 44 | obj-$(CONFIG_X86_32) += tls.o |
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 80ab20d4fa39..fabbcb7020fb 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -712,6 +712,14 @@ void __cpuinit cpu_init(void) | |||
712 | current_thread_info()->status = 0; | 712 | current_thread_info()->status = 0; |
713 | clear_used_math(); | 713 | clear_used_math(); |
714 | mxcsr_feature_mask_init(); | 714 | mxcsr_feature_mask_init(); |
715 | |||
716 | /* | ||
717 | * Boot processor to setup the FP and extended state context info. | ||
718 | */ | ||
719 | if (!smp_processor_id()) | ||
720 | init_thread_xstate(); | ||
721 | |||
722 | xsave_init(); | ||
715 | } | 723 | } |
716 | 724 | ||
717 | #ifdef CONFIG_HOTPLUG_CPU | 725 | #ifdef CONFIG_HOTPLUG_CPU |
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c index eb9ddd8efb82..e22a9a9dce8a 100644 --- a/arch/x86/kernel/i387.c +++ b/arch/x86/kernel/i387.c | |||
@@ -61,6 +61,11 @@ void __init init_thread_xstate(void) | |||
61 | return; | 61 | return; |
62 | } | 62 | } |
63 | 63 | ||
64 | if (cpu_has_xsave) { | ||
65 | xsave_cntxt_init(); | ||
66 | return; | ||
67 | } | ||
68 | |||
64 | if (cpu_has_fxsr) | 69 | if (cpu_has_fxsr) |
65 | xstate_size = sizeof(struct i387_fxsave_struct); | 70 | xstate_size = sizeof(struct i387_fxsave_struct); |
66 | #ifdef CONFIG_X86_32 | 71 | #ifdef CONFIG_X86_32 |
@@ -83,6 +88,13 @@ void __cpuinit fpu_init(void) | |||
83 | 88 | ||
84 | write_cr0(oldcr0 & ~(X86_CR0_TS|X86_CR0_EM)); /* clear TS and EM */ | 89 | write_cr0(oldcr0 & ~(X86_CR0_TS|X86_CR0_EM)); /* clear TS and EM */ |
85 | 90 | ||
91 | /* | ||
92 | * Boot processor to setup the FP and extended state context info. | ||
93 | */ | ||
94 | if (!smp_processor_id()) | ||
95 | init_thread_xstate(); | ||
96 | xsave_init(); | ||
97 | |||
86 | mxcsr_feature_mask_init(); | 98 | mxcsr_feature_mask_init(); |
87 | /* clean state in init */ | 99 | /* clean state in init */ |
88 | current_thread_info()->status = 0; | 100 | current_thread_info()->status = 0; |
diff --git a/arch/x86/kernel/traps_32.c b/arch/x86/kernel/traps_32.c index 03df8e45e5a1..da5a5964fccb 100644 --- a/arch/x86/kernel/traps_32.c +++ b/arch/x86/kernel/traps_32.c | |||
@@ -1228,7 +1228,6 @@ void __init trap_init(void) | |||
1228 | 1228 | ||
1229 | set_bit(SYSCALL_VECTOR, used_vectors); | 1229 | set_bit(SYSCALL_VECTOR, used_vectors); |
1230 | 1230 | ||
1231 | init_thread_xstate(); | ||
1232 | /* | 1231 | /* |
1233 | * Should be a barrier for any external CPU state: | 1232 | * Should be a barrier for any external CPU state: |
1234 | */ | 1233 | */ |
diff --git a/arch/x86/kernel/traps_64.c b/arch/x86/kernel/traps_64.c index 513caaca7115..3580a7938a2e 100644 --- a/arch/x86/kernel/traps_64.c +++ b/arch/x86/kernel/traps_64.c | |||
@@ -1173,10 +1173,6 @@ void __init trap_init(void) | |||
1173 | set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall); | 1173 | set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall); |
1174 | #endif | 1174 | #endif |
1175 | /* | 1175 | /* |
1176 | * initialize the per thread extended state: | ||
1177 | */ | ||
1178 | init_thread_xstate(); | ||
1179 | /* | ||
1180 | * Should be a barrier for any external CPU state: | 1176 | * Should be a barrier for any external CPU state: |
1181 | */ | 1177 | */ |
1182 | cpu_init(); | 1178 | cpu_init(); |
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c new file mode 100644 index 000000000000..c68b7c4ca249 --- /dev/null +++ b/arch/x86/kernel/xsave.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | * xsave/xrstor support. | ||
3 | * | ||
4 | * Author: Suresh Siddha <suresh.b.siddha@intel.com> | ||
5 | */ | ||
6 | #include <linux/bootmem.h> | ||
7 | #include <linux/compat.h> | ||
8 | #include <asm/i387.h> | ||
9 | |||
10 | /* | ||
11 | * Supported feature mask by the CPU and the kernel. | ||
12 | */ | ||
13 | unsigned int pcntxt_hmask, pcntxt_lmask; | ||
14 | |||
15 | /* | ||
16 | * Represents init state for the supported extended state. | ||
17 | */ | ||
18 | struct xsave_struct *init_xstate_buf; | ||
19 | |||
20 | /* | ||
21 | * Enable the extended processor state save/restore feature | ||
22 | */ | ||
23 | void __cpuinit xsave_init(void) | ||
24 | { | ||
25 | if (!cpu_has_xsave) | ||
26 | return; | ||
27 | |||
28 | set_in_cr4(X86_CR4_OSXSAVE); | ||
29 | |||
30 | /* | ||
31 | * Enable all the features that the HW is capable of | ||
32 | * and the Linux kernel is aware of. | ||
33 | * | ||
34 | * xsetbv(); | ||
35 | */ | ||
36 | asm volatile(".byte 0x0f,0x01,0xd1" : : "c" (0), | ||
37 | "a" (pcntxt_lmask), "d" (pcntxt_hmask)); | ||
38 | } | ||
39 | |||
40 | /* | ||
41 | * setup the xstate image representing the init state | ||
42 | */ | ||
43 | void setup_xstate_init(void) | ||
44 | { | ||
45 | init_xstate_buf = alloc_bootmem(xstate_size); | ||
46 | init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT; | ||
47 | } | ||
48 | |||
49 | /* | ||
50 | * Enable and initialize the xsave feature. | ||
51 | */ | ||
52 | void __init xsave_cntxt_init(void) | ||
53 | { | ||
54 | unsigned int eax, ebx, ecx, edx; | ||
55 | |||
56 | cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx); | ||
57 | |||
58 | pcntxt_lmask = eax; | ||
59 | pcntxt_hmask = edx; | ||
60 | |||
61 | if ((pcntxt_lmask & XSTATE_FPSSE) != XSTATE_FPSSE) { | ||
62 | printk(KERN_ERR "FP/SSE not shown under xsave features %x\n", | ||
63 | pcntxt_lmask); | ||
64 | BUG(); | ||
65 | } | ||
66 | |||
67 | /* | ||
68 | * for now OS knows only about FP/SSE | ||
69 | */ | ||
70 | pcntxt_lmask = pcntxt_lmask & XCNTXT_LMASK; | ||
71 | pcntxt_hmask = pcntxt_hmask & XCNTXT_HMASK; | ||
72 | |||
73 | xsave_init(); | ||
74 | |||
75 | /* | ||
76 | * Recompute the context size for enabled features | ||
77 | */ | ||
78 | cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx); | ||
79 | |||
80 | xstate_size = ebx; | ||
81 | |||
82 | setup_xstate_init(); | ||
83 | |||
84 | printk(KERN_INFO "xsave/xrstor: enabled xstate_bv 0x%Lx, " | ||
85 | "cntxt size 0x%x\n", | ||
86 | (pcntxt_lmask | ((u64) pcntxt_hmask << 32)), xstate_size); | ||
87 | } | ||
diff --git a/include/asm-x86/i387.h b/include/asm-x86/i387.h index 3958de6aad0e..6a6647896670 100644 --- a/include/asm-x86/i387.h +++ b/include/asm-x86/i387.h | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <asm/sigcontext.h> | 18 | #include <asm/sigcontext.h> |
19 | #include <asm/user.h> | 19 | #include <asm/user.h> |
20 | #include <asm/uaccess.h> | 20 | #include <asm/uaccess.h> |
21 | #include <asm/xsave.h> | ||
21 | 22 | ||
22 | extern void fpu_init(void); | 23 | extern void fpu_init(void); |
23 | extern void mxcsr_feature_mask_init(void); | 24 | extern void mxcsr_feature_mask_init(void); |
diff --git a/include/asm-x86/processor-flags.h b/include/asm-x86/processor-flags.h index 5dd79774f693..dc5f0712f9fa 100644 --- a/include/asm-x86/processor-flags.h +++ b/include/asm-x86/processor-flags.h | |||
@@ -59,6 +59,7 @@ | |||
59 | #define X86_CR4_OSFXSR 0x00000200 /* enable fast FPU save and restore */ | 59 | #define X86_CR4_OSFXSR 0x00000200 /* enable fast FPU save and restore */ |
60 | #define X86_CR4_OSXMMEXCPT 0x00000400 /* enable unmasked SSE exceptions */ | 60 | #define X86_CR4_OSXMMEXCPT 0x00000400 /* enable unmasked SSE exceptions */ |
61 | #define X86_CR4_VMXE 0x00002000 /* enable VMX virtualization */ | 61 | #define X86_CR4_VMXE 0x00002000 /* enable VMX virtualization */ |
62 | #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */ | ||
62 | 63 | ||
63 | /* | 64 | /* |
64 | * x86-64 Task Priority Register, CR8 | 65 | * x86-64 Task Priority Register, CR8 |
diff --git a/include/asm-x86/processor.h b/include/asm-x86/processor.h index d60b4d81febe..d7c0221c0278 100644 --- a/include/asm-x86/processor.h +++ b/include/asm-x86/processor.h | |||
@@ -346,6 +346,18 @@ struct i387_soft_struct { | |||
346 | u32 entry_eip; | 346 | u32 entry_eip; |
347 | }; | 347 | }; |
348 | 348 | ||
349 | struct xsave_hdr_struct { | ||
350 | u64 xstate_bv; | ||
351 | u64 reserved1[2]; | ||
352 | u64 reserved2[5]; | ||
353 | } __attribute__((packed)); | ||
354 | |||
355 | struct xsave_struct { | ||
356 | struct i387_fxsave_struct i387; | ||
357 | struct xsave_hdr_struct xsave_hdr; | ||
358 | /* new processor state extensions will go here */ | ||
359 | } __attribute__ ((packed, aligned (64))); | ||
360 | |||
349 | union thread_xstate { | 361 | union thread_xstate { |
350 | struct i387_fsave_struct fsave; | 362 | struct i387_fsave_struct fsave; |
351 | struct i387_fxsave_struct fxsave; | 363 | struct i387_fxsave_struct fxsave; |
diff --git a/include/asm-x86/xsave.h b/include/asm-x86/xsave.h new file mode 100644 index 000000000000..6d70e62c6bdc --- /dev/null +++ b/include/asm-x86/xsave.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #ifndef __ASM_X86_XSAVE_H | ||
2 | #define __ASM_X86_XSAVE_H | ||
3 | |||
4 | #include <asm/processor.h> | ||
5 | #include <asm/i387.h> | ||
6 | |||
7 | #define XSTATE_FP 0x1 | ||
8 | #define XSTATE_SSE 0x2 | ||
9 | |||
10 | #define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE) | ||
11 | |||
12 | #define FXSAVE_SIZE 512 | ||
13 | |||
14 | /* | ||
15 | * These are the features that the OS can handle currently. | ||
16 | */ | ||
17 | #define XCNTXT_LMASK (XSTATE_FP | XSTATE_SSE) | ||
18 | #define XCNTXT_HMASK 0x0 | ||
19 | |||
20 | extern unsigned int xstate_size, pcntxt_hmask, pcntxt_lmask; | ||
21 | extern struct xsave_struct *init_xstate_buf; | ||
22 | |||
23 | extern void xsave_cntxt_init(void); | ||
24 | extern void xsave_init(void); | ||
25 | |||
26 | #endif | ||