Skip to content

Commit

Permalink
x86/fpu: Rename copy_fpregs_to_fpstate() to save_fpregs_to_fpstate()
Browse files Browse the repository at this point in the history
A copy is guaranteed to leave the source intact, which is not the case when
FNSAVE is used as that reinitilizes the registers.

Save does not make such guarantees and it matches what this is about,
i.e. to save the state for a later restore.

Rename it to save_fpregs_to_fpstate().

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210623121454.508853062@linutronix.de
  • Loading branch information
Thomas Gleixner authored and Borislav Petkov committed Jun 23, 2021
1 parent 522e927 commit ebe7234
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions arch/x86/include/asm/fpu/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static inline int os_xrstor_safe(struct xregs_state *xstate, u64 mask)
return err;
}

extern int copy_fpregs_to_fpstate(struct fpu *fpu);
extern int save_fpregs_to_fpstate(struct fpu *fpu);

static inline void __copy_kernel_to_fpregs(union fpregs_state *fpstate, u64 mask)
{
Expand Down Expand Up @@ -507,7 +507,7 @@ static inline void __fpregs_load_activate(void)
static inline void switch_fpu_prepare(struct fpu *old_fpu, int cpu)
{
if (static_cpu_has(X86_FEATURE_FPU) && !(current->flags & PF_KTHREAD)) {
if (!copy_fpregs_to_fpstate(old_fpu))
if (!save_fpregs_to_fpstate(old_fpu))
old_fpu->last_cpu = -1;
else
old_fpu->last_cpu = cpu;
Expand Down
10 changes: 5 additions & 5 deletions arch/x86/kernel/fpu/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ EXPORT_SYMBOL(irq_fpu_usable);
* Modern FPU state can be kept in registers, if there are
* no pending FP exceptions.
*/
int copy_fpregs_to_fpstate(struct fpu *fpu)
int save_fpregs_to_fpstate(struct fpu *fpu)
{
if (likely(use_xsave())) {
os_xsave(&fpu->state.xsave);
Expand All @@ -119,7 +119,7 @@ int copy_fpregs_to_fpstate(struct fpu *fpu)

return 0;
}
EXPORT_SYMBOL(copy_fpregs_to_fpstate);
EXPORT_SYMBOL(save_fpregs_to_fpstate);

void kernel_fpu_begin_mask(unsigned int kfpu_mask)
{
Expand All @@ -137,7 +137,7 @@ void kernel_fpu_begin_mask(unsigned int kfpu_mask)
* Ignore return value -- we don't care if reg state
* is clobbered.
*/
copy_fpregs_to_fpstate(&current->thread.fpu);
save_fpregs_to_fpstate(&current->thread.fpu);
}
__cpu_invalidate_fpregs_state();

Expand Down Expand Up @@ -172,7 +172,7 @@ void fpu__save(struct fpu *fpu)
trace_x86_fpu_before_save(fpu);

if (!test_thread_flag(TIF_NEED_FPU_LOAD)) {
if (!copy_fpregs_to_fpstate(fpu)) {
if (!save_fpregs_to_fpstate(fpu)) {
copy_kernel_to_fpregs(&fpu->state);
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ int fpu__copy(struct task_struct *dst, struct task_struct *src)
if (test_thread_flag(TIF_NEED_FPU_LOAD))
memcpy(&dst_fpu->state, &src_fpu->state, fpu_kernel_xstate_size);

else if (!copy_fpregs_to_fpstate(dst_fpu))
else if (!save_fpregs_to_fpstate(dst_fpu))
copy_kernel_to_fpregs(&dst_fpu->state);

fpregs_unlock();
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -9637,7 +9637,7 @@ static void kvm_save_current_fpu(struct fpu *fpu)
memcpy(&fpu->state, &current->thread.fpu.state,
fpu_kernel_xstate_size);
else
copy_fpregs_to_fpstate(fpu);
save_fpregs_to_fpstate(fpu);
}

/* Swap (qemu) user FPU context for the guest FPU context. */
Expand Down

0 comments on commit ebe7234

Please sign in to comment.