]> git.baikalelectronics.ru Git - kernel.git/commit
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT
authorGuo Ren <guoren@linux.alibaba.com>
Thu, 17 Dec 2020 16:01:41 +0000 (16:01 +0000)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Thu, 14 Jan 2021 23:09:05 +0000 (15:09 -0800)
commit353cecac50965dff47ac57011cd2e1167afe51fc
tree034c48f5730615893aa5d89f8c8e2327e2cb8585
parentd4edfa1abb31f870c80d2ba5d136787741085434
riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT

This patch changes the current detour mechanism of dynamic ftrace
which has been discussed during LPC 2020 RISCV-MC [1].

Before the patch, we used mcount for detour:
<funca>:
addi sp,sp,-16
sd   ra,8(sp)
sd   s0,0(sp)
addi s0,sp,16
mv   a5,ra
mv   a0,a5
auipc ra,0x0 -> nop
jalr  -296(ra) <_mcount@plt> ->nop
...

After the patch, we use nop call site area for detour:
<funca>:
nop -> REG_S ra, -SZREG(sp)
nop -> auipc ra, 0x?
nop -> jalr ?(ra)
nop -> REG_L ra, -SZREG(sp)
...

The mcount mechanism is mixed with gcc function prologue which is
not very clear. The patchable function entry just put 16 bytes nop
before the front of the function prologue which could be filled
with a separated detour mechanism.

[1] https://www.linuxplumbersconf.org/event/7/contributions/807/

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/Makefile
arch/riscv/kernel/ftrace.c
arch/riscv/kernel/mcount-dyn.S