Commit 7b4c5a37 authored by Luo Gengkun's avatar Luo Gengkun Committed by Peter Zijlstra
Browse files

perf/core: Fix the WARN_ON_ONCE is out of lock protected region



commit 3172fb98 ("perf/core: Fix WARN in perf_cgroup_switch()") try to
fix a concurrency problem between perf_cgroup_switch and
perf_cgroup_event_disable. But it does not to move the WARN_ON_ONCE into
lock-protected region, so the warning is still be triggered.

Fixes: 3172fb98 ("perf/core: Fix WARN in perf_cgroup_switch()")
Signed-off-by: default avatarLuo Gengkun <luogengkun@huaweicloud.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20250626135403.2454105-1-luogengkun@huaweicloud.com
parent d0b3b7b2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -951,8 +951,6 @@ static void perf_cgroup_switch(struct task_struct *task)
	if (READ_ONCE(cpuctx->cgrp) == NULL)
		return;

	WARN_ON_ONCE(cpuctx->ctx.nr_cgroups == 0);

	cgrp = perf_cgroup_from_task(task, NULL);
	if (READ_ONCE(cpuctx->cgrp) == cgrp)
		return;
@@ -964,6 +962,8 @@ static void perf_cgroup_switch(struct task_struct *task)
	if (READ_ONCE(cpuctx->cgrp) == NULL)
		return;

	WARN_ON_ONCE(cpuctx->ctx.nr_cgroups == 0);

	perf_ctx_disable(&cpuctx->ctx, true);

	ctx_sched_out(&cpuctx->ctx, NULL, EVENT_ALL|EVENT_CGROUP);