Re: [PATCH] KVM: VMX: Use _safe MSR accessors in LBR handler
From: Sean Christopherson
Date: Tue May 26 2026 - 18:12:16 EST
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.