]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
riscv: add CALLER_ADDRx support
authorZong Li <zong.li@sifive.com>
Fri, 2 Feb 2024 01:51:02 +0000 (01:51 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 Mar 2024 14:48:41 +0000 (14:48 +0000)
commit9537603a54361938cbd3253ef8304de2e67eae7f
tree9e3ee0d7757e213a5844d74eab520099378680ca
parent0c8a3d3354cd704f587182bd56a001cd4cec23a7
riscv: add CALLER_ADDRx support

commit 680341382da56bd192ebfa4e58eaf4fec2e5bca7 upstream.

CALLER_ADDRx returns caller's address at specified level, they are used
for several tracers. These macros eventually use
__builtin_return_address(n) to get the caller's address if arch doesn't
define their own implementation.

In RISC-V, __builtin_return_address(n) only works when n == 0, we need
to walk the stack frame to get the caller's address at specified level.

data.level started from 'level + 3' due to the call flow of getting
caller's address in RISC-V implementation. If we don't have additional
three iteration, the level is corresponding to follows:

callsite -> return_address -> arch_stack_walk -> walk_stackframe
|           |                 |                  |
level 3     level 2           level 1            level 0

Fixes: 10626c32e382 ("riscv/ftrace: Add basic support")
Cc: stable@vger.kernel.org
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Zong Li <zong.li@sifive.com>
Link: https://lore.kernel.org/r/20240202015102.26251-1-zong.li@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/riscv/include/asm/ftrace.h
arch/riscv/kernel/Makefile
arch/riscv/kernel/return_address.c [new file with mode: 0644]