From: Shuai Xue <xueshuai@linux.alibaba.com>
To: Tengda Wu <wutengda@huaweicloud.com>,
Namhyung Kim <namhyung@kernel.org>,
james.clark@linaro.org, Li Huafei <lihuafei1@huawei.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
leo.yan@linux.dev, Ian Rogers <irogers@google.com>,
Kim Phillips <kim.phillips@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Bill Wendling <morbo@google.com>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Zecheng Li <zli94@ncsu.edu>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH v4 21/23] perf annotate-arm64: Support 'adrp' instruction to track global variables
Date: Tue, 11 Aug 2026 16:50:36 +0800 [thread overview]
Message-ID: <59b826f3-b3c9-4964-bf82-9e43913d80e2@linux.alibaba.com> (raw)
In-Reply-To: <20260808122400.2961238-22-wutengda@huaweicloud.com>
On 8/8/26 8:23 PM, Tengda Wu wrote:
> Extend update_insn_state() for arm64 to track global variable types
> calculated via page-relative addressing.
>
> On arm64, global variables are typically accessed by first calculating
> the page address using 'adrp', followed by an 'add' or 'ldr' to get the
> specific symbol address. Without tracking 'adrp', the instruction
> tracker loses the base address, making it impossible to resolve
> global symbols and their associated DWARF types.
>
> Introduce TSR_KIND_GLOBAL_ADDR to represent a partial global address
> state. When encountering 'adrp', store the page-aligned target address
> in the register's type state. Upon a subsequent 'add' or 'ldr'
> instruction that references a TSR_KIND_GLOBAL_ADDR register, combine
> the page address with the immediate offset.
>
> A real-world example is shown below:
>
> ffff80008032e008 <folios_put_refs>:
> ffff80008032e048: adrp x24, ffff80008202f000 <nr_cpu_ids>
> ffff80008032e050: add x24, x24, #0xd40
> * ffff80008032e078: ldr x0, [x24]
>
> Before this commit, x24 was unknown, leading to no type information:
>
> chk [70] reg24 offset=0 ok=0 kind=0 cfa : no type information
> final result: no type information
>
> After this commit, the tracker correctly follows the adrp/add flow:
>
> adrp [40] global addr=0xffff80008202f000 -> reg24
> add [48] global 0xd40(reg24) -> reg24
> chk [70] reg24 offset=0 ok=1 kind=7 global addr : Good!
> final result: type='struct folio*'
>
> Signed-off-by: Li Huafei <lihuafei1@huawei.com>
> Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
> ---
> .../perf/util/annotate-arch/annotate-arm64.c | 82 +++++++++++++++++--
> tools/perf/util/annotate-data.c | 25 +++++-
> tools/perf/util/annotate-data.h | 1 +
> 3 files changed, 98 insertions(+), 10 deletions(-)
>
> diff --git a/tools/perf/util/annotate-arch/annotate-arm64.c b/tools/perf/util/annotate-arch/annotate-arm64.c
> index eaeb4433fc3a..7eb3bef26a64 100644
> --- a/tools/perf/util/annotate-arch/annotate-arm64.c
> +++ b/tools/perf/util/annotate-arch/annotate-arm64.c
> @@ -408,7 +408,7 @@ static void adjust_reg_index_state(struct type_state *state,
> * to the source struct's field offset.
> */
> static int propagate_load_reg_state(struct type_state *state,
> - struct data_loc_info *dloc,
> + struct data_loc_info *dloc, Dwarf_Die *cu_die,
> struct disasm_line *dl, int dreg,
> struct annotated_op_loc *src,
> int reg_offset, const char *insn_name)
> @@ -500,6 +500,32 @@ static int propagate_load_reg_state(struct type_state *state,
> pr_debug_type_name(&tsr->type, tsr->kind);
> return 0;
> }
> + /* Or check if it's a global variable */
> + else if (src_tsr.kind == TSR_KIND_GLOBAL_ADDR) {
> + u64 ip = dloc->ms->sym->start + dl->al.offset;
> + u64 addr = src_tsr.imm_value + reg_offset;
> + int offset;
> +
> + if (!get_global_var_type(cu_die, dloc, ip, addr, &offset, &type_die) ||
> + !die_get_member_type(&type_die, offset, &type_die))
> + return -1;
> +
> + tsr->type = type_die;
> + tsr->kind = TSR_KIND_TYPE;
> + tsr->offset = 0;
> + tsr->imm_value = 0;
> + tsr->ok = true;
> +
> + if (src->multi_regs) {
> + pr_debug_dtp("%s [%x] global (reg%d, reg%d) -> reg%d",
> + insn_name, insn_offset, src->reg1, src->reg2, dreg);
> + } else {
> + pr_debug_dtp("%s [%x] global (reg%d) -> reg%d",
> + insn_name, insn_offset, sreg, dreg);
> + }
> + pr_debug_type_name(&tsr->type, tsr->kind);
> + return 0;
> + }
> /* Or try another register if any */
> else if (src->multi_regs && src->reg1 != src->reg2 && sreg != src->reg2) {
> sreg = src->reg2;
> @@ -510,7 +536,7 @@ static int propagate_load_reg_state(struct type_state *state,
> }
>
> static void update_load_insn_state(struct type_state *state,
> - struct data_loc_info *dloc,
> + struct data_loc_info *dloc, Dwarf_Die *cu_die,
> struct disasm_line *dl,
> struct annotated_op_loc *src,
> struct annotated_op_loc *dst)
> @@ -523,7 +549,7 @@ static void update_load_insn_state(struct type_state *state,
> goto out_err_adjust;
>
> /* Handle the first destination register */
> - if (propagate_load_reg_state(state, dloc, dl, dst->reg1, src,
> + if (propagate_load_reg_state(state, dloc, cu_die, dl, dst->reg1, src,
> reg_offset, insn_name))
> goto out_err_adjust;
>
> @@ -532,7 +558,7 @@ static void update_load_insn_state(struct type_state *state,
> int reg_size = arm64__reg_size(dl->ops.target.raw);
>
> if (reg_size < 0 ||
> - propagate_load_reg_state(state, dloc, dl, dst->reg2, src,
> + propagate_load_reg_state(state, dloc, cu_die, dl, dst->reg2, src,
> reg_offset + reg_size, insn_name))
> goto out_err_adjust;
> }
> @@ -735,14 +761,16 @@ static void update_add_insn_state(struct type_state *state,
> imm_value = state->regs[reg2].imm_value;
> }
>
> - if (src_tsr.kind == TSR_KIND_CONST) {
> + if (src_tsr.kind == TSR_KIND_CONST || src_tsr.kind == TSR_KIND_GLOBAL_ADDR) {
GLOBAL_ADDR inherits the two add-handler issues raised on patch 20:
a non-constant reg2 still propagates with an implicit addend of 0
(now producing a wrong global address), and the commutative
add rd, const_reg, global_reg case still drops the global side.
Fixes discussed there would cover both.
Thanks.
Shuai
next prev parent reply other threads:[~2026-08-11 8:50 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 12:23 [PATCH v4 00/23] perf arm64: Support data type profiling Tengda Wu
2026-08-08 12:23 ` [PATCH v4 01/23] perf capstone: Fix arm64 jump/adrp disassembly mismatch with objdump Tengda Wu
2026-08-10 13:08 ` Shuai Xue
2026-08-11 2:27 ` Tengda Wu
2026-08-11 3:25 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 02/23] perf llvm: Fix arm64 adrp instruction " Tengda Wu
2026-08-08 12:23 ` [PATCH v4 03/23] perf annotate-arm64: Generalize arm64_mov__parse to support more instructions Tengda Wu
2026-08-08 12:23 ` [PATCH v4 04/23] perf annotate-arm64: Handle load and store instructions Tengda Wu
2026-08-08 12:23 ` [PATCH v4 05/23] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64 Tengda Wu
2026-08-08 12:23 ` [PATCH v4 06/23] perf annotate: Adapt arch__dwarf_regnum() " Tengda Wu
2026-08-11 6:33 ` Shuai Xue
2026-08-11 8:16 ` Tengda Wu
2026-08-08 12:23 ` [PATCH v4 07/23] perf annotate: Introduce extract_op_location callback for arch-specific parsing Tengda Wu
2026-08-08 12:23 ` [PATCH v4 08/23] perf annotate-arm64: Implement extract_op_location() callback Tengda Wu
2026-08-11 6:50 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 09/23] perf annotate: Deduplicate overlapping ARM SPE events for data type profiling Tengda Wu
2026-08-10 6:57 ` Adrian Hunter
2026-08-08 12:23 ` [PATCH v4 10/23] perf arm-spe: Set default synthesized event period to 1 Tengda Wu
2026-08-08 12:23 ` [PATCH v4 11/23] perf annotate-data: Extract invalidate_reg_state() as a common helper Tengda Wu
2026-08-11 7:09 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 12/23] perf annotate-arm64: Enable instruction tracking support Tengda Wu
2026-08-08 12:23 ` [PATCH v4 13/23] perf annotate-arm64: Track return type after call instructions Tengda Wu
2026-08-08 12:23 ` [PATCH v4 14/23] perf annotate-arm64: Support load instruction tracking Tengda Wu
2026-08-11 7:36 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 15/23] perf annotate-arm64: Support store " Tengda Wu
2026-08-11 8:00 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 16/23] perf annotate-data: Expand type_state_reg imm_value to u64 Tengda Wu
2026-08-11 8:10 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 17/23] perf annotate-data: Track imm_value for stack variables Tengda Wu
2026-08-11 8:16 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 18/23] perf annotate-arm64: Support stack variable tracking Tengda Wu
2026-08-11 8:24 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 19/23] perf annotate-arm64: Support 'mov' instruction tracking Tengda Wu
2026-08-11 8:37 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 20/23] perf annotate-arm64: Support 'add' " Tengda Wu
2026-08-11 8:45 ` Shuai Xue
2026-08-08 12:23 ` [PATCH v4 21/23] perf annotate-arm64: Support 'adrp' instruction to track global variables Tengda Wu
2026-08-11 8:50 ` Shuai Xue [this message]
2026-08-08 12:23 ` [PATCH v4 22/23] perf annotate-arm64: Support per-cpu variable access tracking Tengda Wu
2026-08-08 12:24 ` [PATCH v4 23/23] perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer Tengda Wu
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=59b826f3-b3c9-4964-bf82-9e43913d80e2@linux.alibaba.com \
--to=xueshuai@linux.alibaba.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=kim.phillips@arm.com \
--cc=leo.yan@linux.dev \
--cc=lihuafei1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=namhyung@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=peterz@infradead.org \
--cc=wutengda@huaweicloud.com \
--cc=zli94@ncsu.edu \
/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