* [PATCH 1/1] ARM: add stacktrace support for non current tasks on SMP
@ 2017-09-19 12:57 ` Zhen Lei
0 siblings, 0 replies; 2+ messages in thread
From: Zhen Lei @ 2017-09-19 12:57 UTC (permalink / raw)
To: Russell King, linux-arm-kernel, linux-kernel
Cc: Tianhong Ding, Hanjun Guo, Libin, Kefeng Wang, Zhen Lei
1. An invalid frame.xx can not lead kernel to crash, this should be
guaranteed by function unwind_frame itself. Otherwise, walk the stack
trace of current is also at risk.
2. There is no way to prevent the walked task becoming rq->curr during
walk_stackframe. This means some entries traced maybe inconsistent. But
it's better than none. Besides, we can dump it again.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
arch/arm/kernel/stacktrace.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c
index 92b7237..80a0e9d 100644
--- a/arch/arm/kernel/stacktrace.c
+++ b/arch/arm/kernel/stacktrace.c
@@ -120,13 +120,20 @@ static noinline void __save_stack_trace(struct task_struct *tsk,
if (tsk != current) {
#ifdef CONFIG_SMP
/*
- * What guarantees do we have here that 'tsk' is not
- * running on another CPU? For now, ignore it as we
- * can't guarantee we won't explode.
+ * There is no way to prevent tsk becoming rq->curr during
+ * walk_stackframe. frame.xx should be sanity checked in
+ * function unwind_frame.
*/
- if (trace->nr_entries < trace->max_entries)
- trace->entries[trace->nr_entries++] = ULONG_MAX;
- return;
+ if (!task_curr(tsk)) {
+ frame.fp = thread_saved_fp(tsk);
+ frame.sp = thread_saved_sp(tsk);
+ frame.lr = 0; /* recovered from the stack */
+ frame.pc = thread_saved_pc(tsk);
+ } else {
+ if (trace->nr_entries < trace->max_entries)
+ trace->entries[trace->nr_entries++] = ULONG_MAX;
+ return;
+ }
#else
frame.fp = thread_saved_fp(tsk);
frame.sp = thread_saved_sp(tsk);
--
2.5.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 1/1] ARM: add stacktrace support for non current tasks on SMP
@ 2017-09-19 12:57 ` Zhen Lei
0 siblings, 0 replies; 2+ messages in thread
From: Zhen Lei @ 2017-09-19 12:57 UTC (permalink / raw)
To: linux-arm-kernel
1. An invalid frame.xx can not lead kernel to crash, this should be
guaranteed by function unwind_frame itself. Otherwise, walk the stack
trace of current is also at risk.
2. There is no way to prevent the walked task becoming rq->curr during
walk_stackframe. This means some entries traced maybe inconsistent. But
it's better than none. Besides, we can dump it again.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
arch/arm/kernel/stacktrace.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c
index 92b7237..80a0e9d 100644
--- a/arch/arm/kernel/stacktrace.c
+++ b/arch/arm/kernel/stacktrace.c
@@ -120,13 +120,20 @@ static noinline void __save_stack_trace(struct task_struct *tsk,
if (tsk != current) {
#ifdef CONFIG_SMP
/*
- * What guarantees do we have here that 'tsk' is not
- * running on another CPU? For now, ignore it as we
- * can't guarantee we won't explode.
+ * There is no way to prevent tsk becoming rq->curr during
+ * walk_stackframe. frame.xx should be sanity checked in
+ * function unwind_frame.
*/
- if (trace->nr_entries < trace->max_entries)
- trace->entries[trace->nr_entries++] = ULONG_MAX;
- return;
+ if (!task_curr(tsk)) {
+ frame.fp = thread_saved_fp(tsk);
+ frame.sp = thread_saved_sp(tsk);
+ frame.lr = 0; /* recovered from the stack */
+ frame.pc = thread_saved_pc(tsk);
+ } else {
+ if (trace->nr_entries < trace->max_entries)
+ trace->entries[trace->nr_entries++] = ULONG_MAX;
+ return;
+ }
#else
frame.fp = thread_saved_fp(tsk);
frame.sp = thread_saved_sp(tsk);
--
2.5.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-09-20 1:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-19 12:57 [PATCH 1/1] ARM: add stacktrace support for non current tasks on SMP Zhen Lei
2017-09-19 12:57 ` Zhen Lei
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.