From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
<linux-riscv@lists.infradead.org>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH 3/3] riscv: Enable ARCH_STACKWALK
Date: Fri, 13 Nov 2020 14:42:23 +0800 [thread overview]
Message-ID: <20201113064223.103530-4-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <20201113064223.103530-1-wangkefeng.wang@huawei.com>
Convert to ARCH_STACKWALK to reduce duplicated code in stack trace.
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
arch/riscv/Kconfig | 1 +
arch/riscv/kernel/stacktrace.c | 49 +++++++---------------------------
2 files changed, 11 insertions(+), 39 deletions(-)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index dfbc1351ee62..d9da5d92e40d 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -14,6 +14,7 @@ config RISCV
def_bool y
select ARCH_CLOCKSOURCE_INIT
select ARCH_SUPPORTS_ATOMIC_RMW
+ select ARCH_STACKWALK
select ARCH_HAS_BINFMT_FLAT
select ARCH_HAS_DEBUG_VM_PGTABLE
select ARCH_HAS_DEBUG_VIRTUAL if MMU
diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
index 81c48144c504..48b870a685b3 100644
--- a/arch/riscv/kernel/stacktrace.c
+++ b/arch/riscv/kernel/stacktrace.c
@@ -19,7 +19,7 @@ register unsigned long sp_in_global __asm__("sp");
#ifdef CONFIG_FRAME_POINTER
void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
- bool (*fn)(unsigned long, void *), void *arg)
+ bool (*fn)(void *, unsigned long), void *arg)
{
unsigned long fp, sp, pc;
@@ -43,7 +43,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
unsigned long low, high;
struct stackframe *frame;
- if (unlikely(!__kernel_text_address(pc) || fn(arg, pc)))
+ if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc)))
break;
/* Validate frame pointer */
@@ -85,7 +85,7 @@ void notrace walk_stackframe(struct task_struct *task,
ksp = (unsigned long *)sp;
while (!kstack_end(ksp)) {
- if (__kernel_text_address(pc) && unlikely(fn(arg, pc)))
+ if (__kernel_text_address(pc) && unlikely(!fn(arg, pc)))
break;
pc = (*ksp++) - 0x4;
}
@@ -93,12 +93,12 @@ void notrace walk_stackframe(struct task_struct *task,
#endif /* CONFIG_FRAME_POINTER */
-static bool print_trace_address(unsigned long pc, void *arg)
+static bool print_trace_address(void *arg, unsigned long pc)
{
const char *loglvl = arg;
print_ip_sym(loglvl, pc);
- return false;
+ return true;
}
void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
@@ -112,9 +112,9 @@ static bool save_wchan(void *arg, unsigned long pc)
if (!in_sched_functions(pc)) {
unsigned long *p = arg;
*p = pc;
- return true;
+ return false;
}
- return false;
+ return true;
}
unsigned long get_wchan(struct task_struct *task)
@@ -128,39 +128,10 @@ unsigned long get_wchan(struct task_struct *task)
#ifdef CONFIG_STACKTRACE
-static bool __save_trace(unsigned long pc, void *arg, bool nosched)
-{
- struct stack_trace *trace = arg;
-
- if (unlikely(nosched && in_sched_functions(pc)))
- return false;
- if (unlikely(trace->skip > 0)) {
- trace->skip--;
- return false;
- }
-
- trace->entries[trace->nr_entries++] = pc;
- return (trace->nr_entries >= trace->max_entries);
-}
-
-static bool save_trace(void *arg, unsigned long pc)
-{
- return __save_trace(pc, arg, false);
-}
-
-/*
- * Save stack-backtrace addresses into a stack_trace buffer.
- */
-void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
-{
- walk_stackframe(tsk, NULL, save_trace, trace);
-}
-EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
-
-void save_stack_trace(struct stack_trace *trace)
+void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
+ struct task_struct *task, struct pt_regs *regs)
{
- save_stack_trace_tsk(NULL, trace);
+ walk_stackframe(task, regs, consume_entry, cookie);
}
-EXPORT_SYMBOL_GPL(save_stack_trace);
#endif /* CONFIG_STACKTRACE */
--
2.26.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2020-11-13 6:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-13 6:42 [PATCH 0/3] riscv: cover to ARCH_STACKWALK Kefeng Wang
2020-11-13 6:42 ` [PATCH 1/3] riscv: Cleanup stacktrace Kefeng Wang
2020-11-13 6:42 ` [PATCH 2/3] riscv: Make stack walk callback consistent with generic code Kefeng Wang
2020-11-13 6:42 ` Kefeng Wang [this message]
2020-11-21 3:01 ` [PATCH 0/3] riscv: cover to ARCH_STACKWALK Palmer Dabbelt
2020-11-24 11:20 ` [PATCH 1/2] riscv: Add dump stack in show_regs Kefeng Wang
2020-11-24 11:20 ` [PATCH 2/2] riscv: Fix __show_regs printing formats Kefeng Wang
2020-11-25 22:58 ` Atish Patra
2020-11-26 1:10 ` Kefeng Wang
2020-11-26 10:02 ` John Ogness
2020-11-26 11:55 ` John Ogness
2020-11-26 12:49 ` Kefeng Wang
2020-11-26 13:33 ` [PATCH v2] riscv: Using printk directly in __show_regs Kefeng Wang
2020-12-11 1:43 ` Palmer Dabbelt
2020-12-11 8:48 ` John Ogness
2020-12-14 11:49 ` Kefeng Wang
2020-11-25 23:04 ` [PATCH 1/2] riscv: Add dump stack in show_regs Atish Patra
2020-12-14 11:52 ` Kefeng Wang
2021-01-09 22:24 ` Palmer Dabbelt
2021-01-11 3:23 ` Kefeng Wang
2020-12-17 2:34 ` [PATCH 0/3] riscv: cover to ARCH_STACKWALK Kefeng Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201113064223.103530-4-wangkefeng.wang@huawei.com \
--to=wangkefeng.wang@huawei.com \
--cc=aou@eecs.berkeley.edu \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox