All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64: stacktrace: Stop unwinding when the PC is zero
@ 2021-04-29  1:43 ` Leo Yan
  0 siblings, 0 replies; 8+ messages in thread
From: Leo Yan @ 2021-04-29  1:43 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Mark Brown, Mark Rutland,
	Miroslav Benes, linux-arm-kernel, linux-kernel, Masami Hiramatsu
  Cc: Leo Yan

When use ftrace for stack trace, it reports the spurious frame with the
PC value is zero.  This can be reproduced with commands:

  # cd /sys/kernel/debug/tracing/
  # echo "prev_pid == 0" > events/sched/sched_switch/filter
  # echo stacktrace > events/sched/sched_switch/trigger
  # echo 1 > events/sched/sched_switch/enable
  # cat trace

           <idle>-0       [005] d..2   259.621390: sched_switch: ...
           <idle>-0       [005] d..3   259.621394: <stack trace>
  => __schedule
  => schedule_idle
  => do_idle
  => cpu_startup_entry
  => secondary_start_kernel
  => 0

The kernel initializes FP/PC values as zero for swapper threads in
head.S, when walk the stack frame, this patch stops unwinding if detect
the PC value is zero, therefore can avoid the spurious frame.

Below is the stacktrace after applying the change:

  # cat trace

           <idle>-0       [005] d..2   259.621390: sched_switch: ...
           <idle>-0       [005] d..3   259.621394: <stack trace>
  => __schedule
  => schedule_idle
  => do_idle
  => cpu_startup_entry
  => secondary_start_kernel

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 arch/arm64/kernel/stacktrace.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 84b676bcf867..02b1e85b2026 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -145,7 +145,11 @@ void notrace walk_stackframe(struct task_struct *tsk, struct stackframe *frame,
 		if (!fn(data, frame->pc))
 			break;
 		ret = unwind_frame(tsk, frame);
-		if (ret < 0)
+		/*
+		 * When the frame->pc is zero, it has reached to the initial pc
+		 * and fp values; stop unwinding for this case.
+		 */
+		if (ret < 0 || !frame->pc)
 			break;
 	}
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-04-30 17:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-29  1:43 [PATCH] arm64: stacktrace: Stop unwinding when the PC is zero Leo Yan
2021-04-29  1:43 ` Leo Yan
2021-04-29 10:48 ` Mark Rutland
2021-04-29 10:48   ` Mark Rutland
2021-04-29 12:26   ` Leo Yan
2021-04-29 12:26     ` Leo Yan
2021-04-30 17:32   ` Catalin Marinas
2021-04-30 17:32     ` Catalin Marinas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.