linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: X86: Do not yield to self
@ 2021-04-08 11:23 Wanpeng Li
  2021-04-08 16:56 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Wanpeng Li @ 2021-04-08 11:23 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

From: Wanpeng Li <wanpengli@tencent.com>

If the target is self we do not need to yield, we can avoid malicious 
guest to play this.

Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
Rebased on https://lore.kernel.org/kvm/1617697935-4158-1-git-send-email-wanpengli@tencent.com/

 arch/x86/kvm/x86.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 43c9f9b..260650f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8230,6 +8230,10 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
 	if (!target)
 		goto no_yield;
 
+	/* yield to self */
+	if (vcpu->vcpu_id == target->vcpu_id)
+		goto no_yield;
+
 	if (!READ_ONCE(target->ready))
 		goto no_yield;
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: X86: Do not yield to self
  2021-04-08 11:23 [PATCH] KVM: X86: Do not yield to self Wanpeng Li
@ 2021-04-08 16:56 ` Sean Christopherson
  2021-04-09  3:05   ` Wanpeng Li
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2021-04-08 16:56 UTC (permalink / raw)
  To: Wanpeng Li
  Cc: linux-kernel, kvm, Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

On Thu, Apr 08, 2021, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
> 
> If the target is self we do not need to yield, we can avoid malicious 
> guest to play this.
> 
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> Rebased on https://lore.kernel.org/kvm/1617697935-4158-1-git-send-email-wanpengli@tencent.com/
> 
>  arch/x86/kvm/x86.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 43c9f9b..260650f 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8230,6 +8230,10 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
>  	if (!target)
>  		goto no_yield;
>  
> +	/* yield to self */

If you're going to bother with a comment, maybe elaborate a bit, e.g.

	/* Ignore requests to yield to self. */

> +	if (vcpu->vcpu_id == target->vcpu_id)
> +		goto no_yield;
> +
>  	if (!READ_ONCE(target->ready))
>  		goto no_yield;
>  
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: X86: Do not yield to self
  2021-04-08 16:56 ` Sean Christopherson
@ 2021-04-09  3:05   ` Wanpeng Li
  0 siblings, 0 replies; 3+ messages in thread
From: Wanpeng Li @ 2021-04-09  3:05 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: LKML, kvm, Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

On Fri, 9 Apr 2021 at 00:56, Sean Christopherson <seanjc@google.com> wrote:
>
> On Thu, Apr 08, 2021, Wanpeng Li wrote:
> > From: Wanpeng Li <wanpengli@tencent.com>
> >
> > If the target is self we do not need to yield, we can avoid malicious
> > guest to play this.
> >
> > Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> > ---
> > Rebased on https://lore.kernel.org/kvm/1617697935-4158-1-git-send-email-wanpengli@tencent.com/
> >
> >  arch/x86/kvm/x86.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 43c9f9b..260650f 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -8230,6 +8230,10 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
> >       if (!target)
> >               goto no_yield;
> >
> > +     /* yield to self */
>
> If you're going to bother with a comment, maybe elaborate a bit, e.g.
>
>         /* Ignore requests to yield to self. */

Looks good, thanks.

    Wanpeng

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-09  3:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 11:23 [PATCH] KVM: X86: Do not yield to self Wanpeng Li
2021-04-08 16:56 ` Sean Christopherson
2021-04-09  3:05   ` Wanpeng Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).