From: bot+bpf-ci@kernel.org
To: irogers@google.com,peterz@infradead.org,mingo@redhat.com,acme@kernel.org,namhyung@kernel.org
Cc: mark.rutland@arm.com,alexander.shishkin@linux.intel.com,jolsa@kernel.org,irogers@google.com,adrian.hunter@intel.com,james.clark@linaro.org,song@kernel.org,ast@kernel.org,linux-perf-users@vger.kernel.org,linux-kernel@vger.kernel.org,bpf@vger.kernel.org,stable@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH v1] perf/core: Restore header fields in sideband output callbacks
Date: Tue, 29 Sep 2026 23:37:15 +0000 (UTC) [thread overview]
Message-ID: <d8aa770b82f03b9cbae1bc84c8505c32d451abde5fe4517a903f1311b940b0d6@mail.kernel.org> (raw)
In-Reply-To: <20260929014206.4175245-1-irogers@google.com>
[-- Attachment #1: Type: text/plain, Size: 5160 bytes --]
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index db7b76d6b68a..2be915a293ce 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -9032,6 +9032,11 @@ static void perf_iterate_sb_cpu(perf_iterate_f output, void *data)
> *
> * For new callers; ensure that account_pmu_sb_event() includes
> * your event, otherwise it might not get delivered.
> + *
> + * Note: @data is shared across all @output calls, so any fields modified
> + * incrementally or conditionally (e.g. header.size via
> + * perf_event_header__init_id()) must be saved and restored by @output,
> + * or unconditionally re-initialized on each call.
> */
> static void
> perf_iterate_sb(perf_iterate_f output, void *data,
Peter Zijlstra identified that perf_event_switch_output() also modifies
header.type and header.size before calling perf_event_header__init_id()
and suggested it might need similar treatment.
Looking at perf_event_switch_output():
if (event->ctx->task) {
se->event_id.header.type = PERF_RECORD_SWITCH;
se->event_id.header.size = sizeof(se->event_id.header);
} else {
se->event_id.header.type = PERF_RECORD_SWITCH_CPU_WIDE;
se->event_id.header.size = sizeof(se->event_id);
...
}
perf_event_header__init_id(&se->event_id.header, &sample, event);
The new comment mentions that fields must be "saved and restored by
@output, or unconditionally re-initialized on each call."
perf_event_switch_output() does unconditionally reinitialize both
header.type and header.size at the start of each callback invocation,
which should prevent the accumulation bug.
Is this analysis correct, or does perf_event_switch_output() need the
save/restore pattern as well?
> @@ -9726,6 +9731,7 @@ static void perf_event_mmap_output(struct perf_event *event,
> struct perf_sample_data sample;
> int size = mmap_event->event_id.header.size;
> u32 type = mmap_event->event_id.header.type;
> + u16 misc = mmap_event->event_id.header.misc;
> bool use_build_id;
> int ret;
>
[ ... ]
> @@ -9783,6 +9789,7 @@ static void perf_event_mmap_output(struct perf_event *event,
> out:
> mmap_event->event_id.header.size = size;
> mmap_event->event_id.header.type = type;
> + mmap_event->event_id.header.misc = misc;
> }
[ ... ]
> @@ -10247,6 +10254,7 @@ static void perf_event_ksymbol_output(struct perf_event *event, void *data)
> struct perf_ksymbol_event *ksymbol_event = data;
> struct perf_output_handle handle;
> struct perf_sample_data sample;
> + u16 header_size = ksymbol_event->event_id.header.size;
> int ret;
>
> if (!perf_event_ksymbol_match(event))
> @@ -10257,13 +10265,15 @@ static void perf_event_ksymbol_output(struct perf_event *event, void *data)
> ret = perf_output_begin(&handle, &sample, event,
> ksymbol_event->event_id.header.size);
> if (ret)
> - return;
> + goto out;
>
> perf_output_put(&handle, ksymbol_event->event_id);
> __output_copy(&handle, ksymbol_event->name, ksymbol_event->name_len);
> perf_event__output_id_sample(event, &handle, &sample);
>
> perf_output_end(&handle);
> +out:
> + ksymbol_event->event_id.header.size = header_size;
> }
[ ... ]
> @@ -10337,6 +10347,7 @@ static void perf_event_bpf_output(struct perf_event *event, void *data)
> struct perf_bpf_event *bpf_event = data;
> struct perf_output_handle handle;
> struct perf_sample_data sample;
> + u16 header_size = bpf_event->event_id.header.size;
> int ret;
>
> if (!perf_event_bpf_match(event))
> @@ -10347,12 +10358,14 @@ static void perf_event_bpf_output(struct perf_event *event, void *data)
> ret = perf_output_begin(&handle, &sample, event,
> bpf_event->event_id.header.size);
> if (ret)
> - return;
> + goto out;
>
> perf_output_put(&handle, bpf_event->event_id);
> perf_event__output_id_sample(event, &handle, &sample);
>
> perf_output_end(&handle);
> +out:
> + bpf_event->event_id.header.size = header_size;
> }
[ ... ]
> @@ -10499,6 +10512,7 @@ static void perf_event_text_poke_output(struct perf_event *event, void *data)
> struct perf_text_poke_event *text_poke_event = data;
> struct perf_output_handle handle;
> struct perf_sample_data sample;
> + u16 header_size = text_poke_event->event_id.header.size;
> u64 padding = 0;
> int ret;
>
> @@ -10510,7 +10524,7 @@ static void perf_event_text_poke_output(struct perf_event *event, void *data)
> ret = perf_output_begin(&handle, &sample, event,
> text_poke_event->event_id.header.size);
> if (ret)
> - return;
> + goto out;
>
> perf_output_put(&handle, text_poke_event->event_id);
> perf_output_put(&handle, text_poke_event->old_len);
> @@ -10525,6 +10539,8 @@ static void perf_event_text_poke_output(struct perf_event *event, void *data)
> perf_event__output_id_sample(event, &handle, &sample);
>
> perf_output_end(&handle);
> +out:
> + text_poke_event->event_id.header.size = header_size;
> }
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/36643934404
prev parent reply other threads:[~2026-09-29 23:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 1:42 Ian Rogers
2026-09-29 12:04 ` Peter Zijlstra
2026-09-29 18:21 ` Ian Rogers
2026-09-29 22:23 ` [PATCH v1] perf/core: Replace perf_event_header__init_id with full header init Ian Rogers
2026-10-01 7:07 ` Peter Zijlstra
2026-10-01 16:45 ` Ian Rogers
2026-10-02 9:33 ` [tip: perf/urgent] perf: " tip-bot2 for Ian Rogers
2026-10-09 23:30 ` [PATCH v1] perf/core: " patchwork-bot+netdevbpf
2026-09-29 23:37 ` bot+bpf-ci [this message]
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=d8aa770b82f03b9cbae1bc84c8505c32d451abde5fe4517a903f1311b940b0d6@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--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=martin.lau@kernel.org \
--cc=mason@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
--cc=yonghong.song@linux.dev \
/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®