From: Wanpeng Li Date: Fri, 9 Apr 2021 04:18:31 +0000 (+0800) Subject: KVM: X86: Do not yield to self X-Git-Tag: v5.13-rc1~76^2~92 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a1fa4cbd53d9bc7bb0eaa7bcf7c8a5904372a4ec;p=thirdparty%2Fkernel%2Flinux.git KVM: X86: Do not yield to self If the target is self we do not need to yield, we can avoid malicious guest to play this. Signed-off-by: Wanpeng Li Message-Id: <1617941911-5338-3-git-send-email-wanpengli@tencent.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini --- diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 05a4bce181d7c..66d2ab074a5f3 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8228,6 +8228,10 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id) if (!target || !READ_ONCE(target->ready)) goto no_yield; + /* Ignore requests to yield to self */ + if (vcpu == target) + goto no_yield; + if (kvm_vcpu_yield_to(target) <= 0) goto no_yield;