* [PATCH] KVM: x86: Add a WARN on TIF_NEED_FPU_LOAD in kvm_load_guest_fpu()
@ 2019-12-09 20:05 Sean Christopherson
2019-12-10 10:29 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2019-12-09 20:05 UTC (permalink / raw)
To: Paolo Bonzini, Radim Krčmář
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel
WARN once in kvm_load_guest_fpu() if TIF_NEED_FPU_LOAD is observed, as
that would mean that KVM is corrupting userspace's FPU by saving
unknown register state into arch.user_fpu. Add a comment to explain
why KVM WARNs on TIF_NEED_FPU_LOAD instead of implementing logic
similar to fpu__copy().
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
arch/x86/kvm/x86.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 3ed167e039e5..f2c8a053b017 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8474,6 +8474,13 @@ static void kvm_load_guest_fpu(struct kvm_vcpu *vcpu)
{
fpregs_lock();
+ /*
+ * Reloading userspace's FPU is handled by kvm_arch_vcpu_load(), both
+ * for direct calls from userspace (via vcpu_load()) and if this task
+ * is preempted (via kvm_arch_sched_in()) between vcpu_load() and now.
+ */
+ WARN_ON_ONCE(test_thread_flag(TIF_NEED_FPU_LOAD));
+
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,
--
2.24.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] KVM: x86: Add a WARN on TIF_NEED_FPU_LOAD in kvm_load_guest_fpu()
2019-12-09 20:05 [PATCH] KVM: x86: Add a WARN on TIF_NEED_FPU_LOAD in kvm_load_guest_fpu() Sean Christopherson
@ 2019-12-10 10:29 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2019-12-10 10:29 UTC (permalink / raw)
To: Sean Christopherson, Radim Krčmář
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel
On 09/12/19 21:05, Sean Christopherson wrote:
> + /*
> + * Reloading userspace's FPU is handled by kvm_arch_vcpu_load(), both
> + * for direct calls from userspace (via vcpu_load()) and if this task
> + * is preempted (via kvm_arch_sched_in()) between vcpu_load() and now.
via kvm_sched_in (not the arch_ function). Applied with that change.
Paolo
> + */
> + WARN_ON_ONCE(test_thread_flag(TIF_NEED_FPU_LOAD));
> +
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-12-10 10:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-09 20:05 [PATCH] KVM: x86: Add a WARN on TIF_NEED_FPU_LOAD in kvm_load_guest_fpu() Sean Christopherson
2019-12-10 10:29 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®