[Patch v2 12/16] perf/x86/intel: Check period setting return value for PEBS events
From: Dapeng Mi
Date: Mon Nov 30 2026 - 19:46:46 EST
For a non-auto-reload PEBS event (typically used in sample frequency
mode), perf/core may calculate a target sample period that is much larger
than the maximum sample period supported by the PEBS counter.
Consequently, a PEBS counter overflow does not necessarily mean that the
overall sample period calculated by perf/core has fully elapsed.
Fix this by checking the return value of x86_perf_event_set_period() (or
intel_pmu_save_and_restart()). Only invoke perf_event_output() or
perf_event_overflow() when the returned value is 1, which indicates that
the full sample period has indeed elapsed, matching the logic already
used in handle_pmi_common().
Fixes: 3c00ed344cef ("perf/x86/intel/ds: Factor out functions for PEBS records processing")
Fixes: 7da9960b59fb ("perf/x86/intel/ds: Fix counter backwards of non-precise events counters-snapshotting")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/ds.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
index 98825d333ccb..bc44f507f872 100644
--- a/arch/x86/events/intel/ds.c
+++ b/arch/x86/events/intel/ds.c
@@ -2951,6 +2951,7 @@ __intel_pmu_pebs_last_event(struct perf_event *event,
setup_fn setup_sample)
{
struct hw_perf_event *hwc = &event->hw;
+ int ret = 0;
/* Skip parsing corrupted PEBS record. */
if (corrupted) {
@@ -2984,6 +2985,7 @@ __intel_pmu_pebs_last_event(struct perf_event *event,
*/
intel_pmu_save_and_restart_reload(event, count);
}
+ ret = 1;
} else {
/*
* For a non-precise event, it's possible the
@@ -2997,13 +2999,19 @@ __intel_pmu_pebs_last_event(struct perf_event *event,
* Since the event value has been updated when processing the
* counters-snapshotting record, only needs to set the new
* period for the counter.
+ *
+ * A return value of 1 indicates the full sample period has
+ * indeed elapsed and the overflow handler should be invoked.
*/
if (is_pebs_counter_event_group(event) && !corrupted)
- static_call(x86_pmu_set_period)(event);
+ ret = static_call(x86_pmu_set_period)(event);
else
- intel_pmu_save_and_restart(event);
+ ret = intel_pmu_save_and_restart(event);
}
+ if (!ret)
+ return;
+
if (iregs == &dummy_iregs) {
/*
* The PEBS records may be drained in the non-overflow context,
--
2.34.1