Re: [PATCH v2] perf/core: Fix pending work re-queued in __perf_event_overflow

From: Sebastian Andrzej Siewior

Date: Tue Nov 11 2025 - 08:30:27 EST


On 2025-11-10 00:41:22 [+0800], Liangyan wrote:
> We got warning below during perf test.

>
> A race condition occurs between task context and IRQ context when
> handling sigtrap tracepoint event overflows:
>
> 1. In task context, an event is overflowed and its pending work is
> queued to task->task_works
> 2. Before pending_work is set, the same event overflows in IRQ context
> 3. Both contexts queue the same perf pending work to task->task_works
>
> This double queuing causes:
> - task_work_run() enters infinite loop calling perf_pending_task()
> - Potential warnings and use-after-free when event is freed in
> perf_pending_task()
>
> Fix the race by disabling interrupts during queuing of perf pending work.

Makes sense. Lets it does not overflow in NMI, too.
Either way I suggest to trim the commit message and remove the
backtrace as it probably does not add any value.

Sebastian