|
20 | 20 | #include "legacy.h"
|
21 | 21 | #include "xstate.h"
|
22 | 22 |
|
23 |
| -static struct _fpx_sw_bytes fx_sw_reserved __ro_after_init; |
24 |
| -static struct _fpx_sw_bytes fx_sw_reserved_ia32 __ro_after_init; |
25 |
| - |
26 | 23 | /*
|
27 | 24 | * Check for the presence of extended state information in the
|
28 | 25 | * user fpstate pointer in the sigcontext.
|
@@ -98,23 +95,42 @@ static inline bool save_fsave_header(struct task_struct *tsk, void __user *buf)
|
98 | 95 | return true;
|
99 | 96 | }
|
100 | 97 |
|
| 98 | +/* |
| 99 | + * Prepare the SW reserved portion of the fxsave memory layout, indicating |
| 100 | + * the presence of the extended state information in the memory layout |
| 101 | + * pointed to by the fpstate pointer in the sigcontext. |
| 102 | + * This is saved when ever the FP and extended state context is |
| 103 | + * saved on the user stack during the signal handler delivery to the user. |
| 104 | + */ |
| 105 | +static inline void save_sw_bytes(struct _fpx_sw_bytes *sw_bytes, bool ia32_frame, |
| 106 | + struct fpstate *fpstate) |
| 107 | +{ |
| 108 | + sw_bytes->magic1 = FP_XSTATE_MAGIC1; |
| 109 | + sw_bytes->extended_size = fpstate->user_size + FP_XSTATE_MAGIC2_SIZE; |
| 110 | + sw_bytes->xfeatures = fpstate->user_xfeatures; |
| 111 | + sw_bytes->xstate_size = fpstate->user_size; |
| 112 | + |
| 113 | + if (ia32_frame) |
| 114 | + sw_bytes->extended_size += sizeof(struct fregs_state); |
| 115 | +} |
| 116 | + |
101 | 117 | static inline bool save_xstate_epilog(void __user *buf, int ia32_frame,
|
102 |
| - unsigned int usize) |
| 118 | + struct fpstate *fpstate) |
103 | 119 | {
|
104 | 120 | struct xregs_state __user *x = buf;
|
105 |
| - struct _fpx_sw_bytes *sw_bytes; |
| 121 | + struct _fpx_sw_bytes sw_bytes; |
106 | 122 | u32 xfeatures;
|
107 | 123 | int err;
|
108 | 124 |
|
109 | 125 | /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
|
110 |
| - sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved; |
111 |
| - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes)); |
| 126 | + save_sw_bytes(&sw_bytes, ia32_frame, fpstate); |
| 127 | + err = __copy_to_user(&x->i387.sw_reserved, &sw_bytes, sizeof(sw_bytes)); |
112 | 128 |
|
113 | 129 | if (!use_xsave())
|
114 | 130 | return !err;
|
115 | 131 |
|
116 | 132 | err |= __put_user(FP_XSTATE_MAGIC2,
|
117 |
| - (__u32 __user *)(buf + usize)); |
| 133 | + (__u32 __user *)(buf + fpstate->user_size)); |
118 | 134 |
|
119 | 135 | /*
|
120 | 136 | * Read the xfeatures which we copied (directly from the cpu or
|
@@ -173,7 +189,7 @@ bool copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
|
173 | 189 | {
|
174 | 190 | struct task_struct *tsk = current;
|
175 | 191 | struct fpstate *fpstate = tsk->thread.fpu.fpstate;
|
176 |
| - int ia32_fxstate = (buf != buf_fx); |
| 192 | + bool ia32_fxstate = (buf != buf_fx); |
177 | 193 | int ret;
|
178 | 194 |
|
179 | 195 | ia32_fxstate &= (IS_ENABLED(CONFIG_X86_32) ||
|
@@ -226,8 +242,7 @@ bool copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
|
226 | 242 | if ((ia32_fxstate || !use_fxsr()) && !save_fsave_header(tsk, buf))
|
227 | 243 | return false;
|
228 | 244 |
|
229 |
| - if (use_fxsr() && |
230 |
| - !save_xstate_epilog(buf_fx, ia32_fxstate, fpstate->user_size)) |
| 245 | + if (use_fxsr() && !save_xstate_epilog(buf_fx, ia32_fxstate, fpstate)) |
231 | 246 | return false;
|
232 | 247 |
|
233 | 248 | return true;
|
@@ -523,28 +538,3 @@ unsigned long __init fpu__get_fpstate_size(void)
|
523 | 538 | return ret;
|
524 | 539 | }
|
525 | 540 |
|
526 |
| -/* |
527 |
| - * Prepare the SW reserved portion of the fxsave memory layout, indicating |
528 |
| - * the presence of the extended state information in the memory layout |
529 |
| - * pointed by the fpstate pointer in the sigcontext. |
530 |
| - * This will be saved when ever the FP and extended state context is |
531 |
| - * saved on the user stack during the signal handler delivery to the user. |
532 |
| - */ |
533 |
| -void __init fpu__init_prepare_fx_sw_frame(void) |
534 |
| -{ |
535 |
| - int size = fpu_user_cfg.default_size + FP_XSTATE_MAGIC2_SIZE; |
536 |
| - |
537 |
| - fx_sw_reserved.magic1 = FP_XSTATE_MAGIC1; |
538 |
| - fx_sw_reserved.extended_size = size; |
539 |
| - fx_sw_reserved.xfeatures = fpu_user_cfg.default_features; |
540 |
| - fx_sw_reserved.xstate_size = fpu_user_cfg.default_size; |
541 |
| - |
542 |
| - if (IS_ENABLED(CONFIG_IA32_EMULATION) || |
543 |
| - IS_ENABLED(CONFIG_X86_32)) { |
544 |
| - int fsave_header_size = sizeof(struct fregs_state); |
545 |
| - |
546 |
| - fx_sw_reserved_ia32 = fx_sw_reserved; |
547 |
| - fx_sw_reserved_ia32.extended_size = size + fsave_header_size; |
548 |
| - } |
549 |
| -} |
550 |
| - |
0 commit comments