From: "tip-bot2 for Usama Arif" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Usama Arif <usama.arif@linux.dev>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
stable@vger.kernel.org, x86@kernel.org,
linux-kernel@vger.kernel.org
Subject: [tip: perf/urgent] perf/core: Fix perf_sample_data reuse across software events
Date: Sun, 22 Nov 2026 22:49:10 -0000 [thread overview]
Message-ID: <179538775038.92412.1181985385445483116.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20261119211235.99805-2-usama.arif@linux.dev>
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: a3c976da55a8da3b5759bcca94832f757763059d
Gitweb: https://git.kernel.org/tip/a3c976da55a8da3b5759bcca94832f757763059d
Author: Usama Arif <usama.arif@linux.dev>
AuthorDate: Thu, 19 Nov 2026 13:10:44 -08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Sun, 22 Nov 2026 16:07:42 +01:00
perf/core: Fix perf_sample_data reuse across software events
do_perf_sw_event() passes one on-stack struct perf_sample_data to every
matching event. perf_prepare_sample() fills in the fields an event
samples, marks them in data->sample_flags and skips fields that are
already marked, and those marks survive from one event to the next.
So a sampling event later in the list emits the sample ID, timestamp,
pid/tid and callchain prepared for an earlier one. Its record size is
computed from the earlier event's dynamic fields as well and can come
out smaller than what is written, in which case the kernel writes past
its ring-buffer reservation over the records that follow.
Two "perf record -e page-faults,context-switches -c 1 -a" sessions
running at the same time hit this: the one started first gets the
other's sample IDs and fails with "Bad address".
Commit:
1d1bfe30dad5 ("perf/core: Fix perf_sample_data not properly initialized for different swevents in perf_tp_event()")
fixed the same problem for tracepoints. Do the same here: initialize
the struct for each matching event. While at it, drop the unused 'data'
argument of perf_swevent_match().
Fixes: bb447c27a467 ("perf/core: Set data->sample_flags in perf_prepare_sample()")
Signed-off-by: Usama Arif <usama.arif@linux.dev>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261119211235.99805-2-usama.arif@linux.dev
---
kernel/events/core.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 51c251c..42bd8ad 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11142,7 +11142,6 @@ int perf_exclude_event(struct perf_event *event, struct pt_regs *regs)
static int perf_swevent_match(struct perf_event *event,
enum perf_type_id type,
u32 event_id,
- struct perf_sample_data *data,
struct pt_regs *regs)
{
if (event->attr.type != type)
@@ -11207,11 +11206,10 @@ find_swevent_head(struct swevent_htable *swhash, struct perf_event *event)
}
static void do_perf_sw_event(enum perf_type_id type, u32 event_id,
- u64 nr,
- struct perf_sample_data *data,
- struct pt_regs *regs)
+ u64 nr, struct pt_regs *regs, u64 addr)
{
struct swevent_htable *swhash = this_cpu_ptr(&swevent_htable);
+ struct perf_sample_data data;
struct perf_event *event;
struct hlist_head *head;
@@ -11221,8 +11219,10 @@ static void do_perf_sw_event(enum perf_type_id type, u32 event_id,
goto end;
hlist_for_each_entry_rcu(event, head, hlist_entry) {
- if (perf_swevent_match(event, type, event_id, data, regs))
- perf_swevent_event(event, nr, data, regs);
+ if (perf_swevent_match(event, type, event_id, regs)) {
+ perf_sample_data_init(&data, addr, 0);
+ perf_swevent_event(event, nr, &data, regs);
+ }
}
end:
rcu_read_unlock();
@@ -11243,13 +11243,10 @@ void perf_swevent_put_recursion_context(int rctx)
void ___perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr)
{
- struct perf_sample_data data;
-
if (WARN_ON_ONCE(!regs))
return;
- perf_sample_data_init(&data, addr, 0);
- do_perf_sw_event(PERF_TYPE_SOFTWARE, event_id, nr, &data, regs);
+ do_perf_sw_event(PERF_TYPE_SOFTWARE, event_id, nr, regs, addr);
}
void __perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr)
next prev parent reply other threads:[~2026-11-22 22:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 21:10 [PATCH 0/3] perf/core: Fix software event sample data, then stop zeroing it Usama Arif
2026-11-19 21:10 ` [PATCH 1/3] perf/core: Fix perf_sample_data reuse across software events Usama Arif
2026-11-22 22:49 ` tip-bot2 for Usama Arif [this message]
2026-11-19 21:10 ` [PATCH 2/3] perf/core: Don't let BPF programs read an uninitialized sample address Usama Arif
2026-11-22 22:49 ` [tip: perf/urgent] " tip-bot2 for Usama Arif
2026-11-19 21:10 ` [PATCH 3/3] perf/core: Don't zero perf_sample_data in do_perf_sw_event() Usama Arif
2026-11-20 9:11 ` Peter Zijlstra
2026-11-20 9:12 ` Peter Zijlstra
2026-11-20 20:05 ` Usama Arif
2026-11-20 20:02 ` Usama Arif
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=179538775038.92412.1181985385445483116.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=usama.arif@linux.dev \
--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®