Skip to content

Commit 885af35

Browse files
Yang ShiAlex Shi
authored andcommitted
arm64: make irq_stack_ptr more robust
Switching between stacks is only valid if we are tracing ourselves while on the irq_stack, so it is only valid when in current and non-preemptible context, otherwise is is just zeroed off. Fixes: 132cd887b5c5 ("arm64: Modify stack trace and dump for use with irq_stack") Acked-by: James Morse <james.morse@arm.com> Tested-by: James Morse <james.morse@arm.com> Signed-off-by: Yang Shi <yang.shi@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com> (cherry picked from commit a80a0eb70c358f8c7dda4bb62b2278dc6285217b) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent e009472 commit 885af35

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

arch/arm64/kernel/stacktrace.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame)
4444
unsigned long irq_stack_ptr;
4545

4646
/*
47-
* Use raw_smp_processor_id() to avoid false-positives from
48-
* CONFIG_DEBUG_PREEMPT. get_wchan() calls unwind_frame() on sleeping
49-
* task stacks, we can be pre-empted in this case, so
50-
* {raw_,}smp_processor_id() may give us the wrong value. Sleeping
51-
* tasks can't ever be on an interrupt stack, so regardless of cpu,
52-
* the checks will always fail.
47+
* Switching between stacks is valid when tracing current and in
48+
* non-preemptible context.
5349
*/
54-
irq_stack_ptr = IRQ_STACK_PTR(raw_smp_processor_id());
50+
if (tsk == current && !preemptible())
51+
irq_stack_ptr = IRQ_STACK_PTR(smp_processor_id());
52+
else
53+
irq_stack_ptr = 0;
5554

5655
low = frame->sp;
5756
/* irq stacks are not THREAD_SIZE aligned */

arch/arm64/kernel/traps.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,18 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
146146
static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
147147
{
148148
struct stackframe frame;
149-
unsigned long irq_stack_ptr = IRQ_STACK_PTR(smp_processor_id());
149+
unsigned long irq_stack_ptr;
150150
int skip;
151151

152+
/*
153+
* Switching between stacks is valid when tracing current and in
154+
* non-preemptible context.
155+
*/
156+
if (tsk == current && !preemptible())
157+
irq_stack_ptr = IRQ_STACK_PTR(smp_processor_id());
158+
else
159+
irq_stack_ptr = 0;
160+
152161
pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk);
153162

154163
if (!tsk)

0 commit comments

Comments
 (0)