20
* Represents init state for the supported extended state.
22
static struct xsave_struct *init_xstate_buf;
19
24
struct _fpx_sw_bytes fx_sw_reserved;
20
25
#ifdef CONFIG_IA32_EMULATION
21
26
struct _fpx_sw_bytes fx_sw_reserved_ia32;
29
static unsigned int *xstate_offsets, *xstate_sizes, xstate_features;
32
* If a processor implementation discern that a processor state component is
33
* in its initialized state it may modify the corresponding bit in the
34
* xsave_hdr.xstate_bv as '0', with out modifying the corresponding memory
35
* layout in the case of xsaveopt. While presenting the xstate information to
36
* the user, we always ensure that the memory layout of a feature will be in
37
* the init state if the corresponding header bit is zero. This is to ensure
38
* that the user doesn't see some stale state in the memory layout during
39
* signal handling, debugging etc.
41
void __sanitize_i387_state(struct task_struct *tsk)
44
int feature_bit = 0x2;
45
struct i387_fxsave_struct *fx = &tsk->thread.fpu.state->fxsave;
50
BUG_ON(task_thread_info(tsk)->status & TS_USEDFPU);
52
xstate_bv = tsk->thread.fpu.state->xsave.xsave_hdr.xstate_bv;
55
* None of the feature bits are in init state. So nothing else
56
* to do for us, as the memory layout is upto date.
58
if ((xstate_bv & pcntxt_mask) == pcntxt_mask)
64
if (!(xstate_bv & XSTATE_FP)) {
71
memset(&fx->st_space[0], 0, 128);
75
* SSE is in init state
77
if (!(xstate_bv & XSTATE_SSE))
78
memset(&fx->xmm_space[0], 0, 256);
80
xstate_bv = (pcntxt_mask & ~xstate_bv) >> 2;
83
* Update all the other memory layouts for which the corresponding
84
* header bit is in the init state.
87
if (xstate_bv & 0x1) {
88
int offset = xstate_offsets[feature_bit];
89
int size = xstate_sizes[feature_bit];
91
memcpy(((void *) fx) + offset,
92
((void *) init_xstate_buf) + offset,
25
102
* Check for the presence of extended state information in the
26
103
* user fpstate pointer in the sigcontext.
52
128
if (fx_sw_user->xstate_size < min_xstate_size ||
53
129
fx_sw_user->xstate_size > xstate_size ||
54
130
fx_sw_user->xstate_size > fx_sw_user->extended_size)
57
133
err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
58
134
fx_sw_user->extended_size -
59
135
FP_XSTATE_MAGIC2_SIZE));
61
139
* Check for the presence of second magic word at the end of memory
62
140
* layout. This detects the case where the user just copied the legacy
63
141
* fpstate layout with out copying the extended state information
64
142
* in the memory layout.
66
if (err || magic2 != FP_XSTATE_MAGIC2)
144
if (magic2 != FP_XSTATE_MAGIC2)
109
179
task_thread_info(tsk)->status &= ~TS_USEDFPU;
112
if (__copy_to_user(buf, &tsk->thread.xstate->fxsave,
182
sanitize_i387_state(tsk);
183
if (__copy_to_user(buf, &tsk->thread.fpu.state->fxsave,
117
188
clear_used_math(); /* trigger finit */
119
if (task_thread_info(tsk)->status & TS_XSAVE) {
120
191
struct _fpstate __user *fx = buf;
121
192
struct _xstate __user *x = buf;
287
353
* Enable the extended processor state save/restore feature
289
void __cpuinit xsave_init(void)
355
static inline void xstate_enable(void)
294
357
set_in_cr4(X86_CR4_OSXSAVE);
297
* Enable all the features that the HW is capable of
298
* and the Linux kernel is aware of.
300
358
xsetbv(XCR_XFEATURE_ENABLED_MASK, pcntxt_mask);
362
* Record the offsets and sizes of different state managed by the xsave
365
static void __init setup_xstate_features(void)
367
int eax, ebx, ecx, edx, leaf = 0x2;
369
xstate_features = fls64(pcntxt_mask);
370
xstate_offsets = alloc_bootmem(xstate_features * sizeof(int));
371
xstate_sizes = alloc_bootmem(xstate_features * sizeof(int));
374
cpuid_count(XSTATE_CPUID, leaf, &eax, &ebx, &ecx, &edx);
379
xstate_offsets[leaf] = ebx;
380
xstate_sizes[leaf] = eax;
304
387
* setup the xstate image representing the init state
306
389
static void __init setup_xstate_init(void)
308
init_xstate_buf = alloc_bootmem(xstate_size);
391
setup_xstate_features();
394
* Setup init_xstate_buf to represent the init state of
395
* all the features managed by the xsave
397
init_xstate_buf = alloc_bootmem_align(xstate_size,
398
__alignof__(struct xsave_struct));
309
399
init_xstate_buf->i387.mxcsr = MXCSR_DEFAULT;
403
* Init all the features state with header_bv being 0x0
405
xrstor_state(init_xstate_buf, -1);
407
* Dump the init state again. This is to identify the init state
408
* of any feature which is not represented by all zero's.
410
xsave_state(init_xstate_buf, -1);
313
415
* Enable and initialize the xsave feature.
315
void __ref xsave_cntxt_init(void)
417
static void __init xstate_enable_boot_cpu(void)
317
419
unsigned int eax, ebx, ecx, edx;
319
cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
421
if (boot_cpu_data.cpuid_level < XSTATE_CPUID) {
422
WARN(1, KERN_ERR "XSTATE_CPUID missing\n");
426
cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
320
427
pcntxt_mask = eax + ((u64)edx << 32);
322
429
if ((pcntxt_mask & XSTATE_FPSSE) != XSTATE_FPSSE) {
329
436
* Support only the state known to OS.
331
438
pcntxt_mask = pcntxt_mask & XCNTXT_MASK;
335
443
* Recompute the context size for enabled features
337
cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
445
cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
338
446
xstate_size = ebx;
448
update_regset_xstate_info(xstate_size, pcntxt_mask);
340
449
prepare_fx_sw_frame();
342
451
setup_xstate_init();
345
454
"cntxt size 0x%x\n",
346
455
pcntxt_mask, xstate_size);
459
* For the very first instance, this calls xstate_enable_boot_cpu();
460
* for all subsequent instances, this calls xstate_enable().
462
* This is somewhat obfuscated due to the lack of powerful enough
463
* overrides for the section checks.
465
void __cpuinit xsave_init(void)
467
static __refdata void (*next_func)(void) = xstate_enable_boot_cpu;
468
void (*this_func)(void);
473
this_func = next_func;
474
next_func = xstate_enable;