Skip to content

Commit f6b5d51

Browse files
liu-song-6gregkh
authored andcommitted
perf: Fix list corruption in perf_cgroup_switch()
commit 5f4e5ce upstream. There's list corruption on cgrp_cpuctx_list. This happens on the following path: perf_cgroup_switch: list_for_each_entry(cgrp_cpuctx_list) cpu_ctx_sched_in ctx_sched_in ctx_pinned_sched_in merge_sched_in perf_cgroup_event_disable: remove the event from the list Use list_for_each_entry_safe() to allow removing an entry during iteration. Fixes: 058fe1c ("perf/core: Make cgroup switch visit only cpuctxs with cgroup events") Signed-off-by: Song Liu <song@kernel.org> Reviewed-by: Rik van Riel <riel@surriel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20220204004057.2961252-1-song@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ce3ca12 commit f6b5d51

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎kernel/events/core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ static DEFINE_PER_CPU(struct list_head, cgrp_cpuctx_list);
838838
*/
839839
static void perf_cgroup_switch(struct task_struct *task, int mode)
840840
{
841-
struct perf_cpu_context *cpuctx;
841+
struct perf_cpu_context *cpuctx, *tmp;
842842
struct list_head *list;
843843
unsigned long flags;
844844

@@ -849,7 +849,7 @@ static void perf_cgroup_switch(struct task_struct *task, int mode)
849849
local_irq_save(flags);
850850

851851
list = this_cpu_ptr(&cgrp_cpuctx_list);
852-
list_for_each_entry(cpuctx, list, cgrp_cpuctx_entry) {
852+
list_for_each_entry_safe(cpuctx, tmp, list, cgrp_cpuctx_entry) {
853853
WARN_ON_ONCE(cpuctx->ctx.nr_cgroups == 0);
854854

855855
perf_ctx_lock(cpuctx, cpuctx->task_ctx);

0 commit comments

Comments
 (0)