From: sashiko-bot@kernel.org
To: "Leo Yan" <leo.yan@arm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v7 7/8] perf cs-etm: Synthesize callchains for instruction samples
Date: Tue, 23 Jun 2026 20:24:25 +0000 [thread overview]
Message-ID: <20260623202425.8CB831F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260611-b4-arm_cs_callchain_support_v1-v7-7-1ba770c862ae@arm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The error path in the newly introduced `cs_etm__context()` leaks the thread reference count and causes a subsequent deterministic NULL pointer dereference.
--
commit 08ea8a8a8959ce5cc5f77e8d3b133c16e92cb0b7
Author: Leo Yan <leo.yan@linux.dev>
perf cs-etm: Synthesize callchains for instruction samples
This commit adds callchain synthesis for instruction samples in CS ETM.
It allocates a callchain buffer per queue and uses thread_stack__sample()
when synthesizing instruction samples, and introduces cs_etm__context()
for handling context packets.
> 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
[ ... ]
> @@ -1895,6 +1932,34 @@ static int cs_etm__sample(struct cs_etm_queue *etmq,
> return 0;
> }
>
> +static int cs_etm__context(struct cs_etm_queue *etmq,
> + struct cs_etm_traceid_queue *tidq)
> +{
> + ocsd_ex_level el = tidq->packet->el;
> + struct machine *machine;
> + int ret;
> +
> + machine = cs_etm__get_machine(etmq, el);
> + if (!machine) {
> + ret = -EINVAL;
> + goto err;
> + }
> +
> + tidq->kernel_start = machine__kernel_start(machine);
> +
> + ret = cs_etm__etmq_update_thread(etmq, el, tidq->packet->tid,
> + &tidq->frontend_thread);
> + if (ret)
> + goto err;
> +
> + return 0;
> +
> +err:
> + tidq->frontend_thread = NULL;
> + tidq->kernel_start = 0;
> + return ret;
> +}
[Severity: Medium]
If the code jumps to the err label, it sets tidq->frontend_thread = NULL.
Since the thread struct uses reference counting, does this overwrite leak
the existing thread reference?
Additionally, if the outer decoding loop ignores this error and continues
processing trace packets, could this lead to a crash? When a subsequent
CS_ETM_RANGE packet is processed, cs_etm__synth_instruction_sample() will
unconditionally dereference the NULL thread pointer here:
tools/perf/util/cs-etm.c:cs_etm__synth_instruction_sample() {
...
sample.ip = addr;
sample.pid = thread__pid(tidq->frontend_thread);
sample.tid = thread__tid(tidq->frontend_thread);
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260611-b4-arm_cs_callchain_support_v1-v7-0-1ba770c862ae@arm.com?part=7
next prev parent reply other threads:[~2026-06-23 20:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 7:56 [PATCH v7 0/8] perf cs-etm: Support thread stack and callchain Leo Yan
2026-06-11 7:56 ` [PATCH v7 1/8] perf cs-etm: Filter synthesized branch samples Leo Yan
2026-06-11 8:58 ` James Clark
2026-06-11 7:56 ` [PATCH v7 2/8] perf cs-etm: Decode ETE exception packets Leo Yan
2026-06-11 7:56 ` [PATCH v7 3/8] perf cs-etm: Refactor instruction size handling Leo Yan
2026-06-11 7:56 ` [PATCH v7 4/8] perf cs-etm: Use thread-stack for last branch entries Leo Yan
2026-06-11 9:01 ` James Clark
2026-06-23 19:46 ` sashiko-bot
2026-06-11 7:56 ` [PATCH v7 5/8] perf cs-etm: Flush thread stacks after decoder reset Leo Yan
2026-06-23 19:58 ` sashiko-bot
2026-06-11 7:57 ` [PATCH v7 6/8] perf cs-etm: Support call indentation Leo Yan
2026-06-23 20:11 ` sashiko-bot
2026-06-11 7:57 ` [PATCH v7 7/8] perf cs-etm: Synthesize callchains for instruction samples Leo Yan
2026-06-23 20:24 ` sashiko-bot [this message]
2026-06-11 7:57 ` [PATCH v7 8/8] perf test: Add Arm CoreSight callchain test Leo Yan
2026-06-11 9:11 ` James Clark
2026-06-11 12:42 ` Leo Yan
2026-06-23 20:31 ` sashiko-bot
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=20260623202425.8CB831F000E9@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