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