Browse Source

x86/fpu: Standardize the parameter type of copy_kernel_to_fpregs()

Bring the __copy_fpstate_to_fpregs() and copy_fpstate_to_fpregs() functions
in line with the parameter passing convention of other kernel-to-FPU-registers
copying functions: pass around an in-memory FPU register state pointer,
instead of struct fpu *.

NOTE: This patch also changes the assembly constraint of the FXSAVE-leak
      workaround from 'fpu->fpregs_active' to 'fpstate' - but that is fine,
      as we only need a valid memory address there for the FILDL instruction.

Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Bobby Powers <bobbypowers@gmail.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Ingo Molnar 10 years ago
parent
commit
003e2e8b57
3 changed files with 11 additions and 11 deletions
  1. 8 8
      arch/x86/include/asm/fpu/internal.h
  2. 2 2
      arch/x86/kernel/fpu/core.c
  3. 1 1
      arch/x86/kvm/x86.c

+ 8 - 8
arch/x86/include/asm/fpu/internal.h

@@ -446,19 +446,19 @@ static inline int copy_fpregs_to_fpstate(struct fpu *fpu)
 	return 0;
 	return 0;
 }
 }
 
 
-static inline void __copy_kernel_to_fpregs(struct fpu *fpu)
+static inline void __copy_kernel_to_fpregs(union fpregs_state *fpstate)
 {
 {
 	if (use_xsave()) {
 	if (use_xsave()) {
-		copy_kernel_to_xregs(&fpu->state.xsave, -1);
+		copy_kernel_to_xregs(&fpstate->xsave, -1);
 	} else {
 	} else {
 		if (use_fxsr())
 		if (use_fxsr())
-			copy_kernel_to_fxregs(&fpu->state.fxsave);
+			copy_kernel_to_fxregs(&fpstate->fxsave);
 		else
 		else
-			copy_kernel_to_fregs(&fpu->state.fsave);
+			copy_kernel_to_fregs(&fpstate->fsave);
 	}
 	}
 }
 }
 
 
-static inline void copy_kernel_to_fpregs(struct fpu *fpu)
+static inline void copy_kernel_to_fpregs(union fpregs_state *fpstate)
 {
 {
 	/*
 	/*
 	 * AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception is
 	 * AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception is
@@ -470,10 +470,10 @@ static inline void copy_kernel_to_fpregs(struct fpu *fpu)
 			"fnclex\n\t"
 			"fnclex\n\t"
 			"emms\n\t"
 			"emms\n\t"
 			"fildl %P[addr]"	/* set F?P to defined value */
 			"fildl %P[addr]"	/* set F?P to defined value */
-			: : [addr] "m" (fpu->fpregs_active));
+			: : [addr] "m" (fpstate));
 	}
 	}
 
 
-	__copy_kernel_to_fpregs(fpu);
+	__copy_kernel_to_fpregs(fpstate);
 }
 }
 
 
 extern int copy_fpstate_to_sigframe(void __user *buf, void __user *fp, int size);
 extern int copy_fpstate_to_sigframe(void __user *buf, void __user *fp, int size);
@@ -642,7 +642,7 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
 static inline void switch_fpu_finish(struct fpu *new_fpu, fpu_switch_t fpu_switch)
 static inline void switch_fpu_finish(struct fpu *new_fpu, fpu_switch_t fpu_switch)
 {
 {
 	if (fpu_switch.preload)
 	if (fpu_switch.preload)
-		copy_kernel_to_fpregs(new_fpu);
+		copy_kernel_to_fpregs(&new_fpu->state);
 }
 }
 
 
 /*
 /*

+ 2 - 2
arch/x86/kernel/fpu/core.c

@@ -127,7 +127,7 @@ void __kernel_fpu_end(void)
 	struct fpu *fpu = &current->thread.fpu;
 	struct fpu *fpu = &current->thread.fpu;
 
 
 	if (fpu->fpregs_active)
 	if (fpu->fpregs_active)
-		copy_kernel_to_fpregs(fpu);
+		copy_kernel_to_fpregs(&fpu->state);
 	else
 	else
 		__fpregs_deactivate_hw();
 		__fpregs_deactivate_hw();
 
 
@@ -368,7 +368,7 @@ void fpu__restore(struct fpu *fpu)
 	/* Avoid __kernel_fpu_begin() right after fpregs_activate() */
 	/* Avoid __kernel_fpu_begin() right after fpregs_activate() */
 	kernel_fpu_disable();
 	kernel_fpu_disable();
 	fpregs_activate(fpu);
 	fpregs_activate(fpu);
-	copy_kernel_to_fpregs(fpu);
+	copy_kernel_to_fpregs(&fpu->state);
 	fpu->counter++;
 	fpu->counter++;
 	kernel_fpu_enable();
 	kernel_fpu_enable();
 }
 }

+ 1 - 1
arch/x86/kvm/x86.c

@@ -7030,7 +7030,7 @@ void kvm_load_guest_fpu(struct kvm_vcpu *vcpu)
 	kvm_put_guest_xcr0(vcpu);
 	kvm_put_guest_xcr0(vcpu);
 	vcpu->guest_fpu_loaded = 1;
 	vcpu->guest_fpu_loaded = 1;
 	__kernel_fpu_begin();
 	__kernel_fpu_begin();
-	__copy_kernel_to_fpregs(&vcpu->arch.guest_fpu);
+	__copy_kernel_to_fpregs(&vcpu->arch.guest_fpu.state);
 	trace_kvm_fpu(1);
 	trace_kvm_fpu(1);
 }
 }