Commit 5f66e187 authored by Palmer Dabbelt's avatar Palmer Dabbelt

Merge patch series "RISC-V: Dynamic ftrace support for RV32I"

Jamie Iles <jamie@jamieiles.com> says:

This series enables dynamic ftrace support for RV32I bringing it to
parity with RV64I.  Most of the work is already there, this is largely
just assembly fixes to handle register sizes, correct handling of the
psABI calling convention and Kconfig change.

Validated with all ftrace boot time self test with qemu for RV32I and
RV64I in addition to real tracing on an RV32I FPGA design.

* b4-shazam-merge:
  RISC-V: enable dynamic ftrace for RV32I
  RISC-V: preserve a1 in mcount
  RISC-V: reduce mcount save space on RV32
  RISC-V: use REG_S/REG_L for mcount

Link: https://lore.kernel.org/r/20221115200832.706370-1-jamie@jamieiles.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parents 41555cc9 f32b4b46
...@@ -131,6 +131,11 @@ config RISCV ...@@ -131,6 +131,11 @@ config RISCV
select TRACE_IRQFLAGS_SUPPORT select TRACE_IRQFLAGS_SUPPORT
select UACCESS_MEMCPY if !MMU select UACCESS_MEMCPY if !MMU
select ZONE_DMA32 if 64BIT select ZONE_DMA32 if 64BIT
select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && $(cc-option,-fpatchable-function-entry=8)
select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
select HAVE_FUNCTION_GRAPH_TRACER
select HAVE_FUNCTION_TRACER if !XIP_KERNEL
config ARCH_MMAP_RND_BITS_MIN config ARCH_MMAP_RND_BITS_MIN
default 18 if 64BIT default 18 if 64BIT
...@@ -276,11 +281,6 @@ config ARCH_RV64I ...@@ -276,11 +281,6 @@ config ARCH_RV64I
bool "RV64I" bool "RV64I"
select 64BIT select 64BIT
select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && $(cc-option,-fpatchable-function-entry=8)
select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
select HAVE_FUNCTION_GRAPH_TRACER
select HAVE_FUNCTION_TRACER if !XIP_KERNEL
select SWIOTLB if MMU select SWIOTLB if MMU
endchoice endchoice
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
.macro SAVE_ABI_STATE .macro SAVE_ABI_STATE
addi sp, sp, -16 addi sp, sp, -16
sd s0, 0(sp) REG_S s0, 0*SZREG(sp)
sd ra, 8(sp) REG_S ra, 1*SZREG(sp)
addi s0, sp, 16 addi s0, sp, 16
.endm .endm
...@@ -25,24 +25,26 @@ ...@@ -25,24 +25,26 @@
* register if a0 was not saved. * register if a0 was not saved.
*/ */
.macro SAVE_RET_ABI_STATE .macro SAVE_RET_ABI_STATE
addi sp, sp, -32 addi sp, sp, -4*SZREG
sd s0, 16(sp) REG_S s0, 2*SZREG(sp)
sd ra, 24(sp) REG_S ra, 3*SZREG(sp)
sd a0, 8(sp) REG_S a0, 1*SZREG(sp)
addi s0, sp, 32 REG_S a1, 0*SZREG(sp)
addi s0, sp, 4*SZREG
.endm .endm
.macro RESTORE_ABI_STATE .macro RESTORE_ABI_STATE
ld ra, 8(sp) REG_L ra, 1*SZREG(sp)
ld s0, 0(sp) REG_L s0, 0*SZREG(sp)
addi sp, sp, 16 addi sp, sp, 16
.endm .endm
.macro RESTORE_RET_ABI_STATE .macro RESTORE_RET_ABI_STATE
ld ra, 24(sp) REG_L ra, 3*SZREG(sp)
ld s0, 16(sp) REG_L s0, 2*SZREG(sp)
ld a0, 8(sp) REG_L a0, 1*SZREG(sp)
addi sp, sp, 32 REG_L a1, 0*SZREG(sp)
addi sp, sp, 4*SZREG
.endm .endm
ENTRY(ftrace_stub) ENTRY(ftrace_stub)
...@@ -71,9 +73,9 @@ ENTRY(return_to_handler) ...@@ -71,9 +73,9 @@ ENTRY(return_to_handler)
mv a0, t6 mv a0, t6
#endif #endif
call ftrace_return_to_handler call ftrace_return_to_handler
mv a1, a0 mv a2, a0
RESTORE_RET_ABI_STATE RESTORE_RET_ABI_STATE
jalr a1 jalr a2
ENDPROC(return_to_handler) ENDPROC(return_to_handler)
#endif #endif
...@@ -82,16 +84,16 @@ ENTRY(MCOUNT_NAME) ...@@ -82,16 +84,16 @@ ENTRY(MCOUNT_NAME)
la t4, ftrace_stub la t4, ftrace_stub
#ifdef CONFIG_FUNCTION_GRAPH_TRACER #ifdef CONFIG_FUNCTION_GRAPH_TRACER
la t0, ftrace_graph_return la t0, ftrace_graph_return
ld t1, 0(t0) REG_L t1, 0(t0)
bne t1, t4, do_ftrace_graph_caller bne t1, t4, do_ftrace_graph_caller
la t3, ftrace_graph_entry la t3, ftrace_graph_entry
ld t2, 0(t3) REG_L t2, 0(t3)
la t6, ftrace_graph_entry_stub la t6, ftrace_graph_entry_stub
bne t2, t6, do_ftrace_graph_caller bne t2, t6, do_ftrace_graph_caller
#endif #endif
la t3, ftrace_trace_function la t3, ftrace_trace_function
ld t5, 0(t3) REG_L t5, 0(t3)
bne t5, t4, do_trace bne t5, t4, do_trace
ret ret
...@@ -101,10 +103,10 @@ ENTRY(MCOUNT_NAME) ...@@ -101,10 +103,10 @@ ENTRY(MCOUNT_NAME)
* prepare_to_return(&ra_to_caller_of_caller, ra_to_caller) * prepare_to_return(&ra_to_caller_of_caller, ra_to_caller)
*/ */
do_ftrace_graph_caller: do_ftrace_graph_caller:
addi a0, s0, -8 addi a0, s0, -SZREG
mv a1, ra mv a1, ra
#ifdef HAVE_FUNCTION_GRAPH_FP_TEST #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
ld a2, -16(s0) REG_L a2, -2*SZREG(s0)
#endif #endif
SAVE_ABI_STATE SAVE_ABI_STATE
call prepare_ftrace_return call prepare_ftrace_return
...@@ -117,7 +119,7 @@ do_ftrace_graph_caller: ...@@ -117,7 +119,7 @@ do_ftrace_graph_caller:
* (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller) * (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller)
*/ */
do_trace: do_trace:
ld a1, -8(s0) REG_L a1, -SZREG(s0)
mv a0, ra mv a0, ra
SAVE_ABI_STATE SAVE_ABI_STATE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment