ftrace.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * arch/arm64/include/asm/ftrace.h
  4. *
  5. * Copyright (C) 2013 Linaro Limited
  6. * Author: AKASHI Takahiro <[email protected]>
  7. */
  8. #ifndef __ASM_FTRACE_H
  9. #define __ASM_FTRACE_H
  10. #include <asm/insn.h>
  11. #define HAVE_FUNCTION_GRAPH_FP_TEST
  12. /*
  13. * HAVE_FUNCTION_GRAPH_RET_ADDR_PTR means that the architecture can provide a
  14. * "return address pointer" which can be used to uniquely identify a return
  15. * address which has been overwritten.
  16. *
  17. * On arm64 we use the address of the caller's frame record, which remains the
  18. * same for the lifetime of the instrumented function, unlike the return
  19. * address in the LR.
  20. */
  21. #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
  22. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  23. #define ARCH_SUPPORTS_FTRACE_OPS 1
  24. #else
  25. #define MCOUNT_ADDR ((unsigned long)_mcount)
  26. #endif
  27. /* The BL at the callsite's adjusted rec->ip */
  28. #define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE
  29. #define FTRACE_PLT_IDX 0
  30. #define FTRACE_REGS_PLT_IDX 1
  31. #define NR_FTRACE_PLTS 2
  32. /*
  33. * Currently, gcc tends to save the link register after the local variables
  34. * on the stack. This causes the max stack tracer to report the function
  35. * frame sizes for the wrong functions. By defining
  36. * ARCH_FTRACE_SHIFT_STACK_TRACER, it will tell the stack tracer to expect
  37. * to find the return address on the stack after the local variables have
  38. * been set up.
  39. *
  40. * Note, this may change in the future, and we will need to deal with that
  41. * if it were to happen.
  42. */
  43. #define ARCH_FTRACE_SHIFT_STACK_TRACER 1
  44. #ifndef __ASSEMBLY__
  45. #include <linux/compat.h>
  46. extern void _mcount(unsigned long);
  47. extern void *return_address(unsigned int);
  48. struct dyn_arch_ftrace {
  49. /* No extra data needed for arm64 */
  50. };
  51. extern unsigned long ftrace_graph_call;
  52. extern void return_to_handler(void);
  53. static inline unsigned long ftrace_call_adjust(unsigned long addr)
  54. {
  55. /*
  56. * Adjust addr to point at the BL in the callsite.
  57. * See ftrace_init_nop() for the callsite sequence.
  58. */
  59. if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS))
  60. return addr + AARCH64_INSN_SIZE;
  61. /*
  62. * addr is the address of the mcount call instruction.
  63. * recordmcount does the necessary offset calculation.
  64. */
  65. return addr;
  66. }
  67. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  68. struct dyn_ftrace;
  69. struct ftrace_ops;
  70. struct ftrace_regs;
  71. int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
  72. #define ftrace_init_nop ftrace_init_nop
  73. void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
  74. struct ftrace_ops *op, struct ftrace_regs *fregs);
  75. #define ftrace_graph_func ftrace_graph_func
  76. #endif
  77. #define ftrace_return_address(n) return_address(n)
  78. /*
  79. * Because AArch32 mode does not share the same syscall table with AArch64,
  80. * tracing compat syscalls may result in reporting bogus syscalls or even
  81. * hang-up, so just do not trace them.
  82. * See kernel/trace/trace_syscalls.c
  83. *
  84. * x86 code says:
  85. * If the user really wants these, then they should use the
  86. * raw syscall tracepoints with filtering.
  87. */
  88. #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
  89. static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
  90. {
  91. return is_compat_task();
  92. }
  93. #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
  94. static inline bool arch_syscall_match_sym_name(const char *sym,
  95. const char *name)
  96. {
  97. /*
  98. * Since all syscall functions have __arm64_ prefix, we must skip it.
  99. * However, as we described above, we decided to ignore compat
  100. * syscalls, so we don't care about __arm64_compat_ prefix here.
  101. */
  102. return !strcmp(sym + 8, name);
  103. }
  104. #endif /* ifndef __ASSEMBLY__ */
  105. #endif /* __ASM_FTRACE_H */