Skip to content

Commit 558abc7

Browse files
author
Peter Zijlstra
committed
perf: Fix event_function_call() locking
All the event_function/@func call context already uses perf_ctx_lock() except for the !ctx->is_active case. Make it all consistent. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Kan Liang <kan.liang@linux.intel.com> Reviewed-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20240807115550.138301094@infradead.org
1 parent 9a32bd9 commit 558abc7

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

kernel/events/core.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ static int event_function(void *info)
263263
static void event_function_call(struct perf_event *event, event_f func, void *data)
264264
{
265265
struct perf_event_context *ctx = event->ctx;
266+
struct perf_cpu_context *cpuctx = this_cpu_ptr(&perf_cpu_context);
266267
struct task_struct *task = READ_ONCE(ctx->task); /* verified in event_function */
267268
struct event_function_struct efs = {
268269
.event = event,
@@ -291,22 +292,22 @@ static void event_function_call(struct perf_event *event, event_f func, void *da
291292
if (!task_function_call(task, event_function, &efs))
292293
return;
293294

294-
raw_spin_lock_irq(&ctx->lock);
295+
perf_ctx_lock(cpuctx, ctx);
295296
/*
296297
* Reload the task pointer, it might have been changed by
297298
* a concurrent perf_event_context_sched_out().
298299
*/
299300
task = ctx->task;
300301
if (task == TASK_TOMBSTONE) {
301-
raw_spin_unlock_irq(&ctx->lock);
302+
perf_ctx_unlock(cpuctx, ctx);
302303
return;
303304
}
304305
if (ctx->is_active) {
305-
raw_spin_unlock_irq(&ctx->lock);
306+
perf_ctx_unlock(cpuctx, ctx);
306307
goto again;
307308
}
308309
func(event, NULL, ctx, data);
309-
raw_spin_unlock_irq(&ctx->lock);
310+
perf_ctx_unlock(cpuctx, ctx);
310311
}
311312

312313
/*

0 commit comments

Comments
 (0)