Skip to content

Commit a1d863a

Browse files
iii-iVasily Gorbik
authored andcommitted
s390/unwind: fix mixing regs and sp
unwind_for_each_frame stops after the first frame if regs->gprs[15] <= sp. The reason is that in case regs are specified, the first frame should be regs->psw.addr and the second frame should be sp->gprs[8]. However, currently the second frame is regs->gprs[15], which confuses outside_of_stack(). Fix by introducing a flag to distinguish this special case from unwinding the interrupt handler, for which the current behavior is appropriate. Fixes: 78c98f9 ("s390/unwind: introduce stack unwind API") Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Cc: stable@vger.kernel.org # v5.2+ Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent b8e51a6 commit a1d863a

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎arch/s390/include/asm/unwind.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct unwind_state {
3535
struct task_struct *task;
3636
struct pt_regs *regs;
3737
unsigned long sp, ip;
38+
bool reuse_sp;
3839
int graph_idx;
3940
bool reliable;
4041
bool error;

‎arch/s390/kernel/unwind_bc.c‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ bool unwind_next_frame(struct unwind_state *state)
4646

4747
regs = state->regs;
4848
if (unlikely(regs)) {
49-
sp = READ_ONCE_NOCHECK(regs->gprs[15]);
50-
if (unlikely(outside_of_stack(state, sp))) {
51-
if (!update_stack_info(state, sp))
52-
goto out_err;
49+
if (state->reuse_sp) {
50+
sp = state->sp;
51+
state->reuse_sp = false;
52+
} else {
53+
sp = READ_ONCE_NOCHECK(regs->gprs[15]);
54+
if (unlikely(outside_of_stack(state, sp))) {
55+
if (!update_stack_info(state, sp))
56+
goto out_err;
57+
}
5358
}
5459
sf = (struct stack_frame *) sp;
5560
ip = READ_ONCE_NOCHECK(sf->gprs[8]);
@@ -107,9 +112,9 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
107112
{
108113
struct stack_info *info = &state->stack_info;
109114
unsigned long *mask = &state->stack_mask;
115+
bool reliable, reuse_sp;
110116
struct stack_frame *sf;
111117
unsigned long ip;
112-
bool reliable;
113118

114119
memset(state, 0, sizeof(*state));
115120
state->task = task;
@@ -134,10 +139,12 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
134139
if (regs) {
135140
ip = READ_ONCE_NOCHECK(regs->psw.addr);
136141
reliable = true;
142+
reuse_sp = true;
137143
} else {
138144
sf = (struct stack_frame *) sp;
139145
ip = READ_ONCE_NOCHECK(sf->gprs[8]);
140146
reliable = false;
147+
reuse_sp = false;
141148
}
142149

143150
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
@@ -151,5 +158,6 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
151158
state->sp = sp;
152159
state->ip = ip;
153160
state->reliable = reliable;
161+
state->reuse_sp = reuse_sp;
154162
}
155163
EXPORT_SYMBOL_GPL(__unwind_start);

0 commit comments

Comments
 (0)