All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v4 08/19] perf session: Avoid double byte-swapping re-parsed deferred samples
Date: Wed, 25 Nov 2026 01:12:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-232319@kernel.org> (raw)
In-Reply-To: <20261125005108.1020003-9-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf evsel: perf_evsel__parse_id_sample() ignores needs_swap
  and in-place swap
--

commit 16d772fa0fe35fd77ab000644b7cb3a76f3ccb40
Author: Ian Rogers <irogers@google.com>

perf session: Avoid double byte-swapping re-parsed deferred samples

This commit unswaps PERF_SAMPLE_TID, PERF_SAMPLE_CPU, and PERF_SAMPLE_RAW's
size prefix in-place during the initial cross-endian sample parse and adds
evlist__parse_sample_unswapped() so deferred samples can be re-parsed
without double byte-swapping.

> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 737a8680aaae3..322582bb4f40b 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -3520,6 +3520,7 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event,
>  			u.val64 = bswap_64(u.val64);
>  			u.val32[0] = bswap_32(u.val32[0]);
>  			u.val32[1] = bswap_32(u.val32[1]);
> +			*(__u64 *)array = u.val64;
>  		}
>  
>  		data->pid = u.val32[0];
> @@ -3554,6 +3555,8 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event,
>  			/* undo swap of u64, then swap on individual u32s */
>  			u.val64 = bswap_64(u.val64);
>  			u.val32[0] = bswap_32(u.val32[0]);
> +			u.val32[1] = bswap_32(u.val32[1]);
> +			*(__u64 *)array = u.val64;
>  		}
>  
>  		data->cpu = u.val32[0];

[Severity: Medium]
Does perf_evsel__parse_id_sample() also need to take needs_swap and unswap
PERF_SAMPLE_CPU and PERF_SAMPLE_TID in-place in the sample_id_all trailer?

For non-PERF_RECORD_SAMPLE events (and PERF_RECORD_CALLCHAIN_DEFERRED)
with sample_id_all enabled, __evsel__parse_sample() delegates to
perf_evsel__parse_id_sample(), which still reads evsel->needs_swap directly
and only unswaps the 32-bit fields into a local variable:

tools/perf/util/evsel.c:perf_evsel__parse_id_sample() {
	bool swapped = evsel->needs_swap;
	...
	if (type & PERF_SAMPLE_CPU) {
		...
		u.val64 = array[i--];
		if (swapped) {
			/* undo swap of u64, then swap on individual u32s */
			u.val64 = bswap_64(u.val64);
			u.val32[0] = bswap_32(u.val32[0]);
		}
		sample->cpu = u.val32[0];
	}
}

When pyrf_event__copy() re-parses a copied non-sample event (such as
PERF_RECORD_SWITCH) with needs_swap=false on a cross-endian recording, the
sample_id_all trailer in event_copy still has its 32-bit halves in
post-bswap_64 order, leaving pid and tid swapped and cpu reading the
reserved word (0); conversely, calling __evsel__parse_sample() with
needs_swap=false without mutating evsel->needs_swap still swaps in
perf_evsel__parse_id_sample().

Passing needs_swap to perf_evsel__parse_id_sample() (with needs_swap=false
from evsel__parse_sample_timestamp() so the trailer is not modified before
perf_session__deliver_event()) and writing the unswapped u.val64 back into
array would keep sample_id_all trailers consistent with
PERF_RECORD_SAMPLE.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125005108.1020003-1-irogers@google.com?part=8

  reply	other threads:[~2026-11-25  1:12 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  0:50 [PATCH v4 00/19] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support Ian Rogers
2026-11-25  0:50 ` [PATCH v4 01/19] perf/core: Protect per-CPU callchain buffer across bpf_overflow_handler() Ian Rogers
2026-11-25  0:50 ` [PATCH v4 02/19] perf/uapi: Factor perf_build_id out into its own top-level struct Ian Rogers
2026-11-25 13:17   ` Peter Zijlstra
2026-11-30 19:34     ` Ian Rogers
2026-11-25  0:50 ` [PATCH v4 03/19] perf/uapi: Add BUILD_ID_OFFSET sample types to UAPI Ian Rogers
2026-11-25 13:25   ` Peter Zijlstra
2026-11-25 21:45     ` Namhyung Kim
2026-11-30 19:38       ` Ian Rogers
2026-12-01  8:14         ` Peter Zijlstra
2026-12-01 17:10           ` Ian Rogers
2026-12-01  8:10       ` Peter Zijlstra
2026-11-25  0:50 ` [PATCH v4 04/19] bpf: Export stack_map_get_build_id_offset() for perf events Ian Rogers
2026-11-25  0:50 ` [PATCH v4 05/19] perf/core: Implement BUILD_ID_OFFSET and CALLCHAIN_BUILD_ID_OFFSET sample types Ian Rogers
2026-11-25  1:19   ` sashiko-bot
2026-11-25  0:50 ` [PATCH v4 06/19] perf/core: Support deferred unwinding for BUILD_ID_OFFSET " Ian Rogers
2026-11-25  0:50 ` [PATCH v4 07/19] perf inject: Set ordered_events and ordering_requires_timestamps for --aslr Ian Rogers
2026-11-25  0:50 ` [PATCH v4 08/19] perf session: Avoid double byte-swapping re-parsed deferred samples Ian Rogers
2026-11-25  1:12   ` sashiko-bot [this message]
2026-11-25  0:50 ` [PATCH v4 09/19] perf inject: Fix PERF_SAMPLE_READ layout and bounds checks in aslr_tool__process_sample() Ian Rogers
2026-11-25  0:50 ` [PATCH v4 10/19] tools headers UAPI: Sync linux/perf_event.h for struct perf_build_id Ian Rogers
2026-11-25  0:51 ` [PATCH v4 11/19] tools headers UAPI: Sync linux/perf_event.h for BUILD_ID_OFFSET Ian Rogers
2026-11-25  0:51 ` [PATCH v4 12/19] perf: Refactor thread map and symbol APIs to take perf_sample Ian Rogers
2026-11-25  0:51 ` [PATCH v4 13/19] perf maps: Add dsos__find_by_build_id() and maps__find_by_build_id() Ian Rogers
2026-11-25  0:51 ` [PATCH v4 14/19] perf evsel: Parse, synthesize, and dump BUILD_ID_OFFSET sample types Ian Rogers
2026-11-25  0:51 ` [PATCH v4 15/19] perf symbol: Resolve symbols and callchains using build ID and offset Ian Rogers
2026-11-25  0:51 ` [PATCH v4 16/19] perf inject: Add --sample-buildids to convert samples to build ID + offset Ian Rogers
2026-11-25  1:18   ` sashiko-bot
2026-11-25  0:51 ` [PATCH v4 17/19] perf record: Add --buildid-offset option Ian Rogers
2026-11-25  1:19   ` sashiko-bot
2026-11-25  0:51 ` [PATCH v4 18/19] perf test: Add BUILD_ID_OFFSET C unit tests Ian Rogers
2026-11-25  0:51 ` [PATCH v4 19/19] perf test: Add inject --sample-buildids and record --buildid-offset shell tests Ian Rogers
2026-11-25  1:19 ` [PATCH v4 00/19] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support sashiko-bot

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=sashiko-outbox-232319@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=irogers@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.