hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/riscv/kernel/stacktrace.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2008 ARM Limited
34 * Copyright (C) 2014 Regents of the University of California
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
135 */
146
157 #include <linux/export.h>
....@@ -20,6 +12,8 @@
2012 #include <linux/stacktrace.h>
2113 #include <linux/ftrace.h>
2214
15
+register unsigned long sp_in_global __asm__("sp");
16
+
2317 #ifdef CONFIG_FRAME_POINTER
2418
2519 struct stackframe {
....@@ -27,17 +21,17 @@
2721 unsigned long ra;
2822 };
2923
30
-static void notrace walk_stackframe(struct task_struct *task,
31
- struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg)
24
+void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
25
+ bool (*fn)(unsigned long, void *), void *arg)
3226 {
3327 unsigned long fp, sp, pc;
3428
3529 if (regs) {
36
- fp = GET_FP(regs);
37
- sp = GET_USP(regs);
38
- pc = GET_IP(regs);
30
+ fp = frame_pointer(regs);
31
+ sp = user_stack_pointer(regs);
32
+ pc = instruction_pointer(regs);
3933 } else if (task == NULL || task == current) {
40
- const register unsigned long current_sp __asm__ ("sp");
34
+ const register unsigned long current_sp = sp_in_global;
4135 fp = (unsigned long)__builtin_frame_address(0);
4236 sp = current_sp;
4337 pc = (unsigned long)walk_stackframe;
....@@ -64,12 +58,8 @@
6458 frame = (struct stackframe *)fp - 1;
6559 sp = fp;
6660 fp = frame->fp;
67
-#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
6861 pc = ftrace_graph_ret_addr(current, NULL, frame->ra,
6962 (unsigned long *)(fp - 8));
70
-#else
71
- pc = frame->ra - 0x4;
72
-#endif
7363 }
7464 }
7565
....@@ -82,11 +72,10 @@
8272 unsigned long *ksp;
8373
8474 if (regs) {
85
- sp = GET_USP(regs);
86
- pc = GET_IP(regs);
75
+ sp = user_stack_pointer(regs);
76
+ pc = instruction_pointer(regs);
8777 } else if (task == NULL || task == current) {
88
- const register unsigned long current_sp __asm__ ("sp");
89
- sp = current_sp;
78
+ sp = sp_in_global;
9079 pc = (unsigned long)walk_stackframe;
9180 } else {
9281 /* task blocked in __switch_to */
....@@ -110,16 +99,17 @@
11099
111100 static bool print_trace_address(unsigned long pc, void *arg)
112101 {
113
- print_ip_sym(pc);
102
+ const char *loglvl = arg;
103
+
104
+ print_ip_sym(loglvl, pc);
114105 return false;
115106 }
116107
117
-void show_stack(struct task_struct *task, unsigned long *sp)
108
+void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
118109 {
119110 pr_cont("Call Trace:\n");
120
- walk_stackframe(task, NULL, print_trace_address, NULL);
111
+ walk_stackframe(task, NULL, print_trace_address, (void *)loglvl);
121112 }
122
-
123113
124114 static bool save_wchan(unsigned long pc, void *arg)
125115 {
....@@ -169,8 +159,6 @@
169159 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
170160 {
171161 walk_stackframe(tsk, NULL, save_trace, trace);
172
- if (trace->nr_entries < trace->max_entries)
173
- trace->entries[trace->nr_entries++] = ULONG_MAX;
174162 }
175163 EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
176164