tracing: Fix the bug where bpf_get_stackid returns -EFAULT on the ARM64
Subsystems (3)
PATCH 1/1 tracing: Fix the bug where bpf_get_stackid returns -EFAULT on the ARM64
From: Feng Yang <[email protected]>
commit fd2f74f8f3d3c1a524637caf5bead9757fae4332 upstream.
When using bpf_program__attach_kprobe_multi_opts on ARM64 to hook a BPF program that contains the bpf_get_stackid function, the BPF program fails to obtain the stack trace and returns -EFAULT.
This is because ftrace_partial_regs omits the configuration of the pstate register, leaving pstate at the default value of 0. When get_perf_callchain executes, it uses user_mode(regs) to determine whether it is in kernel mode. This leads to a misjudgment that the code is in user mode,
so perf_callchain_kernel is not executed and the function returns directly. As a result, trace->nr becomes 0, and finally -EFAULT is returned.
Therefore, the assignment of the pstate register is added here.
--- arch/arm64/include/asm/ftrace.h | 1 + 1 file changed, 1 insertion(+)
arch/arm64/include/asm/ftrace.h +1 -0
@@ -145,6 +145,7 @@ ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs) regs->pc = afregs->pc; regs->regs[29 ] = afregs->fp; regs->regs[30 ] = afregs->lr; + regs->pstate = PSR_MODE_EL1h;return regs; }
Signature · 12 lines
2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Quoted 5 lines
commit
fd2f74f8f3d3c1a524637caf5bead9757fae4332upstream.When using
bpf_program__attach_kprobe_multi_optson ARM64 to hook a BPF program that contains thebpf_get_stackidfunction, the BPF program fails to obtain the stack trace and returns-EFAULT.
Queued for 6.12.y, thanks.
--
Thanks,
Sasha