bpftool: Enable aarch64 ISA extensions for JIT disassembly
PATCH v4 1/1 bpftool: Enable aarch64 ISA extensions for JIT disassembly
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
---
Changelog:
v3: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Add acked by Quentin
- Rebased on bpf-next/master
v2: https://lore.kernel.org/all/[email protected]/
Chnages in v3:
- Fix bug in usage of strncmp() (AI)
v1: https://lore.kernel.org/all/[email protected]/
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(-)
tools/bpf/bpftool/jit_disasm.c +10 -1
@@ -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
Signature · 1 line
2.52.0
Quoted 68 lines · Puranjay Mohan
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, #1After:
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
Quoted 4 lines
Signed-off-by Puranjay Mohan <[email protected]>Acked-by Yonghong Song <[email protected]>Acked-by Leon Hwang <[email protected]>Acked-by Quentin Monnet <[email protected]>
Quoted 26 lines
---
Changelog:
v3: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Add acked by Quentin
- Rebased on bpf-next/master
v2: https://lore.kernel.org/all/[email protected]/
Chnages in v3:
- Fix bug in usage ofstrncmp()(AI)
v1: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Fix coding style issue (Quentin)
- Usestrncmp()in place ofstrstr()for detecting aarch64 in triple. (Quentin)--- tools/bpf/bpftool/jit_disasm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)tools/bpf/bpftool/jit_disasm.c +0
-1@@ -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);
tools/bpf/bpftool/jit_disasm.c init_context(disasm_ctx_t *ctx, const char *arch, · line 105
Quoted 10 lines
tools/bpf/bpftool/jit_disasm.c +10
-0+ +/* +* 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);
Question: Are there advantages to special casing aarch64? Shouldn't this be a no-op for other architectures where it seems the JIT doesn't emit any feature-dependent instructions?
Quoted 5 lines
tools/bpf/bpftool/jit_disasm.c +0
-0LLVMDisposeMessage (triple);if (!*ctx) {base-commit:
77378dabb50f593c756d393d8eacb0b91b758863
Quoted 109 lines · Emil Tsalapatis
Quoted 68 lines · Puranjay Mohan
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, #1After:
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 x10Quoted 4 lines
Signed-off-by Puranjay Mohan <[email protected]>Acked-by Yonghong Song <[email protected]>Acked-by Leon Hwang <[email protected]>Acked-by Quentin Monnet <[email protected]>Reviewed-by Emil Tsalapatis <[email protected]>Quoted 32 lines
---
Changelog:
v3: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Add acked by Quentin
- Rebased on bpf-next/master
v2: https://lore.kernel.org/all/[email protected]/
Chnages in v3:
- Fix bug in usage ofstrncmp()(AI)
v1: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Fix coding style issue (Quentin)
- Usestrncmp()in place ofstrstr()for detecting aarch64 in triple. (Quentin)--- tools/bpf/bpftool/jit_disasm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)tools/bpf/bpftool/jit_disasm.c +6
-1@@ -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 ))
Quoted 8 lines
tools/bpf/bpftool/jit_disasm.c init_context(disasm_ctx_t *ctx, const char *arch, · line 105
Quoted 4 lines
tools/bpf/bpftool/jit_disasm.c +4
-0+ *ctx =LLVMCreateDisasmCPUFeatures (triple,"" ,"+all" ,NULL ,0 ,NULL , + symbol_lookup_callback); + else + *ctx =LLVMCreateDisasm (triple,NULL ,0 ,NULL , symbol_lookup_callback);Question: Are there advantages to special casing aarch64? Shouldn't this be a no-op for other architectures where it seems the JIT doesn't emit any feature-dependent instructions?
Thanks for the review.
the "+all" is specific to the arm64 target and if I don't special case it, it will be ignored and that is fine but it prints this to the stdout:
'+all' is not a recognized feature for this target (ignoring feature)
this will be printed for every target except arm64, which is not something we want.
Thanks,
Puranjay
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 10 lines · On Wed, 18 Mar 2026 10:22:57 -0700 you wrote:
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.[...]
Here is the summary with links:
- [bpf-next,v4] bpftool: Enable aarch64 ISA extensions for JIT disassembly
https://git.kernel.org/bpf/bpf-next/c/4ea43a435505
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html