2021-04-08 19:14:40

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH] KVM: X86: Do not yield to self

On Thu, Apr 08, 2021, Wanpeng Li wrote:
> From: Wanpeng Li <[email protected]>
>
> If the target is self we do not need to yield, we can avoid malicious
> guest to play this.
>
> Signed-off-by: Wanpeng Li <[email protected]>
> ---
> Rebased on https://lore.kernel.org/kvm/[email protected]/
>
> 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
>


2021-04-09 03:07:10

by Wanpeng Li

[permalink] [raw]
Subject: Re: [PATCH] KVM: X86: Do not yield to self

On Fri, 9 Apr 2021 at 00:56, Sean Christopherson <[email protected]> wrote:
>
> On Thu, Apr 08, 2021, Wanpeng Li wrote:
> > From: Wanpeng Li <[email protected]>
> >
> > If the target is self we do not need to yield, we can avoid malicious
> > guest to play this.
> >
> > Signed-off-by: Wanpeng Li <[email protected]>
> > ---
> > Rebased on https://lore.kernel.org/kvm/[email protected]/
> >
> > 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