Skip to content

Commit 79fdee9

Browse files
AKASHI Takahirowildea01
authored andcommitted
arm64: ftrace: modify a stack frame in a safe way
Function graph tracer modifies a return address (LR) in a stack frame by calling ftrace_prepare_return() in a traced function's function prologue. The current code does this modification before preserving an original address at ftrace_push_return_trace() and there is always a small window of inconsistency when an interrupt occurs. This doesn't matter, as far as an interrupt stack is introduced, because stack tracer won't be invoked in an interrupt context. But it would be better to proactively minimize such a window by moving the LR modification after ftrace_push_return_trace(). Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent d224a69 commit 79fdee9

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

arch/arm64/kernel/ftrace.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,20 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
129129
* on other archs. It's unlikely on AArch64.
130130
*/
131131
old = *parent;
132-
*parent = return_hooker;
133132

134133
trace.func = self_addr;
135134
trace.depth = current->curr_ret_stack + 1;
136135

137136
/* Only trace if the calling function expects to */
138-
if (!ftrace_graph_entry(&trace)) {
139-
*parent = old;
137+
if (!ftrace_graph_entry(&trace))
140138
return;
141-
}
142139

143140
err = ftrace_push_return_trace(old, self_addr, &trace.depth,
144141
frame_pointer);
145-
if (err == -EBUSY) {
146-
*parent = old;
142+
if (err == -EBUSY)
147143
return;
148-
}
144+
else
145+
*parent = return_hooker;
149146
}
150147

151148
#ifdef CONFIG_DYNAMIC_FTRACE

0 commit comments

Comments
 (0)