Skip to content

Commit 95cf59e

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
perf: Fix perf_cgroup_switch for sw-events
Jiri reported that he could trigger the WARN_ON_ONCE() in perf_cgroup_switch() using sw-events. This is because sw-events share a cpuctx with multiple PMUs. Use the ->unique_pmu pointer to limit the pmu iteration to unique cpuctx instances. Reported-and-Tested-by: Jiri Olsa <jolsa@redhat.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/n/tip-so7wi2zf3jjzrwcutm2mkz0j@git.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 3f1f332 commit 95cf59e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kernel/events/core.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ void perf_cgroup_switch(struct task_struct *task, int mode)
372372

373373
list_for_each_entry_rcu(pmu, &pmus, entry) {
374374
cpuctx = this_cpu_ptr(pmu->pmu_cpu_context);
375+
if (cpuctx->unique_pmu != pmu)
376+
continue; /* ensure we process each cpuctx once */
375377

376378
/*
377379
* perf_cgroup_events says at least one
@@ -395,9 +397,10 @@ void perf_cgroup_switch(struct task_struct *task, int mode)
395397

396398
if (mode & PERF_CGROUP_SWIN) {
397399
WARN_ON_ONCE(cpuctx->cgrp);
398-
/* set cgrp before ctxsw in to
399-
* allow event_filter_match() to not
400-
* have to pass task around
400+
/*
401+
* set cgrp before ctxsw in to allow
402+
* event_filter_match() to not have to pass
403+
* task around
401404
*/
402405
cpuctx->cgrp = perf_cgroup_from_task(task);
403406
cpu_ctx_sched_in(cpuctx, EVENT_ALL, task);

0 commit comments

Comments
 (0)