Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

riscv/ftrace: Add DYNAMIC_FTRACE_WITH_REGS support

Cc: Greentime Hu <greentime@andestech.com>
Signed-off-by: Alan Kao <alankao@andestech.com>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>

authored by

Alan Kao and committed by
Palmer Dabbelt
aea4c671 71e736a7

+141
+1
arch/riscv/Kconfig
··· 116 116 select HAVE_FUNCTION_GRAPH_TRACER 117 117 select HAVE_FTRACE_MCOUNT_RECORD 118 118 select HAVE_DYNAMIC_FTRACE 119 + select HAVE_DYNAMIC_FTRACE_WITH_REGS 119 120 120 121 endchoice 121 122
+1
arch/riscv/include/asm/ftrace.h
··· 8 8 #if defined(CONFIG_FUNCTION_GRAPH_TRACER) && defined(CONFIG_FRAME_POINTER) 9 9 #define HAVE_FUNCTION_GRAPH_FP_TEST 10 10 #endif 11 + #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR 11 12 12 13 #define ARCH_SUPPORTS_FTRACE_OPS 1 13 14 #ifndef __ASSEMBLY__
+17
arch/riscv/kernel/ftrace.c
··· 106 106 } 107 107 #endif 108 108 109 + #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 110 + int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, 111 + unsigned long addr) 112 + { 113 + unsigned int call[2]; 114 + int ret; 115 + 116 + make_call(rec->ip, old_addr, call); 117 + ret = ftrace_check_current_call(rec->ip, call); 118 + 119 + if (ret) 120 + return ret; 121 + 122 + return __ftrace_modify_call(rec->ip, addr, true); 123 + } 124 + #endif 125 + 109 126 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 110 127 /* 111 128 * Most of this function is copied from arm64.
+122
arch/riscv/kernel/mcount-dyn.S
··· 115 115 RESTORE_ABI_STATE 116 116 ret 117 117 ENDPROC(ftrace_caller) 118 + 119 + #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS 120 + .macro SAVE_ALL 121 + addi sp, sp, -(PT_SIZE_ON_STACK+16) 122 + sd s0, (PT_SIZE_ON_STACK)(sp) 123 + sd ra, (PT_SIZE_ON_STACK+8)(sp) 124 + addi s0, sp, (PT_SIZE_ON_STACK+16) 125 + 126 + sd x1, PT_RA(sp) 127 + sd x2, PT_SP(sp) 128 + sd x3, PT_GP(sp) 129 + sd x4, PT_TP(sp) 130 + sd x5, PT_T0(sp) 131 + sd x6, PT_T1(sp) 132 + sd x7, PT_T2(sp) 133 + sd x8, PT_S0(sp) 134 + sd x9, PT_S1(sp) 135 + sd x10, PT_A0(sp) 136 + sd x11, PT_A1(sp) 137 + sd x12, PT_A2(sp) 138 + sd x13, PT_A3(sp) 139 + sd x14, PT_A4(sp) 140 + sd x15, PT_A5(sp) 141 + sd x16, PT_A6(sp) 142 + sd x17, PT_A7(sp) 143 + sd x18, PT_S2(sp) 144 + sd x19, PT_S3(sp) 145 + sd x20, PT_S4(sp) 146 + sd x21, PT_S5(sp) 147 + sd x22, PT_S6(sp) 148 + sd x23, PT_S7(sp) 149 + sd x24, PT_S8(sp) 150 + sd x25, PT_S9(sp) 151 + sd x26, PT_S10(sp) 152 + sd x27, PT_S11(sp) 153 + sd x28, PT_T3(sp) 154 + sd x29, PT_T4(sp) 155 + sd x30, PT_T5(sp) 156 + sd x31, PT_T6(sp) 157 + .endm 158 + 159 + .macro RESTORE_ALL 160 + ld x1, PT_RA(sp) 161 + ld x2, PT_SP(sp) 162 + ld x3, PT_GP(sp) 163 + ld x4, PT_TP(sp) 164 + ld x5, PT_T0(sp) 165 + ld x6, PT_T1(sp) 166 + ld x7, PT_T2(sp) 167 + ld x8, PT_S0(sp) 168 + ld x9, PT_S1(sp) 169 + ld x10, PT_A0(sp) 170 + ld x11, PT_A1(sp) 171 + ld x12, PT_A2(sp) 172 + ld x13, PT_A3(sp) 173 + ld x14, PT_A4(sp) 174 + ld x15, PT_A5(sp) 175 + ld x16, PT_A6(sp) 176 + ld x17, PT_A7(sp) 177 + ld x18, PT_S2(sp) 178 + ld x19, PT_S3(sp) 179 + ld x20, PT_S4(sp) 180 + ld x21, PT_S5(sp) 181 + ld x22, PT_S6(sp) 182 + ld x23, PT_S7(sp) 183 + ld x24, PT_S8(sp) 184 + ld x25, PT_S9(sp) 185 + ld x26, PT_S10(sp) 186 + ld x27, PT_S11(sp) 187 + ld x28, PT_T3(sp) 188 + ld x29, PT_T4(sp) 189 + ld x30, PT_T5(sp) 190 + ld x31, PT_T6(sp) 191 + 192 + ld s0, (PT_SIZE_ON_STACK)(sp) 193 + ld ra, (PT_SIZE_ON_STACK+8)(sp) 194 + addi sp, sp, (PT_SIZE_ON_STACK+16) 195 + .endm 196 + 197 + .macro RESTORE_GRAPH_REG_ARGS 198 + ld a0, PT_T0(sp) 199 + ld a1, PT_T1(sp) 200 + #ifdef HAVE_FUNCTION_GRAPH_FP_TEST 201 + ld a2, PT_T2(sp) 202 + #endif 203 + .endm 204 + 205 + /* 206 + * Most of the contents are the same as ftrace_caller. 207 + */ 208 + ENTRY(ftrace_regs_caller) 209 + /* 210 + * a3: the address of all registers in the stack 211 + */ 212 + ld a1, -8(s0) 213 + addi a0, ra, -MCOUNT_INSN_SIZE 214 + la t5, function_trace_op 215 + ld a2, 0(t5) 216 + addi a3, sp, -(PT_SIZE_ON_STACK+16) 217 + 218 + #ifdef CONFIG_FUNCTION_GRAPH_TRACER 219 + addi t0, s0, -8 220 + mv t1, a0 221 + #ifdef HAVE_FUNCTION_GRAPH_FP_TEST 222 + ld t2, -16(s0) 223 + #endif 224 + #endif 225 + SAVE_ALL 226 + 227 + ftrace_regs_call: 228 + .global ftrace_regs_call 229 + call ftrace_stub 230 + 231 + #ifdef CONFIG_FUNCTION_GRAPH_TRACER 232 + RESTORE_GRAPH_REG_ARGS 233 + call ftrace_graph_caller 234 + #endif 235 + 236 + RESTORE_ALL 237 + ret 238 + ENDPROC(ftrace_regs_caller) 239 + #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */