Skip to content

Commit 586411d

Browse files
Johannes Weinerczankel
authored andcommitted
xtensa: always use correct stack pointer for stack traces
Commit '28a0ce7 xtensa: use correct stack pointer for stack traces' changed the stack tracer from always reading the stack pointer register to always using the saved value in the task descriptor. The author was too dense to consider the fact that the saved stack value is stale for a running process und thus unusable for 'current'. What we do now is to use the stack pointer register (a1) for when the task is unknown - we can't help it then - or when the task is 'current'. For everything else use the saved stack pointer value contained in the task descriptor. Signed-off-by: Johannes Weiner <jw@emlix.com> Signed-off-by: Chris Zankel <chris@zankel.net>
1 parent 7dbe5c5 commit 586411d

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎arch/xtensa/kernel/traps.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,18 @@ void show_regs(struct pt_regs * regs)
369369
regs->syscall);
370370
}
371371

372+
static __always_inline unsigned long *stack_pointer(struct task_struct *task)
373+
{
374+
unsigned long *sp;
375+
376+
if (!task || task == current)
377+
__asm__ __volatile__ ("mov %0, a1\n" : "=a"(sp));
378+
else
379+
sp = (unsigned long *)task->thread.sp;
380+
381+
return sp;
382+
}
383+
372384
void show_trace(struct task_struct *task, unsigned long *sp)
373385
{
374386
unsigned long a0, a1, pc;
@@ -377,7 +389,7 @@ void show_trace(struct task_struct *task, unsigned long *sp)
377389
if (sp)
378390
a1 = (unsigned long)sp;
379391
else
380-
a1 = task->thread.sp;
392+
a1 = (unsigned long)stack_pointer(task);
381393

382394
sp_start = a1 & ~(THREAD_SIZE-1);
383395
sp_end = sp_start + THREAD_SIZE;
@@ -420,7 +432,7 @@ void show_stack(struct task_struct *task, unsigned long *sp)
420432
unsigned long *stack;
421433

422434
if (!sp)
423-
sp = (unsigned long *)task->thread.sp;
435+
sp = stack_pointer(task);
424436
stack = sp;
425437

426438
printk("\nStack: ");

0 commit comments

Comments
 (0)