| .. | .. |
|---|
| 12 | 12 | #include <asm/frame.h> |
|---|
| 13 | 13 | |
|---|
| 14 | 14 | .code64 |
|---|
| 15 | | - .section .entry.text, "ax" |
|---|
| 16 | | - |
|---|
| 17 | | -#ifdef CC_USING_FENTRY |
|---|
| 18 | | -# define function_hook __fentry__ |
|---|
| 19 | | -EXPORT_SYMBOL(__fentry__) |
|---|
| 20 | | -#else |
|---|
| 21 | | -# define function_hook mcount |
|---|
| 22 | | -EXPORT_SYMBOL(mcount) |
|---|
| 23 | | -#endif |
|---|
| 15 | + .section .text, "ax" |
|---|
| 24 | 16 | |
|---|
| 25 | 17 | #ifdef CONFIG_FRAME_POINTER |
|---|
| 26 | | -# ifdef CC_USING_FENTRY |
|---|
| 27 | 18 | /* Save parent and function stack frames (rip and rbp) */ |
|---|
| 28 | 19 | # define MCOUNT_FRAME_SIZE (8+16*2) |
|---|
| 29 | | -# else |
|---|
| 30 | | -/* Save just function stack frame (rip and rbp) */ |
|---|
| 31 | | -# define MCOUNT_FRAME_SIZE (8+16) |
|---|
| 32 | | -# endif |
|---|
| 33 | 20 | #else |
|---|
| 34 | 21 | /* No need to save a stack frame */ |
|---|
| 35 | 22 | # define MCOUNT_FRAME_SIZE 0 |
|---|
| 36 | 23 | #endif /* CONFIG_FRAME_POINTER */ |
|---|
| 37 | 24 | |
|---|
| 38 | 25 | /* Size of stack used to save mcount regs in save_mcount_regs */ |
|---|
| 39 | | -#define MCOUNT_REG_SIZE (SS+8 + MCOUNT_FRAME_SIZE) |
|---|
| 26 | +#define MCOUNT_REG_SIZE (FRAME_SIZE + MCOUNT_FRAME_SIZE) |
|---|
| 40 | 27 | |
|---|
| 41 | 28 | /* |
|---|
| 42 | 29 | * gcc -pg option adds a call to 'mcount' in most functions. |
|---|
| .. | .. |
|---|
| 76 | 63 | * fentry is called before the stack frame is set up, where as mcount |
|---|
| 77 | 64 | * is called afterward. |
|---|
| 78 | 65 | */ |
|---|
| 79 | | -#ifdef CC_USING_FENTRY |
|---|
| 66 | + |
|---|
| 80 | 67 | /* Save the parent pointer (skip orig rbp and our return address) */ |
|---|
| 81 | 68 | pushq \added+8*2(%rsp) |
|---|
| 82 | 69 | pushq %rbp |
|---|
| 83 | 70 | movq %rsp, %rbp |
|---|
| 84 | 71 | /* Save the return address (now skip orig rbp, rbp and parent) */ |
|---|
| 85 | 72 | pushq \added+8*3(%rsp) |
|---|
| 86 | | -#else |
|---|
| 87 | | - /* Can't assume that rip is before this (unless added was zero) */ |
|---|
| 88 | | - pushq \added+8(%rsp) |
|---|
| 89 | | -#endif |
|---|
| 90 | 73 | pushq %rbp |
|---|
| 91 | 74 | movq %rsp, %rbp |
|---|
| 92 | 75 | #endif /* CONFIG_FRAME_POINTER */ |
|---|
| .. | .. |
|---|
| 94 | 77 | /* |
|---|
| 95 | 78 | * We add enough stack to save all regs. |
|---|
| 96 | 79 | */ |
|---|
| 97 | | - subq $(MCOUNT_REG_SIZE - MCOUNT_FRAME_SIZE), %rsp |
|---|
| 80 | + subq $(FRAME_SIZE), %rsp |
|---|
| 98 | 81 | movq %rax, RAX(%rsp) |
|---|
| 99 | 82 | movq %rcx, RCX(%rsp) |
|---|
| 100 | 83 | movq %rdx, RDX(%rsp) |
|---|
| .. | .. |
|---|
| 102 | 85 | movq %rdi, RDI(%rsp) |
|---|
| 103 | 86 | movq %r8, R8(%rsp) |
|---|
| 104 | 87 | movq %r9, R9(%rsp) |
|---|
| 88 | + movq $0, ORIG_RAX(%rsp) |
|---|
| 105 | 89 | /* |
|---|
| 106 | 90 | * Save the original RBP. Even though the mcount ABI does not |
|---|
| 107 | 91 | * require this, it helps out callers. |
|---|
| .. | .. |
|---|
| 114 | 98 | movq %rdx, RBP(%rsp) |
|---|
| 115 | 99 | |
|---|
| 116 | 100 | /* Copy the parent address into %rsi (second parameter) */ |
|---|
| 117 | | -#ifdef CC_USING_FENTRY |
|---|
| 118 | 101 | movq MCOUNT_REG_SIZE+8+\added(%rsp), %rsi |
|---|
| 119 | | -#else |
|---|
| 120 | | - /* %rdx contains original %rbp */ |
|---|
| 121 | | - movq 8(%rdx), %rsi |
|---|
| 122 | | -#endif |
|---|
| 123 | 102 | |
|---|
| 124 | 103 | /* Move RIP to its proper location */ |
|---|
| 125 | 104 | movq MCOUNT_REG_SIZE+\added(%rsp), %rdi |
|---|
| .. | .. |
|---|
| 133 | 112 | subq $MCOUNT_INSN_SIZE, %rdi |
|---|
| 134 | 113 | .endm |
|---|
| 135 | 114 | |
|---|
| 136 | | -.macro restore_mcount_regs |
|---|
| 115 | +.macro restore_mcount_regs save=0 |
|---|
| 116 | + |
|---|
| 117 | + /* ftrace_regs_caller or frame pointers require this */ |
|---|
| 118 | + movq RBP(%rsp), %rbp |
|---|
| 119 | + |
|---|
| 137 | 120 | movq R9(%rsp), %r9 |
|---|
| 138 | 121 | movq R8(%rsp), %r8 |
|---|
| 139 | 122 | movq RDI(%rsp), %rdi |
|---|
| .. | .. |
|---|
| 142 | 125 | movq RCX(%rsp), %rcx |
|---|
| 143 | 126 | movq RAX(%rsp), %rax |
|---|
| 144 | 127 | |
|---|
| 145 | | - /* ftrace_regs_caller can modify %rbp */ |
|---|
| 146 | | - movq RBP(%rsp), %rbp |
|---|
| 147 | | - |
|---|
| 148 | | - addq $MCOUNT_REG_SIZE, %rsp |
|---|
| 128 | + addq $MCOUNT_REG_SIZE-\save, %rsp |
|---|
| 149 | 129 | |
|---|
| 150 | 130 | .endm |
|---|
| 151 | 131 | |
|---|
| 152 | 132 | #ifdef CONFIG_DYNAMIC_FTRACE |
|---|
| 153 | 133 | |
|---|
| 154 | | -ENTRY(function_hook) |
|---|
| 155 | | - retq |
|---|
| 156 | | -ENDPROC(function_hook) |
|---|
| 134 | +SYM_FUNC_START(__fentry__) |
|---|
| 135 | + RET |
|---|
| 136 | +SYM_FUNC_END(__fentry__) |
|---|
| 137 | +EXPORT_SYMBOL(__fentry__) |
|---|
| 157 | 138 | |
|---|
| 158 | | -ENTRY(ftrace_caller) |
|---|
| 139 | +SYM_FUNC_START(ftrace_caller) |
|---|
| 159 | 140 | /* save_mcount_regs fills in first two parameters */ |
|---|
| 160 | 141 | save_mcount_regs |
|---|
| 161 | 142 | |
|---|
| 162 | | -GLOBAL(ftrace_caller_op_ptr) |
|---|
| 143 | +SYM_INNER_LABEL(ftrace_caller_op_ptr, SYM_L_GLOBAL) |
|---|
| 163 | 144 | /* Load the ftrace_ops into the 3rd parameter */ |
|---|
| 164 | 145 | movq function_trace_op(%rip), %rdx |
|---|
| 165 | 146 | |
|---|
| 166 | 147 | /* regs go into 4th parameter (but make it NULL) */ |
|---|
| 167 | 148 | movq $0, %rcx |
|---|
| 168 | 149 | |
|---|
| 169 | | -GLOBAL(ftrace_call) |
|---|
| 150 | +SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL) |
|---|
| 170 | 151 | call ftrace_stub |
|---|
| 171 | 152 | |
|---|
| 172 | 153 | restore_mcount_regs |
|---|
| .. | .. |
|---|
| 176 | 157 | * think twice before adding any new code or changing the |
|---|
| 177 | 158 | * layout here. |
|---|
| 178 | 159 | */ |
|---|
| 179 | | -GLOBAL(ftrace_epilogue) |
|---|
| 160 | +SYM_INNER_LABEL(ftrace_caller_end, SYM_L_GLOBAL) |
|---|
| 180 | 161 | |
|---|
| 162 | + jmp ftrace_epilogue |
|---|
| 163 | +SYM_FUNC_END(ftrace_caller); |
|---|
| 164 | + |
|---|
| 165 | +SYM_FUNC_START(ftrace_epilogue) |
|---|
| 181 | 166 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
|---|
| 182 | | -GLOBAL(ftrace_graph_call) |
|---|
| 167 | +SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL) |
|---|
| 183 | 168 | jmp ftrace_stub |
|---|
| 184 | 169 | #endif |
|---|
| 185 | 170 | |
|---|
| 186 | 171 | /* |
|---|
| 187 | 172 | * This is weak to keep gas from relaxing the jumps. |
|---|
| 188 | | - * It is also used to copy the retq for trampolines. |
|---|
| 189 | 173 | */ |
|---|
| 190 | | -WEAK(ftrace_stub) |
|---|
| 191 | | - retq |
|---|
| 192 | | -ENDPROC(ftrace_caller) |
|---|
| 174 | +SYM_INNER_LABEL_ALIGN(ftrace_stub, SYM_L_WEAK) |
|---|
| 175 | + UNWIND_HINT_FUNC |
|---|
| 176 | + RET |
|---|
| 177 | +SYM_FUNC_END(ftrace_epilogue) |
|---|
| 193 | 178 | |
|---|
| 194 | | -ENTRY(ftrace_regs_caller) |
|---|
| 179 | +SYM_FUNC_START(ftrace_regs_caller) |
|---|
| 195 | 180 | /* Save the current flags before any operations that can change them */ |
|---|
| 196 | 181 | pushfq |
|---|
| 197 | 182 | |
|---|
| .. | .. |
|---|
| 199 | 184 | save_mcount_regs 8 |
|---|
| 200 | 185 | /* save_mcount_regs fills in first two parameters */ |
|---|
| 201 | 186 | |
|---|
| 202 | | -GLOBAL(ftrace_regs_caller_op_ptr) |
|---|
| 187 | +SYM_INNER_LABEL(ftrace_regs_caller_op_ptr, SYM_L_GLOBAL) |
|---|
| 203 | 188 | /* Load the ftrace_ops into the 3rd parameter */ |
|---|
| 204 | 189 | movq function_trace_op(%rip), %rdx |
|---|
| 205 | 190 | |
|---|
| .. | .. |
|---|
| 228 | 213 | /* regs go into 4th parameter */ |
|---|
| 229 | 214 | leaq (%rsp), %rcx |
|---|
| 230 | 215 | |
|---|
| 231 | | -GLOBAL(ftrace_regs_call) |
|---|
| 216 | +SYM_INNER_LABEL(ftrace_regs_call, SYM_L_GLOBAL) |
|---|
| 232 | 217 | call ftrace_stub |
|---|
| 233 | 218 | |
|---|
| 234 | 219 | /* Copy flags back to SS, to restore them */ |
|---|
| .. | .. |
|---|
| 247 | 232 | movq R10(%rsp), %r10 |
|---|
| 248 | 233 | movq RBX(%rsp), %rbx |
|---|
| 249 | 234 | |
|---|
| 250 | | - restore_mcount_regs |
|---|
| 235 | + movq ORIG_RAX(%rsp), %rax |
|---|
| 236 | + movq %rax, MCOUNT_REG_SIZE-8(%rsp) |
|---|
| 251 | 237 | |
|---|
| 238 | + /* |
|---|
| 239 | + * If ORIG_RAX is anything but zero, make this a call to that. |
|---|
| 240 | + * See arch_ftrace_set_direct_caller(). |
|---|
| 241 | + */ |
|---|
| 242 | + movq ORIG_RAX(%rsp), %rax |
|---|
| 243 | + testq %rax, %rax |
|---|
| 244 | +SYM_INNER_LABEL(ftrace_regs_caller_jmp, SYM_L_GLOBAL) |
|---|
| 245 | + jnz 1f |
|---|
| 246 | + |
|---|
| 247 | + restore_mcount_regs |
|---|
| 252 | 248 | /* Restore flags */ |
|---|
| 253 | 249 | popfq |
|---|
| 254 | 250 | |
|---|
| .. | .. |
|---|
| 258 | 254 | * The trampoline will add the code to jump |
|---|
| 259 | 255 | * to the return. |
|---|
| 260 | 256 | */ |
|---|
| 261 | | -GLOBAL(ftrace_regs_caller_end) |
|---|
| 262 | | - |
|---|
| 257 | +SYM_INNER_LABEL(ftrace_regs_caller_end, SYM_L_GLOBAL) |
|---|
| 263 | 258 | jmp ftrace_epilogue |
|---|
| 264 | 259 | |
|---|
| 265 | | -ENDPROC(ftrace_regs_caller) |
|---|
| 260 | + /* Swap the flags with orig_rax */ |
|---|
| 261 | +1: movq MCOUNT_REG_SIZE(%rsp), %rdi |
|---|
| 262 | + movq %rdi, MCOUNT_REG_SIZE-8(%rsp) |
|---|
| 263 | + movq %rax, MCOUNT_REG_SIZE(%rsp) |
|---|
| 264 | + |
|---|
| 265 | + restore_mcount_regs 8 |
|---|
| 266 | + /* Restore flags */ |
|---|
| 267 | + popfq |
|---|
| 268 | + UNWIND_HINT_FUNC |
|---|
| 269 | + jmp ftrace_epilogue |
|---|
| 270 | + |
|---|
| 271 | +SYM_FUNC_END(ftrace_regs_caller) |
|---|
| 266 | 272 | |
|---|
| 267 | 273 | |
|---|
| 268 | 274 | #else /* ! CONFIG_DYNAMIC_FTRACE */ |
|---|
| 269 | 275 | |
|---|
| 270 | | -ENTRY(function_hook) |
|---|
| 276 | +SYM_FUNC_START(__fentry__) |
|---|
| 271 | 277 | cmpq $ftrace_stub, ftrace_trace_function |
|---|
| 272 | 278 | jnz trace |
|---|
| 273 | 279 | |
|---|
| .. | .. |
|---|
| 280 | 286 | jnz ftrace_graph_caller |
|---|
| 281 | 287 | #endif |
|---|
| 282 | 288 | |
|---|
| 283 | | -GLOBAL(ftrace_stub) |
|---|
| 284 | | - retq |
|---|
| 289 | +SYM_INNER_LABEL(ftrace_stub, SYM_L_GLOBAL) |
|---|
| 290 | + RET |
|---|
| 285 | 291 | |
|---|
| 286 | 292 | trace: |
|---|
| 287 | 293 | /* save_mcount_regs fills in first two parameters */ |
|---|
| .. | .. |
|---|
| 294 | 300 | * function tracing is enabled. |
|---|
| 295 | 301 | */ |
|---|
| 296 | 302 | movq ftrace_trace_function, %r8 |
|---|
| 297 | | - CALL_NOSPEC %r8 |
|---|
| 303 | + CALL_NOSPEC r8 |
|---|
| 298 | 304 | restore_mcount_regs |
|---|
| 299 | 305 | |
|---|
| 300 | 306 | jmp fgraph_trace |
|---|
| 301 | | -ENDPROC(function_hook) |
|---|
| 307 | +SYM_FUNC_END(__fentry__) |
|---|
| 308 | +EXPORT_SYMBOL(__fentry__) |
|---|
| 302 | 309 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
|---|
| 303 | 310 | |
|---|
| 304 | 311 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
|---|
| 305 | | -ENTRY(ftrace_graph_caller) |
|---|
| 312 | +SYM_FUNC_START(ftrace_graph_caller) |
|---|
| 306 | 313 | /* Saves rbp into %rdx and fills first parameter */ |
|---|
| 307 | 314 | save_mcount_regs |
|---|
| 308 | 315 | |
|---|
| 309 | | -#ifdef CC_USING_FENTRY |
|---|
| 310 | 316 | leaq MCOUNT_REG_SIZE+8(%rsp), %rsi |
|---|
| 311 | 317 | movq $0, %rdx /* No framepointers needed */ |
|---|
| 312 | | -#else |
|---|
| 313 | | - /* Save address of the return address of traced function */ |
|---|
| 314 | | - leaq 8(%rdx), %rsi |
|---|
| 315 | | - /* ftrace does sanity checks against frame pointers */ |
|---|
| 316 | | - movq (%rdx), %rdx |
|---|
| 317 | | -#endif |
|---|
| 318 | 318 | call prepare_ftrace_return |
|---|
| 319 | 319 | |
|---|
| 320 | 320 | restore_mcount_regs |
|---|
| 321 | 321 | |
|---|
| 322 | | - retq |
|---|
| 323 | | -ENDPROC(ftrace_graph_caller) |
|---|
| 322 | + RET |
|---|
| 323 | +SYM_FUNC_END(ftrace_graph_caller) |
|---|
| 324 | 324 | |
|---|
| 325 | | -ENTRY(return_to_handler) |
|---|
| 325 | +SYM_CODE_START(return_to_handler) |
|---|
| 326 | 326 | UNWIND_HINT_EMPTY |
|---|
| 327 | | - subq $24, %rsp |
|---|
| 327 | + subq $16, %rsp |
|---|
| 328 | 328 | |
|---|
| 329 | 329 | /* Save the return values */ |
|---|
| 330 | 330 | movq %rax, (%rsp) |
|---|
| .. | .. |
|---|
| 336 | 336 | movq %rax, %rdi |
|---|
| 337 | 337 | movq 8(%rsp), %rdx |
|---|
| 338 | 338 | movq (%rsp), %rax |
|---|
| 339 | | - addq $24, %rsp |
|---|
| 340 | | - JMP_NOSPEC %rdi |
|---|
| 341 | | -END(return_to_handler) |
|---|
| 339 | + |
|---|
| 340 | + addq $16, %rsp |
|---|
| 341 | + /* |
|---|
| 342 | + * Jump back to the old return address. This cannot be JMP_NOSPEC rdi |
|---|
| 343 | + * since IBT would demand that contain ENDBR, which simply isn't so for |
|---|
| 344 | + * return addresses. Use a retpoline here to keep the RSB balanced. |
|---|
| 345 | + */ |
|---|
| 346 | + ANNOTATE_INTRA_FUNCTION_CALL |
|---|
| 347 | + call .Ldo_rop |
|---|
| 348 | + int3 |
|---|
| 349 | +.Ldo_rop: |
|---|
| 350 | + mov %rdi, (%rsp) |
|---|
| 351 | + UNWIND_HINT_FUNC |
|---|
| 352 | + RET |
|---|
| 353 | +SYM_CODE_END(return_to_handler) |
|---|
| 342 | 354 | #endif |
|---|