Skip to content

Commit dbaccb6

Browse files
FlorentRevestrostedt
authored andcommitted
ftrace: Store direct called addresses in their ops
All direct calls are now registered using the register_ftrace_direct API so each ops can jump to only one direct-called trampoline. By storing the direct called trampoline address directly in the ops we can save one hashmap lookup in the direct call ops and implement arm64 direct calls on top of call ops. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Florent Revest <[email protected]> Acked-by: Jiri Olsa <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent da8bdfb commit dbaccb6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

include/linux/ftrace.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ struct ftrace_ops {
321321
unsigned long trampoline_size;
322322
struct list_head list;
323323
ftrace_ops_func_t ops_func;
324+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
325+
unsigned long direct_call;
326+
#endif
324327
#endif
325328
};
326329

kernel/trace/ftrace.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,9 +2583,8 @@ ftrace_add_rec_direct(unsigned long ip, unsigned long addr,
25832583
static void call_direct_funcs(unsigned long ip, unsigned long pip,
25842584
struct ftrace_ops *ops, struct ftrace_regs *fregs)
25852585
{
2586-
unsigned long addr;
2586+
unsigned long addr = READ_ONCE(ops->direct_call);
25872587

2588-
addr = ftrace_find_rec_direct(ip);
25892588
if (!addr)
25902589
return;
25912590

@@ -5381,6 +5380,7 @@ int register_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)
53815380
ops->func = call_direct_funcs;
53825381
ops->flags = MULTI_FLAGS;
53835382
ops->trampoline = FTRACE_REGS_ADDR;
5383+
ops->direct_call = addr;
53845384

53855385
err = register_ftrace_function_nolock(ops);
53865386

@@ -5455,6 +5455,7 @@ __modify_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)
54555455
/* Enable the tmp_ops to have the same functions as the direct ops */
54565456
ftrace_ops_init(&tmp_ops);
54575457
tmp_ops.func_hash = ops->func_hash;
5458+
tmp_ops.direct_call = addr;
54585459

54595460
err = register_ftrace_function_nolock(&tmp_ops);
54605461
if (err)
@@ -5476,6 +5477,8 @@ __modify_ftrace_direct(struct ftrace_ops *ops, unsigned long addr)
54765477
entry->direct = addr;
54775478
}
54785479
}
5480+
/* Prevent store tearing if a trampoline concurrently accesses the value */
5481+
WRITE_ONCE(ops->direct_call, addr);
54795482

54805483
mutex_unlock(&ftrace_lock);
54815484

0 commit comments

Comments
 (0)