Skip to content

Commit f89b30b

Browse files
committed
Merge tag 'trace-direct-v6.3-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace into for-next/ftrace
Pull in ftrace trampoline updates from Steve so that we can implement support for direct calls for arm64 on top: tracing: Direct trampoline updates Updates to the direct trampoline to allow ARM64 to have direct trampolines.
2 parents e8d018d + fee86a4 commit f89b30b

File tree

14 files changed

+101
-491
lines changed

14 files changed

+101
-491
lines changed

arch/s390/kernel/mcount.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ ENTRY(ftrace_stub)
3232
BR_EX %r14
3333
ENDPROC(ftrace_stub)
3434

35+
SYM_CODE_START(ftrace_stub_direct_tramp)
36+
lgr %r1, %r0
37+
BR_EX %r1
38+
SYM_CODE_END(ftrace_stub_direct_tramp)
39+
3540
.macro ftrace_regs_entry, allregs=0
3641
stg %r14,(__SF_GPRS+8*8)(%r15) # save traced function caller
3742

arch/x86/kernel/ftrace_32.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ SYM_INNER_LABEL(ftrace_regs_call, SYM_L_GLOBAL)
163163
jmp .Lftrace_ret
164164
SYM_CODE_END(ftrace_regs_caller)
165165

166+
SYM_FUNC_START(ftrace_stub_direct_tramp)
167+
CALL_DEPTH_ACCOUNT
168+
RET
169+
SYM_FUNC_END(ftrace_stub_direct_tramp)
170+
166171
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
167172
SYM_CODE_START(ftrace_graph_caller)
168173
pushl %eax

arch/x86/kernel/ftrace_64.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ SYM_INNER_LABEL(ftrace_regs_caller_end, SYM_L_GLOBAL)
309309
SYM_FUNC_END(ftrace_regs_caller)
310310
STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller)
311311

312+
SYM_FUNC_START(ftrace_stub_direct_tramp)
313+
CALL_DEPTH_ACCOUNT
314+
RET
315+
SYM_FUNC_END(ftrace_stub_direct_tramp)
312316

313317
#else /* ! CONFIG_DYNAMIC_FTRACE */
314318

include/linux/ftrace.h

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ enum {
241241
FTRACE_OPS_FL_DIRECT = BIT(17),
242242
};
243243

244+
#ifndef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
245+
#define FTRACE_OPS_FL_SAVE_ARGS FTRACE_OPS_FL_SAVE_REGS
246+
#else
247+
#define FTRACE_OPS_FL_SAVE_ARGS 0
248+
#endif
249+
244250
/*
245251
* FTRACE_OPS_CMD_* commands allow the ftrace core logic to request changes
246252
* to a ftrace_ops. Note, the requests may fail.
@@ -321,6 +327,9 @@ struct ftrace_ops {
321327
unsigned long trampoline_size;
322328
struct list_head list;
323329
ftrace_ops_func_t ops_func;
330+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
331+
unsigned long direct_call;
332+
#endif
324333
#endif
325334
};
326335

@@ -397,64 +406,36 @@ struct ftrace_func_entry {
397406

398407
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
399408
extern int ftrace_direct_func_count;
400-
int register_ftrace_direct(unsigned long ip, unsigned long addr);
401-
int unregister_ftrace_direct(unsigned long ip, unsigned long addr);
402-
int modify_ftrace_direct(unsigned long ip, unsigned long old_addr, unsigned long new_addr);
403-
struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr);
404-
int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
405-
struct dyn_ftrace *rec,
406-
unsigned long old_addr,
407-
unsigned long new_addr);
408409
unsigned long ftrace_find_rec_direct(unsigned long ip);
409-
int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
410-
int unregister_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
411-
int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr);
412-
int modify_ftrace_direct_multi_nolock(struct ftrace_ops *ops, unsigned long addr);
410+
int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr);
411+
int unregister_ftrace_direct(struct ftrace_ops *ops, unsigned long addr,
412+
bool free_filters);
413+
int modify_ftrace_direct(struct ftrace_ops *ops, unsigned long addr);
414+
int modify_ftrace_direct_nolock(struct ftrace_ops *ops, unsigned long addr);
415+
416+
void ftrace_stub_direct_tramp(void);
413417

414418
#else
415419
struct ftrace_ops;
416420
# define ftrace_direct_func_count 0
417-
static inline int register_ftrace_direct(unsigned long ip, unsigned long addr)
418-
{
419-
return -ENOTSUPP;
420-
}
421-
static inline int unregister_ftrace_direct(unsigned long ip, unsigned long addr)
422-
{
423-
return -ENOTSUPP;
424-
}
425-
static inline int modify_ftrace_direct(unsigned long ip,
426-
unsigned long old_addr, unsigned long new_addr)
427-
{
428-
return -ENOTSUPP;
429-
}
430-
static inline struct ftrace_direct_func *ftrace_find_direct_func(unsigned long addr)
431-
{
432-
return NULL;
433-
}
434-
static inline int ftrace_modify_direct_caller(struct ftrace_func_entry *entry,
435-
struct dyn_ftrace *rec,
436-
unsigned long old_addr,
437-
unsigned long new_addr)
438-
{
439-
return -ENODEV;
440-
}
441421
static inline unsigned long ftrace_find_rec_direct(unsigned long ip)
442422
{
443423
return 0;
444424
}
445-
static inline int register_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
425+
static inline int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)
446426
{
447427
return -ENODEV;
448428
}
449-
static inline int unregister_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
429+
static inline int unregister_ftrace_direct(struct ftrace_ops *ops, unsigned long addr,
430+
bool free_filters)
450431
{
451432
return -ENODEV;
452433
}
453-
static inline int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
434+
static inline int modify_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)
454435
{
455436
return -ENODEV;
456437
}
457-
static inline int modify_ftrace_direct_multi_nolock(struct ftrace_ops *ops, unsigned long addr)
438+
static inline int modify_ftrace_direct_nolock(struct ftrace_ops *ops, unsigned long addr)
458439
{
459440
return -ENODEV;
460441
}

kernel/bpf/trampoline.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ static int bpf_tramp_ftrace_ops_func(struct ftrace_ops *ops, enum ftrace_ops_cmd
4545
lockdep_assert_held_once(&tr->mutex);
4646

4747
/* Instead of updating the trampoline here, we propagate
48-
* -EAGAIN to register_ftrace_direct_multi(). Then we can
49-
* retry register_ftrace_direct_multi() after updating the
48+
* -EAGAIN to register_ftrace_direct(). Then we can
49+
* retry register_ftrace_direct() after updating the
5050
* trampoline.
5151
*/
5252
if ((tr->flags & BPF_TRAMP_F_CALL_ORIG) &&
@@ -198,7 +198,7 @@ static int unregister_fentry(struct bpf_trampoline *tr, void *old_addr)
198198
int ret;
199199

200200
if (tr->func.ftrace_managed)
201-
ret = unregister_ftrace_direct_multi(tr->fops, (long)old_addr);
201+
ret = unregister_ftrace_direct(tr->fops, (long)old_addr, false);
202202
else
203203
ret = bpf_arch_text_poke(ip, BPF_MOD_CALL, old_addr, NULL);
204204

@@ -215,9 +215,9 @@ static int modify_fentry(struct bpf_trampoline *tr, void *old_addr, void *new_ad
215215

216216
if (tr->func.ftrace_managed) {
217217
if (lock_direct_mutex)
218-
ret = modify_ftrace_direct_multi(tr->fops, (long)new_addr);
218+
ret = modify_ftrace_direct(tr->fops, (long)new_addr);
219219
else
220-
ret = modify_ftrace_direct_multi_nolock(tr->fops, (long)new_addr);
220+
ret = modify_ftrace_direct_nolock(tr->fops, (long)new_addr);
221221
} else {
222222
ret = bpf_arch_text_poke(ip, BPF_MOD_CALL, old_addr, new_addr);
223223
}
@@ -243,7 +243,7 @@ static int register_fentry(struct bpf_trampoline *tr, void *new_addr)
243243

244244
if (tr->func.ftrace_managed) {
245245
ftrace_set_filter_ip(tr->fops, (unsigned long)ip, 0, 1);
246-
ret = register_ftrace_direct_multi(tr->fops, (long)new_addr);
246+
ret = register_ftrace_direct(tr->fops, (long)new_addr);
247247
} else {
248248
ret = bpf_arch_text_poke(ip, BPF_MOD_CALL, NULL, new_addr);
249249
}

kernel/trace/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ config DYNAMIC_FTRACE_WITH_REGS
257257

258258
config DYNAMIC_FTRACE_WITH_DIRECT_CALLS
259259
def_bool y
260-
depends on DYNAMIC_FTRACE_WITH_REGS
260+
depends on DYNAMIC_FTRACE_WITH_REGS || DYNAMIC_FTRACE_WITH_ARGS
261261
depends on HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
262262

263263
config DYNAMIC_FTRACE_WITH_CALL_OPS

0 commit comments

Comments
 (0)