Skip to content

Commit fe826cc

Browse files
namhyungPeter Zijlstra
authored andcommitted
perf: Really fix event_function_call() locking
Commit 558abc7 ("perf: Fix event_function_call() locking") lost IRQ disabling by mistake. Fixes: 558abc7 ("perf: Fix event_function_call() locking") Reported-by: Pengfei Xu <[email protected]> Reported-by: Naresh Kamboju <[email protected]> Tested-by: Pengfei Xu <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
1 parent 3e15a3f commit fe826cc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

kernel/events/core.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ static int event_function(void *info)
298298
static void event_function_call(struct perf_event *event, event_f func, void *data)
299299
{
300300
struct perf_event_context *ctx = event->ctx;
301-
struct perf_cpu_context *cpuctx = this_cpu_ptr(&perf_cpu_context);
302301
struct task_struct *task = READ_ONCE(ctx->task); /* verified in event_function */
302+
struct perf_cpu_context *cpuctx;
303303
struct event_function_struct efs = {
304304
.event = event,
305305
.func = func,
@@ -327,22 +327,25 @@ static void event_function_call(struct perf_event *event, event_f func, void *da
327327
if (!task_function_call(task, event_function, &efs))
328328
return;
329329

330+
local_irq_disable();
331+
cpuctx = this_cpu_ptr(&perf_cpu_context);
330332
perf_ctx_lock(cpuctx, ctx);
331333
/*
332334
* Reload the task pointer, it might have been changed by
333335
* a concurrent perf_event_context_sched_out().
334336
*/
335337
task = ctx->task;
336-
if (task == TASK_TOMBSTONE) {
337-
perf_ctx_unlock(cpuctx, ctx);
338-
return;
339-
}
338+
if (task == TASK_TOMBSTONE)
339+
goto unlock;
340340
if (ctx->is_active) {
341341
perf_ctx_unlock(cpuctx, ctx);
342+
local_irq_enable();
342343
goto again;
343344
}
344345
func(event, NULL, ctx, data);
346+
unlock:
345347
perf_ctx_unlock(cpuctx, ctx);
348+
local_irq_enable();
346349
}
347350

348351
/*

0 commit comments

Comments
 (0)