public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/core: restore __perf_remove_from_context when DETACH_EXIT not set
@ 2025-06-03  3:26 David Wang
  2025-06-03  8:33 ` [PATCH v2] " David Wang
  0 siblings, 1 reply; 10+ messages in thread
From: David Wang @ 2025-06-03  3:26 UTC (permalink / raw)
  To: peterz, mingo, acme, namhyung, mingo, yeoreum.yun
  Cc: leo.yan, linux-perf-users, linux-kernel, David Wang

commit a3c3c66670ce ("perf/core: Fix child_total_time_enabled accounting
bug at task exit") made changes to __perf_remove_from_context() to
coordinate its changes with perf_event_exit_event(), but the change are
unconditional, it impacts callpaths to __perf_remove_from_context()
other than from perf_event_exit_event(). One of the impact is to cgroup,
which is not properly handled and would cause kernel panic with high
probalibity during reboot on some system[1].

To confine the side effects, make the changes to
__perf_remove_from_context() conditional, restore to its previous state
except when DETACH_EXIT is set.

Closes: https://lore.kernel.org/lkml/20250601173603.3920-1-00107082@163.com/ [1]
Fixes: a3c3c66670ce ("perf/core: Fix child_total_time_enabled accounting bug at task exit")
Signed-off-by: David Wang <00107082@163.com>
---
 kernel/events/core.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 95e703891b24..6a7e3f5c5af5 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2466,7 +2466,7 @@ __perf_remove_from_context(struct perf_event *event,
 			   void *info)
 {
 	struct perf_event_pmu_context *pmu_ctx = event->pmu_ctx;
-	enum perf_event_state state = PERF_EVENT_STATE_OFF;
+	enum perf_event_state exit_state = PERF_EVENT_STATE_EXIT;
 	unsigned long flags = (unsigned long)info;
 
 	ctx_time_update(cpuctx, ctx);
@@ -2475,19 +2475,20 @@ __perf_remove_from_context(struct perf_event *event,
 	 * Ensure event_sched_out() switches to OFF, at the very least
 	 * this avoids raising perf_pending_task() at this time.
 	 */
-	if (flags & DETACH_EXIT)
-		state = PERF_EVENT_STATE_EXIT;
 	if (flags & DETACH_DEAD) {
 		event->pending_disable = 1;
-		state = PERF_EVENT_STATE_DEAD;
+		exit_state = PERF_EVENT_STATE_DEAD;
 	}
 	event_sched_out(event, ctx);
-	perf_event_set_state(event, min(event->state, state));
+	if (flags & DETACH_EXIT)
+		perf_event_set_state(event, min(event->state, exit_state));
 	if (flags & DETACH_GROUP)
 		perf_group_detach(event);
 	if (flags & DETACH_CHILD)
 		perf_child_detach(event);
 	list_del_event(event, ctx);
+	if (flags & DETACH_DEAD)
+		event->state = PERF_EVENT_STATE_DEAD;
 
 	if (!pmu_ctx->nr_events) {
 		pmu_ctx->rotate_necessary = 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-06-03 14:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-03  3:26 [PATCH] perf/core: restore __perf_remove_from_context when DETACH_EXIT not set David Wang
2025-06-03  8:33 ` [PATCH v2] " David Wang
2025-06-03  9:13   ` Peter Zijlstra
2025-06-03 10:44     ` David Wang
2025-06-03 12:50       ` Peter Zijlstra
2025-06-03 12:54         ` Peter Zijlstra
2025-06-03 13:03           ` David Wang
2025-06-03 13:49             ` David Wang
2025-06-03 13:22           ` Yeoreum Yun
2025-06-03 14:08             ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox