Blame SOURCES/0007-bt-arm64-add-support-for-bt-n-idle.patch

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