7 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <asm/sigframe.h>
26 static struct _fpx_sw_bytes fx_sw_reserved, fx_sw_reserved_ia32;
27 static unsigned int *xstate_offsets, *xstate_sizes, xstate_features;
42 int feature_bit = 0x2;
48 xstate_bv = tsk->
thread.fpu.state->xsave.xsave_hdr.xstate_bv;
76 xstate_bv = (pcntxt_mask & ~xstate_bv) >> 2;
83 if (xstate_bv & 0x1) {
84 int offset = xstate_offsets[feature_bit];
85 int size = xstate_sizes[feature_bit];
87 memcpy(((
void *) fx) + offset,
88 ((
void *) init_xstate_buf) + offset,
102 void __user *fpstate,
135 static inline int save_fsave_header(
struct task_struct *tsk,
void __user *buf)
158 static inline int save_xstate_epilog(
void __user *buf,
int ia32_frame)
166 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
198 static inline int save_user_xstate(
struct xsave_struct __user *buf)
203 err = xsave_user(buf);
238 int ia32_fxstate = (buf != buf_fx);
251 if (user_has_fpu()) {
253 if (save_user_xstate(buf_fx))
257 fpu_fxsave(&tsk->
thread.fpu);
259 sanitize_i387_state(tsk);
265 if ((ia32_fxstate || !use_fxsr()) && save_fsave_header(tsk, buf))
268 if (use_fxsr() && save_xstate_epilog(buf_fx, ia32_fxstate))
279 u64 xstate_bv,
int fx_only)
312 static inline int restore_user_xstate(
void __user *buf,
u64 xbv,
int fx_only)
315 if ((
unsigned long)buf % 64 || fx_only) {
317 xrstor_state(init_xstate_buf, init_bv);
318 return fxrstor_user(buf);
322 xrstor_state(init_xstate_buf, init_bv);
323 return xrestore_user(buf, xbv);
325 }
else if (use_fxsr()) {
326 return fxrstor_user(buf);
328 return frstor_user(buf);
333 int ia32_fxstate = (buf != buf_fx);
361 if (
unlikely(check_for_xstate(buf_fx, buf_fx, &fx_sw_user))) {
399 sanitize_restored_xstate(tsk, &env, xstate_bv, fx_only);
413 if (restore_user_xstate(buf_fx, xstate_bv, fx_only)) {
429 static void prepare_fx_sw_frame(
void)
435 size += fsave_header_size;
438 fx_sw_reserved.extended_size =
size;
443 fx_sw_reserved_ia32 = fx_sw_reserved;
444 fx_sw_reserved_ia32.extended_size += fsave_header_size;
451 static inline void xstate_enable(
void)
461 static void __init setup_xstate_features(
void)
466 xstate_offsets =
alloc_bootmem(xstate_features *
sizeof(
int));
470 cpuid_count(
XSTATE_CPUID, leaf, &eax, &ebx, &ecx, &edx);
475 xstate_offsets[leaf] =
ebx;
476 xstate_sizes[leaf] = eax;
485 static void __init setup_init_fpu_buf(
void)
493 fx_finit(&init_xstate_buf->
i387);
498 setup_xstate_features();
503 xrstor_state(init_xstate_buf, -1);
508 xsave_state(init_xstate_buf, -1);
512 static int __init eager_fpu_setup(
char *
s)
516 else if (!
strcmp(s,
"off"))
518 else if (!
strcmp(s,
"auto"))
522 __setup(
"eagerfpu=", eager_fpu_setup);
527 static void __init xstate_enable_boot_cpu(
void)
529 unsigned int eax,
ebx,
ecx, edx;
540 pr_err(
"FP/SSE not shown under xsave features 0x%llx\n",
559 prepare_fx_sw_frame();
560 setup_init_fpu_buf();
563 if (cpu_has_xsaveopt && eagerfpu !=
DISABLE)
566 pr_info(
"enabled xstate_bv 0x%llx, cntxt size 0x%x\n",
585 this_func = next_func;
586 next_func = xstate_enable;
590 static inline void __init eager_fpu_init_bp(
void)
594 if (!init_xstate_buf)
595 setup_init_fpu_buf();
608 if (!cpu_has_eager_fpu) {
625 xrstor_state(init_xstate_buf, -1);
627 fxrstor_checking(&init_xstate_buf->
i387);