Commit 64468860 authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Greg Kroah-Hartman

Revert "kvm: x86: Use task structs fpu field for user"

commit ec269475 upstream.

This reverts commit 240c35a3
("kvm: x86: Use task structs fpu field for user", 2018-11-06).
The commit is broken and causes QEMU's FPU state to be destroyed
when KVM_RUN is preempted.

Fixes: 240c35a3 ("kvm: x86: Use task structs fpu field for user")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 79a43134
...@@ -609,15 +609,16 @@ struct kvm_vcpu_arch { ...@@ -609,15 +609,16 @@ struct kvm_vcpu_arch {
/* /*
* QEMU userspace and the guest each have their own FPU state. * QEMU userspace and the guest each have their own FPU state.
* In vcpu_run, we switch between the user, maintained in the * In vcpu_run, we switch between the user and guest FPU contexts.
* task_struct struct, and guest FPU contexts. While running a VCPU, * While running a VCPU, the VCPU thread will have the guest FPU
* the VCPU thread will have the guest FPU context. * context.
* *
* Note that while the PKRU state lives inside the fpu registers, * Note that while the PKRU state lives inside the fpu registers,
* it is switched out separately at VMENTER and VMEXIT time. The * it is switched out separately at VMENTER and VMEXIT time. The
* "guest_fpu" state here contains the guest FPU context, with the * "guest_fpu" state here contains the guest FPU context, with the
* host PRKU bits. * host PRKU bits.
*/ */
struct fpu user_fpu;
struct fpu *guest_fpu; struct fpu *guest_fpu;
u64 xcr0; u64 xcr0;
......
...@@ -8172,7 +8172,7 @@ static int complete_emulated_mmio(struct kvm_vcpu *vcpu) ...@@ -8172,7 +8172,7 @@ static int complete_emulated_mmio(struct kvm_vcpu *vcpu)
static void kvm_load_guest_fpu(struct kvm_vcpu *vcpu) static void kvm_load_guest_fpu(struct kvm_vcpu *vcpu)
{ {
preempt_disable(); preempt_disable();
copy_fpregs_to_fpstate(&current->thread.fpu); copy_fpregs_to_fpstate(&vcpu->arch.user_fpu);
/* PKRU is separately restored in kvm_x86_ops->run. */ /* PKRU is separately restored in kvm_x86_ops->run. */
__copy_kernel_to_fpregs(&vcpu->arch.guest_fpu->state, __copy_kernel_to_fpregs(&vcpu->arch.guest_fpu->state,
~XFEATURE_MASK_PKRU); ~XFEATURE_MASK_PKRU);
...@@ -8185,7 +8185,7 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) ...@@ -8185,7 +8185,7 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
{ {
preempt_disable(); preempt_disable();
copy_fpregs_to_fpstate(vcpu->arch.guest_fpu); copy_fpregs_to_fpstate(vcpu->arch.guest_fpu);
copy_kernel_to_fpregs(&current->thread.fpu.state); copy_kernel_to_fpregs(&vcpu->arch.user_fpu.state);
preempt_enable(); preempt_enable();
++vcpu->stat.fpu_reload; ++vcpu->stat.fpu_reload;
trace_kvm_fpu(0); trace_kvm_fpu(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment