[Patch v3 4/8] perf/x86/intel: Unwind cpuc state if PEBS buffer setup fails
From: Dapeng Mi
Date: Fri Jul 17 2026 - 04:10:45 EST
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>
Reviewed-by: Thomas Falcon <thomas.falcon@xxxxxxxxx>
---
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 a991fc4f1575..b47d2f00ac13 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -5924,13 +5924,20 @@ int intel_cpuc_prepare(struct cpu_hw_events *cpuc, int cpu)
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)
--
2.34.1