public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Mingwei Zhang <mizhang@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dapeng Mi <dapeng1.mi@intel.com>,
	Jim Mattson <jmattson@google.com>, Like Xu <likexu@tencent.com>
Subject: Re: [PATCH] KVM: vPMU: Use atomic bit operations for global_status
Date: Mon, 11 Sep 2023 08:01:44 -0700	[thread overview]
Message-ID: <ZP8r2CDsv3JkGYzX@google.com> (raw)
In-Reply-To: <20230911061147.409152-1-mizhang@google.com>

On Mon, Sep 11, 2023, Mingwei Zhang wrote:
> Use atomic bit operations for pmu->global_status because it may suffer from
> race conditions between emulated overflow in KVM vPMU and PEBS overflow in
> host PMI handler.

Only if the host PMI occurs on a different pCPU, and if that can happen don't we
have a much larger problem?

> Fixes: f331601c65ad ("KVM: x86/pmu: Don't generate PEBS records for emulated instructions")
> Signed-off-by: Mingwei Zhang <mizhang@google.com>
> ---
>  arch/x86/kvm/pmu.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index edb89b51b383..00b48f25afdb 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -117,11 +117,11 @@ static inline void __kvm_perf_overflow(struct kvm_pmc *pmc, bool in_pmi)
>  			skip_pmi = true;
>  		} else {
>  			/* Indicate PEBS overflow PMI to guest. */
> -			skip_pmi = __test_and_set_bit(GLOBAL_STATUS_BUFFER_OVF_BIT,
> -						      (unsigned long *)&pmu->global_status);
> +			skip_pmi = test_and_set_bit(GLOBAL_STATUS_BUFFER_OVF_BIT,
> +						    (unsigned long *)&pmu->global_status);
>  		}
>  	} else {
> -		__set_bit(pmc->idx, (unsigned long *)&pmu->global_status);
> +		set_bit(pmc->idx, (unsigned long *)&pmu->global_status);
>  	}
>  
>  	if (!pmc->intr || skip_pmi)
> 
> base-commit: e2013f46ee2e721567783557c301e5c91d0b74ff
> -- 
> 2.42.0.283.g2d96d420d3-goog
> 

  reply	other threads:[~2023-09-11 20:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11  6:11 [PATCH] KVM: vPMU: Use atomic bit operations for global_status Mingwei Zhang
2023-09-11 15:01 ` Sean Christopherson [this message]
2023-09-11 18:00   ` Mingwei Zhang
2023-09-11 18:09     ` Sean Christopherson
2023-09-11 23:42       ` Mingwei Zhang

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=ZP8r2CDsv3JkGYzX@google.com \
    --to=seanjc@google.com \
    --cc=dapeng1.mi@intel.com \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=likexu@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mizhang@google.com \
    --cc=pbonzini@redhat.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