[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <164424191171.16921.7739193739267946142.tip-bot2@tip-bot2>
Date: Mon, 07 Feb 2022 13:51:51 -0000
From: "tip-bot2 for Song Liu" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: Song Liu <song@...nel.org>, Rik van Riel <riel@...riel.com>,
"Peter Zijlstra (Intel)" <peterz@...radead.org>, x86@...nel.org,
linux-kernel@...r.kernel.org
Subject: [tip: perf/urgent] perf: Fix list corruption in perf_cgroup_switch()
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: 5f4e5ce638e6a490b976ade4a40017b40abb2da0
Gitweb: https://git.kernel.org/tip/5f4e5ce638e6a490b976ade4a40017b40abb2da0
Author: Song Liu <song@...nel.org>
AuthorDate: Thu, 03 Feb 2022 16:40:57 -08:00
Committer: Peter Zijlstra <peterz@...radead.org>
CommitterDate: Sun, 06 Feb 2022 22:37:27 +01:00
perf: Fix list corruption in perf_cgroup_switch()
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: 058fe1c0440e ("perf/core: Make cgroup switch visit only cpuctxs with cgroup events")
Signed-off-by: Song Liu <song@...nel.org>
Reviewed-by: Rik van Riel <riel@...riel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Link: https://lkml.kernel.org/r/20220204004057.2961252-1-song@kernel.org
---
kernel/events/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 57c7197..6859229 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -839,7 +839,7 @@ static DEFINE_PER_CPU(struct list_head, cgrp_cpuctx_list);
*/
static void perf_cgroup_switch(struct task_struct *task, int mode)
{
- struct perf_cpu_context *cpuctx;
+ struct perf_cpu_context *cpuctx, *tmp;
struct list_head *list;
unsigned long flags;
@@ -850,7 +850,7 @@ static void perf_cgroup_switch(struct task_struct *task, int mode)
local_irq_save(flags);
list = this_cpu_ptr(&cgrp_cpuctx_list);
- list_for_each_entry(cpuctx, list, cgrp_cpuctx_entry) {
+ list_for_each_entry_safe(cpuctx, tmp, list, cgrp_cpuctx_entry) {
WARN_ON_ONCE(cpuctx->ctx.nr_cgroups == 0);
perf_ctx_lock(cpuctx, cpuctx->task_ctx);
Powered by blists - more mailing lists