ftrace.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_FTRACE_H
  3. #define _ASM_X86_FTRACE_H
  4. #ifdef CONFIG_FUNCTION_TRACER
  5. #ifndef CC_USING_FENTRY
  6. # error Compiler does not support fentry?
  7. #endif
  8. # define MCOUNT_ADDR ((unsigned long)(__fentry__))
  9. #define MCOUNT_INSN_SIZE 5 /* sizeof mcount call */
  10. /* Ignore unused weak functions which will have non zero offsets */
  11. #ifdef CONFIG_HAVE_FENTRY
  12. # include <asm/ibt.h>
  13. /* Add offset for endbr64 if IBT enabled */
  14. # define FTRACE_MCOUNT_MAX_OFFSET ENDBR_INSN_SIZE
  15. #endif
  16. #ifdef CONFIG_DYNAMIC_FTRACE
  17. #define ARCH_SUPPORTS_FTRACE_OPS 1
  18. #endif
  19. #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
  20. #ifndef __ASSEMBLY__
  21. extern void __fentry__(void);
  22. static inline unsigned long ftrace_call_adjust(unsigned long addr)
  23. {
  24. /*
  25. * addr is the address of the mcount call instruction.
  26. * recordmcount does the necessary offset calculation.
  27. */
  28. return addr;
  29. }
  30. /*
  31. * When a ftrace registered caller is tracing a function that is
  32. * also set by a register_ftrace_direct() call, it needs to be
  33. * differentiated in the ftrace_caller trampoline. To do this, we
  34. * place the direct caller in the ORIG_AX part of pt_regs. This
  35. * tells the ftrace_caller that there's a direct caller.
  36. */
  37. static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
  38. {
  39. /* Emulate a call */
  40. regs->orig_ax = addr;
  41. }
  42. #ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
  43. struct ftrace_regs {
  44. struct pt_regs regs;
  45. };
  46. static __always_inline struct pt_regs *
  47. arch_ftrace_get_regs(struct ftrace_regs *fregs)
  48. {
  49. /* Only when FL_SAVE_REGS is set, cs will be non zero */
  50. if (!fregs->regs.cs)
  51. return NULL;
  52. return &fregs->regs;
  53. }
  54. #define ftrace_instruction_pointer_set(fregs, _ip) \
  55. do { (fregs)->regs.ip = (_ip); } while (0)
  56. struct ftrace_ops;
  57. #define ftrace_graph_func ftrace_graph_func
  58. void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
  59. struct ftrace_ops *op, struct ftrace_regs *fregs);
  60. #else
  61. #define FTRACE_GRAPH_TRAMP_ADDR FTRACE_GRAPH_ADDR
  62. #endif
  63. #ifdef CONFIG_DYNAMIC_FTRACE
  64. struct dyn_arch_ftrace {
  65. /* No extra data needed for x86 */
  66. };
  67. #endif /* CONFIG_DYNAMIC_FTRACE */
  68. #endif /* __ASSEMBLY__ */
  69. #endif /* CONFIG_FUNCTION_TRACER */
  70. #ifndef __ASSEMBLY__
  71. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  72. extern void set_ftrace_ops_ro(void);
  73. #else
  74. static inline void set_ftrace_ops_ro(void) { }
  75. #endif
  76. #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
  77. static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
  78. {
  79. /*
  80. * Compare the symbol name with the system call name. Skip the
  81. * "__x64_sys", "__ia32_sys", "__do_sys" or simple "sys" prefix.
  82. */
  83. return !strcmp(sym + 3, name + 3) ||
  84. (!strncmp(sym, "__x64_", 6) && !strcmp(sym + 9, name + 3)) ||
  85. (!strncmp(sym, "__ia32_", 7) && !strcmp(sym + 10, name + 3)) ||
  86. (!strncmp(sym, "__do_sys", 8) && !strcmp(sym + 8, name + 3));
  87. }
  88. #ifndef COMPILE_OFFSETS
  89. #if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_IA32_EMULATION)
  90. #include <linux/compat.h>
  91. /*
  92. * Because ia32 syscalls do not map to x86_64 syscall numbers
  93. * this screws up the trace output when tracing a ia32 task.
  94. * Instead of reporting bogus syscalls, just do not trace them.
  95. *
  96. * If the user really wants these, then they should use the
  97. * raw syscall tracepoints with filtering.
  98. */
  99. #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS 1
  100. static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
  101. {
  102. return in_32bit_syscall();
  103. }
  104. #endif /* CONFIG_FTRACE_SYSCALLS && CONFIG_IA32_EMULATION */
  105. #endif /* !COMPILE_OFFSETS */
  106. #endif /* !__ASSEMBLY__ */
  107. #endif /* _ASM_X86_FTRACE_H */