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

sashiko-bot
2026-04-23T23:31:46Z

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?

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?

>
> /* Note, nr_msrs may be garbage if perf_guest_get_msrs() returns NULL. */
> - msrs = perf_guest_get_msrs(&nr_msrs, (void *)pmu);
> + msrs = perf_guest_get_msrs(&nr_msrs, &guest_pebs);

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260423150340.463896-1-seanjc@google.com?part=4