Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dapeng Mi" <dapeng1.mi@linux.intel.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [Patch v4 3/8] perf/x86/intel: Fallback to sw branch type decoding if no hw decoding
Date: Tue, 16 Jun 2026 05:03:42 +0000	[thread overview]
Message-ID: <20260616050343.5D8111F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260616044654.3468742-4-dapeng1.mi@linux.intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Forcing `X86_BR_TYPE_SAVE` on Arch LBR CPUs without hardware branch-type support causes massive NMI overhead due to an unconditional fallback to software decoding.
--

commit f25e57aa8ef5b59fd749c6fcb24f34aa7668326f
Author: Dapeng Mi <dapeng1.mi@linux.intel.com>

perf/x86/intel: Fallback to sw branch type decoding if no hw decoding

This commit updates the arch-LBR filtering to fall back to software
branch-type decoding when the hardware feature is unavailable. This ensures
branch classification works correctly across different arch-LBR
configurations.

> diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
> index 72f2adcda7c68..e2657f791e507 100644
> --- a/arch/x86/events/intel/lbr.c
> +++ b/arch/x86/events/intel/lbr.c
> @@ -1231,7 +1231,7 @@ intel_pmu_lbr_filter(struct cpu_hw_events *cpuc)
>  		 * Doesn't support OTHER_BRANCH decoding for now.
>  		 * OTHER_BRANCH branch type still rely on software decoding.
>  		 */
> -		if (static_cpu_has(X86_FEATURE_ARCH_LBR) &&
> +		if (static_branch_likely(&x86_lbr_type) &&

[Severity: High]
Does this change unintentionally cause a massive performance regression on
systems without hardware branch-type support?

In intel_pmu_setup_hw_lbr_filter(), X86_BR_TYPE_SAVE is always forced
for all Arch LBR CPUs:

arch/x86/events/intel/lbr.c:intel_pmu_setup_hw_lbr_filter() {
    ...
    if (static_cpu_has(X86_FEATURE_ARCH_LBR)) {
        reg->config = mask;
        ...
        reg->reg |= X86_BR_TYPE_SAVE;
        return 0;
    }
}

Because X86_BR_TYPE_SAVE is forced, the fast-path early exit in
intel_pmu_lbr_filter() is never taken:

arch/x86/events/intel/lbr.c:intel_pmu_lbr_filter() {
    ...
    if (((br_sel & X86_BR_ALL) == X86_BR_ALL) &&
        ((br_sel & X86_BR_TYPE_SAVE) != X86_BR_TYPE_SAVE))
        return;
    ...
}

With the fallback introduced by this patch, won't every sampled branch be
forced to undergo high-overhead software disassembly in the NMI context, even
when the user requested no specific branch type filtering?

Should intel_pmu_setup_hw_lbr_filter() be updated to conditionally force
X86_BR_TYPE_SAVE only if x86_lbr_type is actually enabled?

>  		    type <= ARCH_LBR_BR_TYPE_KNOWN_MAX) {
>  			to_plm = kernel_ip(to) ? X86_BR_KERNEL : X86_BR_USER;
>  			type = arch_lbr_br_type_map[type] | to_plm;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260616044654.3468742-1-dapeng1.mi@linux.intel.com?part=3

  reply	other threads:[~2026-06-16  5:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-16  4:46 [Patch v4 0/8] perf/x86: Miscellaneous PMU bug fixes Dapeng Mi
2026-06-16  4:46 ` [Patch v4 1/8] perf/x86/intel: Remove anythread_deprecated bit from perf_capabilities Dapeng Mi
2026-06-16  4:46 ` [Patch v4 2/8] perf/x86/intel: Keep cap_user_rdpmc in sync with RDPMC user-disable state Dapeng Mi
2026-06-16  4:46 ` [Patch v4 3/8] perf/x86/intel: Fallback to sw branch type decoding if no hw decoding Dapeng Mi
2026-06-16  5:03   ` sashiko-bot [this message]
2026-06-16  4:46 ` [Patch v4 4/8] perf/x86/intel: Fix kernel address leakages in LBR stack Dapeng Mi
2026-06-16  5:03   ` sashiko-bot
2026-06-16  4:46 ` [Patch v4 5/8] perf/x86/intel: Validate the return value of intel_pmu_init_hybrid() Dapeng Mi
2026-06-16  4:46 ` [Patch v4 6/8] perf/x86/intel: Drop fixed-counter PEBS constraints for baseline PEBS Dapeng Mi
2026-06-16  4:46 ` [Patch v4 7/8] perf/core: Fix kernel register info leak via hardware skid Dapeng Mi
2026-06-16  4:46 ` [Patch v4 8/8] perf/core: Check kernel access when kernel callchains are requested Dapeng Mi

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=20260616050343.5D8111F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@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