ftrace.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_S390_FTRACE_H
  3. #define _ASM_S390_FTRACE_H
  4. #define ARCH_SUPPORTS_FTRACE_OPS 1
  5. #if defined(CC_USING_HOTPATCH) || defined(CC_USING_NOP_MCOUNT)
  6. #define MCOUNT_INSN_SIZE 6
  7. #else
  8. #define MCOUNT_INSN_SIZE 24
  9. #define MCOUNT_RETURN_FIXUP 18
  10. #endif
  11. #ifndef __ASSEMBLY__
  12. #define ftrace_return_address(n) __builtin_return_address(n)
  13. void _mcount(void);
  14. void ftrace_caller(void);
  15. extern char ftrace_graph_caller_end;
  16. extern unsigned long ftrace_plt;
  17. struct dyn_arch_ftrace { };
  18. #define MCOUNT_ADDR ((unsigned long)_mcount)
  19. #define FTRACE_ADDR ((unsigned long)ftrace_caller)
  20. #define KPROBE_ON_FTRACE_NOP 0
  21. #define KPROBE_ON_FTRACE_CALL 1
  22. static inline unsigned long ftrace_call_adjust(unsigned long addr)
  23. {
  24. return addr;
  25. }
  26. struct ftrace_insn {
  27. u16 opc;
  28. s32 disp;
  29. } __packed;
  30. static inline void ftrace_generate_nop_insn(struct ftrace_insn *insn)
  31. {
  32. #ifdef CONFIG_FUNCTION_TRACER
  33. #if defined(CC_USING_HOTPATCH) || defined(CC_USING_NOP_MCOUNT)
  34. /* brcl 0,0 */
  35. insn->opc = 0xc004;
  36. insn->disp = 0;
  37. #else
  38. /* jg .+24 */
  39. insn->opc = 0xc0f4;
  40. insn->disp = MCOUNT_INSN_SIZE / 2;
  41. #endif
  42. #endif
  43. }
  44. static inline int is_ftrace_nop(struct ftrace_insn *insn)
  45. {
  46. #ifdef CONFIG_FUNCTION_TRACER
  47. #if defined(CC_USING_HOTPATCH) || defined(CC_USING_NOP_MCOUNT)
  48. if (insn->disp == 0)
  49. return 1;
  50. #else
  51. if (insn->disp == MCOUNT_INSN_SIZE / 2)
  52. return 1;
  53. #endif
  54. #endif
  55. return 0;
  56. }
  57. static inline void ftrace_generate_call_insn(struct ftrace_insn *insn,
  58. unsigned long ip)
  59. {
  60. #ifdef CONFIG_FUNCTION_TRACER
  61. unsigned long target;
  62. /* brasl r0,ftrace_caller */
  63. target = is_module_addr((void *) ip) ? ftrace_plt : FTRACE_ADDR;
  64. insn->opc = 0xc005;
  65. insn->disp = (target - ip) / 2;
  66. #endif
  67. }
  68. #endif /* __ASSEMBLY__ */
  69. #endif /* _ASM_S390_FTRACE_H */