Re: [PATCH 04/25] coresight: perf: End AUX output when an event is throttled
From: Song Liu
Date: Mon Nov 23 2026 - 14:07:56 EST
Hi Leo,
On Tue, Sep 15, 2026 at 8:49 AM Leo Yan <leo.yan@xxxxxxx> wrote:
>
> Since commit 9734e25fbf5a ("perf: Fix the throttle logic for a
> group"), the perf core stops every event in a throttled group by calling
> the PMU stop callback with flags set to zero:
>
> perf_event_throttle()
> `> event->pmu->stop(event, 0)
>
> The ETM perf stop callback only ends the AUX output handle when
> PERF_EF_UPDATE was set. For throttling with mode is zero, it skips to
> end the AUX handle. When the event is later unthrottled and ETM tracing
> is started again, perf_aux_output_begin() sees the perf handle is nest
> enabled and triggers a warning:
While testing this patch, we found a crash:
[20122.800818] Unable to handle kernel NULL pointer dereference at
virtual address 0000000000000038
[20122.800836] Mem abort info:
[20122.800839] ESR = 0x0000000096000007
[20122.800842] EC = 0x25: DABT (current EL), IL = 32 bits
[20122.800845] SET = 0, FnV = 0
[20122.800847] EA = 0, S1PTW = 0
[20122.800849] FSC = 0x07: level 3 translation fault
[20122.800852] Data abort info:
[20122.800854] ISV = 0, ISS = 0x00000007, ISS2 = 0x00000000
[20122.800857] CM = 0, WnR = 0, TnD = 0, TagAccess = 0
[20122.800860] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
[20122.800862] user pgtable: 64k pages, 48-bit VAs, pgdp=00000001683e1800
[...]
[20123.261147] pstate: 034010c9 (nzcv daIF +PAN -UAO +TCO +DIT +SSBS BTYPE=--)
[20123.275144] pc : arm_trbe_irq_handler+0x58/0x4d8 [coresight_trbe]
[20123.287396] lr : arm_trbe_irq_handler+0x28/0x4d8 [coresight_trbe]
[20123.299645] sp : ffff800083ccff40
[20123.306298] x29: ffff800083ccff40 x28: ffff0000b1bbdb80 x27: 0000000000000000
[20123.320645] x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000
[20123.334992] x23: 0000000000000028 x22: ffff800083095f98 x21: ffff0000e8380280
[20123.349338] x20: 0000000000520001 x19: ffff003fe685c8e0 x18: 0000000000000000
[20123.363686] x17: ffff803f64150000 x16: ffff800083cc0000 x15: 0000000000000000
[20123.378033] x14: 0000000000000000 x13: 000000000000000c x12: 0000000000200000
[20123.392380] x11: ffff0000c00010d0 x10: ffff803f64150000 x9 : 0000000000000028
[20123.406725] x8 : 0000000000000000 x7 : 0000000000000000 x6 : 0000000000000000
[20123.421072] x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000
[20123.435420] x2 : 0000000000000000 x1 : ffffffdfbf459f58 x0 : 0000000000000000
[20123.449766] Call trace:
[20123.454671] arm_trbe_irq_handler+0x58/0x4d8 [coresight_trbe] (P)
[20123.466920] handle_percpu_devid_irq+0x80/0x1b0
[20123.476029] generic_handle_domain_irq+0x3c/0x80
[20123.485308] gic_handle_irq+0x174/0x328
[20123.493014] call_on_irq_stack+0x30/0x48
[20123.500894] do_interrupt_handler+0x50/0x78
[20123.509299] el0_interrupt+0x48/0x2c8
[20123.516654] __el0_irq_handler_common+0x14/0x20
[20123.525755] el0t_64_irq_handler+0xc/0x18
[20123.533807] el0t_64_irq+0x17c/0x180
[20123.540987] Code: d5381237 927ef6e9 d5181229 d5033fdf (f9401d15)
[20123.553236] SMP: stopping secondary CPUs
[20124.617250] SMP: failed to stop secondary CPUs 60
LLM suggests the following change should fix it. Does this make
sense to you?
Thanks,
Song
diff --git a/drivers/hwtracing/coresight/coresight-trbe.c
b/drivers/hwtracing/coresight/coresight-trbe.c
index 3fa663c7f026..a11381675ef7 100644
--- a/drivers/hwtracing/coresight/coresight-trbe.c
+++ b/drivers/hwtracing/coresight/coresight-trbe.c
@@ -1060,6 +1060,16 @@ static int arm_trbe_disable(struct
coresight_device *csdev)
return -EINVAL;
trbe_drain_and_disable_local(cpudata);
+ /*
+ * The TRBE may have raised an IRQ (e.g. on reaching the limit) that
+ * has not been taken yet, as our caller runs with IRQs disabled. When
+ * the event is stopped without PERF_EF_UPDATE (e.g. on throttling),
+ * update_buffer() did not run to consume it, and the AUX handle and
+ * this buffer may be gone by the time the IRQ is taken. The session
+ * on this CPU is over, so there is nothing left to handle: drop it.
+ */
+ clr_trbe_irq();
+ isb();
buf->cpudata = NULL;
cpudata->buf = NULL;
cpudata->mode = CS_MODE_DISABLED;
@@ -1144,7 +1154,7 @@ static irqreturn_t arm_trbe_irq_handler(int irq,
void *dev)
{
struct perf_output_handle **handle_ptr = dev;
struct perf_output_handle *handle = *handle_ptr;
- struct trbe_buf *buf = etm_perf_sink_config(handle);
+ struct trbe_buf *buf;
enum trbe_fault_action act;
u64 status;
bool truncated = false;
@@ -1161,6 +1171,22 @@ static irqreturn_t arm_trbe_irq_handler(int
irq, void *dev)
/* Prohibit the CPU from tracing before we disable the TRBE */
trfcr = cpu_prohibit_trace();
+
+ /*
+ * The event may have been stopped, and the AUX handle closed or the
+ * sink disabled, after the IRQ was raised but before it was taken.
+ * The TRBE was disabled then and there is nothing to collect, so just
+ * acknowledge the IRQ. Don't touch buf->cpudata, it may be NULL.
+ */
+ buf = handle ? etm_perf_sink_config(handle) : NULL;
+ if (!buf || !buf->cpudata) {
+ WARN_ON_ONCE(is_trbe_enabled());
+ clr_trbe_irq();
+ isb();
+ write_trfcr(trfcr);
+ return IRQ_HANDLED;
+ }
+
/*
* Ensure the trace is visible to the CPUs and
* any external aborts have been resolved.
@@ -1169,9 +1195,6 @@ static irqreturn_t arm_trbe_irq_handler(int irq,
void *dev)
clr_trbe_irq();
isb();
- if (WARN_ON_ONCE(!handle) || !perf_get_aux(handle))
- return IRQ_NONE;
-
if (!is_perf_trbe(handle))
return IRQ_NONE;