~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/riscv/include/asm/ftrace.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /* Copyright (C) 2017 Andes Technology Corporation */
  3 
  4 #ifndef _ASM_RISCV_FTRACE_H
  5 #define _ASM_RISCV_FTRACE_H
  6 
  7 /*
  8  * The graph frame test is not possible if CONFIG_FRAME_POINTER is not enabled.
  9  * Check arch/riscv/kernel/mcount.S for detail.
 10  */
 11 #if defined(CONFIG_FUNCTION_GRAPH_TRACER) && defined(CONFIG_FRAME_POINTER)
 12 #define HAVE_FUNCTION_GRAPH_FP_TEST
 13 #endif
 14 
 15 #define ARCH_SUPPORTS_FTRACE_OPS 1
 16 #ifndef __ASSEMBLY__
 17 
 18 extern void *return_address(unsigned int level);
 19 
 20 #define ftrace_return_address(n) return_address(n)
 21 
 22 void _mcount(void);
 23 static inline unsigned long ftrace_call_adjust(unsigned long addr)
 24 {
 25         return addr;
 26 }
 27 
 28 /*
 29  * Let's do like x86/arm64 and ignore the compat syscalls.
 30  */
 31 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
 32 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
 33 {
 34         return is_compat_task();
 35 }
 36 
 37 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
 38 static inline bool arch_syscall_match_sym_name(const char *sym,
 39                                                const char *name)
 40 {
 41         /*
 42          * Since all syscall functions have __riscv_ prefix, we must skip it.
 43          * However, as we described above, we decided to ignore compat
 44          * syscalls, so we don't care about __riscv_compat_ prefix here.
 45          */
 46         return !strcmp(sym + 8, name);
 47 }
 48 
 49 struct dyn_arch_ftrace {
 50 };
 51 #endif
 52 
 53 #ifdef CONFIG_DYNAMIC_FTRACE
 54 /*
 55  * A general call in RISC-V is a pair of insts:
 56  * 1) auipc: setting high-20 pc-related bits to ra register
 57  * 2) jalr: setting low-12 offset to ra, jump to ra, and set ra to
 58  *          return address (original pc + 4)
 59  *
 60  *<ftrace enable>:
 61  * 0: auipc  t0/ra, 0x?
 62  * 4: jalr   t0/ra, ?(t0/ra)
 63  *
 64  *<ftrace disable>:
 65  * 0: nop
 66  * 4: nop
 67  *
 68  * Dynamic ftrace generates probes to call sites, so we must deal with
 69  * both auipc and jalr at the same time.
 70  */
 71 
 72 #define MCOUNT_ADDR             ((unsigned long)_mcount)
 73 #define JALR_SIGN_MASK          (0x00000800)
 74 #define JALR_OFFSET_MASK        (0x00000fff)
 75 #define AUIPC_OFFSET_MASK       (0xfffff000)
 76 #define AUIPC_PAD               (0x00001000)
 77 #define JALR_SHIFT              20
 78 #define JALR_RA                 (0x000080e7)
 79 #define AUIPC_RA                (0x00000097)
 80 #define JALR_T0                 (0x000282e7)
 81 #define AUIPC_T0                (0x00000297)
 82 #define NOP4                    (0x00000013)
 83 
 84 #define to_jalr_t0(offset)                                              \
 85         (((offset & JALR_OFFSET_MASK) << JALR_SHIFT) | JALR_T0)
 86 
 87 #define to_auipc_t0(offset)                                             \
 88         ((offset & JALR_SIGN_MASK) ?                                    \
 89         (((offset & AUIPC_OFFSET_MASK) + AUIPC_PAD) | AUIPC_T0) :       \
 90         ((offset & AUIPC_OFFSET_MASK) | AUIPC_T0))
 91 
 92 #define make_call_t0(caller, callee, call)                              \
 93 do {                                                                    \
 94         unsigned int offset =                                           \
 95                 (unsigned long) callee - (unsigned long) caller;        \
 96         call[0] = to_auipc_t0(offset);                                  \
 97         call[1] = to_jalr_t0(offset);                                   \
 98 } while (0)
 99 
100 #define to_jalr_ra(offset)                                              \
101         (((offset & JALR_OFFSET_MASK) << JALR_SHIFT) | JALR_RA)
102 
103 #define to_auipc_ra(offset)                                             \
104         ((offset & JALR_SIGN_MASK) ?                                    \
105         (((offset & AUIPC_OFFSET_MASK) + AUIPC_PAD) | AUIPC_RA) :       \
106         ((offset & AUIPC_OFFSET_MASK) | AUIPC_RA))
107 
108 #define make_call_ra(caller, callee, call)                              \
109 do {                                                                    \
110         unsigned int offset =                                           \
111                 (unsigned long) callee - (unsigned long) caller;        \
112         call[0] = to_auipc_ra(offset);                                  \
113         call[1] = to_jalr_ra(offset);                                   \
114 } while (0)
115 
116 /*
117  * Let auipc+jalr be the basic *mcount unit*, so we make it 8 bytes here.
118  */
119 #define MCOUNT_INSN_SIZE 8
120 
121 #ifndef __ASSEMBLY__
122 struct dyn_ftrace;
123 int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
124 #define ftrace_init_nop ftrace_init_nop
125 
126 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
127 #define arch_ftrace_get_regs(regs) NULL
128 struct ftrace_ops;
129 struct ftrace_regs {
130         unsigned long epc;
131         unsigned long ra;
132         unsigned long sp;
133         unsigned long s0;
134         unsigned long t1;
135         union {
136                 unsigned long args[8];
137                 struct {
138                         unsigned long a0;
139                         unsigned long a1;
140                         unsigned long a2;
141                         unsigned long a3;
142                         unsigned long a4;
143                         unsigned long a5;
144                         unsigned long a6;
145                         unsigned long a7;
146                 };
147         };
148 };
149 
150 static __always_inline unsigned long ftrace_regs_get_instruction_pointer(const struct ftrace_regs
151                                                                          *fregs)
152 {
153         return fregs->epc;
154 }
155 
156 static __always_inline void ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
157                                                                 unsigned long pc)
158 {
159         fregs->epc = pc;
160 }
161 
162 static __always_inline unsigned long ftrace_regs_get_stack_pointer(const struct ftrace_regs *fregs)
163 {
164         return fregs->sp;
165 }
166 
167 static __always_inline unsigned long ftrace_regs_get_argument(struct ftrace_regs *fregs,
168                                                               unsigned int n)
169 {
170         if (n < 8)
171                 return fregs->args[n];
172         return 0;
173 }
174 
175 static __always_inline unsigned long ftrace_regs_get_return_value(const struct ftrace_regs *fregs)
176 {
177         return fregs->a0;
178 }
179 
180 static __always_inline void ftrace_regs_set_return_value(struct ftrace_regs *fregs,
181                                                          unsigned long ret)
182 {
183         fregs->a0 = ret;
184 }
185 
186 static __always_inline void ftrace_override_function_with_return(struct ftrace_regs *fregs)
187 {
188         fregs->epc = fregs->ra;
189 }
190 
191 int ftrace_regs_query_register_offset(const char *name);
192 
193 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
194                        struct ftrace_ops *op, struct ftrace_regs *fregs);
195 #define ftrace_graph_func ftrace_graph_func
196 
197 static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsigned long addr)
198 {
199         fregs->t1 = addr;
200 }
201 #endif /* CONFIG_DYNAMIC_FTRACE_WITH_ARGS */
202 
203 #endif /* __ASSEMBLY__ */
204 
205 #endif /* CONFIG_DYNAMIC_FTRACE */
206 
207 #ifndef __ASSEMBLY__
208 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
209 struct fgraph_ret_regs {
210         unsigned long a1;
211         unsigned long a0;
212         unsigned long s0;
213         unsigned long ra;
214 };
215 
216 static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
217 {
218         return ret_regs->a0;
219 }
220 
221 static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
222 {
223         return ret_regs->s0;
224 }
225 #endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */
226 #endif
227 
228 #endif /* _ASM_RISCV_FTRACE_H */
229 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php