Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: bpf@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1 3/7] perf annotate: Implement elfutils libasm disassembler backend
Date: Tue, 09 Jun 2026 05:30:05 +0000	[thread overview]
Message-ID: <20260609053006.429141F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609051759.405027-4-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incorrect usage of the elfutils libasm API causes severely truncated disassembly output and incorrect error handling.
--

commit a3f0b9f1213f96fa27632210d1db364c7cad8286
Author: Ian Rogers <irogers@google.com>

perf annotate: Implement elfutils libasm disassembler backend

This commit implements the core disassembler backend in libasm.c utilizing
elfutils' libasm API. It hooks the backend into perf annotate disassembler
routing and configures libasm as the first-choice disassembler backend.

> diff --git a/tools/perf/util/libasm.c b/tools/perf/util/libasm.c
> new file mode 100644
> index 0000000000000..6daac121b8f81
> --- /dev/null
> +++ b/tools/perf/util/libasm.c

[ ... ]

> +struct disasm_output_arg {
> +	char *buf;
> +	size_t size;
> +};
> +
> +static int disasm_output_cb(char *str, size_t len, void *arg)
> +{
> +	struct disasm_output_arg *oa = arg;
> +	size_t to_copy = len < oa->size - 1 ? len : oa->size - 1;
> +
> +	memcpy(oa->buf, str, to_copy);
> +	oa->buf[to_copy] = '\0';
> +	return 1;

[Severity: High]
Does returning 1 here cause the elfutils libasm API to abort parsing the
instruction? If elfutils expects 0 for success, this non-zero return
value might indicate an error and cause disassembly to stop prematurely.

Also, does this correctly append successive chunks to the buffer, or does it
overwrite the beginning each time it is called? It appears that oa->buf and
oa->size are not advanced by to_copy, which might cause successive strings
(like mnemonics and operands) to repeatedly overwrite the buffer at index 0.

> +}

[ ... ]

> +	offset = 0;
> +	while (pc < end) {
> +		struct disasm_output_arg oa = {
> +			.buf = disasm_buf,
> +			.size = sizeof(disasm_buf),
> +		};
> +		const uint8_t *prev_pc = pc;
> +
> +		ret = disasm_cb(handle, &pc, end, addr, "%7m %.1o,%.2o,%.3o,%.4o,%.5o",
> +				    disasm_output_cb, &oa, NULL);
> +		if (ret != 1 || pc == prev_pc) {

[Severity: High]
If disasm_cb propagates the 1 returned by the callback, does checking for
ret != 1 instead of ret != 0 cause us to treat an aborted disassembly
as a success? This might mask the truncation error occurring in the
callback.

> +			/* Disassembly failed or got stuck */
> +			break;
> +		}
> +
> +		args->offset = offset;
> +		args->line = disasm_buf;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260609051759.405027-1-irogers@google.com?part=3

  reply	other threads:[~2026-06-09  5:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09  5:17 [PATCH v1 0/7] perf annotate: Add elfutils libasm disassembler backend Ian Rogers
2026-06-09  5:17 ` [PATCH v1 1/7] tools build: Add feature check for elfutils libasm Ian Rogers
2026-06-09  5:28   ` sashiko-bot
2026-06-09  5:17 ` [PATCH v1 2/7] perf build: Add build support and capability " Ian Rogers
2026-06-09  5:28   ` sashiko-bot
2026-06-09  5:17 ` [PATCH v1 3/7] perf annotate: Implement elfutils libasm disassembler backend Ian Rogers
2026-06-09  5:30   ` sashiko-bot [this message]
2026-06-09  5:17 ` [PATCH v1 4/7] perf annotate: Add --disassembler command-line option Ian Rogers
2026-06-09  5:17 ` [PATCH v1 5/7] perf test: Enhance annotate test coverage and isolate config Ian Rogers
2026-06-09  5:28   ` sashiko-bot
2026-06-09  5:17 ` [PATCH v1 6/7] perf annotate: Support BPF JIT disassembly via genelf Ian Rogers
2026-06-09  5:33   ` sashiko-bot
2026-06-09  5:17 ` [PATCH v1 7/7] perf test: Add BPF JIT annotation test coverage for all disassemblers Ian Rogers
2026-06-09  5:36   ` 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=20260609053006.429141F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=irogers@google.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