]> git.hungrycats.org Git - linux/commitdiff
perf: Really fix event_function_call() locking
authorNamhyung Kim <namhyung@kernel.org>
Tue, 13 Aug 2024 20:55:11 +0000 (22:55 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Oct 2024 10:00:42 +0000 (12:00 +0200)
[ Upstream commit fe826cc2654e8561b64246325e6a51b62bf2488c ]

Commit 558abc7e3f89 ("perf: Fix event_function_call() locking") lost
IRQ disabling by mistake.

Fixes: 558abc7e3f89 ("perf: Fix event_function_call() locking")
Reported-by: Pengfei Xu <pengfei.xu@intel.com>
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Tested-by: Pengfei Xu <pengfei.xu@intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/events/core.c

index e18a07de9920a41b6680daa407aa325c07d350da..e5188b0899b63f1341f1d483829e0848d1dfa69c 100644 (file)
@@ -263,8 +263,8 @@ unlock:
 static void event_function_call(struct perf_event *event, event_f func, void *data)
 {
        struct perf_event_context *ctx = event->ctx;
-       struct perf_cpu_context *cpuctx = this_cpu_ptr(&perf_cpu_context);
        struct task_struct *task = READ_ONCE(ctx->task); /* verified in event_function */
+       struct perf_cpu_context *cpuctx;
        struct event_function_struct efs = {
                .event = event,
                .func = func,
@@ -292,22 +292,25 @@ again:
        if (!task_function_call(task, event_function, &efs))
                return;
 
+       local_irq_disable();
+       cpuctx = this_cpu_ptr(&perf_cpu_context);
        perf_ctx_lock(cpuctx, ctx);
        /*
         * Reload the task pointer, it might have been changed by
         * a concurrent perf_event_context_sched_out().
         */
        task = ctx->task;
-       if (task == TASK_TOMBSTONE) {
-               perf_ctx_unlock(cpuctx, ctx);
-               return;
-       }
+       if (task == TASK_TOMBSTONE)
+               goto unlock;
        if (ctx->is_active) {
                perf_ctx_unlock(cpuctx, ctx);
+               local_irq_enable();
                goto again;
        }
        func(event, NULL, ctx, data);
+unlock:
        perf_ctx_unlock(cpuctx, ctx);
+       local_irq_enable();
 }
 
 /*