From: sashiko-bot@kernel.org
To: "James Clark" <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 15/34] perf cs-etm: Use time from Perf samples
Date: Wed, 18 Nov 2026 16:51:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-221567@kernel.org> (raw)
In-Reply-To: <20261118-james-coresight-jit-v1-15-dad4d90747f6@linaro.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf cs-etm: uninitialized pointer deref in
cs_etm__queue_aux_fragment()
- [Medium] perf cs-etm: unvalidated (u64)-1 sample time in
cs_etm__queue_aux_fragment()
--
commit 3c88e19ea9cd0c9b777217d6c7decbf883a6a671
Author: James Clark <james.clark@linaro.org>
perf cs-etm: Use time from Perf samples
This commit records the sample timestamp from each PERF_RECORD_AUX event on
its auxtrace_buffer and uses it in place of latest_kernel_timestamp when
virtual trace timestamps are unavailable or disabled. It also replaces
timeless_decoding with has_timestamps.
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 4252d25c991d8..ca3878a3b74e0 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
[ ... ]
> @@ -1625,10 +1637,14 @@ static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq,
> struct cs_etm_auxtrace *etm = etmq->etm;
> struct cs_etm_packet_queue *packet_queue = &tidq->packet_queue;
>
> - if (!etm->timeless_decoding && etm->has_virtual_ts)
> + if (etm->has_virtual_ts)
> return packet_queue->cs_timestamp;
> - else
> - return etm->latest_kernel_timestamp;
> +
> + /*
> + * Timestamps were disabled or no virtual TS. All samples are assigned
> + * the kernel time from when the trace block was emitted.
> + */
> + return etmq->buffer->time;
> }
[ ... ]
> @@ -1897,10 +1913,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
> attr.sample_type = evsel->core.attr.sample_type & PERF_SAMPLE_MASK;
> attr.sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID |
> PERF_SAMPLE_PERIOD;
> - if (etm->timeless_decoding)
> - attr.sample_type &= ~(u64)PERF_SAMPLE_TIME;
> - else
> - attr.sample_type |= PERF_SAMPLE_TIME;
> + attr.sample_type |= PERF_SAMPLE_TIME;
>
> attr.exclude_user = evsel->core.attr.exclude_user;
> attr.exclude_kernel = evsel->core.attr.exclude_kernel;
[ ... ]
> @@ -3076,15 +3089,6 @@ static int cs_etm__process_event(struct perf_session *session,
> case PERF_RECORD_SWITCH:
> return cs_etm__process_switch(etm, sample);
>
> - case PERF_RECORD_AUX:
> - /*
> - * Record the latest kernel timestamp available in the header
> - * for samples so that synthesised samples occur from this point
> - * onwards.
> - */
> - if (sample->time && (sample->time != (u64)-1))
> - etm->latest_kernel_timestamp = sample->time;
> - break;
>
> default:
> break;
[Severity: Medium]
Does dropping the sample->time != (u64)-1 check propagate (u64)-1 into
synthesized samples when PERF_SAMPLE_TIME is not set on the cs_etm evsel?
__evsel__parse_sample() initializes sample->time to (u64)-1 and only
updates it when PERF_SAMPLE_TIME is present in sample_type. For
recordings without PERF_SAMPLE_TIME (such as perf record --no-timestamp)
decoded without virtual timestamps, cs_etm__queue_aux_fragment() now
stores (u64)-1 in buffer->time and cs_etm__resolve_sample_time() assigns
it to every synthesized sample, which produces bogus timestamps in perf
script and causes ordered_events__queue() to reject perf inject --itrace
output with -ETIME.
[ ... ]
> @@ -3287,6 +3274,7 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o
> /* Old per-thread files have no CPU (before v6.4) */
> int queue_idx = sample->cpu == (u32)-1 ? 0 : sample->cpu;
> struct cs_etm_queue *etmq = cs_etm__get_queue(etm, queue_idx);
> + struct auxtrace_buffer *buffer;
>
> if (!etmq)
> return -EINVAL;
> @@ -3306,10 +3294,12 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o
> pr_debug3("CS ETM: Queue buffer size: %#"PRI_lx64" offset: %#"PRI_lx64
> " tid: %d cpu: %d\n", frag_size, frag_start, sample->tid, sample->cpu);
> err = auxtrace_queues__add_event(&etm->queues, session, &auxtrace_fragment,
> - file_offset, NULL);
> + file_offset, &buffer);
> if (err)
> return err;
>
> + buffer->time = sample->time;
[Severity: Medium]
Can buffer->time = sample->time dereference an uninitialized pointer when
CPU filtering (-C / --cpu) is active?
auxtrace_queues__add_event() -> auxtrace_queues__add_buffer() returns 0
without writing to *buffer_ptr when the AUX record's CPU is excluded by
filter_cpu():
tools/perf/util/auxtrace.c:auxtrace_queues__add_buffer() {
if (filter_cpu(session, buffer->cpu))
return 0;
...
}
Because buffer is not initialized to NULL and checked before writing
buffer->time, any PERF_RECORD_AUX event for a filtered-out CPU
dereferences the uninitialized stack pointer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-james-coresight-jit-v1-0-dad4d90747f6@linaro.org?part=15
next prev parent reply other threads:[~2026-11-18 16:51 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
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 [this message]
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-221567@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.