Re: [PATCH v5 1/2] perf/core: Prevent duplicate sigtrap task work enqueue
From: Peter Zijlstra
Date: Fri Nov 20 2026 - 10:45:30 EST
On Thu, Nov 19, 2026 at 09:51:00AM +0000, Tengda Wu wrote:
> The sigtrap handling in __perf_event_overflow() checks
> event->pending_work before calling task_work_add(), but only sets
> pending_work after the task work has been queued.
>
> This leaves a window where an NMI can interrupt task_work_add()
> and re-enter __perf_event_overflow() for the same event. Since
> pending_work is still zero, the nested invocation can enqueue
> the same pending_task again.
>
> The re-entrant call path looks like this:
>
> __perf_event_overflow()
> task_work_add()
> kasan_record_aux_stack()
> <NMI>
> __perf_event_overflow()
> task_work_add()
How? If an event is NMI driven, it will only ever cause an overflow from
NMI context.
If it is not, then the same event will not trigger from NMI.
Some key ingredient is missing here. Is this some software event that is
missing recursion checks?