public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: sashiko@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 4/4] perf/x86: KVM: Have perf define a dedicated struct for getting guest PEBS data
Date: Mon, 27 Apr 2026 10:37:56 -0700	[thread overview]
Message-ID: <ae-e9FQzmhnMVn1Q@google.com> (raw)
In-Reply-To: <20260423233145.DDC5BC2BCAF@smtp.kernel.org>

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?



  reply	other threads:[~2026-04-27 17:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23 15:03 [PATCH v2 0/4] perf/x86: Don't write PEBS_ENABLED on KVM transitions Sean Christopherson
2026-04-23 15:03 ` [PATCH v2 1/4] perf/x86/intel: Don't write PEBS_ENABLED on host<=>guest xfers if CPU has isolation Sean Christopherson
2026-04-23 16:22   ` Peter Zijlstra
2026-04-23 17:59   ` Jim Mattson
2026-04-27  2:10     ` Mi, Dapeng
2026-04-27 18:07       ` Sean Christopherson
2026-04-23 15:03 ` [PATCH v2 2/4] perf/x86/intel: Don't context switch DS_AREA (and PEBS config) if PEBS is unused Sean Christopherson
2026-04-27  2:24   ` Mi, Dapeng
2026-04-27 17:34     ` Sean Christopherson
2026-04-23 15:03 ` [PATCH v2 3/4] perf/x86/intel: Make @data a mandatory param for intel_guest_get_msrs() Sean Christopherson
2026-04-27  2:28   ` Mi, Dapeng
2026-04-23 15:03 ` [PATCH v2 4/4] perf/x86: KVM: Have perf define a dedicated struct for getting guest PEBS data Sean Christopherson
2026-04-23 18:14   ` Jim Mattson
2026-04-23 23:31   ` sashiko-bot
2026-04-27 17:37     ` Sean Christopherson [this message]
2026-04-23 15:33 ` [PATCH v2 0/4] perf/x86: Don't write PEBS_ENABLED on KVM transitions Jim Mattson
2026-04-23 16:16 ` Peter Zijlstra
2026-04-24 12:17   ` Mi, Dapeng
2026-04-24 12:23     ` Peter Zijlstra

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=ae-e9FQzmhnMVn1Q@google.com \
    --to=seanjc@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko@lists.linux.dev \
    /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