* [PATCH] arm64: smp call when task currently running on other cpu
@ 2020-06-12 7:41 Wang Qing
2020-06-12 13:29 ` Mark Rutland
0 siblings, 1 reply; 2+ messages in thread
From: Wang Qing @ 2020-06-12 7:41 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, James Morse, Mark Rutland,
Dave Martin, Dmitry Safonov, Thomas Gleixner, Wang Qing,
jinho lim, linux-arm-kernel, linux-kernel
Cc: opensource.kernel
We cannot get FP and PC when the task is running on another CPU,
task->thread.cpu_context is the last time the task was switched out,
we can use smp call to print backtrace itself.
Signed-off-by: Wang Qing <wangqing@vivo.com>
---
arch/arm64/kernel/traps.c | 11 +++++++++++
1 file changed, 11 insertions(+)
mode change 100644 => 100755 arch/arm64/kernel/traps.c
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index 50cc30a..17a07b9
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -83,6 +83,11 @@ static void dump_kernel_instr(const char *lvl, struct pt_regs *regs)
printk("%sCode: %s\n", lvl, str);
}
+static void dump_backtrace_smp_fun(struct task_struct *tsk)
+{
+ dump_backtrace(NULL, tsk, KERN_DEFAULT);
+}
+
void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
const char *loglvl)
{
@@ -107,6 +112,12 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
start_backtrace(&frame,
(unsigned long)__builtin_frame_address(0),
(unsigned long)dump_backtrace);
+ } else if (task_curr(tsk)) {
+ /*
+ * The task is currently running on other cpu
+ */
+ smp_call_function_single(tsk->cpu, dump_backtrace_fun, tsk, 0);
+ return;
} else {
/*
* task blocked in __switch_to
--
2.7.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] arm64: smp call when task currently running on other cpu
2020-06-12 7:41 [PATCH] arm64: smp call when task currently running on other cpu Wang Qing
@ 2020-06-12 13:29 ` Mark Rutland
0 siblings, 0 replies; 2+ messages in thread
From: Mark Rutland @ 2020-06-12 13:29 UTC (permalink / raw)
To: Wang Qing
Cc: opensource.kernel, Catalin Marinas, Dmitry Safonov, linux-kernel,
jinho lim, James Morse, Thomas Gleixner, Will Deacon, Dave Martin,
linux-arm-kernel
On Fri, Jun 12, 2020 at 03:41:46PM +0800, Wang Qing wrote:
> We cannot get FP and PC when the task is running on another CPU,
> task->thread.cpu_context is the last time the task was switched out,
> we can use smp call to print backtrace itself.
>
> Signed-off-by: Wang Qing <wangqing@vivo.com>
Sorry, but NAK to this as-is. This is not a legitimate use of
dump_backtrace(), and even if we wanted to dump a backtrace of a
remotely running task, the patch is:
* Insufficient, since a remotely running task can become blocked after
task_curr() is sampled.
* Insufficient and incorrect, since the task can be rescheduled after
task->cpu is sampled. This patch could cause *another* task to dump a
stacktrace.
* Unsafe, since tsk->cpu is accessed racily. In practice we'd likely get
away with that, but it's not something we should rely on.
* Unsafe, since if this were ever called in IRQ context it could result
in a deadlock.
Taking a step back, please explain *why* you think you need this?
What code in mainline is calling dumop_backtrace() on a remotely running
task?
Thanks,
Mark.
> ---
> arch/arm64/kernel/traps.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
> mode change 100644 => 100755 arch/arm64/kernel/traps.c
>
> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
> index 50cc30a..17a07b9
> --- a/arch/arm64/kernel/traps.c
> +++ b/arch/arm64/kernel/traps.c
> @@ -83,6 +83,11 @@ static void dump_kernel_instr(const char *lvl, struct pt_regs *regs)
> printk("%sCode: %s\n", lvl, str);
> }
>
> +static void dump_backtrace_smp_fun(struct task_struct *tsk)
> +{
> + dump_backtrace(NULL, tsk, KERN_DEFAULT);
> +}
> +
> void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
> const char *loglvl)
> {
> @@ -107,6 +112,12 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
> start_backtrace(&frame,
> (unsigned long)__builtin_frame_address(0),
> (unsigned long)dump_backtrace);
> + } else if (task_curr(tsk)) {
> + /*
> + * The task is currently running on other cpu
> + */
> + smp_call_function_single(tsk->cpu, dump_backtrace_fun, tsk, 0);
> + return;
> } else {
> /*
> * task blocked in __switch_to
> --
> 2.7.4
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-12 13:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-12 7:41 [PATCH] arm64: smp call when task currently running on other cpu Wang Qing
2020-06-12 13:29 ` Mark Rutland
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox