Linux Perf Users
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@arm.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 3/3] perf cs-etm: Check frontend instruction reads
Date: Fri, 13 Nov 2026 13:52:28 +0000	[thread overview]
Message-ID: <20261113135228.GP9176@e132581.arm.com> (raw)
In-Reply-To: <sashiko-outbox-212661@kernel.org>

On Fri, Nov 13, 2026 at 11:03:02AM +0000, sashiko-bot@kernel.org wrote:

> [Severity: Medium]
> This problem wasn't introduced by this patch, but can
> cs_etm__synth_instruction_sample() and cs_etm__synth_branch_sample() leak
> sample resources when event injection fails [1]?
> 
> Both functions initialize sample with perf_sample__init(&sample, true),
> which allocates sub-structures, and then return early before
> perf_sample__exit(&sample) if cs_etm__inject_event() returns an error:
> 
> tools/perf/util/cs-etm.c:cs_etm__synth_instruction_sample() {
> 	...
> 	perf_sample__init(&sample, /*all=*/true);
> 	...
> 	if (etm->synth_opts.inject) {
> 		ret = cs_etm__inject_event(etm, event, &sample,
> 					   etm->instructions_sample_type);
> 		if (ret)
> 			return ret;
> 	}
> 	...
> 	perf_sample__exit(&sample);
> 	return ret;
> }

Seems this comment is not valid on perf-tools-next. perf_sample__init()
does not allocate sub-structures.

> [Severity: Medium]
> This problem wasn't introduced by this patch, but can cs_etm__sample() spin
> forever when the user specifies an instruction sample period of 0 (for
> example, --itrace=i0i) [2]?
> 
> The loop condition is:
> 
> tools/perf/util/cs-etm.c:cs_etm__sample() {
> 	...
> 		while (tidq->period_instructions >=
> 				etm->instructions_sample_period) {
> 			...
> 			offset += etm->instructions_sample_period;
> 			tidq->period_instructions -=
> 				etm->instructions_sample_period;
> 		}
> }
> 
> Because both operands are unsigned, tidq->period_instructions >= 0 is
> always true and subtracting 0 never reduces tidq->period_instructions.

It will infinitely loop with "--itrace=i0i", but this is a usage
problem. We can reject it in common code with a separate patch.
This is no matter with current change.

> [1] https://sashiko.dev/#/bug/linux-313ce3d0-12d6-4671-8007-6e3925af60fc
> [2] https://sashiko.dev/#/bug/linux-88c200a9-e322-487b-904a-28d581ccee8b
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261113-perf_fix_gcc15_failure-v1-0-eae592c5ff64@arm.com?part=3

      reply	other threads:[~2026-11-13 13:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 10:54 [PATCH 0/3] perf cs-etm: Fix GCC 15 build failure Leo Yan
2026-11-13 10:54 ` [PATCH 1/3] perf cs-etm: Initialize the Thumb instruction buffer Leo Yan
2026-11-13 10:58   ` sashiko-bot
2026-11-13 10:54 ` [PATCH 2/3] perf cs-etm: Use the packet instruction size for stack events Leo Yan
2026-11-13 11:01   ` sashiko-bot
2026-11-13 10:54 ` [PATCH 3/3] perf cs-etm: Check frontend instruction reads Leo Yan
2026-11-13 11:03   ` sashiko-bot
2026-11-13 13:52     ` Leo Yan [this message]

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=20261113135228.GP9176@e132581.arm.com \
    --to=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