[Patch v7 14/24] perf/x86/intel: Account lbr_pebs_users for arch-PEBS events

From: Dapeng Mi

Date: Tue Nov 17 2026 - 22:24:30 EST


lbr_pebs_users tracks how many PEBS events are currently using LBR.
It is updated for legacy PEBS events, but arch-PEBS events were missing
from that accounting.

Add the missing lbr_pebs_users accounting for arch-PEBS as well.

Fixes: d243d0bb64af ("perf/x86/intel: Initialize architectural PEBS")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://lore.kernel.org/all/sashiko-outbox-179823@xxxxxxxxxx/
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/lbr.c | 4 ++--
arch/x86/events/perf_event.h | 7 +++++++
2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
index 6c7123c1f9ae..3a282352b0d2 100644
--- a/arch/x86/events/intel/lbr.c
+++ b/arch/x86/events/intel/lbr.c
@@ -616,7 +616,7 @@ void intel_pmu_lbr_add(struct perf_event *event)
* be 'new'. Conversely, a new event can get installed through the
* context switch path for the first time.
*/
- if (x86_pmu.intel_cap.pebs_baseline && event->attr.precise_ip > 0)
+ if (intel_pmu_has_pebs_lbr(event->pmu) && event->attr.precise_ip > 0)
cpuc->lbr_pebs_users++;
perf_sched_cb_inc(event->pmu);
if (!cpuc->lbr_users++ && !event->total_time_running)
@@ -687,7 +687,7 @@ void intel_pmu_lbr_del(struct perf_event *event)
if (event->hw.flags & PERF_X86_EVENT_LBR_SELECT)
cpuc->lbr_select = 0;

- if (x86_pmu.intel_cap.pebs_baseline && event->attr.precise_ip > 0)
+ if (intel_pmu_has_pebs_lbr(event->pmu) && event->attr.precise_ip > 0)
cpuc->lbr_pebs_users--;
cpuc->lbr_users--;
WARN_ON_ONCE(cpuc->lbr_users < 0);
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index fa0af528cd1e..8d64bfcdc82d 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -2096,6 +2096,13 @@ static inline bool intel_pmu_has_pebs(void)
return x86_pmu.ds_pebs || x86_pmu.arch_pebs;
}

+static inline bool intel_pmu_has_pebs_lbr(struct pmu *pmu)
+{
+ if (x86_pmu.arch_pebs)
+ return hybrid(pmu, arch_pebs_cap).caps & ARCH_PEBS_LBR;
+ return x86_pmu.intel_cap.pebs_baseline;
+}
+
#else /* CONFIG_CPU_SUP_INTEL */

static inline void reserve_ds_buffers(void)
--
2.34.1