All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Clark" <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 06/34] perf cs-etm: Don't read past the end of the map
Date: Wed, 18 Nov 2026 17:11:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-221594@kernel.org> (raw)
In-Reply-To: <20261118-james-coresight-jit-v1-6-dad4d90747f6@linaro.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf cs-etm: __cs_etm__mem_access() uses map bounds before
  map__load()
- [Low] perf cs-etm: Fixes trailer cites c9a01a11dfe6 instead of
  20d9c478b01a
--

commit 12640a74a59159fbba9b39a02acb1bd86e89bf8a
Author: James Clark <james.clark@linaro.org>

> perf cs-etm: Don't read past the end of the map
>
> OpenCSD caches instruction memory one page size at a time. Perf reads
> this requested size from the file on disk without limiting it to the end
> of the map, so the page can contain ELF metadata from the file that
> wasn't mapped. If a subsequent read for a different .so file falls into
> this range, then it won't be decoded properly.
>
> Fix it by clamping the read size to the end of the map. Now when OpenCSD
> requests an address outside of that range, Perf will load the next .so
> file rather than OpenCSD using the mis-cached data.
>
> Fixes: c9a01a11dfe6 ("perf tools: Add support for decoding CoreSight trace data")
> Signed-off-by: James Clark <james.clark@linaro.org>

[Severity: Low]
Commit c9a01a11dfe6 ("perf tools: Add support for decoding CoreSight trace
data") only added packet buffering and trace element printing in
cs-etm-decoder.c.  The unclamped dso__data_read_offset() call in
cs_etm__mem_access() was introduced in commit 20d9c478b01a ("pert tools:
Add queue management functionality"), so should the Fixes tag reference
that commit instead?

> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 3fce3c3579438..fb4582dc378e1 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -1213,6 +1213,12 @@ static u32 __cs_etm__mem_access(struct cs_etm_queue *etmq,
>  
>  	offset = map__map_ip(al.map, address);
>  
> +	/*
> +	 * Clamp to the map size to avoid putting unmapped ELF file data from
> +	 * the .so into OpenCSD's cache as map data.
> +	 */
> +	size = min_t(u64, size, map__end(al.map) - address);
> +
>  	map__load(al.map);
>  
>  	len = dso__data_read_offset(dso, maps__machine(thread__maps(thread)),

[Severity: Medium]
Can map__end(al.map) - address underflow or evaluate against stale map
bounds when decoding kernel or module traces?

When symbol_conf.lazy_load_kernel_maps is false (the default in perf
script and perf report), thread__find_map() calls map__load(al->map) after
maps__find(), which shrinks vmlinux_map in place to the .text section
(e.g., via remap_kernel_cb()) and splits other executable sections into
separate maps without re-looking up al->map.  If address was in one of
those split sections above the new map__end(al.map), map__end(al.map) -
address underflows u64 (or evaluates to 0 at the boundary, causing
dso__data_read_offset() to return 0 and fail decoding).

Conversely, when symbol_conf.lazy_load_kernel_maps is true (such as in
perf inject --itrace), thread__find_map() skips map__load(), so offset and
map__end(al.map) here are computed from the unloaded map before
map__load(al.map) updates map bounds, pgoff, and mapping_type.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-james-coresight-jit-v1-0-dad4d90747f6@linaro.org?part=6

  reply	other threads:[~2026-11-18 17:11 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 16:29 [PATCH 00/34] perf cs-etm: JIT decoding support James Clark
2026-11-18 16:29 ` [PATCH 01/34] perf jit: Support JITDUMP_USE_ARCH_TIMESTAMP on arm64 James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 02/34] perf jit: Add name of clock in error message James Clark
2026-11-18 16:32   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 03/34] perf jit: Add address ranges to DWARF compilation units James Clark
2026-11-18 16:34   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 04/34] perf libdw: Don't look up the module by ELF address James Clark
2026-11-18 16:36   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 05/34] perf cs-etm: Use the exception level to tell kernel from user James Clark
2026-11-18 16:47   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 06/34] perf cs-etm: Don't read past the end of the map James Clark
2026-11-18 17:11   ` sashiko-bot [this message]
2026-11-18 16:29 ` [PATCH 07/34] perf build-id: Cache the vDSO in build ID mmap mode James Clark
2026-11-18 17:03   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 08/34] perf cs-etm: arm-spe: Use arch timestamp in HW tracers James Clark
2026-11-18 16:42   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 09/34] perf cs-etm: arm-spe: Report error if default clock isn't used James Clark
2026-11-18 16:35   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 10/34] perf cs-etm: Remove old pipe mode support James Clark
2026-11-18 16:44   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 11/34] perf cs-etm: Track threads in timeless mode James Clark
2026-11-18 16:35   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 12/34] perf cs-etm: Track sched out events James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 13/34] perf cs-etm: Handle PERF_RECORD_SWITCH events James Clark
2026-11-18 16:36   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 14/34] perf cs-etm: Always enable Perf event timestamps James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 15/34] perf cs-etm: Use time from Perf samples James Clark
2026-11-18 16:51   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 16/34] perf cs-etm: Don't buffer non-timestamped packets James Clark
2026-11-18 16:43   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 17/34] perf cs-etm: Decode in order of Perf samples James Clark
2026-11-18 17:10   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 18/34] perf cs-etm: Don't special case per-thread mode James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 19/34] perf cs-etm: Decode one packet at a time and don't estimate timestamps James Clark
2026-11-18 16:39   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 20/34] perf cs-etm: Remove the decoded packet ring buffer James Clark
2026-11-18 16:46   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 21/34] perf cs-etm: Fold packet state into the trace ID queue James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 22/34] perf cs-etm: Rename trace ID queues to trace ID contexts James Clark
2026-11-18 16:40   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 23/34] perf cs-etm: Rename tidq variables to tidc James Clark
2026-11-18 16:49   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 24/34] perf cs-etm: Share the thread ctxt between frontend and backend James Clark
2026-11-18 16:47   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 25/34] perf cs-etm: Consume each OpenCSD packet immediately James Clark
2026-11-18 16:44   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 26/34] perf cs-etm: Split base and packet decoder state James Clark
2026-11-18 16:42   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 27/34] perf cs-etm: Add packet-only timestamp decoder ops James Clark
2026-11-18 16:42   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 28/34] perf cs-etm: Create timestamp decoders James Clark
2026-11-18 16:48   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 29/34] perf cs-etm: Find timestamps by searching ahead James Clark
2026-11-18 17:01   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 30/34] perf cs-etm: Invalidate OpenCSD's cache on MMAPs James Clark
2026-11-18 16:45   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 31/34] perf test cs-etm: Add a Java JIT source-line test James Clark
2026-11-18 17:11   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 32/34] perf test cs-etm: Test trace is ordered with context switch records James Clark
2026-11-18 16:49   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 33/34] perf test cs-etm: Test decoding of kernel modules James Clark
2026-11-18 16:57   ` sashiko-bot
2026-11-18 16:29 ` [PATCH 34/34] perf test cs-etm: Add an HHVM JIT call stack test James Clark
2026-11-18 17:01   ` sashiko-bot
2026-11-18 16:33 ` [PATCH 00/34] perf cs-etm: JIT decoding support James Clark

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-221594@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=james.clark@linaro.org \
    --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.