mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@arm.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	 Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	 Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	 James Clark <james.clark@linaro.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	linux-perf-users@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Sashiko AI <sashiko-bot@kernel.org>,  Leo Yan <leo.yan@arm.com>
Subject: [PATCH v3] perf/core: Fix ITRACE start suppression for inherited events
Date: Wed, 02 Dec 2026 17:58:51 +0000	[thread overview]
Message-ID: <20261202-perf_core_itrace_start_fix_inherit_event-v3-1-72e96d7e1f30@arm.com> (raw)

ITRACE_START supplies the initial PID/TID for AUX trace decoding. For
inherited events, perf_log_itrace_start() checks the parent, but
perf_event_itrace_started() marks the child. If a child starts first,
the parent's flag stays clear and subsequent schedule-ins can emit
redundant records.

One option is to set PERF_ATTACH_ITRACE in the parent's attach_state.
The child holds its own context lock during schedule-in, so this update
could race with parent teardown and overwrite changes to other flags.
Taking the parent's lock as well would require nesting the two context
locks in a consistent order.

Use a separate bool on the event to record whether the PMU has reported
a trace start for it or any of its children. This lets subsequent
schedule-ins suppress ITRACE_START independently of event attachment.

On the tested x86-64 and arm64 builds, the bool fits in existing
padding, preserving sizeof(struct perf_event) and the offsets of all
existing members.

Reported-by: Sashiko AI <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/linux-perf-users/20260901164705.042781F000E9@smtp.kernel.org/
Fixes: 9a6694cfa239 ("perf/x86/intel/pt: Do not force sync packets on every schedule-in")
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
Changes in v3:
- Added a new the bool flag to avoid race condition with parent.
- Link to v2: https://lore.kernel.org/r/20260929-perf_core_itrace_start_fix_inherit_event-v2-1-9361a946ed56@arm.com

Changes in v2:
- Changed setter to fetch parent event instead (James).
- Link to v1: https://lore.kernel.org/r/20260903-perf_core_itrace_start_fix_inherit_event-v1-1-6bff7e675af5@arm.com
---
 include/linux/perf_event.h | 2 +-
 kernel/events/core.c       | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index b52348eca6ef10ffd5938968846846433bc7f02c..aa232d3ebb7c297b69362e31e5ce6e8218ee675b 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -728,7 +728,6 @@ struct swevent_hlist {
 #define PERF_ATTACH_CHILD		0x0040
 #define PERF_ATTACH_EXCLUSIVE		0x0080
 #define PERF_ATTACH_CALLCHAIN		0x0100
-#define PERF_ATTACH_ITRACE		0x0200
 
 struct bpf_prog;
 struct perf_cgroup;
@@ -827,6 +826,7 @@ struct perf_event {
 	u16				header_size;
 	u16				id_header_size;
 	u16				read_size;
+	bool				itrace_started;
 	struct hw_perf_event		hw;
 
 	struct perf_event_context	*ctx;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4ab3919ac78e903685a8693e78762d8b165cba20..e9d24000828868dac3f99939555950ed3134d92a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10691,7 +10691,10 @@ void perf_event_text_poke(const void *addr, const void *old_bytes,
 
 void perf_event_itrace_started(struct perf_event *event)
 {
-	WRITE_ONCE(event->attach_state, event->attach_state | PERF_ATTACH_ITRACE);
+	if (event->parent)
+		event = event->parent;
+
+	WRITE_ONCE(event->itrace_started, true);
 }
 EXPORT_SYMBOL_GPL(perf_event_itrace_started);
 
@@ -10710,7 +10713,7 @@ static void perf_log_itrace_start(struct perf_event *event)
 		event = event->parent;
 
 	if (!(event->pmu->capabilities & PERF_PMU_CAP_ITRACE) ||
-	    event->attach_state & PERF_ATTACH_ITRACE)
+	    READ_ONCE(event->itrace_started))
 		return;
 
 	rec.pid	= perf_event_pid(event, current);
@@ -14758,7 +14761,6 @@ perf_event_exit_event(struct perf_event *event,
 		 */
 		detach_flags |= DETACH_GROUP | DETACH_CHILD;
 		mutex_lock(&parent_event->child_mutex);
-		/* PERF_ATTACH_ITRACE might be set concurrently */
 		attach_state = READ_ONCE(event->attach_state);
 
 		if (attach_state & PERF_ATTACH_CHILD)

---
base-commit: 693c2e04e3f1d4c59af236e1211b7b8cb165a790
change-id: 20260903-perf_core_itrace_start_fix_inherit_event-a8930d792899

Best regards,
-- 
Leo Yan <leo.yan@arm.com>


                 reply	other threads:[~2026-12-02 17:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261202-perf_core_itrace_start_fix_inherit_event-v3-1-72e96d7e1f30@arm.com \
    --to=leo.yan@arm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sashiko-bot@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®