From: sashiko-bot@kernel.org
To: "James Clark" <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 01/19] perf cs-etm: Queue context packets for frontend
Date: Wed, 03 Jun 2026 10:32:19 +0000 [thread overview]
Message-ID: <20260603103219.633D61F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260603-james-cs-context-tracking-fix-v3-1-c392945d9ed5@linaro.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Removing `prev_packet_thread` breaks branch sample cross-context instruction decoding when transitions cross machine boundaries (e.g., hypervisor to guest).
- [Medium] `cs_etm__synth_instruction_sample()` ignores its new `packet` argument and hardcodes `tidq->packet`, causing instruction copying to fail during trace flush.
--
commit 588f2ae34f926c74679fbf78b98515da3192e351
Author: James Clark <james.clark@linaro.org>
perf cs-etm: Queue context packets for frontend
This commit adds a CS_ETM_CONTEXT packet carrying the TID and exception
level to the frontend, keeping context changes ordered with the packet stream.
It separates the memory access functions for the frontend and decoder backend,
and removes tracking for the previous packet's thread.
Link: https://lore.kernel.org/linux-perf-users/20260515021135.1729028-1-aaupov@meta.com/
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 40c6ddfa8c8d9..ce570913669c1 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
[ ... ]
> @@ -1158,6 +1151,30 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id,
> return ret;
> }
>
> +static u32 cs_etm__frontend_mem_access(struct cs_etm_queue *etmq,
> + struct cs_etm_traceid_queue *tidq,
> + struct cs_etm_packet *packet,
> + u64 address, size_t size, u8 *buffer)
> +{
> + return __cs_etm__mem_access(etmq, address, size, buffer, 0, packet->el,
> + tidq->frontend_thread);
> +}
[Severity: Medium]
Will this mix the previous packet's exception level with the newly updated
frontend thread?
When tracing virtualized environments, an exception return from a hypervisor
to a guest causes a machine context change. The decoder emits a context
packet which updates the frontend thread to the guest thread before
generating the branch sample for the hypervisor's execution range.
By passing the newly updated frontend thread to the memory access function
while using the previous packet's exception level, the map lookup could
look up the host kernel address in the guest's map group, causing the
lookup to fail and result in missing instruction bytes.
[ ... ]
> @@ -1579,6 +1614,7 @@ static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq,
>
> static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
> struct cs_etm_traceid_queue *tidq,
> + struct cs_etm_packet *packet,
> u64 addr, u64 period)
> {
> int ret = 0;
[ ... ]
> @@ -1604,7 +1640,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
> sample.cpu = tidq->packet->cpu;
> sample.flags = tidq->prev_packet->flags;
> sample.cpumode = event->sample.header.misc;
>
> - cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->packet, &sample);
> + cs_etm__copy_insn(etmq, tidq, tidq->packet, &sample);
[Severity: Medium]
Does this ignore the newly added packet argument?
The function signature was updated to accept a packet argument so it can
process the previous packet during a flush. However, the function body
still hardcodes tidq->packet for sample.cpu and in the call to
cs_etm__copy_insn().
When called from a flush, tidq->packet is typically a discontinuity or
empty packet. This could cause cs_etm__copy_insn() to bail out early and
silently drop the instruction bytes for the flushed sample.
[ ... ]
> @@ -1649,15 +1685,15 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,
>
> event->sample.header.type = PERF_RECORD_SAMPLE;
> event->sample.header.misc = cs_etm__cpu_mode(etmq, ip,
> - tidq->prev_packet_el);
> + tidq->prev_packet->el);
> event->sample.header.size = sizeof(struct perf_event_header);
>
> /* Set time field based on etm auxtrace config. */
> sample.time = cs_etm__resolve_sample_time(etmq, tidq);
>
> sample.ip = ip;
> - sample.pid = thread__pid(tidq->prev_packet_thread);
> - sample.tid = thread__tid(tidq->prev_packet_thread);
> + sample.pid = thread__pid(tidq->frontend_thread);
> + sample.tid = thread__tid(tidq->frontend_thread);
[Severity: Medium]
Does the removal of the previous packet thread tracking break cross-context
branch samples?
By using the newly updated frontend thread instead of the previous packet
thread here, it appears a branch sample from the previous context could be
misattributed to the new thread when transitions cross machine boundaries.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260603-james-cs-context-tracking-fix-v3-0-c392945d9ed5@linaro.org?part=1
next prev parent reply other threads:[~2026-06-03 10:32 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 10:17 [PATCH v3 00/19] perf cs-etm: Queue context packets for frontend James Clark
2026-06-03 10:17 ` [PATCH v3 01/19] " James Clark
2026-06-03 10:32 ` sashiko-bot [this message]
2026-06-03 20:14 ` Amir Ayupov
2026-06-03 10:17 ` [PATCH v3 02/19] perf test: Add workload-ctl option James Clark
2026-06-03 10:17 ` [PATCH v3 03/19] perf test: Add a workload that forces context switches James Clark
2026-06-03 10:28 ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 04/19] perf test cs-etm: Test process attribution James Clark
2026-06-03 10:17 ` [PATCH v3 05/19] perf test: Add deterministic workload James Clark
2026-06-03 10:24 ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 06/19] perf test cs-etm: Replace unroll loop thread with deterministic decode test James Clark
2026-06-03 10:30 ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 07/19] perf test cs-etm: Remove asm_pure_loop test James Clark
2026-06-03 10:17 ` [PATCH v3 08/19] perf test cs-etm: Replace memcpy test with raw dump stress test James Clark
2026-06-03 10:17 ` [PATCH v3 09/19] perf test: Add named_threads workload James Clark
2026-06-03 10:26 ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 10/19] perf test cs-etm: Test decoding for concurrent threads test James Clark
2026-06-03 10:17 ` [PATCH v3 11/19] perf test cs-etm: Remove duplicate branch tests James Clark
2026-06-03 10:17 ` [PATCH v3 12/19] perf test cs-etm: Skip if not root James Clark
2026-06-03 10:17 ` [PATCH v3 13/19] perf test cs-etm: Reduce snapshot size James Clark
2026-06-03 10:17 ` [PATCH v3 14/19] perf test cs-etm: Speed up basic test James Clark
2026-06-03 10:17 ` [PATCH v3 15/19] perf test cs-etm: Remove unused Coresight workloads James Clark
2026-06-03 10:41 ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 16/19] perf test cs-etm: Make disassembly test use kcore James Clark
2026-06-03 10:36 ` sashiko-bot
2026-06-03 10:17 ` [PATCH v3 17/19] perf test cs-etm: Add all branch instructions to test James Clark
2026-06-03 10:17 ` [PATCH v3 18/19] perf test cs-etm: Speed up disassembly test James Clark
2026-06-03 10:17 ` [PATCH v3 19/19] perf test cs-etm: Move existing tests to coresight folder 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=20260603103219.633D61F00893@smtp.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox