Linux Perf Users
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Tengda Wu <wutengda@huaweicloud.com>
Cc: sashiko-reviews@lists.linux.dev, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 08/21] perf annotate: Introduce extract_op_location callback for arch-specific parsing
Date: Wed, 8 Jul 2026 23:31:16 -0700	[thread overview]
Message-ID: <ak9ANIuZLqWvAJWa@z2> (raw)
In-Reply-To: <2da387b1-ff15-4d7a-9cfe-062a9aa55368@huaweicloud.com>

On Wed, Jul 01, 2026 at 03:29:57PM +0800, Tengda Wu wrote:
> 
> 
> On 2026/7/1 12:06, sashiko-bot@kernel.org wrote:
> > Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> > - [Medium] Refactoring changes the error propagation behavior for memory operands with unrecognized registers, causing valid instructions to be incorrectly marked as bad.
> > - [Low] Missing explicit inclusion of `<stdlib.h>` for the POSIX libc function `strtol()`, breaking musl compatibility.
> > --
> > 
> > commit a79e03a1004b442317df26b7478d0a1daed1e563
> > Author: Tengda Wu <wutengda@huaweicloud.com>
> > 
> > perf annotate: Introduce extract_op_location callback for arch-specific parsing
> > 
> > This patch refactors operand parsing by moving it from the central
> > annotate_get_insn_location() into architecture-specific callbacks. By
> > introducing extract_op_location callbacks for PowerPC and x86, it aims to
> > simplify the core logic and improve maintainability without making functional
> > changes.
> > 
> >> diff --git a/tools/perf/util/annotate-arch/annotate-x86.c b/tools/perf/util/annotate-arch/annotate-x86.c
> >> index 7e61365363938..6a4b4bdcd7a7c 100644
> >> --- a/tools/perf/util/annotate-arch/annotate-x86.c
> >> +++ b/tools/perf/util/annotate-arch/annotate-x86.c
> >> @@ -2,6 +2,7 @@
> >>  #include <string.h>
> >>  #include <linux/compiler.h>
> >>  #include <linux/zalloc.h>
> >> +#include <linux/ctype.h>
> >>  #include <assert.h>
> >>  #include <inttypes.h>
> >>  #include "../annotate-data.h"
> > 
> > [Severity: Low]
> > Does this file need an explicit include of <stdlib.h> for musl libc
> > compatibility?
> > 
> > It appears strtol() is used later in extract_op_location_x86() without
> > the required <stdlib.h> header being directly included here, which might
> > lead to implicit function declaration errors on musl-based systems.
> > 
> 
> Agreed.
> 
> > [ ... ]
> > 
> >> @@ -809,6 +810,86 @@ static void update_insn_state_x86(struct type_state *state,
> >>  }
> >>  #endif
> >>  
> >> +/*
> >> + * Get register number and access offset from the given instruction.
> >> + * It assumes AT&T x86 asm format like OFFSET(REG).  Maybe it needs
> >> + * to revisit the format when it handles different architecture.
> >> + * Fills @reg and @offset when return 0.
> >> + */
> >> +static int extract_reg_offset(const struct arch *arch, const char *str,
> >> +			      struct annotated_op_loc *op_loc)
> >> +{
> > 
> > [ ... ]
> > 
> >> +static int extract_op_location_x86(const struct arch *arch,
> >> +				   struct disasm_line *dl __maybe_unused,
> >> +				   const char *op_str, int op_idx __maybe_unused,
> >> +				   struct annotated_op_loc *op_loc)
> >> +{
> >> +	const char *s = op_str;
> >> +	char *p = NULL;
> >> +
> >> +	if (op_str == NULL)
> >> +		return 0;
> >> +
> >> +	if (strchr(op_str, arch->objdump.memory_ref_char)) {
> >> +		op_loc->mem_ref = true;
> >> +		return extract_reg_offset(arch, op_str, op_loc);
> > 
> > [Severity: Medium]
> > Does returning the result of extract_reg_offset() here alter the error
> > propagation behavior?
> > 
> > In the previous annotate_get_insn_location() logic, the return value of
> > extract_reg_offset() was safely ignored:
> > 
> >         } else if (strchr(insn_str, arch->objdump.memory_ref_char)) {
> >                 op_loc->mem_ref = true;
> >                 op_loc->multi_regs = multi_regs;
> >                 extract_reg_offset(arch, insn_str, op_loc);
> >         } else {
> > 
> > By returning it here, extract_op_location_x86() might return -1 if the
> > register is unrecognized. This regression is now propagated back to the
> > caller in annotate_get_insn_location():
> > 
> >         if (arch->extract_op_location) {
> >                 ret = arch->extract_op_location(arch, dl, insn_str, i, op_loc);
> >                 if (ret)
> >                         return ret;
> >         }
> > 
> > Could this cause valid instructions to be completely skipped and
> > incorrectly marked as bad?
> > 
> 
> I don't think this is a problem. If we don't return an error here,
> extract_reg_offset() would continue with an uninitialized or invalid
> offset, which would then cause update_insn_state() to make incorrect
> judgments. Returning -1 and marking it as bad is actually safer than
> silently propagating wrong information.

I agree.  I'm not sure if there's actual case it fails there, but I
prefer not to process when it failed.

Thanks,
Namhyung


  reply	other threads:[~2026-07-09  6:31 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  3:53 [PATCH v3 00/21] perf arm64: Support data type profiling Tengda Wu
2026-07-01  3:53 ` [PATCH v3 01/21] perf capstone: Fix kernel map reference count leak Tengda Wu
2026-07-09  5:57   ` Namhyung Kim
2026-07-10 21:49     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 02/21] perf capstone: Fix arm64 jump/adrp disassembly mismatch with objdump Tengda Wu
2026-07-01  4:07   ` sashiko-bot
2026-07-01  6:44     ` Tengda Wu
2026-07-09  6:10       ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 03/21] perf llvm: Fix arm64 adrp instruction " Tengda Wu
2026-07-01  4:05   ` sashiko-bot
2026-07-01  6:45     ` Tengda Wu
2026-07-09  6:18   ` Namhyung Kim
2026-07-09  7:49     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 04/21] perf annotate-arm64: Generalize arm64_mov__parse to support more instructions Tengda Wu
2026-07-01  4:03   ` sashiko-bot
2026-07-01  6:57     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 05/21] perf annotate-arm64: Handle load and store instructions Tengda Wu
2026-07-01  4:07   ` sashiko-bot
2026-07-01  7:03     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 06/21] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64 Tengda Wu
2026-07-01  4:07   ` sashiko-bot
2026-07-01  7:14     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 07/21] perf annotate: Adapt arch__dwarf_regnum() " Tengda Wu
2026-07-01  3:53 ` [PATCH v3 08/21] perf annotate: Introduce extract_op_location callback for arch-specific parsing Tengda Wu
2026-07-01  4:06   ` sashiko-bot
2026-07-01  7:29     ` Tengda Wu
2026-07-09  6:31       ` Namhyung Kim [this message]
2026-07-01  3:53 ` [PATCH v3 09/21] perf annotate-arm64: Implement extract_op_location() callback Tengda Wu
2026-07-01  4:10   ` sashiko-bot
2026-07-01  7:36     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 10/21] perf annotate: Deduplicate overlapping ARM SPE events for data type profiling Tengda Wu
2026-07-01  4:06   ` sashiko-bot
2026-07-09  6:47     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 11/21] perf auxtrace: Set default period to 1 for PERF_ITRACE_PERIOD_INSTRUCTIONS type Tengda Wu
2026-07-01  4:05   ` sashiko-bot
2026-07-01  3:53 ` [PATCH v3 12/21] perf annotate-data: Extract invalidate_reg_state() as a common helper Tengda Wu
2026-07-01  3:53 ` [PATCH v3 13/21] perf annotate-arm64: Enable instruction tracking support Tengda Wu
2026-07-01  4:12   ` sashiko-bot
2026-07-01  7:56     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 14/21] perf annotate-arm64: Support load instruction tracking Tengda Wu
2026-07-01  4:14   ` sashiko-bot
2026-07-01  8:37     ` Tengda Wu
2026-07-09  7:05       ` Namhyung Kim
2026-07-09  7:25         ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 15/21] perf annotate-arm64: Support store " Tengda Wu
2026-07-01  3:53 ` [PATCH v3 16/21] perf annotate-arm64: Support stack variable tracking Tengda Wu
2026-07-01  4:16   ` sashiko-bot
2026-07-09  7:11     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 17/21] perf annotate-arm64: Support 'mov' instruction tracking Tengda Wu
2026-07-01  4:21   ` sashiko-bot
2026-07-01  8:46     ` Tengda Wu
2026-07-09  7:17       ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 18/21] perf annotate-arm64: Support 'add' " Tengda Wu
2026-07-01  4:16   ` sashiko-bot
2026-07-01  8:47     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 19/21] perf annotate-arm64: Support 'adrp' instruction to track global variables Tengda Wu
2026-07-01  4:15   ` sashiko-bot
2026-07-01  8:48     ` Tengda Wu
2026-07-09  7:31   ` Namhyung Kim
2026-07-09  7:42     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 20/21] perf annotate-arm64: Support per-cpu variable access tracking Tengda Wu
2026-07-01  4:18   ` sashiko-bot
2026-07-09  7:29   ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 21/21] perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer Tengda Wu
2026-07-01  4:16   ` sashiko-bot
2026-07-01  8:56     ` Tengda Wu
2026-07-09  7:36       ` Namhyung Kim
2026-07-09  5:54 ` [PATCH v3 00/21] perf arm64: Support data type profiling Namhyung Kim
2026-07-09  8:01   ` 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=ak9ANIuZLqWvAJWa@z2 \
    --to=namhyung@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