Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71e308a2 authored by Steven Rostedt's avatar Steven Rostedt Committed by Steven Rostedt
Browse files

function-graph: add stack frame test



In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.

An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.

This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.

There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.

This test detected the problem and pointed out where the issue was.

This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.

Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent eb4a0378
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -605,7 +605,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
		return;
	}

	if (ftrace_push_return_trace(old, self_addr, &trace.depth) == -EBUSY) {
	if (ftrace_push_return_trace(old, self_addr, &trace.depth, 0) == -EBUSY) {
		*parent = old;
		return;
	}
+1 −1
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ unsigned long prepare_ftrace_return(unsigned long ip, unsigned long parent)
		goto out;
	if (unlikely(atomic_read(&current->tracing_graph_pause)))
		goto out;
	if (ftrace_push_return_trace(parent, ip, &trace.depth) == -EBUSY)
	if (ftrace_push_return_trace(parent, ip, &trace.depth, 0) == -EBUSY)
		goto out;
	trace.func = ftrace_mcount_call_adjust(ip) & PSW_ADDR_INSN;
	/* Only trace if the calling function expects to. */
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ config X86
	select HAVE_DYNAMIC_FTRACE
	select HAVE_FUNCTION_TRACER
	select HAVE_FUNCTION_GRAPH_TRACER
	select HAVE_FUNCTION_GRAPH_FP_TEST
	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
	select HAVE_FTRACE_NMI_ENTER if DYNAMIC_FTRACE
	select HAVE_FTRACE_SYSCALLS
+2 −0
Original line number Diff line number Diff line
@@ -1154,6 +1154,7 @@ ENTRY(ftrace_graph_caller)
	pushl %edx
	movl 0xc(%esp), %edx
	lea 0x4(%ebp), %eax
	movl (%ebp), %ecx
	subl $MCOUNT_INSN_SIZE, %edx
	call prepare_ftrace_return
	popl %edx
@@ -1168,6 +1169,7 @@ return_to_handler:
	pushl %eax
	pushl %ecx
	pushl %edx
	movl %ebp, %eax
	call ftrace_return_to_handler
	movl %eax, 0xc(%esp)
	popl %edx
+2 −0
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ ENTRY(ftrace_graph_caller)

	leaq 8(%rbp), %rdi
	movq 0x38(%rsp), %rsi
	movq (%rbp), %rdx
	subq $MCOUNT_INSN_SIZE, %rsi

	call	prepare_ftrace_return
@@ -150,6 +151,7 @@ GLOBAL(return_to_handler)
	/* Save the return values */
	movq %rax, (%rsp)
	movq %rdx, 8(%rsp)
	movq %rbp, %rdi

	call ftrace_return_to_handler

Loading