From: sashiko-bot@kernel.org
To: "Leo Yan" <leo.yan@arm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v11 5/9] perf cs-etm: Use thread-stack for last branch entries
Date: Thu, 02 Jul 2026 20:07:51 +0000 [thread overview]
Message-ID: <20260702200751.7FE1F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260702-b4-arm_cs_callchain_support_v1-v11-5-846abbf600d7@arm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Branch stack corruption and trace history loss in CPU-wide and idle-thread traces due to `thread_stack` sharing and global flushing.
--
commit 2e2bc54f5f904af76d7d22b2bf5c9fcfc4cc32e8
Author: Leo Yan <leo.yan@arm.com>
perf cs-etm: Use thread-stack for last branch entries
This commit replaces the private last branch circular array with the common
thread_stack helpers. It records taken branches with thread_stack__event()
and synthesizes PERF_SAMPLE_BRANCH_STACK data with thread_stack__br_sample().
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
[ ... ]
> @@ -1637,6 +1550,57 @@ static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq,
> +static void cs_etm__add_stack_event(struct cs_etm_queue *etmq,
> + struct cs_etm_traceid_queue *tidq)
> +{
> + struct cs_etm_auxtrace *etm = etmq->etm;
> + u64 from, to;
> + int size;
> +
> + if (!etm->synth_opts.branches && !etm->synth_opts.instructions)
> + return;
> +
> + if (!cs_etm__packet_has_taken_branch(tidq->prev_packet))
> + return;
> +
> + if (etmq->etm->synth_opts.last_branch) {
> + from = cs_etm__last_executed_instr(tidq->prev_packet);
> + to = cs_etm__first_executed_instr(tidq->packet);
> +
> + size = cs_etm__instr_size(etmq, tidq, tidq->prev_packet, from);
> +
> + /* Enable callchain so thread stack entry can be allocated */
> + thread_stack__event(tidq->frontend_thread, tidq->prev_packet->cpu,
> + tidq->prev_packet->flags, from, to, size,
> + etmq->buffer->buffer_nr + 1, false,
> + tidq->br_stack_sz, 0);
[Severity: High]
In CPU-wide trace scenarios where queue->tid is -1,
cs_etm__init_traceid_queue() assigns the same dummy thread (PID -1, TID -1)
to tidq->frontend_thread across all queues.
Since thread_stack__per_cpu() returns false for PID -1, will all CPUs end up
sharing a single thread_stack?
If they share a single stack, interleaving cross-CPU decoding will pass
different etmq->buffer->buffer_nr + 1 trace numbers into
thread_stack__event(). Can this cause the stack to be continuously flushed
due to the mismatched trace numbers, leading to branch trace history loss?
[ ... ]
> @@ -2046,7 +1992,7 @@ static int cs_etm__flush(struct cs_etm_queue *etmq,
>
> /* Reset last branches after flush the trace */
> if (etm->synth_opts.last_branch)
> - cs_etm__reset_last_branch_rb(tidq);
> + thread_stack__flush(tidq->frontend_thread);
[Severity: High]
For threads that do get per-CPU stacks, such as the idle thread (PID 0,
TID 0), thread_stack__flush() unconditionally iterates over and flushes the
stacks for all CPUs associated with that thread.
Does calling thread_stack__flush() here inadvertently wipe the branch trace
history for all CPUs on the idle thread, rather than performing a
queue-local reset for just the one CPU being processed?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260702-b4-arm_cs_callchain_support_v1-v11-0-846abbf600d7@arm.com?part=5
next prev parent reply other threads:[~2026-07-02 20:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 19:51 [PATCH v11 0/9] perf cs-etm: Support thread stack and callchain Leo Yan
2026-07-02 19:51 ` [PATCH v11 1/9] perf cs-etm: Fix thread leaks on trace queue init failure Leo Yan
2026-07-02 20:07 ` sashiko-bot
2026-07-02 19:51 ` [PATCH v11 2/9] perf cs-etm: Filter synthesized branch samples Leo Yan
2026-07-02 19:51 ` [PATCH v11 3/9] perf cs-etm: Decode ETE exception packets Leo Yan
2026-07-02 19:51 ` [PATCH v11 4/9] perf cs-etm: Refactor instruction size handling Leo Yan
2026-07-02 19:51 ` [PATCH v11 5/9] perf cs-etm: Use thread-stack for last branch entries Leo Yan
2026-07-02 20:07 ` sashiko-bot [this message]
2026-07-02 19:51 ` [PATCH v11 6/9] perf cs-etm: Flush thread stacks after decoder reset Leo Yan
2026-07-02 20:06 ` sashiko-bot
2026-07-02 19:51 ` [PATCH v11 7/9] perf cs-etm: Support call indentation Leo Yan
2026-07-02 20:11 ` sashiko-bot
2026-07-02 19:51 ` [PATCH v11 8/9] perf cs-etm: Synthesize callchains for instruction samples Leo Yan
2026-07-02 20:07 ` sashiko-bot
2026-07-02 19:51 ` [PATCH v11 9/9] perf test: Add Arm CoreSight callchain test Leo Yan
2026-07-04 16:11 ` [PATCH v11 0/9] perf cs-etm: Support thread stack and callchain Namhyung Kim
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=20260702200751.7FE1F1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=leo.yan@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox