[Patch v3 0/4] perf/x86: Limit branch snapshots to valid entries
From: Dapeng Mi
Date: Mon Oct 19 2026 - 03:18:08 EST
Sashiko reported that the vendor-specific branch snapshot callbacks
used by bpf_get_branch_snapshot() copy up to x86_pmu.lbr_nr entries
from cpuc->lbr_entries[], regardless of how many valid entries the
last LBR read produced. This makes BPF programs read stale or invalid
branch records. Patch 1 addresses AMD and patch 2 addresses Intel.
Changes in v3:
- Patch 01: A new patch to ensure x86_pmu.lbr_nr not to exclude
MAX_LBR_ENTRIES (Internal Sashiko).
- Patch 03: Clean cached LBR stack when reseting hardware LBR registers,
which prevents stale LBR stack leakage.
- Patch 04: Don't reset cached LBR stack if all LBR events are PEBS
events. This ensures PEBS captured LBR stack isn't cleared (Sashiko).
Changes in v2:
- Include a fix for Intel LBR.
- Add Tested-by from Dapeng to the Intel fix.
https://lore.kernel.org/all/eb6c7bda-0dcf-4fac-ad69-9f5b24abc21b@xxxxxxxxxxxxxxx/
History:
v2: https://lore.kernel.org/all/cover.1792064123.git.sandipan.das@xxxxxxx/
v1: https://lore.kernel.org/all/20261007181002.4005262-1-sandipan.das@xxxxxxx/
Dapeng Mi (3):
perf/x86: Clamp x86_pmu.lbr_nr to MAX_LBR_ENTRIES
perf/x86/intel/lbr: Reset the cached LBR stack in
intel_pmu_lbr_reset()
perf/x86/intel/lbr: Limit branch snapshots to valid entries
Sandipan Das (1):
perf/x86/amd/lbr: Limit branch snapshots to valid entries
arch/x86/events/amd/core.c | 2 +-
arch/x86/events/amd/lbr.c | 4 +++-
arch/x86/events/core.c | 2 ++
arch/x86/events/intel/core.c | 2 +-
arch/x86/events/intel/lbr.c | 14 +++++++++++---
5 files changed, 18 insertions(+), 6 deletions(-)
base-commit: f5a78ecccd98a04c47cea1cd63c2a2fdce8a4b48
--
2.34.1