Skip to content

Commit 9705bc7

Browse files
mrutland-armwilldeacon
authored andcommitted
ftrace: pass fregs to arch_ftrace_set_direct_caller()
In subsequent patches we'll arrange for architectures to have an ftrace_regs which is entirely distinct from pt_regs. In preparation for this, we need to minimize the use of pt_regs to where strictly necessary in the core ftrace code. This patch changes the prototype of arch_ftrace_set_direct_caller() to take ftrace_regs rather than pt_regs, and moves the extraction of the pt_regs into arch_ftrace_set_direct_caller(). On x86, arch_ftrace_set_direct_caller() can be used even when CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS=n, and <linux/ftrace.h> defines struct ftrace_regs. Due to this, it's necessary to define arch_ftrace_set_direct_caller() as a macro to avoid using an incomplete type. I've also moved the body of arch_ftrace_set_direct_caller() after the CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS=y defineidion of struct ftrace_regs. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <[email protected]> Cc: Florent Revest <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Steven Rostedt <[email protected]> Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Reviewed-by: Steven Rostedt (Google) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent f0c4d9f commit 9705bc7

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

arch/s390/include/asm/ftrace.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,20 @@ static __always_inline void ftrace_instruction_pointer_set(struct ftrace_regs *f
6060
fregs->regs.psw.addr = ip;
6161
}
6262

63+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
6364
/*
6465
* When an ftrace registered caller is tracing a function that is
6566
* also set by a register_ftrace_direct() call, it needs to be
6667
* differentiated in the ftrace_caller trampoline. To do this,
6768
* place the direct caller in the ORIG_GPR2 part of pt_regs. This
6869
* tells the ftrace_caller that there's a direct caller.
6970
*/
70-
static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
71+
static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsigned long addr)
7172
{
73+
struct pt_regs *regs = &fregs->regs;
7274
regs->orig_gpr2 = addr;
7375
}
76+
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
7477

7578
/*
7679
* Even though the system call numbers are identical for s390/s390x a

arch/x86/include/asm/ftrace.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr)
3434
return addr;
3535
}
3636

37-
/*
38-
* When a ftrace registered caller is tracing a function that is
39-
* also set by a register_ftrace_direct() call, it needs to be
40-
* differentiated in the ftrace_caller trampoline. To do this, we
41-
* place the direct caller in the ORIG_AX part of pt_regs. This
42-
* tells the ftrace_caller that there's a direct caller.
43-
*/
44-
static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
45-
{
46-
/* Emulate a call */
47-
regs->orig_ax = addr;
48-
}
49-
5037
#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
5138
struct ftrace_regs {
5239
struct pt_regs regs;
@@ -72,6 +59,24 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
7259
#define FTRACE_GRAPH_TRAMP_ADDR FTRACE_GRAPH_ADDR
7360
#endif
7461

62+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
63+
/*
64+
* When a ftrace registered caller is tracing a function that is
65+
* also set by a register_ftrace_direct() call, it needs to be
66+
* differentiated in the ftrace_caller trampoline. To do this, we
67+
* place the direct caller in the ORIG_AX part of pt_regs. This
68+
* tells the ftrace_caller that there's a direct caller.
69+
*/
70+
static inline void
71+
__arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
72+
{
73+
/* Emulate a call */
74+
regs->orig_ax = addr;
75+
}
76+
#define arch_ftrace_set_direct_caller(fregs, addr) \
77+
__arch_ftrace_set_direct_caller(&(fregs)->regs, addr)
78+
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
79+
7580
#ifdef CONFIG_DYNAMIC_FTRACE
7681

7782
struct dyn_arch_ftrace {

include/linux/ftrace.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ extern void ftrace_boot_snapshot(void);
3737
static inline void ftrace_boot_snapshot(void) { }
3838
#endif
3939

40-
#ifdef CONFIG_FUNCTION_TRACER
4140
struct ftrace_ops;
4241
struct ftrace_regs;
42+
43+
#ifdef CONFIG_FUNCTION_TRACER
4344
/*
4445
* If the arch's mcount caller does not support all of ftrace's
4546
* features, then it must call an indirect function that
@@ -427,9 +428,7 @@ static inline int modify_ftrace_direct_multi_nolock(struct ftrace_ops *ops, unsi
427428
{
428429
return -ENODEV;
429430
}
430-
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
431431

432-
#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
433432
/*
434433
* This must be implemented by the architecture.
435434
* It is the way the ftrace direct_ops helper, when called
@@ -443,9 +442,9 @@ static inline int modify_ftrace_direct_multi_nolock(struct ftrace_ops *ops, unsi
443442
* the return from the trampoline jump to the direct caller
444443
* instead of going back to the function it just traced.
445444
*/
446-
static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs,
445+
static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs,
447446
unsigned long addr) { }
448-
#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
447+
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
449448

450449
#ifdef CONFIG_STACK_TRACER
451450

kernel/trace/ftrace.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,14 +2487,13 @@ ftrace_add_rec_direct(unsigned long ip, unsigned long addr,
24872487
static void call_direct_funcs(unsigned long ip, unsigned long pip,
24882488
struct ftrace_ops *ops, struct ftrace_regs *fregs)
24892489
{
2490-
struct pt_regs *regs = ftrace_get_regs(fregs);
24912490
unsigned long addr;
24922491

24932492
addr = ftrace_find_rec_direct(ip);
24942493
if (!addr)
24952494
return;
24962495

2497-
arch_ftrace_set_direct_caller(regs, addr);
2496+
arch_ftrace_set_direct_caller(fregs, addr);
24982497
}
24992498

25002499
struct ftrace_ops direct_ops = {

0 commit comments

Comments
 (0)