Skip to content

Commit 429a967

Browse files
MQ-mengqingchenhuacai
authored andcommitted
LoongArch: Get frame info in unwind_start() when regs is not available
At unwind_start(), it is better to get its frame info here rather than get them outside, even we don't have 'regs'. In this way we can simply use unwind_{start, next_frame, done} outside. Signed-off-by: Jinyang He <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent e2f2739 commit 429a967

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

arch/loongarch/kernel/process.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,14 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
191191

192192
unsigned long __get_wchan(struct task_struct *task)
193193
{
194-
unsigned long pc;
194+
unsigned long pc = 0;
195195
struct unwind_state state;
196196

197197
if (!try_get_task_stack(task))
198198
return 0;
199199

200-
unwind_start(&state, task, NULL);
201-
state.sp = thread_saved_fp(task);
202-
get_stack_info(state.sp, state.task, &state.stack_info);
203-
state.pc = thread_saved_ra(task);
204-
#ifdef CONFIG_UNWINDER_PROLOGUE
205-
state.type = UNWINDER_PROLOGUE;
206-
#endif
207-
for (; !unwind_done(&state); unwind_next_frame(&state)) {
200+
for (unwind_start(&state, task, NULL);
201+
!unwind_done(&state); unwind_next_frame(&state)) {
208202
pc = unwind_get_return_address(&state);
209203
if (!pc)
210204
break;

arch/loongarch/kernel/unwind_guess.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ void unwind_start(struct unwind_state *state, struct task_struct *task,
2626
if (regs) {
2727
state->sp = regs->regs[3];
2828
state->pc = regs->csr_era;
29+
} else if (task && task != current) {
30+
state->sp = thread_saved_fp(task);
31+
state->pc = thread_saved_ra(task);
32+
} else {
33+
state->sp = (unsigned long)__builtin_frame_address(0);
34+
state->pc = (unsigned long)__builtin_return_address(0);
2935
}
3036

3137
state->task = task;

arch/loongarch/kernel/unwind_prologue.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,22 @@ void unwind_start(struct unwind_state *state, struct task_struct *task,
146146
struct pt_regs *regs)
147147
{
148148
memset(state, 0, sizeof(*state));
149+
state->type = UNWINDER_PROLOGUE;
149150

150-
if (regs && __kernel_text_address(regs->csr_era)) {
151-
state->pc = regs->csr_era;
151+
if (regs) {
152152
state->sp = regs->regs[3];
153+
state->pc = regs->csr_era;
153154
state->ra = regs->regs[1];
154-
state->type = UNWINDER_PROLOGUE;
155+
if (!__kernel_text_address(state->pc))
156+
state->type = UNWINDER_GUESS;
157+
} else if (task && task != current) {
158+
state->sp = thread_saved_fp(task);
159+
state->pc = thread_saved_ra(task);
160+
state->ra = 0;
161+
} else {
162+
state->sp = (unsigned long)__builtin_frame_address(0);
163+
state->pc = (unsigned long)__builtin_return_address(0);
164+
state->ra = 0;
155165
}
156166

157167
state->task = task;

0 commit comments

Comments
 (0)