Linux Perf Users
 help / color / mirror / Atom feed
From: Athira Rajeev <atrajeev@linux.ibm.com>
To: acme@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com,
	james.clark@linaro.org, tmricht@linux.ibm.com,
	maddy@linux.ibm.com, irogers@google.com, namhyung@kernel.org,
	bradley.morgan@linux.dev
Cc: linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	atrajeev@linux.ibm.com, hbathini@linux.vnet.ibm.com,
	tejas05@linux.ibm.com, tshah@linux.ibm.com,
	Narendra Nalli <narnalli@in.ibm.com>,
	Vijay Puliyala <vpuliyal@in.ibm.com>
Subject: [PATCH V2 2/2] perf disasm powerpc: handle Power10 prefixed instruction continuation lines
Date: Wed,  2 Dec 2026 18:13:37 +0530	[thread overview]
Message-ID: <20261202124337.10434-2-atrajeev@linux.ibm.com> (raw)
In-Reply-To: <20261202124337.10434-1-atrajeev@linux.ibm.com>

Power10 introduces prefixed instructions that are 8 bytes wide.  objdump
emits these as two lines: the first carries both the raw bytes and the
mnemonic, while the second carries only the raw bytes of the second word
with no mnemonic:

  1020900c:  0b 00 10 06  pla  r31,757280  # 102c1e2c <func>
  10209010:  20 8e e0 3b

disasm_line__parse_powerpc() calls disasm_line__parse() on the mnemonic
portion of the line.  disasm_line__parse() returns -1 when the name
string is empty, which causes disasm_line__new() to return NULL, which
causes symbol__parse_objdump_line() to return -1, which immediately
breaks the objdump output parsing loop in symbol__disassemble_objdump().

The result is that annotation of any function containing a prefixed
instruction stops at the continuation word and all subsequent
instructions in the function are lost.

Fix this by treating an empty mnemonic as a valid case in
disasm_line__parse_powerpc(): skip the call to disasm_line__parse() and
set the instruction name to an empty heap-allocated string instead,
allowing parsing to continue to the next line.

Also point the operands at the (empty) end of the line, since
disasm_line__parse() is what normally sets them and the instruction
printing callbacks print them with "%s".

check_ppc_insn() names raw instructions from their opcode when the name
is empty, and so replaces the empty string allocated above.  Free it
first, to not leak it.

Reported-by: Narendra Nalli <narnalli@in.ibm.com>
Reported-by: Vijay Puliyala <vpuliyal@in.ibm.com>
Signed-off-by: Athira Rajeev <atrajeev@linux.ibm.com>
---
Changelog:
V1 -> V2:
 Addressed review comment from Sashiko.
 Set the operand value and also free the instruction name
 before picking from opcode value

 tools/perf/util/annotate-arch/annotate-powerpc.c |  5 ++++-
 tools/perf/util/disasm.c                         | 14 +++++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/annotate-arch/annotate-powerpc.c b/tools/perf/util/annotate-arch/annotate-powerpc.c
index 00b93296fc94..896c74a349f0 100644
--- a/tools/perf/util/annotate-arch/annotate-powerpc.c
+++ b/tools/perf/util/annotate-arch/annotate-powerpc.c
@@ -300,6 +300,7 @@ const struct ins_ops *check_ppc_insn(struct disasm_line *dl)
 		 */
 		if (!strlen(dl->ins.name)) {
 			sprintf(name_insn, "%d", opcode);
+			free((void *)dl->ins.name);
 			dl->ins.name = strdup(name_insn);
 		}
 		return &load_store_ops;
@@ -307,8 +308,10 @@ const struct ins_ops *check_ppc_insn(struct disasm_line *dl)
 		/* Check for memory instructions with opcode 31 */
 		ret = bsearch(&mem_insns_31_opcode, ins_array, ARRAY_SIZE(ins_array), sizeof(ins_array[0]), cmp_offset);
 		if (ret) {
-			if (!strlen(dl->ins.name))
+			if (!strlen(dl->ins.name)) {
+				free((void *)dl->ins.name);
 				dl->ins.name = strdup(ret->name);
+			}
 			return &load_store_ops;
 		} else {
 			mem_insns_31_opcode.value = PPC_22_30(raw_insn);
diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index a1787a9c4bfd..32e91b95ee72 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -908,16 +908,28 @@ static int disasm_line__parse_powerpc(struct disasm_line *dl, struct annotate_ar
 	if (name_raw_insn[0] == '\0')
 		return -1;
 
-	if (disasm) {
+	if (disasm && name[0] != '\0') {
 		ret = disasm_line__parse(name, namep, rawp);
 	} else {
 		/*
 		 * The name is freed in disasm_line__free() and may be replaced
 		 * by check_ppc_insn(), so it must be heap allocated.
+		 *
+		 * Power10 prefixed instructions are 8 bytes and objdump emits
+		 * the second word on its own line with raw bytes but no
+		 * mnemonic, e.g.:
+		 *   1020900c:  0b 00 10 06  pla  r31,757280
+		 *   10209010:  20 8e e0 3b
+		 *
+		 * Treat a missing mnemonic as an empty instruction name with
+		 * empty operands rather than a parse failure, so that parsing
+		 * continues past it.
 		 */
 		*namep = strdup("");
 		if (*namep == NULL)
 			return -1;
+		if (disasm)
+			*rawp = name;	/* the '\0' at the end of dl->al.line */
 	}
 
 	tmp_raw_insn = strndup(name_raw_insn, 11);
-- 
2.52.0


      reply	other threads:[~2026-12-02 12:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:43 [PATCH V2 1/2] perf disasm powerpc: Don't use a string literal as the instruction name Athira Rajeev
2026-12-02 12:43 ` Athira Rajeev [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=20261202124337.10434-2-atrajeev@linux.ibm.com \
    --to=atrajeev@linux.ibm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=bradley.morgan@linux.dev \
    --cc=hbathini@linux.vnet.ibm.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=namhyung@kernel.org \
    --cc=narnalli@in.ibm.com \
    --cc=tejas05@linux.ibm.com \
    --cc=tmricht@linux.ibm.com \
    --cc=tshah@linux.ibm.com \
    --cc=vpuliyal@in.ibm.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