diff options
| author | Tengda Wu <wutengda@huaweicloud.com> | 2026-11-19 09:51:00 +0000 |
|---|---|---|
| committer | Peter Zijlstra <peterz@infradead.org> | 2026-11-26 13:41:02 +0100 |
| commit | e4c5112f01816b0ac6d74724545eca1195788c38 (patch) | |
| tree | 73bad7147e431cb0c0d4df3ae9078dadc188043c /tools/lib/python | |
| parent | c9ef606bc68a7bbbaa5fc9cef968a5226c12a283 (diff) | |
perf: Prevent duplicate sigtrap task work enqueue
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 (software/tracepoint)
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()
<NMI>
__perf_event_overflow()
task_work_add()
The nested invocation may enqueue pending_task before the outer
invocation does. When the outer invocation resumes, it inserts the
same task work entry again, potentially creating a cycle in the task
work list.
As a result, perf_pending_task() may be executed repeatedly, leading
to unbalanced event reference counting.
Fix this by atomically claiming pending_work with cmpxchg_local()
before calling task_work_add(). This ensures that only one invocation
can enqueue the task work, even when another overflow occurs
re-entrantly from an NMI.
Notably: sigtrap events must be per-task, meaning that the there is no
concurrency, only re-entrancy.
[peterz: clarify and rewrite]
Fixes: c5d93d23a260 ("perf: Enqueue SIGTRAP always via task_work.")
Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/45bd71c976aea1a0e8bf5762dd6b6552e6009439.1795053619.git.wutengda@huaweicloud.com
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions
