Skip to content

Commit 222ee90

Browse files
author
Vasily Gorbik
committed
s390/unwind: start unwinding from reliable state
A comment in arch/s390/include/asm/unwind.h says: > If 'first_frame' is not zero unwind_start skips unwind frames until it > reaches the specified stack pointer. > The end of the unwinding is indicated with unwind_done, this can be true > right after unwind_start, e.g. with first_frame!=0 that can not be found. > unwind_next_frame skips to the next frame. > Once the unwind is completed unwind_error() can be used to check if there > has been a situation where the unwinder could not correctly understand > the tasks call chain. With this change backchain unwinder now comply with behaviour described. As well as matches orc unwinder implementation. Now unwinder starts from reliable state, i.e. __unwind_start own stack frame is taken or stack frame generated by __switch_to (ksp) - both known to be valid. In case of pt_regs %r15 is better match for pt_regs psw, than sometimes random "sp" caller passed. Reviewed-by: Heiko Carstens <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent de6921c commit 222ee90

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

arch/s390/include/asm/unwind.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ static inline bool unwind_error(struct unwind_state *state)
5858
static inline void unwind_start(struct unwind_state *state,
5959
struct task_struct *task,
6060
struct pt_regs *regs,
61-
unsigned long sp)
61+
unsigned long first_frame)
6262
{
6363
task = task ?: current;
64-
sp = sp ?: get_stack_pointer(task, regs);
65-
__unwind_start(state, task, regs, sp);
64+
first_frame = first_frame ?: get_stack_pointer(task, regs);
65+
__unwind_start(state, task, regs, first_frame);
6666
}
6767

6868
static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)

arch/s390/kernel/unwind_bc.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,11 @@ bool unwind_next_frame(struct unwind_state *state)
105105
EXPORT_SYMBOL_GPL(unwind_next_frame);
106106

107107
void __unwind_start(struct unwind_state *state, struct task_struct *task,
108-
struct pt_regs *regs, unsigned long sp)
108+
struct pt_regs *regs, unsigned long first_frame)
109109
{
110110
struct stack_info *info = &state->stack_info;
111-
unsigned long *mask = &state->stack_mask;
112-
bool reliable;
113111
struct stack_frame *sf;
114-
unsigned long ip;
112+
unsigned long ip, sp;
115113

116114
memset(state, 0, sizeof(*state));
117115
state->task = task;
@@ -123,30 +121,46 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
123121
return;
124122
}
125123

124+
/* Get the instruction pointer from pt_regs or the stack frame */
125+
if (regs) {
126+
ip = regs->psw.addr;
127+
sp = regs->gprs[15];
128+
} else if (task == current) {
129+
sp = current_frame_address();
130+
} else {
131+
sp = task->thread.ksp;
132+
}
133+
126134
/* Get current stack pointer and initialize stack info */
127-
if (get_stack_info(sp, task, info, mask) != 0 ||
128-
!on_stack(info, sp, sizeof(struct stack_frame))) {
135+
if (!update_stack_info(state, sp)) {
129136
/* Something is wrong with the stack pointer */
130137
info->type = STACK_TYPE_UNKNOWN;
131138
state->error = true;
132139
return;
133140
}
134141

135-
/* Get the instruction pointer from pt_regs or the stack frame */
136-
if (regs) {
137-
ip = READ_ONCE_NOCHECK(regs->psw.addr);
138-
reliable = true;
139-
} else {
140-
sf = (struct stack_frame *) sp;
142+
if (!regs) {
143+
/* Stack frame is within valid stack */
144+
sf = (struct stack_frame *)sp;
141145
ip = READ_ONCE_NOCHECK(sf->gprs[8]);
142-
reliable = false;
143146
}
144147

145148
ip = ftrace_graph_ret_addr(state->task, &state->graph_idx, ip, NULL);
146149

147150
/* Update unwind state */
148151
state->sp = sp;
149152
state->ip = ip;
150-
state->reliable = reliable;
153+
state->reliable = true;
154+
155+
if (!first_frame)
156+
return;
157+
/* Skip through the call chain to the specified starting frame */
158+
while (!unwind_done(state)) {
159+
if (on_stack(&state->stack_info, first_frame, sizeof(struct stack_frame))) {
160+
if (state->sp >= first_frame)
161+
break;
162+
}
163+
unwind_next_frame(state);
164+
}
151165
}
152166
EXPORT_SYMBOL_GPL(__unwind_start);

0 commit comments

Comments
 (0)