riscv: stacktrace: Add USER_STACKTRACE support
authorJinjie Ruan <ruanjinjie@huawei.com>
Mon, 8 Jul 2024 03:28:47 +0000 (11:28 +0800)
committerPalmer Dabbelt <palmer@rivosinc.com>
Sun, 15 Sep 2024 06:57:16 +0000 (23:57 -0700)
commit1a7483318274d0ec60f160e604c2a1dbce27fc0a
tree706610cda2f4e121a796d77626930a0e29bb0ea4
parent22ab08955ea13be04a8efd20cc30890e0afaa49c
riscv: stacktrace: Add USER_STACKTRACE support

Currently, userstacktrace is unsupported for riscv. So use the
perf_callchain_user() code as blueprint to implement the
arch_stack_walk_user() which add userstacktrace support on riscv.
Meanwhile, we can use arch_stack_walk_user() to simplify the implementation
of perf_callchain_user().

A ftrace test case is shown as below:

# cd /sys/kernel/debug/tracing
# echo 1 > options/userstacktrace
# echo 1 > options/sym-userobj
# echo 1 > events/sched/sched_process_fork/enable
# cat trace
......
            bash-178     [000] ...1.    97.968395: sched_process_fork: comm=bash pid=178 child_comm=bash child_pid=231
            bash-178     [000] ...1.    97.970075: <user stack trace>
 => /lib/libc.so.6[+0xb5090]

Also a simple perf test is ok as below:

# perf record -e cpu-clock --call-graph fp top
# perf report --call-graph

.....
[[31m  66.54%[[m     0.00%  top      [kernel.kallsyms]            [k] ret_from_exception
            |
            ---ret_from_exception
               |
               |--[[31m58.97%[[m--do_trap_ecall_u
               |          |
               |          |--[[31m17.34%[[m--__riscv_sys_read
               |          |          ksys_read
               |          |          |
               |          |           --[[31m16.88%[[m--vfs_read
               |          |                     |
               |          |                     |--[[31m10.90%[[m--seq_read

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Tested-by: Jinjie Ruan <ruanjinjie@huawei.com>
Cc: Björn Töpel <bjorn@kernel.org>
Link: https://lore.kernel.org/r/20240708032847.2998158-3-ruanjinjie@huawei.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/Kconfig
arch/riscv/kernel/perf_callchain.c
arch/riscv/kernel/stacktrace.c