Skip to content

Commit 82aad7f

Browse files
author
Peter Zijlstra
committed
perf/hw_breakpoint: Annotate tsk->perf_event_mutex vs ctx->mutex
Perf fuzzer gifted a lockdep splat: perf_event_init_context() mutex_lock(parent_ctx->mutex); (B) inherit_task_group() inherit_group() inherit_event() perf_event_alloc() perf_try_init_event() := hw_breakpoint_event_init() register_perf_hw_breakpoint() mutex_lock(child->perf_event_mutex); (A) Which is against the normal (documented) order. Now, this is a false positive in that child is not published yet, but also inherited events never end up on ->perf_event_list. Annotate this one away. Fixes: 0912037 ("perf/hw_breakpoint: Reduce contention with large number of tasks") Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
1 parent 7be51cc commit 82aad7f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

kernel/events/hw_breakpoint.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,17 @@ static struct mutex *bp_constraints_lock(struct perf_event *bp)
117117
struct mutex *tsk_mtx = get_task_bps_mutex(bp);
118118

119119
if (tsk_mtx) {
120-
mutex_lock(tsk_mtx);
120+
/*
121+
* Fully analogous to the perf_try_init_event() nesting
122+
* argument in the comment near perf_event_ctx_lock_nested();
123+
* this child->perf_event_mutex cannot ever deadlock against
124+
* the parent->perf_event_mutex usage from
125+
* perf_event_task_{en,dis}able().
126+
*
127+
* Specifically, inherited events will never occur on
128+
* ->perf_event_list.
129+
*/
130+
mutex_lock_nested(tsk_mtx, SINGLE_DEPTH_NESTING);
121131
percpu_down_read(&bp_cpuinfo_sem);
122132
} else {
123133
percpu_down_write(&bp_cpuinfo_sem);

0 commit comments

Comments
 (0)