Skip to content

Commit a5f5e12

Browse files
Dapeng MiIngo Molnar
authored andcommitted
perf/x86/intel: Don't clear perf metrics overflow bit unconditionally
The below code would always unconditionally clear other status bits like perf metrics overflow bit once PEBS buffer overflows: status &= intel_ctrl | GLOBAL_STATUS_TRACE_TOPAPMI; This is incorrect. Perf metrics overflow bit should be cleared only when fixed counter 3 in PEBS counter group. Otherwise perf metrics overflow could be missed to handle. Closes: https://lore.kernel.org/all/20250225110012.GK31462@noisy.programming.kicks-ass.net/ Fixes: 7b2c05a ("perf/x86/intel: Generic support for hardware TopDown metrics") Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Kan Liang <kan.liang@linux.intel.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250415104135.318169-1-dapeng1.mi@linux.intel.com
1 parent 506f981 commit a5f5e12

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

arch/x86/events/intel/core.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,6 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
30493049
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
30503050
int bit;
30513051
int handled = 0;
3052-
u64 intel_ctrl = hybrid(cpuc->pmu, intel_ctrl);
30533052

30543053
inc_irq_stat(apic_perf_irqs);
30553054

@@ -3093,7 +3092,6 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
30933092
handled++;
30943093
x86_pmu_handle_guest_pebs(regs, &data);
30953094
static_call(x86_pmu_drain_pebs)(regs, &data);
3096-
status &= intel_ctrl | GLOBAL_STATUS_TRACE_TOPAPMI;
30973095

30983096
/*
30993097
* PMI throttle may be triggered, which stops the PEBS event.
@@ -3104,6 +3102,15 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
31043102
*/
31053103
if (pebs_enabled != cpuc->pebs_enabled)
31063104
wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled);
3105+
3106+
/*
3107+
* Above PEBS handler (PEBS counters snapshotting) has updated fixed
3108+
* counter 3 and perf metrics counts if they are in counter group,
3109+
* unnecessary to update again.
3110+
*/
3111+
if (cpuc->events[INTEL_PMC_IDX_FIXED_SLOTS] &&
3112+
is_pebs_counter_event_group(cpuc->events[INTEL_PMC_IDX_FIXED_SLOTS]))
3113+
status &= ~GLOBAL_STATUS_PERF_METRICS_OVF_BIT;
31073114
}
31083115

31093116
/*
@@ -3123,6 +3130,8 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
31233130
static_call(intel_pmu_update_topdown_event)(NULL, NULL);
31243131
}
31253132

3133+
status &= hybrid(cpuc->pmu, intel_ctrl);
3134+
31263135
/*
31273136
* Checkpointed counters can lead to 'spurious' PMIs because the
31283137
* rollback caused by the PMI will have cleared the overflow status

0 commit comments

Comments
 (0)