Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tengda Wu" <wutengda@huaweicloud.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v7 15/15] perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer
Date: Tue, 13 Oct 2026 14:03:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-169878@kernel.org> (raw)
In-Reply-To: <0615c314accfce4f3db561db1b1e02efcc5fd66b.1791629326.git.wutengda@huaweicloud.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf annotate-arm64: missing lifetime cleanup in update_mrs_insn_state()
--

commit 084f7875323701c8124c43b96de264a478df7634
Author: Tengda Wu <wutengda@huaweicloud.com>

perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer

This patch extends update_insn_state_arm64() to handle the mrs instruction.
It enables tracking the current task pointer in the kernel, which is
typically accessed via the sp_el0 system register.

> diff --git a/tools/perf/util/annotate-arch/annotate-arm64.c b/tools/perf/util/annotate-arch/annotate-arm64.c
> index 5683215f07708..6da558f7e8648 100644
> --- a/tools/perf/util/annotate-arch/annotate-arm64.c
> +++ b/tools/perf/util/annotate-arch/annotate-arm64.c
[ ... ]
> @@ -1030,6 +1032,71 @@ static void update_adrp_insn_state(struct type_state *state,
>  		     insn_offset, tsr->imm_value, dreg);
>  }
>  
> +static void update_mrs_insn_state(struct type_state *state,
> +				  struct data_loc_info *dloc, Dwarf_Die *cu_die,
> +				  struct disasm_line *dl,
> +				  struct annotated_op_loc *dst)
> +{
> +	struct type_state_reg *tsr;
> +	Dwarf_Die type_die;
> +	u32 insn_offset = dl->al.offset;
> +	int dreg = dst->reg1;
> +	Dwarf_Die func_die;
> +	Dwarf_Attribute attr;
> +	u64 ip, pc;
> +	struct strbuf sb;
> +	char *type_name;
> +
> +	if (!has_reg_type(state, dreg))
> +		return;
> +
> +	tsr = &state->regs[dreg];
> +	tsr->copied_from = -1;
> +
> +	/* Handle case difference: LLVM (SP_EL0) vs objdump (sp_el0) */
> +	if (!dso__kernel(map__dso(dloc->ms->map)) ||
> +	    strcasecmp(dl->ops.source.raw, "sp_el0")) {
> +		invalidate_reg_state(tsr);
> +		return;
> +	}
[ ... ]
> +	if (!type_name || strcmp(type_name, "struct task_struct*")) {
> +		invalidate_reg_state(tsr);
> +		goto out_free;
> +	}
> +
> +	tsr->type = type_die;
> +	tsr->kind = TSR_KIND_TYPE;
> +	tsr->offset = 0;
> +	tsr->imm_value = 0;
> +	tsr->ok = true;

[Severity: Medium]
Are we missing a cleanup of the previous lifetime state for the destination
register here?

If the target register previously held a variable with an active Dwarf
lifetime, the lifetime_active flag remains true. Upon a subsequent function
call, the register tracking logic skips invalidating caller-saved registers
that have an active lifetime.

This could cause the target register (e.g., x0 holding current) to
incorrectly survive the function call in the analysis state, even though
the hardware register is clobbered by the callee.

Should this path clear tsr->lifetime_active and tsr->lifetime_end, or
perhaps call invalidate_reg_state() earlier before assigning the new
properties?

> +
> +	pr_debug_dtp("mrs [%x] sp_el0 -> reg%d", insn_offset, dreg);
> +	pr_debug_type_name(&type_die, tsr->kind);
> +
> +out_free:
> +	free(type_name);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791629326.git.wutengda@huaweicloud.com?part=15

      reply	other threads:[~2026-10-13 14:03 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 13:27 [PATCH v7 00/15] perf annotate arm64: Support instruction tracking for data type profiling Tengda Wu
2026-10-13 13:27 ` [PATCH v7 01/15] perf annotate-data: Extract invalidate_reg_state() as a common helper Tengda Wu
2026-10-13 13:34   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 02/15] perf annotate-arm64: Enable instruction tracking support Tengda Wu
2026-10-13 13:38   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 03/15] perf annotate-data: Add arch_get_reg_offset helper Tengda Wu
2026-10-13 13:38   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 04/15] perf annotate-arm64: Track return type after call instructions Tengda Wu
2026-10-13 13:36   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 05/15] perf annotate-arm64: Support load instruction tracking Tengda Wu
2026-10-13 13:38   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 06/15] perf annotate-arm64: Support store " Tengda Wu
2026-10-13 13:36   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 07/15] perf annotate-data: Expand type_state_reg imm_value to u64 Tengda Wu
2026-10-13 13:45   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 08/15] perf annotate-data: Track imm_value for stack variables Tengda Wu
2026-10-13 13:47   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 09/15] perf annotate-x86: Delete stale stack state on store of untracked register Tengda Wu
2026-10-13 13:44   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 10/15] perf annotate-arm64: Support stack variable tracking Tengda Wu
2026-10-13 13:44   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 11/15] perf annotate-arm64: Support 'mov' instruction tracking Tengda Wu
2026-10-13 13:45   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 12/15] perf annotate-arm64: Support 'add' " Tengda Wu
2026-10-13 13:47   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 13/15] perf annotate-arm64: Support 'adrp' instruction to track global variables Tengda Wu
2026-10-13 13:57   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 14/15] perf annotate-arm64: Support per-cpu variable access tracking Tengda Wu
2026-10-13 13:49   ` sashiko-bot
2026-10-13 13:28 ` [PATCH v7 15/15] perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer Tengda Wu
2026-10-13 14:03   ` sashiko-bot [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=sashiko-outbox-169878@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wutengda@huaweicloud.com \
    /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