Skip to content

Commit 07c5972

Browse files
liu-song-6Ingo Molnar
authored andcommitted
perf/cgroups: Install cgroup events to correct cpuctx
cgroup events are always installed in the cpuctx. However, when it is not installed via IPI, list_update_cgroup_event() adds it to cpuctx of current CPU, which triggers list corruption: [] list_add double add: new=ffff888ff7cf0db0, prev=ffff888ff7ce82f0, next=ffff888ff7cf0db0. To reproduce this, we can simply run: # perf stat -e cs -a & # perf stat -e cs -G anycgroup Fix this by installing it to cpuctx that contains event->ctx, and the proper cgrp_cpuctx_list. Fixes: db0503e ("perf/core: Optimize perf_install_in_event()") Suggested-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Song Liu <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 0034615 commit 07c5972

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

kernel/events/core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -951,9 +951,9 @@ list_update_cgroup_event(struct perf_event *event,
951951

952952
/*
953953
* Because cgroup events are always per-cpu events,
954-
* this will always be called from the right CPU.
954+
* @ctx == &cpuctx->ctx.
955955
*/
956-
cpuctx = __get_cpu_context(ctx);
956+
cpuctx = container_of(ctx, struct perf_cpu_context, ctx);
957957

958958
/*
959959
* Since setting cpuctx->cgrp is conditional on the current @cgrp
@@ -979,7 +979,8 @@ list_update_cgroup_event(struct perf_event *event,
979979

980980
cpuctx_entry = &cpuctx->cgrp_cpuctx_entry;
981981
if (add)
982-
list_add(cpuctx_entry, this_cpu_ptr(&cgrp_cpuctx_list));
982+
list_add(cpuctx_entry,
983+
per_cpu_ptr(&cgrp_cpuctx_list, event->cpu));
983984
else
984985
list_del(cpuctx_entry);
985986
}

0 commit comments

Comments
 (0)