Skip to content

Commit a4aebff

Browse files
committed
Merge branch 'for-next/ftrace' into for-next/core
* for-next/ftrace: ftrace: arm64: remove static ftrace ftrace: arm64: move from REGS to ARGS ftrace: abstract DYNAMIC_FTRACE_WITH_ARGS accesses ftrace: rename ftrace_instruction_pointer_set() -> ftrace_regs_set_instruction_pointer() ftrace: pass fregs to arch_ftrace_set_direct_caller()
2 parents 1a916ed + cfce092 commit a4aebff

File tree

14 files changed

+310
-202
lines changed

14 files changed

+310
-202
lines changed

arch/arm64/Kconfig

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ config ARM64
118118
select CPU_PM if (SUSPEND || CPU_IDLE)
119119
select CRC32
120120
select DCACHE_WORD_ACCESS
121+
select DYNAMIC_FTRACE if FUNCTION_TRACER
121122
select DMA_DIRECT_REMAP
122123
select EDAC_SUPPORT
123124
select FRAME_POINTER
@@ -182,8 +183,10 @@ config ARM64
182183
select HAVE_DEBUG_KMEMLEAK
183184
select HAVE_DMA_CONTIGUOUS
184185
select HAVE_DYNAMIC_FTRACE
186+
select HAVE_DYNAMIC_FTRACE_WITH_ARGS \
187+
if $(cc-option,-fpatchable-function-entry=2)
185188
select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY \
186-
if DYNAMIC_FTRACE_WITH_REGS
189+
if DYNAMIC_FTRACE_WITH_ARGS
187190
select HAVE_EFFICIENT_UNALIGNED_ACCESS
188191
select HAVE_FAST_GUP
189192
select HAVE_FTRACE_MCOUNT_RECORD
@@ -234,16 +237,16 @@ config ARM64
234237
help
235238
ARM 64-bit (AArch64) Linux support.
236239

237-
config CLANG_SUPPORTS_DYNAMIC_FTRACE_WITH_REGS
240+
config CLANG_SUPPORTS_DYNAMIC_FTRACE_WITH_ARGS
238241
def_bool CC_IS_CLANG
239242
# https://github.com/ClangBuiltLinux/linux/issues/1507
240243
depends on AS_IS_GNU || (AS_IS_LLVM && (LD_IS_LLD || LD_VERSION >= 23600))
241-
select HAVE_DYNAMIC_FTRACE_WITH_REGS
244+
select HAVE_DYNAMIC_FTRACE_WITH_ARGS
242245

243-
config GCC_SUPPORTS_DYNAMIC_FTRACE_WITH_REGS
246+
config GCC_SUPPORTS_DYNAMIC_FTRACE_WITH_ARGS
244247
def_bool CC_IS_GCC
245248
depends on $(cc-option,-fpatchable-function-entry=2)
246-
select HAVE_DYNAMIC_FTRACE_WITH_REGS
249+
select HAVE_DYNAMIC_FTRACE_WITH_ARGS
247250

248251
config 64BIT
249252
def_bool y
@@ -1836,7 +1839,7 @@ config ARM64_PTR_AUTH_KERNEL
18361839
# which is only understood by binutils starting with version 2.33.1.
18371840
depends on LD_IS_LLD || LD_VERSION >= 23301 || (CC_IS_GCC && GCC_VERSION < 90100)
18381841
depends on !CC_IS_CLANG || AS_HAS_CFI_NEGATE_RA_STATE
1839-
depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
1842+
depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_ARGS)
18401843
help
18411844
If the compiler supports the -mbranch-protection or
18421845
-msign-return-address flag (e.g. GCC 7 or later), then this option
@@ -1846,7 +1849,7 @@ config ARM64_PTR_AUTH_KERNEL
18461849
disabled with minimal loss of protection.
18471850

18481851
This feature works with FUNCTION_GRAPH_TRACER option only if
1849-
DYNAMIC_FTRACE_WITH_REGS is enabled.
1852+
DYNAMIC_FTRACE_WITH_ARGS is enabled.
18501853

18511854
config CC_HAS_BRANCH_PROT_PAC_RET
18521855
# GCC 9 or later, clang 8 or later
@@ -1944,7 +1947,7 @@ config ARM64_BTI_KERNEL
19441947
depends on !CC_IS_GCC
19451948
# https://github.com/llvm/llvm-project/commit/a88c722e687e6780dcd6a58718350dc76fcc4cc9
19461949
depends on !CC_IS_CLANG || CLANG_VERSION >= 120000
1947-
depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
1950+
depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_ARGS)
19481951
help
19491952
Build the kernel with Branch Target Identification annotations
19501953
and enable enforcement of this for kernel code. When this option

arch/arm64/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ endif
139139

140140
CHECKFLAGS += -D__aarch64__
141141

142-
ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y)
142+
ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_ARGS),y)
143143
KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
144144
CC_FLAGS_FTRACE := -fpatchable-function-entry=2
145145
endif

arch/arm64/include/asm/ftrace.h

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
2525

26-
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
26+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
2727
#define ARCH_SUPPORTS_FTRACE_OPS 1
2828
#else
2929
#define MCOUNT_ADDR ((unsigned long)_mcount)
@@ -33,8 +33,7 @@
3333
#define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE
3434

3535
#define FTRACE_PLT_IDX 0
36-
#define FTRACE_REGS_PLT_IDX 1
37-
#define NR_FTRACE_PLTS 2
36+
#define NR_FTRACE_PLTS 1
3837

3938
/*
4039
* Currently, gcc tends to save the link register after the local variables
@@ -69,7 +68,7 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr)
6968
* Adjust addr to point at the BL in the callsite.
7069
* See ftrace_init_nop() for the callsite sequence.
7170
*/
72-
if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS))
71+
if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_ARGS))
7372
return addr + AARCH64_INSN_SIZE;
7473
/*
7574
* addr is the address of the mcount call instruction.
@@ -78,10 +77,71 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr)
7877
return addr;
7978
}
8079

81-
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
80+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
8281
struct dyn_ftrace;
8382
struct ftrace_ops;
84-
struct ftrace_regs;
83+
84+
#define arch_ftrace_get_regs(regs) NULL
85+
86+
struct ftrace_regs {
87+
/* x0 - x8 */
88+
unsigned long regs[9];
89+
unsigned long __unused;
90+
91+
unsigned long fp;
92+
unsigned long lr;
93+
94+
unsigned long sp;
95+
unsigned long pc;
96+
};
97+
98+
static __always_inline unsigned long
99+
ftrace_regs_get_instruction_pointer(const struct ftrace_regs *fregs)
100+
{
101+
return fregs->pc;
102+
}
103+
104+
static __always_inline void
105+
ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
106+
unsigned long pc)
107+
{
108+
fregs->pc = pc;
109+
}
110+
111+
static __always_inline unsigned long
112+
ftrace_regs_get_stack_pointer(const struct ftrace_regs *fregs)
113+
{
114+
return fregs->sp;
115+
}
116+
117+
static __always_inline unsigned long
118+
ftrace_regs_get_argument(struct ftrace_regs *fregs, unsigned int n)
119+
{
120+
if (n < 8)
121+
return fregs->regs[n];
122+
return 0;
123+
}
124+
125+
static __always_inline unsigned long
126+
ftrace_regs_get_return_value(const struct ftrace_regs *fregs)
127+
{
128+
return fregs->regs[0];
129+
}
130+
131+
static __always_inline void
132+
ftrace_regs_set_return_value(struct ftrace_regs *fregs,
133+
unsigned long ret)
134+
{
135+
fregs->regs[0] = ret;
136+
}
137+
138+
static __always_inline void
139+
ftrace_override_function_with_return(struct ftrace_regs *fregs)
140+
{
141+
fregs->pc = fregs->lr;
142+
}
143+
144+
int ftrace_regs_query_register_offset(const char *name);
85145

86146
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
87147
#define ftrace_init_nop ftrace_init_nop

arch/arm64/kernel/asm-offsets.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ int main(void)
8282
DEFINE(S_STACKFRAME, offsetof(struct pt_regs, stackframe));
8383
DEFINE(PT_REGS_SIZE, sizeof(struct pt_regs));
8484
BLANK();
85+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
86+
DEFINE(FREGS_X0, offsetof(struct ftrace_regs, regs[0]));
87+
DEFINE(FREGS_X2, offsetof(struct ftrace_regs, regs[2]));
88+
DEFINE(FREGS_X4, offsetof(struct ftrace_regs, regs[4]));
89+
DEFINE(FREGS_X6, offsetof(struct ftrace_regs, regs[6]));
90+
DEFINE(FREGS_X8, offsetof(struct ftrace_regs, regs[8]));
91+
DEFINE(FREGS_FP, offsetof(struct ftrace_regs, fp));
92+
DEFINE(FREGS_LR, offsetof(struct ftrace_regs, lr));
93+
DEFINE(FREGS_SP, offsetof(struct ftrace_regs, sp));
94+
DEFINE(FREGS_PC, offsetof(struct ftrace_regs, pc));
95+
DEFINE(FREGS_SIZE, sizeof(struct ftrace_regs));
96+
BLANK();
97+
#endif
8598
#ifdef CONFIG_COMPAT
8699
DEFINE(COMPAT_SIGFRAME_REGS_OFFSET, offsetof(struct compat_sigframe, uc.uc_mcontext.arm_r0));
87100
DEFINE(COMPAT_RT_SIGFRAME_REGS_OFFSET, offsetof(struct compat_rt_sigframe, sig.uc.uc_mcontext.arm_r0));

0 commit comments

Comments
 (0)