mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: perf/core] perf: Simplify child event tear-down
Date: Tue, 08 Apr 2025 19:05:04 -0000	[thread overview]
Message-ID: <174413910477.31282.11766952801429346476.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250307193305.486326750@infradead.org>

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     0a00a43b8c200df5b9ca2b3e1726479b5916264b
Gitweb:        https://git.kernel.org/tip/0a00a43b8c200df5b9ca2b3e1726479b5916264b
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Fri, 17 Jan 2025 15:25:23 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 08 Apr 2025 20:55:46 +02:00

perf: Simplify child event tear-down

Currently perf_event_release_kernel() will iterate the child events and attempt
tear-down. However, it removes them from the child_list using list_move(),
notably skipping the state management done by perf_child_detach().

Crucially, it fails to clear PERF_ATTACH_CHILD, which opens the door for a
concurrent perf_remove_from_context() to race.

This way child_list management stays fully serialized using child_mutex.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ravi Bangoria <ravi.bangoria@amd.com>
Link: https://lkml.kernel.org/r/20250307193305.486326750@infradead.org
---
 kernel/events/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index a85d63b..3c92b75 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2325,7 +2325,11 @@ static void perf_child_detach(struct perf_event *event)
 	if (WARN_ON_ONCE(!parent_event))
 		return;
 
+	/*
+	 * Can't check this from an IPI, the holder is likey another CPU.
+	 *
 	lockdep_assert_held(&parent_event->child_mutex);
+	 */
 
 	sync_child_event(event);
 	list_del_init(&event->child_list);
@@ -5759,8 +5763,8 @@ again:
 		tmp = list_first_entry_or_null(&event->child_list,
 					       struct perf_event, child_list);
 		if (tmp == child) {
-			perf_remove_from_context(child, DETACH_GROUP);
-			list_move(&child->child_list, &free_list);
+			perf_remove_from_context(child, DETACH_GROUP | DETACH_CHILD);
+			list_add(&child->child_list, &free_list);
 		} else {
 			var = &ctx->refcount;
 		}

  parent reply	other threads:[~2025-04-08 19:05 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-07 19:33 [PATCH v3 0/7] perf: Make perf_pmu_unregister() usable Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 1/7] perf: Ensure bpf_perf_link path is properly serialized Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 2/7] perf: Simplify child event tear-down Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 3/7] perf: Simplify perf_event_free_task() wait Peter Zijlstra
2025-03-17  6:49   ` Ravi Bangoria
2025-04-02  9:15     ` Peter Zijlstra
2025-04-08 19:05   ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-04-09 13:01     ` Frederic Weisbecker
2025-04-10  9:34       ` Peter Zijlstra
2025-04-10  9:45         ` Frederic Weisbecker
2025-04-17 12:03       ` Ingo Molnar
2025-04-17 13:01       ` [tip: perf/core] perf/core: Fix put_ctx() ordering tip-bot2 for Frederic Weisbecker
2025-03-07 19:33 ` [PATCH v3 4/7] perf: Simplify perf_event_release_kernel() Peter Zijlstra
2025-04-08 19:05   ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 5/7] perf: Unify perf_event_free_task() / perf_event_exit_task_context() Peter Zijlstra
2025-03-10 15:35   ` [PATCH v3a " Peter Zijlstra
2025-04-08 19:05   ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 6/7] perf: Rename perf_event_exit_task(.child) Peter Zijlstra
2025-03-10 11:08   ` Ravi Bangoria
2025-03-10 14:47     ` Peter Zijlstra
2025-03-10 15:20       ` Ravi Bangoria
2025-03-10 15:27         ` Peter Zijlstra
2025-03-10 15:37   ` [PATCH v3a " Peter Zijlstra
2025-03-12  6:31     ` Ravi Bangoria
2025-03-12 10:16       ` Peter Zijlstra
2025-03-07 19:33 ` [PATCH v3 7/7] perf: Make perf_pmu_unregister() useable Peter Zijlstra
2025-03-10 15:35   ` Ravi Bangoria
2025-03-10 16:14     ` Peter Zijlstra
2025-03-10 16:46   ` Ravi Bangoria
2025-03-12 12:57     ` Peter Zijlstra
2025-03-12 13:57       ` Ravi Bangoria
2025-04-08 19:05   ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-04-17  8:08     ` Peter Zijlstra
2025-04-17 13:01       ` [tip: perf/core] perf/core: Fix event timekeeping merge tip-bot2 for Peter Zijlstra
2025-04-14  0:37   ` [PATCH v3 7/7] perf: Make perf_pmu_unregister() useable Mi, Dapeng
2025-04-17  8:07     ` Peter Zijlstra
2025-04-17  8:24       ` Mi, Dapeng
2025-04-17 11:30       ` [tip: perf/core] perf/core: Fix perf-stat / read() tip-bot2 for Peter Zijlstra
2025-04-17 13:01       ` tip-bot2 for Peter Zijlstra
2025-03-17  6:54 ` [PATCH v3 0/7] perf: Make perf_pmu_unregister() usable Ravi Bangoria
2025-04-08 19:05 ` [tip: perf/core] perf: Rename perf_event_exit_task(.child) tip-bot2 for Peter Zijlstra
2025-04-08 19:05 ` tip-bot2 for Peter Zijlstra [this message]
2025-04-08 19:05 ` [tip: perf/core] perf: Ensure bpf_perf_link path is properly serialized tip-bot2 for Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=174413910477.31282.11766952801429346476.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®