Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: X86: Fix fpu state crash in kvm guest

The idea before commit 240c35a37 (which has just been reverted)
was that we have the following FPU states:

userspace (QEMU) guest
---------------------------------------------------------------------------
processor vcpu->arch.guest_fpu
>>> KVM_RUN: kvm_load_guest_fpu
vcpu->arch.user_fpu processor
>>> preempt out
vcpu->arch.user_fpu current->thread.fpu
>>> preempt in
vcpu->arch.user_fpu processor
>>> back to userspace
>>> kvm_put_guest_fpu
processor vcpu->arch.guest_fpu
---------------------------------------------------------------------------

With the new lazy model we want to get the state back to the processor
when schedule in from current->thread.fpu.

Reported-by: Thomas Lambertz <mail@thomaslambertz.de>
Reported-by: anthony <antdev66@gmail.com>
Tested-by: anthony <antdev66@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Thomas Lambertz <mail@thomaslambertz.de>
Cc: anthony <antdev66@gmail.com>
Cc: stable@vger.kernel.org
Fixes: 5f409e20b (x86/fpu: Defer FPU state load until return to userspace)
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
[Add a comment in front of the warning. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Wanpeng Li and committed by
Paolo Bonzini
e7517324 ec269475

+6 -3
+6 -3
arch/x86/kvm/x86.c
··· 3306 3306 3307 3307 kvm_x86_ops->vcpu_load(vcpu, cpu); 3308 3308 3309 + fpregs_assert_state_consistent(); 3310 + if (test_thread_flag(TIF_NEED_FPU_LOAD)) 3311 + switch_fpu_return(); 3312 + 3309 3313 /* Apply any externally detected TSC adjustments (due to suspend) */ 3310 3314 if (unlikely(vcpu->arch.tsc_offset_adjustment)) { 3311 3315 adjust_tsc_offset_host(vcpu, vcpu->arch.tsc_offset_adjustment); ··· 7994 7990 trace_kvm_entry(vcpu->vcpu_id); 7995 7991 guest_enter_irqoff(); 7996 7992 7997 - fpregs_assert_state_consistent(); 7998 - if (test_thread_flag(TIF_NEED_FPU_LOAD)) 7999 - switch_fpu_return(); 7993 + /* The preempt notifier should have taken care of the FPU already. */ 7994 + WARN_ON_ONCE(test_thread_flag(TIF_NEED_FPU_LOAD)); 8000 7995 8001 7996 if (unlikely(vcpu->arch.switch_db_regs)) { 8002 7997 set_debugreg(0, 7);