OSDN Git Service

Revert "kvm: x86: Use task structs fpu field for user"
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 22 Jul 2019 11:31:27 +0000 (13:31 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 22 Jul 2019 11:55:47 +0000 (13:55 +0200)
This reverts commit 240c35a3783ab9b3a0afaba0dde7291295680a6b
("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: 240c35a3783a ("kvm: x86: Use task structs fpu field for user")
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/x86.c

index 0cc5b61..b2f1ffb 100644 (file)
@@ -607,15 +607,16 @@ struct kvm_vcpu_arch {
 
        /*
         * QEMU userspace and the guest each have their own FPU state.
-        * In vcpu_run, we switch between the user, maintained in the
-        * task_struct struct, and guest FPU contexts. While running a VCPU,
-        * the VCPU thread will have the guest FPU context.
+        * In vcpu_run, we switch between the user and guest FPU contexts.
+        * While running a VCPU, the VCPU thread will have the guest FPU
+        * context.
         *
         * Note that while the PKRU state lives inside the fpu registers,
         * it is switched out separately at VMENTER and VMEXIT time. The
         * "guest_fpu" state here contains the guest FPU context, with the
         * host PRKU bits.
         */
+       struct fpu user_fpu;
        struct fpu *guest_fpu;
 
        u64 xcr0;
index 58305cf..cf2afdf 100644 (file)
@@ -8270,7 +8270,7 @@ static void kvm_load_guest_fpu(struct kvm_vcpu *vcpu)
 {
        fpregs_lock();
 
-       copy_fpregs_to_fpstate(&current->thread.fpu);
+       copy_fpregs_to_fpstate(&vcpu->arch.user_fpu);
        /* PKRU is separately restored in kvm_x86_ops->run.  */
        __copy_kernel_to_fpregs(&vcpu->arch.guest_fpu->state,
                                ~XFEATURE_MASK_PKRU);
@@ -8287,7 +8287,7 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
        fpregs_lock();
 
        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);
 
        fpregs_mark_activate();
        fpregs_unlock();