From 6288031dacbe753b84515d330f62c1f8ed31d932 Mon Sep 17 00:00:00 2001 From: Sean Christopherson Date: Wed, 20 Nov 2019 10:12:56 -0800 Subject: [PATCH] thread_info: Add a debug hook to detect FPU changes while a vCPU is loaded Signed-off-by: Sean Christopherson --- arch/x86/include/asm/thread_info.h | 2 ++ arch/x86/kvm/x86.c | 4 ++++ include/linux/thread_info.h | 1 + 3 files changed, 7 insertions(+) diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index f9453536f9bb..7b697005cc51 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h @@ -56,6 +56,8 @@ struct task_struct; struct thread_info { unsigned long flags; /* low level flags */ u32 status; /* thread synchronous flags */ + bool vcpu_loaded; + }; #define INIT_THREAD_INFO(tsk) \ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a8ad3a4d86b1..3d9c049e749e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3303,6 +3303,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) } kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu); + + current_thread_info()->vcpu_loaded = 1; } static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu) @@ -3322,6 +3324,8 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) { int idx; + current_thread_info()->vcpu_loaded = 0; + if (vcpu->preempted) vcpu->arch.preempted_in_kernel = !kvm_x86_ops->get_cpl(vcpu); diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index 8d8821b3689a..016c2c887354 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -52,6 +52,7 @@ enum { static inline void set_ti_thread_flag(struct thread_info *ti, int flag) { + WARN_ON_ONCE(ti->vcpu_loaded && flag == TIF_NEED_FPU_LOAD); set_bit(flag, (unsigned long *)&ti->flags); } -- 2.24.0