From: sashiko-bot@kernel.org
To: "Leo Yan" <leo.yan@arm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v9 8/9] perf cs-etm: Synthesize callchains for instruction samples
Date: Tue, 16 Jun 2026 15:12:43 +0000 [thread overview]
Message-ID: <20260616151243.8CC161F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260616-b4-arm_cs_callchain_support_v1-v9-8-f8fad931c413@arm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Prematurely freeing `tidq->frontend_thread` on the error path in `cs_etm__context()` leads to a fatal NULL pointer dereference.
--
commit beaeb914d5e99fcdf91b04714fe39931a7466896
Author: Leo Yan <leo.yan@linux.dev>
perf cs-etm: Synthesize callchains for instruction samples
This commit synthesizes callchains for CS ETM instruction samples. It allocates
a callchain buffer per queue, uses thread_stack__sample() for instruction
samples, and introduces cs_etm__context() to handle context packets.
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index e18d2dec79431..34489476681b8 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
[ ... ]
> @@ -1904,6 +1941,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:
> + thread__zput(tidq->frontend_thread);
[Severity: Medium]
Will this error path result in a NULL pointer dereference?
If cs_etm__get_machine() or cs_etm__etmq_update_thread() fails, thread__zput()
is called which drops the reference and sets tidq->frontend_thread to NULL.
However, the calling loops, such as cs_etm__run_per_cpu_timeless_decoder()
which calls cs_etm__process_traceid_queue(), can ignore the error and continue
processing trace buffer packets.
When a subsequent packet like CS_ETM_RANGE is processed, it calls
cs_etm__synth_instruction_sample() which unconditionally dereferences the NULL
thread pointer:
cs_etm__synth_instruction_sample() {
...
sample.pid = thread__pid(tidq->frontend_thread);
...
}
Should the frontend_thread pointer be preserved on failure, or should the
caller be updated to abort packet processing when an error occurs?
> + tidq->kernel_start = 0;
> + return ret;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260616-b4-arm_cs_callchain_support_v1-v9-0-f8fad931c413@arm.com?part=8
next prev parent reply other threads:[~2026-06-16 15:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 14:51 [PATCH v9 0/9] perf cs-etm: Support thread stack and callchain Leo Yan
2026-06-16 14:51 ` [PATCH v9 1/9] perf cs-etm: Fix thread leaks on trace queue init failure Leo Yan
2026-06-16 14:51 ` [PATCH v9 2/9] perf cs-etm: Filter synthesized branch samples Leo Yan
2026-06-16 14:51 ` [PATCH v9 3/9] perf cs-etm: Decode ETE exception packets Leo Yan
2026-06-16 14:51 ` [PATCH v9 4/9] perf cs-etm: Refactor instruction size handling Leo Yan
2026-06-16 14:51 ` [PATCH v9 5/9] perf cs-etm: Use thread-stack for last branch entries Leo Yan
2026-06-16 15:13 ` sashiko-bot
2026-06-16 15:42 ` Leo Yan
2026-06-16 14:51 ` [PATCH v9 6/9] perf cs-etm: Flush thread stacks after decoder reset Leo Yan
2026-06-16 15:10 ` sashiko-bot
2026-06-16 14:51 ` [PATCH v9 7/9] perf cs-etm: Support call indentation Leo Yan
2026-06-16 15:08 ` sashiko-bot
2026-06-16 14:51 ` [PATCH v9 8/9] perf cs-etm: Synthesize callchains for instruction samples Leo Yan
2026-06-16 15:12 ` sashiko-bot [this message]
2026-06-16 14:51 ` [PATCH v9 9/9] perf test: Add Arm CoreSight callchain test Leo Yan
2026-06-16 15:08 ` 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=20260616151243.8CC161F000E9@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 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.