[Patch v2 15/16] perf/x86/intel: Reject ACR/arch-PEBS events with sample_period > 2^32

From: Dapeng Mi

Date: Mon Nov 30 2026 - 19:46:54 EST


Currently, the *_CFG_C MSR only features a 32-bit reload value field. If
the sample period of an ACR or auto-reload arch-PEBS event exceeds 2^32,
the intended 48-bit reload value (-hwc->sample_period) is truncated to
32 bits when programmed into *_CFG_C[31:0].

Upon counter overflow, the hardware unconditionally 1-extends these 32
bits to 48 bits. Because the upper 16 bits of a 48-bit two's complement
value for periods > 2^32 are not all 1s (for example, for a period of
2^32 + 1, -P is 0xfffe_ffff_ffff), the hardware's 1-extension corrupts
the reload value, causing the counter to reload with a bogus value
(such as -1).

Fix this by rejecting ACR and auto-reload arch-PEBS events with a sample
period > 2^32 in intel_pmu_hw_config(). Additionally, enforce a similar
period check in intel_pmu_check_period() to prevent invalid configurations.

Opportunistically enforce ACR event sample period validation: an ACR event
with 'config2' set must have a non-zero sample period.

Fixes: ec980e4facef ("perf/x86/intel: Support auto counter reload")
Fixes: 52448a0a7390 ("perf/x86/intel: Setup PEBS data configuration and enable legacy groups")
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/core.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 9906eaaef49c..519ef122c1a3 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4995,6 +4995,9 @@ static inline int intel_set_branch_counter_constr(struct perf_event *event,
return 0;
}

+/* The *_CFG_C reload field supports sample periods up to 2^32. */
+#define MAX_CFG_C_RELOAD_PERIOD BIT_ULL(32)
+
static int intel_pmu_hw_config(struct perf_event *event)
{
int ret = x86_pmu_hw_config(event);
@@ -5036,6 +5039,10 @@ static int intel_pmu_hw_config(struct perf_event *event)
pebs_cap.pdists : pebs_cap.counters;
if (cntr_mask != pebs_mask)
event->hw.dyn_constraint &= pebs_mask;
+
+ if ((event->hw.flags & PERF_X86_EVENT_AUTO_RELOAD) &&
+ event->attr.sample_period > MAX_CFG_C_RELOAD_PERIOD)
+ return -EINVAL;
}
}

@@ -5139,6 +5146,7 @@ static int intel_pmu_hw_config(struct perf_event *event)
bool has_sw_event = false;
int num = 0, idx = 0;
u64 cause_mask = 0;
+ u64 max_period;

/* Not support perf metrics */
if (is_metric_event(event))
@@ -5152,8 +5160,14 @@ static int intel_pmu_hw_config(struct perf_event *event)
if (event->attr.config2 && event->attr.precise_ip > 2)
return -EINVAL;

- /* The reload value cannot exceeds the max period */
- if (event->attr.sample_period > x86_pmu.max_period)
+ /*
+ * An ACR event must be a sampling event, and its sample period
+ * must fit in the *_CFG_C reload field.
+ */
+ max_period = min(x86_pmu.max_period, MAX_CFG_C_RELOAD_PERIOD);
+ if (event->attr.config2 &&
+ (!event->attr.sample_period ||
+ event->attr.sample_period > max_period))
return -EINVAL;
/*
* The counter-constraints of each event cannot be finalized
@@ -6727,7 +6741,18 @@ static void intel_pmu_sched_task(struct perf_event_pmu_context *pmu_ctx,

static int intel_pmu_check_period(struct perf_event *event, u64 value)
{
- return intel_pmu_has_bts_period(event, value) ? -EINVAL : 0;
+ if (intel_pmu_has_bts_period(event, value))
+ return -EINVAL;
+
+ if ((event->hw.flags & PERF_X86_EVENT_AUTO_RELOAD) &&
+ x86_pmu.arch_pebs && value > MAX_CFG_C_RELOAD_PERIOD)
+ return -EINVAL;
+
+ if (is_acr_event_group(event) && event->attr.config2 &&
+ value > MAX_CFG_C_RELOAD_PERIOD)
+ return -EINVAL;
+
+ return 0;
}

static void intel_aux_output_init(void)
--
2.34.1