mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>
Subject: Re: [PATCH] KVM: fix avic_set_running for preemptable kernels
Date: Tue, 30 Nov 2021 12:00:22 +0200	[thread overview]
Message-ID: <37f072bb6c5b27ec71ec40bd2e34d75c54d9ff69.camel@redhat.com> (raw)
In-Reply-To: <20211130084644.248435-1-pbonzini@redhat.com>

On Tue, 2021-11-30 at 03:46 -0500, Paolo Bonzini wrote:
> avic_set_running() passes the current CPU to avic_vcpu_load(), albeit
> via vcpu->cpu rather than smp_processor_id().  If the thread is migrated
> while avic_set_running runs, the call to avic_vcpu_load() can use a stale
> value for the processor id.  Avoid this by blocking preemption over the
> entire execution of avic_set_running().
> 
> Reported-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/svm/avic.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
> index 0a58283005f3..560807a2edd4 100644
> --- a/arch/x86/kvm/svm/avic.c
> +++ b/arch/x86/kvm/svm/avic.c
> @@ -1000,16 +1000,18 @@ void avic_vcpu_put(struct kvm_vcpu *vcpu)
>  static void avic_set_running(struct kvm_vcpu *vcpu, bool is_run)
>  {
>  	struct vcpu_svm *svm = to_svm(vcpu);
> +	int cpu = get_cpu();
>  
> +	WARN_ON(cpu != vcpu->cpu);
>  	svm->avic_is_running = is_run;
>  
> -	if (!kvm_vcpu_apicv_active(vcpu))
> -		return;
> -
> -	if (is_run)
> -		avic_vcpu_load(vcpu, vcpu->cpu);
> -	else
> -		avic_vcpu_put(vcpu);
> +	if (kvm_vcpu_apicv_active(vcpu)) {
> +		if (is_run)
> +			avic_vcpu_load(vcpu, cpu);
> +		else
> +			avic_vcpu_put(vcpu);
> +	}
> +	put_cpu();
>  }
>  
>  void svm_vcpu_blocking(struct kvm_vcpu *vcpu)

To be honest, I was thinking to remove vcpu parameter from
avic_vcpu_load and let it figure it out, but this can be
always done later.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>

PS: this patch as expected didn't help with the 'is_running' AVIC bug
I am stuck with.

Best regards,
	Maxim Levitsky


      reply	other threads:[~2021-11-30 10:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30  8:46 Paolo Bonzini
2021-11-30 10:00 ` Maxim Levitsky [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37f072bb6c5b27ec71ec40bd2e34d75c54d9ff69.camel@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome