Skip to content

Commit fbcc9e0

Browse files
Sebastian Andrzej Siewiorsuryasaimadhu
authored andcommitted
x86/fpu: Remove fpu->initialized usage in copy_fpstate_to_sigframe()
With lazy-FPU support the (now named variable) ->initialized was set to true if the CPU's FPU registers were holding a valid state of the FPU registers for the active process. If it was set to false then the FPU state was saved in fpu->state and the FPU was deactivated. With lazy-FPU gone, ->initialized is always true for user threads and kernel threads never call this function so ->initialized is always true in copy_fpstate_to_sigframe(). The using_compacted_format() check is also a leftover from the lazy-FPU time. In the ->initialized == false case copy_to_user() would copy the compacted buffer while userland would expect the non-compacted format instead. So in order to save the FPU state in the non-compacted form it issues XSAVE to save the *current* FPU state. If the FPU is not enabled, the attempt raises the FPU trap, the trap restores the FPU contents and re-enables the FPU and XSAVE is invoked again and succeeds. *This* does not longer work since commit bef8b6d ("x86/fpu: Handle #NM without FPU emulation as an error") Remove the check for ->initialized because it is always true and remove the false condition. Update the comment to reflect that the state is always live. [ bp: Massage. ] Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jann Horn <[email protected]> Cc: "Jason A. Donenfeld" <[email protected]> Cc: kvm ML <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Radim Krčmář <[email protected]> Cc: Rik van Riel <[email protected]> Cc: x86-ml <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 88f5260 commit fbcc9e0

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

arch/x86/kernel/fpu/signal.c

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ static inline int copy_fpregs_to_sigframe(struct xregs_state __user *buf)
144144
* buf == buf_fx for 64-bit frames and 32-bit fsave frame.
145145
* buf != buf_fx for 32-bit frames with fxstate.
146146
*
147-
* If the fpu, extended register state is live, save the state directly
148-
* to the user frame pointed by the aligned pointer 'buf_fx'. Otherwise,
149-
* copy the thread's fpu state to the user frame starting at 'buf_fx'.
147+
* Save the state directly to the user frame pointed by the aligned pointer
148+
* 'buf_fx'.
150149
*
151150
* If this is a 32-bit frame with fxstate, put a fsave header before
152151
* the aligned state at 'buf_fx'.
@@ -157,7 +156,6 @@ static inline int copy_fpregs_to_sigframe(struct xregs_state __user *buf)
157156
int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
158157
{
159158
struct fpu *fpu = &current->thread.fpu;
160-
struct xregs_state *xsave = &fpu->state.xsave;
161159
struct task_struct *tsk = current;
162160
int ia32_fxstate = (buf != buf_fx);
163161

@@ -172,29 +170,12 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
172170
sizeof(struct user_i387_ia32_struct), NULL,
173171
(struct _fpstate_32 __user *) buf) ? -1 : 1;
174172

175-
if (fpu->initialized || using_compacted_format()) {
176-
/* Save the live register state to the user directly. */
177-
if (copy_fpregs_to_sigframe(buf_fx))
178-
return -1;
179-
/* Update the thread's fxstate to save the fsave header. */
180-
if (ia32_fxstate)
181-
copy_fxregs_to_kernel(fpu);
182-
} else {
183-
/*
184-
* It is a *bug* if kernel uses compacted-format for xsave
185-
* area and we copy it out directly to a signal frame. It
186-
* should have been handled above by saving the registers
187-
* directly.
188-
*/
189-
if (boot_cpu_has(X86_FEATURE_XSAVES)) {
190-
WARN_ONCE(1, "x86/fpu: saving compacted-format xsave area to a signal frame!\n");
191-
return -1;
192-
}
193-
194-
fpstate_sanitize_xstate(fpu);
195-
if (__copy_to_user(buf_fx, xsave, fpu_user_xstate_size))
196-
return -1;
197-
}
173+
/* Save the live registers state to the user frame directly. */
174+
if (copy_fpregs_to_sigframe(buf_fx))
175+
return -1;
176+
/* Update the thread's fxstate to save the fsave header. */
177+
if (ia32_fxstate)
178+
copy_fxregs_to_kernel(fpu);
198179

199180
/* Save the fsave header for the 32-bit frames. */
200181
if ((ia32_fxstate || !use_fxsr()) && save_fsave_header(tsk, buf))

0 commit comments

Comments
 (0)