d67611
From 0f162febebc4d11a165dd40cee00f3b0ba691a52 Mon Sep 17 00:00:00 2001
d67611
From: Qi Zheng <zhengqi.arch@bytedance.com>
d67611
Date: Tue, 24 May 2022 20:25:54 +0800
d67611
Subject: [PATCH 08/18] bt: arm64: add support for 'bt -n idle'
d67611
d67611
The '-n idle' option of bt command can help us filter the
d67611
stack of the idle process when debugging the dumpfiles
d67611
captured by kdump.
d67611
d67611
This patch supports this feature on ARM64.
d67611
d67611
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
d67611
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
d67611
---
d67611
 arm64.c  | 19 ++++++++++++++++---
d67611
 help.c   |  2 +-
d67611
 kernel.c |  3 ++-
d67611
 3 files changed, 19 insertions(+), 5 deletions(-)
d67611
d67611
diff --git a/arm64.c b/arm64.c
d67611
index 65f6cdf69fa6..0f615cf52bef 100644
d67611
--- a/arm64.c
d67611
+++ b/arm64.c
d67611
@@ -3681,6 +3681,12 @@ arm64_get_dumpfile_stackframe(struct bt_info *bt, struct arm64_stackframe *frame
d67611
 {
d67611
 	struct machine_specific *ms = machdep->machspec;
d67611
 	struct arm64_pt_regs *ptregs;
d67611
+	bool skip = false;
d67611
+
d67611
+	if (bt->flags & BT_SKIP_IDLE) {
d67611
+		skip = true;
d67611
+		bt->flags &= ~BT_SKIP_IDLE;
d67611
+	}
d67611
 
d67611
 	if (!ms->panic_task_regs ||
d67611
 	    (!ms->panic_task_regs[bt->tc->processor].sp && 
d67611
@@ -3713,8 +3719,11 @@ try_kernel:
d67611
 	}
d67611
 
d67611
 	if (arm64_in_kdump_text(bt, frame) || 
d67611
-	    arm64_in_kdump_text_on_irq_stack(bt))
d67611
+	    arm64_in_kdump_text_on_irq_stack(bt)) {
d67611
 		bt->flags |= BT_KDUMP_ADJUST;
d67611
+		if (skip && is_idle_thread(bt->task))
d67611
+			bt->flags |= BT_SKIP_IDLE;
d67611
+	}
d67611
 
d67611
 	return TRUE;
d67611
 }
d67611
@@ -3738,10 +3747,14 @@ arm64_get_stack_frame(struct bt_info *bt, ulong *pcp, ulong *spp)
d67611
 	int ret;
d67611
 	struct arm64_stackframe stackframe = { 0 };
d67611
 
d67611
-	if (DUMPFILE() && is_task_active(bt->task))
d67611
+	if (DUMPFILE() && is_task_active(bt->task)) {
d67611
 		ret = arm64_get_dumpfile_stackframe(bt, &stackframe);
d67611
-	else
d67611
+	} else {
d67611
+		if (bt->flags & BT_SKIP_IDLE)
d67611
+			bt->flags &= ~BT_SKIP_IDLE;
d67611
+
d67611
 		ret = arm64_get_stackframe(bt, &stackframe);
d67611
+	}
d67611
 
d67611
 	if (!ret)
d67611
 		error(WARNING, 
d67611
diff --git a/help.c b/help.c
d67611
index e1bbc5abe029..99214c1590fa 100644
d67611
--- a/help.c
d67611
+++ b/help.c
d67611
@@ -1915,7 +1915,7 @@ char *help_bt[] = {
d67611
 "       -a  displays the stack traces of the active task on each CPU.",
d67611
 "           (only applicable to crash dumps)",
d67611
 "       -A  same as -a, but also displays vector registers (S390X only).",
d67611
-"  -n idle  filter the stack of idle tasks (x86_64).",
d67611
+"  -n idle  filter the stack of idle tasks (x86_64, arm64).",
d67611
 "           (only applicable to crash dumps)",
d67611
 "       -p  display the stack trace of the panic task only.",
d67611
 "           (only applicable to crash dumps)",
d67611
diff --git a/kernel.c b/kernel.c
d67611
index 411e9da1e54f..a521ef30cdb0 100644
d67611
--- a/kernel.c
d67611
+++ b/kernel.c
d67611
@@ -2673,7 +2673,8 @@ cmd_bt(void)
d67611
 			break;
d67611
 
d67611
 		case 'n':
d67611
-			if (machine_type("X86_64") && STREQ(optarg, "idle"))
d67611
+			if ((machine_type("X86_64") || machine_type("ARM64")) &&
d67611
+			    STREQ(optarg, "idle"))
d67611
 				bt->flags |= BT_SKIP_IDLE;
d67611
 			else
d67611
 				option_not_supported(c);
d67611
-- 
d67611
2.30.2
d67611