[tip: perf/core] perf/x86/intel: Unwind cpuc state if PEBS buffer setup fails

From: tip-bot2 for Dapeng Mi

Date: Wed Aug 12 2026 - 10:11:48 EST


The following commit has been merged into the perf/core branch of tip:

Commit-ID: 85182f902afda28ca7ae3408b72f31640a5cfc73
Gitweb: https://git.kernel.org/tip/85182f902afda28ca7ae3408b72f31640a5cfc73
Author: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
AuthorDate: Fri, 17 Jul 2026 16:03:38 +08:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Mon, 10 Aug 2026 15:05:47 +02:00

perf/x86/intel: Unwind cpuc state if PEBS buffer setup fails

intel_pmu_cpu_prepare() allocates per-CPU perf state first and then sets
up the arch PEBS buffer. If alloc_arch_pebs_buf_on_cpu() fails,
the previously allocated cpuc resources are left behind.

Make the failure path call intel_cpuc_finish(cpuc) to release the per-CPU
state allocated by intel_cpuc_prepare().

Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Reviewed-by: Thomas Falcon <thomas.falcon@xxxxxxxxx>
Reviewed-by: Zide Chen <zide.chen@xxxxxxxxx>
Link: https://patch.msgid.link/20260717080342.1879573-5-dapeng1.mi@xxxxxxxxxxxxxxx
---
arch/x86/events/intel/core.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index a991fc4..b47d2f0 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -5924,13 +5924,20 @@ err:

static int intel_pmu_cpu_prepare(int cpu)
{
+ struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
int ret;

- ret = intel_cpuc_prepare(&per_cpu(cpu_hw_events, cpu), cpu);
+ ret = intel_cpuc_prepare(cpuc, cpu);
if (ret)
return ret;

- return alloc_arch_pebs_buf_on_cpu(cpu);
+ ret = alloc_arch_pebs_buf_on_cpu(cpu);
+ if (ret) {
+ intel_cpuc_finish(cpuc);
+ return ret;
+ }
+
+ return 0;
}

static void flip_smm_bit(void *data)