Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: xuanqingshi <1356292400@qq.com>
Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: VMX: Use _safe MSR accessors in LBR handler
Date: Tue, 26 May 2026 15:12:00 -0700	[thread overview]
Message-ID: <ahYasC7AX3yYrCLR@google.com> (raw)
In-Reply-To: <ahXs2mVqtahs7iG7@google.com>

On Tue, May 26, 2026, Sean Christopherson wrote:
> On Wed, May 27, 2026, xuanqingshi wrote:
> > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
> > index 27eb76e6b6a0..94d2cbffcff4 100644
> > --- a/arch/x86/kvm/vmx/pmu_intel.c
> > +++ b/arch/x86/kvm/vmx/pmu_intel.c
> > @@ -293,6 +293,7 @@ static bool intel_pmu_handle_lbr_msrs_access(struct kvm_vcpu *vcpu,
> >  {
> >  	struct lbr_desc *lbr_desc = vcpu_to_lbr_desc(vcpu);
> >  	u32 index = msr_info->index;
> > +	int err;
> >  
> >  	if (!intel_pmu_is_valid_lbr_msr(vcpu, index))
> >  		return false;
> > @@ -309,12 +310,12 @@ static bool intel_pmu_handle_lbr_msrs_access(struct kvm_vcpu *vcpu,
> >  	local_irq_disable();
> >  	if (lbr_desc->event->state == PERF_EVENT_STATE_ACTIVE) {
> >  		if (read)
> > -			rdmsrq(index, msr_info->data);
> > +			err = rdmsrq_safe(index, &msr_info->data);
> >  		else
> > -			wrmsrq(index, msr_info->data);
> > +			err = wrmsrq_safe(index, msr_info->data);
> 
> I don't love throwing a value at hardware to see what sticks, but given that KVM
> disables interception of these MSRs, it's not like there's a better option.
> 
> No need for a v2, I'll rewrite the changelog when applying.

Actually, I'll post a v2, because I think it makes sense to continue using the
"unsafe" version for RDMSR.  It should be impossible to reach this point with a
bad MSR index, i.e. we _want_ the resulting WARN if RDMSR fails.

      reply	other threads:[~2026-05-26 22:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 17:44 [PATCH] KVM: VMX: Use _safe MSR accessors in LBR handler xuanqingshi
2026-05-26 18:56 ` Sean Christopherson
2026-05-26 22:12   ` Sean Christopherson [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=ahYasC7AX3yYrCLR@google.com \
    --to=seanjc@google.com \
    --cc=1356292400@qq.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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