From: Puranjay Mohan <puranjay@kernel.org>
To: bpf@vger.kernel.org
Cc: Puranjay Mohan <puranjay@kernel.org>,
Puranjay Mohan <puranjay12@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
Quentin Monnet <qmo@kernel.org>,
kernel-team@meta.com, Yonghong Song <yonghong.song@linux.dev>,
Leon Hwang <leon.hwang@linux.dev>
Subject: [PATCH bpf-next v4] bpftool: Enable aarch64 ISA extensions for JIT disassembly
Date: Wed, 18 Mar 2026 10:22:57 -0700 [thread overview]
Message-ID: <20260318172259.2882792-1-puranjay@kernel.org> (raw)
The LLVM disassembler needs ISA extension features enabled to correctly
decode instructions from those extensions. On aarch64, without these
features, instructions like LSE atomics (e.g. ldaddal) are silently
decoded as incorrect instructions and disassembly is truncated.
Use LLVMCreateDisasmCPUFeatures() with "+all" features for aarch64
targets so that the disassembler can handle any instruction the kernel
JIT might emit.
Before:
int bench_trigger_uprobe(void * ctx):
bpf_prog_538c6a43d1c6b84c_bench_trigger_uprobe:
; int cpu = bpf_get_smp_processor_id();
0: mov x9, x30
4: nop
8: stp x29, x30, [sp, #-16]!
c: mov x29, sp
10: stp xzr, x26, [sp, #-16]!
14: mov x26, sp
18: mrs x10, SP_EL0
1c: ldr w7, [x10, #16]
; __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1);
20: and w7, w7, #0xff
; __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1);
24: lsl x7, x7, #7
28: mov x0, #-281474976710656
2c: movk x0, #32768, lsl #32
30: movk x0, #35407, lsl #16
34: add x0, x0, x7
38: mov x1, #1
; __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1);
3c: mov x1, #1
After:
int bench_trigger_uprobe(void * ctx):
bpf_prog_538c6a43d1c6b84c_bench_trigger_uprobe:
; int cpu = bpf_get_smp_processor_id();
0: mov x9, x30
4: nop
8: stp x29, x30, [sp, #-16]!
c: mov x29, sp
10: stp xzr, x26, [sp, #-16]!
14: mov x26, sp
18: mrs x10, SP_EL0
1c: ldr w7, [x10, #16]
; __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1);
20: and w7, w7, #0xff
; __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1);
24: lsl x7, x7, #7
28: mov x0, #-281474976710656
2c: movk x0, #32768, lsl #32
30: movk x0, #35407, lsl #16
34: add x0, x0, x7
38: mov x1, #1
; __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1);
3c: ldaddal x1, x1, [x0]
; return 0;
40: mov w7, #0
44: ldp xzr, x26, [sp], #16
48: ldp x29, x30, [sp], #16
4c: mov x0, x7
50: ret
54: nop
58: ldr x10, #8
5c: br x10
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Acked-by: Leon Hwang <leon.hwang@linux.dev>
Acked-by: Quentin Monnet <qmo@kernel.org>
---
Changelog:
v3: https://lore.kernel.org/all/20260311222608.521549-1-puranjay@kernel.org/
Changes in v4:
- Add acked by Quentin
- Rebased on bpf-next/master
v2: https://lore.kernel.org/all/20260310223456.1706712-1-puranjay@kernel.org/
Chnages in v3:
- Fix bug in usage of strncmp() (AI)
v1: https://lore.kernel.org/all/20260306163906.2870529-1-puranjay@kernel.org/
Changes in v2:
- Fix coding style issue (Quentin)
- Use strncmp() in place of strstr() for detecting aarch64 in triple. (Quentin)
---
tools/bpf/bpftool/jit_disasm.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c
index 8895b4e1f690..04541155e9cc 100644
--- a/tools/bpf/bpftool/jit_disasm.c
+++ b/tools/bpf/bpftool/jit_disasm.c
@@ -93,7 +93,16 @@ init_context(disasm_ctx_t *ctx, const char *arch,
p_err("Failed to retrieve triple");
return -1;
}
- *ctx = LLVMCreateDisasm(triple, NULL, 0, NULL, symbol_lookup_callback);
+
+ /*
+ * Enable all aarch64 ISA extensions so the disassembler can handle any
+ * instruction the kernel JIT might emit (e.g. ARM64 LSE atomics).
+ */
+ if (!strncmp(triple, "aarch64", 7))
+ *ctx = LLVMCreateDisasmCPUFeatures(triple, "", "+all", NULL, 0, NULL,
+ symbol_lookup_callback);
+ else
+ *ctx = LLVMCreateDisasm(triple, NULL, 0, NULL, symbol_lookup_callback);
LLVMDisposeMessage(triple);
if (!*ctx) {
base-commit: 77378dabb50f593c756d393d8eacb0b91b758863
--
2.52.0
next reply other threads:[~2026-03-18 17:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 17:22 Puranjay Mohan [this message]
2026-03-21 22:25 ` [PATCH bpf-next v4] bpftool: Enable aarch64 ISA extensions for JIT disassembly Emil Tsalapatis
2026-03-24 13:07 ` Puranjay Mohan
2026-03-24 15:50 ` patchwork-bot+netdevbpf
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=20260318172259.2882792-1-puranjay@kernel.org \
--to=puranjay@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@meta.com \
--cc=leon.hwang@linux.dev \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=mykyta.yatsenko5@gmail.com \
--cc=puranjay12@gmail.com \
--cc=qmo@kernel.org \
--cc=yonghong.song@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