Re: [PATCH v2 4/4] perf/x86: KVM: Have perf define a dedicated struct for getting guest PEBS data

Sean Christopherson
2026-04-27T17:37:59Z

On Thu, Apr 23, 2026, sashiko-bot@kernel.org wrote:
> Sashiko AI review found 1 potential issue(s):
> - [Medium] Unconditional external function call to intel_pmu_get_cross_mapped_mask() introduced in the VMX hot path.
> --
>
> commit bf596eb4f1ae159ccdd3b9e0517c0eaa4c80ce4a
> Author: Sean Christopherson <seanjc@google.com>
>
> perf/x86: KVM: Have perf define a dedicated struct for getting guest PEBS data
>
> This commit introduces a dedicated struct (x86_guest_pebs) for passing guest
> PEBS data from KVM to perf. It replaces the previous method of passing an
> opaque pointer to kvm_pmu, allowing perf to define its own data requirements
> independently of KVM-internal state.
>
> > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> > index a29896a9ef1456..e6c1c64a8c949d 100644
> > --- a/arch/x86/kvm/vmx/vmx.c
> > +++ b/arch/x86/kvm/vmx/vmx.c
> > @@ -7313,12 +7313,15 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)
> > if (kvm_vcpu_has_mediated_pmu(&vmx->vcpu))
> > return;
> >
> > - pmu->host_cross_mapped_mask = 0;
> > - if (pmu->pebs_enable & pmu->global_ctrl)
> > - intel_pmu_cross_mapped_check(pmu);
> > + struct x86_guest_pebs guest_pebs = {
> > + .enable = pmu->pebs_enable,
> > + .ds_area = pmu->ds_area,
> > + .data_cfg = pmu->pebs_data_cfg,
> > + .cross_mapped_mask = intel_pmu_get_cross_mapped_mask(pmu),
> > + };
>
> Does this introduce an unnecessary function call overhead on the VMX hot path?

Probably. I'm not sure how much we care. Though what does matter and should be
fixed is that intel_pmu_get_cross_mapped_mask() is a bit of a lie. It doesn't
check _all_ PMCs, only those that are globally enabled and configured for PEBS.

I'll figure out a way to address both in the next version.

> Prior to this patch, the external function intel_pmu_cross_mapped_check()
> was conditionally called only when PEBS was enabled, which avoided an
> external function call in the vast majority of cases.
>
> Because intel_pmu_get_cross_mapped_mask() is in a different compilation
> unit (pmu_intel.c), calling it unconditionally here results in a function
> call on every VM-entry.
>
> Would it be better to restore the inline condition check, perhaps using a
> ternary operator when initializing cross_mapped_mask?