[Patch v2 02/16] perf/x86/intel: Check if BTS is active before handling BTS interrupt

From: Dapeng Mi

Date: Mon Nov 30 2026 - 19:45:35 EST


alloc_bts_buffer() may fail while the PEBS buffer allocation succeeds.
In that case cpu_hw_events.ds is non-NULL, but the BTS fields in the DS
area, e.g. bts_interrupt_threshold, are left zero-initialized.

With bts_interrupt_threshold being 0, intel_bts_interrupt() wrongly
treats the BTS buffer as ready to drain and returns 1 on every PMI even
though BTS is not in use. The PMI handler thus always reports one more
"handled" event, which defeats the NMI back-to-back detection in
default_do_nmi() and can swallow genuine unknown NMIs.

Fix it by checking bts_active before handling the BTS interrupt.

Fixes: 4d4c47412464 ("perf/x86/intel/bts: Fix BTS PMI detection")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://sashiko.dev/#/bug/linux-c2fdfad5-341c-48c0-87ab-af4d31d19aee
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/bts.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c
index d871799e4f79..4bc54614978f 100644
--- a/arch/x86/events/intel/bts.c
+++ b/arch/x86/events/intel/bts.c
@@ -464,7 +464,7 @@ int intel_bts_interrupt(void)
s64 old_head;
int err = -ENOSPC, handled = 0;

- if (!bts_ctx)
+ if (!bts_ctx || !x86_pmu.bts_active)
return 0;

bts = this_cpu_ptr(bts_ctx);
--
2.34.1