Skip to content

Commit fd2f74f

Browse files
kknjhwilldeacon
authored andcommitted
tracing: Fix the bug where bpf_get_stackid returns -EFAULT on the ARM64
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. Fixes: b9b55c8 ("tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs") Closes: https://lore.kernel.org/bpf/20250919071902.554223-1-yangfeng59949@163.com/ Signed-off-by: Feng Yang <yangfeng@kylinos.cn> Tested-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Will Deacon <will@kernel.org>
1 parent 195a1b7 commit fd2f74f

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

arch/arm64/include/asm/ftrace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs)
153153
regs->pc = afregs->pc;
154154
regs->regs[29] = afregs->fp;
155155
regs->regs[30] = afregs->lr;
156+
regs->pstate = PSR_MODE_EL1h;
156157
return regs;
157158
}
158159

0 commit comments

Comments
 (0)