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>,
sashiko-bot@kernel.org
Subject: [PATCH V3 2/2] perf disasm powerpc: handle Power10 prefixed instruction continuation lines
Date: Wed, 2 Dec 2026 22:50:48 +0530 [thread overview]
Message-ID: <20261202172048.99786-2-atrajeev@linux.ibm.com> (raw)
In-Reply-To: <20261202172048.99786-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 (after the 11-byte raw hex prefix)
as a valid case in disasm_line__parse_powerpc(): skip the call to
disasm_line__parse(), set the instruction name to an empty heap-allocated
string, and point operands at the empty end of the line so printing
callbacks can safely render "%s".
In check_ppc_insn(), skip decoding raw_insn when dl->ins.name is empty
and dl->ops.raw is non-NULL (indicating an objdump continuation line
rather than a raw disassembly line), so the 32-bit suffix word is not
misclassified as a standalone instruction. Also free the previous
empty dl->ins.name when check_ppc_insn() replaces it in raw mode.
Fixes: 4c3f09e35ca9 ("perf annotate: Return errors from disasm_line__parse_powerpc()")
Reported-by: Narendra Nalli <narnalli@in.ibm.com>
Reported-by: Vijay Puliyala <vpuliyal@in.ibm.com>
Reported-by: sashiko-bot@kernel.org
Signed-off-by: Athira Rajeev <atrajeev@linux.ibm.com>
---
Changelog:
V2 -> V3:
Addressed review comments from Sashiko:
- Avoid out-of-bounds read past dl->al.line when strlen(name_raw_insn) < RAW_BYTES.
- Skip opcode classification in check_ppc_insn() for objdump continuation
lines (where dl->ins.name is empty and dl->ops.raw != NULL).
- Include <stdlib.h> in annotate-powerpc.c, check strdup() return values,
and free old dl->ins.name across all replacement branches.
- Add Fixes: tag.
V1 -> V2:
Addressed review comment from Sashiko.
Set the operand value and also free the instruction name
before picking from opcode value
.../util/annotate-arch/annotate-powerpc.c | 37 +++++++++++++++++--
tools/perf/util/disasm.c | 26 ++++++++++++-
2 files changed, 57 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/annotate-arch/annotate-powerpc.c b/tools/perf/util/annotate-arch/annotate-powerpc.c
index 00b93296fc94..c4cb19f99849 100644
--- a/tools/perf/util/annotate-arch/annotate-powerpc.c
+++ b/tools/perf/util/annotate-arch/annotate-powerpc.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
+#include <stdlib.h>
#include <string.h>
#include <linux/compiler.h>
#include <linux/kernel.h>
@@ -289,6 +290,13 @@ const struct ins_ops *check_ppc_insn(struct disasm_line *dl)
};
char name_insn[32];
+ /*
+ * An empty instruction name with non-NULL raw operands comes from
+ * an objdump Power10 prefixed instruction continuation word; do not decode it.
+ */
+ if (!strlen(dl->ins.name) && dl->ops.raw)
+ return NULL;
+
/*
* Instructions with opcode 32 to 63 are memory
* instructions in powerpc
@@ -299,16 +307,28 @@ const struct ins_ops *check_ppc_insn(struct disasm_line *dl)
* opcode to be used in insn-stat
*/
if (!strlen(dl->ins.name)) {
+ char *name;
+
sprintf(name_insn, "%d", opcode);
- dl->ins.name = strdup(name_insn);
+ name = strdup(name_insn);
+ if (name) {
+ free((void *)dl->ins.name);
+ dl->ins.name = name;
+ }
}
return &load_store_ops;
} else if (opcode == 31) {
/* 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))
- dl->ins.name = strdup(ret->name);
+ if (!strlen(dl->ins.name)) {
+ char *name = strdup(ret->name);
+
+ if (name) {
+ free((void *)dl->ins.name);
+ dl->ins.name = name;
+ }
+ }
return &load_store_ops;
} else {
mem_insns_31_opcode.value = PPC_22_30(raw_insn);
@@ -324,8 +344,17 @@ const struct ins_ops *check_ppc_insn(struct disasm_line *dl)
mem_insns_31_opcode.value = opcode;
ret = bsearch(&mem_insns_31_opcode, arithmetic_two_ops, ARRAY_SIZE(arithmetic_two_ops),
sizeof(arithmetic_two_ops[0]), cmp_offset);
- if (ret != NULL)
+ if (ret != NULL) {
+ if (!strlen(dl->ins.name)) {
+ char *name = strdup(ret->name);
+
+ if (name) {
+ free((void *)dl->ins.name);
+ dl->ins.name = name;
+ }
+ }
return &arithmetic_ops;
+ }
}
return NULL;
diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index 169fc5acbfc5..724e819f9320 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -898,7 +898,7 @@ static int disasm_line__parse_powerpc(struct disasm_line *dl, struct annotate_ar
const char **namep = &dl->ins.name;
char **rawp = &dl->ops.raw;
char *tmp_raw_insn, *name_raw_insn = skip_spaces(line);
- char *name = skip_spaces(name_raw_insn + RAW_BYTES);
+ char *name;
int disasm = 0;
int ret = 0;
@@ -909,7 +909,29 @@ static int disasm_line__parse_powerpc(struct disasm_line *dl, struct annotate_ar
return -1;
if (disasm) {
- ret = disasm_line__parse(name, namep, rawp);
+ if (strlen(name_raw_insn) < RAW_BYTES)
+ return -1;
+
+ name = skip_spaces(name_raw_insn + RAW_BYTES);
+ if (name[0] != '\0') {
+ ret = disasm_line__parse(name, namep, rawp);
+ } else {
+ /*
+ * 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;
+ *rawp = name; /* the '\0' at the end of dl->al.line */
+ }
} else {
/*
* The name is freed in disasm_line__free() and may be replaced
--
2.52.0
next prev parent reply other threads:[~2026-12-02 17:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 17:20 [PATCH V3 1/2] perf disasm powerpc: Don't use a string literal as the instruction name Athira Rajeev
2026-12-02 17:20 ` Athira Rajeev [this message]
2026-12-02 17:37 ` sashiko-bot
2026-12-02 18:01 ` Bradley Morgan
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=20261202172048.99786-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=sashiko-bot@kernel.org \
--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