Explorar o código

KVM: avoid fx_init() schedule in atomic

This make sure not to schedule in atomic during fx_init. I also
changed the name of fpu_init to fx_finit to avoid duplicating the name
with fpu_init that is already used in the kernel, this makes grep
simpler if nothing else.

Signed-off-by: Andrea Arcangeli <andrea@qumranet.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Andrea Arcangeli %!s(int64=17) %!d(string=hai) anos
pai
achega
bc1a34f1bf
Modificáronse 2 ficheiros con 11 adicións e 2 borrados
  1. 10 1
      arch/x86/kvm/x86.c
  2. 1 1
      include/asm-x86/kvm_host.h

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

@@ -3703,10 +3703,19 @@ void fx_init(struct kvm_vcpu *vcpu)
 {
 {
 	unsigned after_mxcsr_mask;
 	unsigned after_mxcsr_mask;
 
 
+	/*
+	 * Touch the fpu the first time in non atomic context as if
+	 * this is the first fpu instruction the exception handler
+	 * will fire before the instruction returns and it'll have to
+	 * allocate ram with GFP_KERNEL.
+	 */
+	if (!used_math())
+		fx_save(&vcpu->arch.host_fx_image);
+
 	/* Initialize guest FPU by resetting ours and saving into guest's */
 	/* Initialize guest FPU by resetting ours and saving into guest's */
 	preempt_disable();
 	preempt_disable();
 	fx_save(&vcpu->arch.host_fx_image);
 	fx_save(&vcpu->arch.host_fx_image);
-	fpu_init();
+	fx_finit();
 	fx_save(&vcpu->arch.guest_fx_image);
 	fx_save(&vcpu->arch.guest_fx_image);
 	fx_restore(&vcpu->arch.host_fx_image);
 	fx_restore(&vcpu->arch.host_fx_image);
 	preempt_enable();
 	preempt_enable();

+ 1 - 1
include/asm-x86/kvm_host.h

@@ -627,7 +627,7 @@ static inline void fx_restore(struct i387_fxsave_struct *image)
 	asm("fxrstor (%0)":: "r" (image));
 	asm("fxrstor (%0)":: "r" (image));
 }
 }
 
 
-static inline void fpu_init(void)
+static inline void fx_finit(void)
 {
 {
 	asm("finit");
 	asm("finit");
 }
 }