[Patch v2 01/16] perf/x86/intel: Reject BTS events when BTS is not active
From: Dapeng Mi
Date: Mon Nov 30 2026 - 19:45:23 EST
The BTS buffer is allocated by alloc_bts_buffer() during
x86_reserve_hardware(). If both the BTS and PEBS buffer allocations
fail, the DS area is released and cpuc->ds is set to NULL, with
x86_pmu.bts_active staying 0.
Currently bts_event_init() doesn't check bts_active, so a BTS event can
be created successfully even though the BTS buffer is unusable. When
the event is started, bts_event_start() and bts_config_buffer()
unconditionally dereference the NULL cpuc->ds pointer, causing a kernel
oops.
Fix it by rejecting BTS event creation with -ENODEV when BTS is not
active.
Fixes: 8062382c8dbe ("perf/x86/intel/bts: Add BTS PMU driver")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://sashiko.dev/#/bug/linux-3e9e2ec1-5f5c-45ca-b48b-117978a3e841
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/bts.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c
index 5849392cf26d..d871799e4f79 100644
--- a/arch/x86/events/intel/bts.c
+++ b/arch/x86/events/intel/bts.c
@@ -586,6 +586,11 @@ static int bts_event_init(struct perf_event *event)
return ret;
}
+ if (!x86_pmu.bts_active) {
+ bts_event_destroy(event);
+ return -ENODEV;
+ }
+
event->destroy = bts_event_destroy;
return 0;
--
2.34.1