Skip to content

Commit 1e377ae

Browse files
Zong LiGreentime Hu
authored andcommitted
nds32/stack: Get real return address by using ftrace_graph_ret_addr
Function graph tracer has modified the return address to 'return_to_handler' on stack, and provide the 'ftrace_graph_ret_addr' to get the real return address. Signed-off-by: Zong Li <[email protected]> Acked-by: Greentime Hu <[email protected]> Signed-off-by: Greentime Hu <[email protected]>
1 parent 95cd2f7 commit 1e377ae

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

arch/nds32/kernel/stacktrace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/sched/debug.h>
55
#include <linux/sched/task_stack.h>
66
#include <linux/stacktrace.h>
7+
#include <linux/ftrace.h>
78

89
void save_stack_trace(struct stack_trace *trace)
910
{
@@ -16,6 +17,7 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
1617
unsigned long *fpn;
1718
int skip = trace->skip;
1819
int savesched;
20+
int graph_idx = 0;
1921

2022
if (tsk == current) {
2123
__asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(fpn));
@@ -33,6 +35,8 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
3335
fpp = fpn[FP_OFFSET];
3436
if (!__kernel_text_address(lpp))
3537
break;
38+
else
39+
lpp = ftrace_graph_ret_addr(tsk, &graph_idx, lpp, NULL);
3640

3741
if (savesched || !in_sched_functions(lpp)) {
3842
if (skip) {

arch/nds32/kernel/traps.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/kdebug.h>
99
#include <linux/sched/task_stack.h>
1010
#include <linux/uaccess.h>
11+
#include <linux/ftrace.h>
1112

1213
#include <asm/proc-fns.h>
1314
#include <asm/unistd.h>
@@ -94,28 +95,6 @@ static void dump_instr(struct pt_regs *regs)
9495
set_fs(fs);
9596
}
9697

97-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
98-
#include <linux/ftrace.h>
99-
static void
100-
get_real_ret_addr(unsigned long *addr, struct task_struct *tsk, int *graph)
101-
{
102-
if (*addr == (unsigned long)return_to_handler) {
103-
int index = tsk->curr_ret_stack;
104-
105-
if (tsk->ret_stack && index >= *graph) {
106-
index -= *graph;
107-
*addr = tsk->ret_stack[index].ret;
108-
(*graph)++;
109-
}
110-
}
111-
}
112-
#else
113-
static inline void
114-
get_real_ret_addr(unsigned long *addr, struct task_struct *tsk, int *graph)
115-
{
116-
}
117-
#endif
118-
11998
#define LOOP_TIMES (100)
12099
static void __dump(struct task_struct *tsk, unsigned long *base_reg)
121100
{
@@ -126,7 +105,8 @@ static void __dump(struct task_struct *tsk, unsigned long *base_reg)
126105
while (!kstack_end(base_reg)) {
127106
ret_addr = *base_reg++;
128107
if (__kernel_text_address(ret_addr)) {
129-
get_real_ret_addr(&ret_addr, tsk, &graph);
108+
ret_addr = ftrace_graph_ret_addr(
109+
tsk, &graph, ret_addr, NULL);
130110
print_ip_sym(ret_addr);
131111
}
132112
if (--cnt < 0)
@@ -145,7 +125,9 @@ static void __dump(struct task_struct *tsk, unsigned long *base_reg)
145125
next_fp = base_reg[FP_OFFSET];
146126
#endif
147127
if (__kernel_text_address(ret_addr)) {
148-
get_real_ret_addr(&ret_addr, tsk, &graph);
128+
129+
ret_addr = ftrace_graph_ret_addr(
130+
tsk, &graph, ret_addr, NULL);
149131
print_ip_sym(ret_addr);
150132
}
151133
if (--cnt < 0)

0 commit comments

Comments
 (0)