Linux Perf Users
 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 v4 07/19] perf test cs-etm: Remove asm_pure_loop test
Date: Tue, 09 Jun 2026 14:53:34 +0000	[thread overview]
Message-ID: <20260609145335.A5DB11F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609-james-cs-context-tracking-fix-v4-7-44f9fb9e5c42@linaro.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Removing `tidq->prev_packet_thread` causes samples belonging to `prev_packet` to be attributed to the wrong thread if a context packet was processed in between.
--

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

perf cs-etm: Queue context packets for frontend

PE_CONTEXT elements update the context ID and exception level, but the
decoder may still have prior packets cached for frontend processing.
Updating the context immediately in the decoder backend can make those
cached packets get consumed with the wrong thread or EL state. Add a
CS_ETM_CONTEXT packet carrying the TID and EL to the frontend.

Closes: 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..5e92359f51a7c 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c

[ ... ]

> @@ -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]
If a context packet was processed just before this, frontend_thread has
already been updated to the new thread. Does using frontend_thread here
instead of tracking the thread that actually executed prev_packet cause the
branch sample to be attributed to the wrong thread?

>  	sample.addr = cs_etm__first_executed_instr(tidq->packet);
>  	sample.id = etmq->etm->branches_id;
>  	sample.stream_id = etmq->etm->branches_id;

[ ... ]

> @@ -1959,7 +1993,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
>  		addr = cs_etm__last_executed_instr(tidq->prev_packet);
>  
>  		err = cs_etm__synth_instruction_sample(
> -			etmq, tidq, addr,
> +			etmq, tidq, tidq->prev_packet, addr,
>  			tidq->period_instructions);

[Severity: Medium]
When flushing the trace, an instruction sample is generated for prev_packet.
However, cs_etm__synth_instruction_sample unconditionally uses
frontend_thread. If a context packet was the last processed packet, could
this lead to misattribution of the sample to the new thread?

>  		if (err)
>  			return err;

[ ... ]

> @@ -2469,6 +2501,19 @@ static int cs_etm__process_traceid_queue(struct cs_etm_queue *etmq,
>  			 */
>  			cs_etm__sample(etmq, tidq);
>  			break;
> +		case CS_ETM_CONTEXT:
> +			/*
> +			 * Update context but don't swap packet. Keep the
> +			 * previous one for branch source address info, if
> +			 * tracing the kernel the context packet will be emitted
> +			 * between two ranges.
> +			 */
> +			ret = cs_etm__etmq_update_thread(etmq, tidq->packet->el,
> +							 tidq->packet->tid,
> +							 &tidq->frontend_thread);

[Severity: Medium]
When CS_ETM_CONTEXT updates frontend_thread without swapping packets, won't
prev_packet still contain the execution range of the old thread? Since the
frontend_thread is updated immediately, could any subsequent samples
generated for prev_packet be attributed to the wrong thread?

> +			if (ret)
> +				goto out;
> +			break;
>  		case CS_ETM_EXCEPTION:
>  		case CS_ETM_EXCEPTION_RET:

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260609-james-cs-context-tracking-fix-v4-0-44f9fb9e5c42@linaro.org?part=7

  reply	other threads:[~2026-06-09 14:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 14:30 [PATCH v4 00/19] perf cs-etm: Queue context packets for frontend James Clark
2026-06-09 14:30 ` [PATCH v4 01/19] " James Clark
2026-06-09 14:46   ` sashiko-bot
2026-06-09 14:30 ` [PATCH v4 02/19] perf test: Add workload-ctl option James Clark
2026-06-09 14:40   ` sashiko-bot
2026-06-09 14:30 ` [PATCH v4 03/19] perf test: Add a workload that forces context switches James Clark
2026-06-09 14:30 ` [PATCH v4 04/19] perf test cs-etm: Test process attribution James Clark
2026-06-09 14:41   ` sashiko-bot
2026-06-09 14:30 ` [PATCH v4 05/19] perf test: Add deterministic workload James Clark
2026-06-09 14:30 ` [PATCH v4 06/19] perf test cs-etm: Replace unroll loop thread with deterministic decode test James Clark
2026-06-09 14:52   ` sashiko-bot
2026-06-09 14:31 ` [PATCH v4 07/19] perf test cs-etm: Remove asm_pure_loop test James Clark
2026-06-09 14:53   ` sashiko-bot [this message]
2026-06-09 14:31 ` [PATCH v4 08/19] perf test cs-etm: Replace memcpy test with raw dump stress test James Clark
2026-06-09 14:31 ` [PATCH v4 09/19] perf test: Add named_threads workload James Clark
2026-06-09 14:50   ` sashiko-bot
2026-06-09 14:31 ` [PATCH v4 10/19] perf test cs-etm: Test decoding for concurrent threads test James Clark
2026-06-09 14:31 ` [PATCH v4 11/19] perf test cs-etm: Remove duplicate branch tests James Clark
2026-06-09 14:31 ` [PATCH v4 12/19] perf test cs-etm: Skip if not root James Clark
2026-06-09 14:53   ` sashiko-bot
2026-06-09 14:31 ` [PATCH v4 13/19] perf test cs-etm: Reduce snapshot size James Clark
2026-06-09 14:31 ` [PATCH v4 14/19] perf test cs-etm: Speed up basic test James Clark
2026-06-09 14:31 ` [PATCH v4 15/19] perf test cs-etm: Remove unused Coresight workloads James Clark
2026-06-09 14:31 ` [PATCH v4 16/19] perf test cs-etm: Make disassembly test use kcore James Clark
2026-06-09 14:31 ` [PATCH v4 17/19] perf test cs-etm: Add all branch instructions to test James Clark
2026-06-09 14:31 ` [PATCH v4 18/19] perf test cs-etm: Speed up disassembly test James Clark
2026-06-09 15:06   ` sashiko-bot
2026-06-09 14:31 ` [PATCH v4 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=20260609145335.A5DB11F00893@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