<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux.git/arch/arm64/kernel/stacktrace.c, branch v5.10.258</title>
<subtitle>Clone of https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git</subtitle>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/'/>
<entry>
<title>arm64: stacktrace: avoid tracing arch_stack_walk()</title>
<updated>2021-08-12T11:22:12+00:00</updated>
<author>
<name>Mark Rutland</name>
<email>mark.rutland@arm.com</email>
</author>
<published>2021-08-02T16:48:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=e5d8fd87091c0fc596caf88c6fd8733486bd939d'/>
<id>e5d8fd87091c0fc596caf88c6fd8733486bd939d</id>
<content type='text'>
commit 0c32706dac1b0a72713184246952ab0f54327c21 upstream.

When the function_graph tracer is in use, arch_stack_walk() may unwind
the stack incorrectly, erroneously reporting itself, missing the final
entry which is being traced, and reporting all traced entries between
these off-by-one from where they should be.

When ftrace hooks a function return, the original return address is
saved to the fgraph ret_stack, and the return address  in the LR (or the
function's frame record) is replaced with `return_to_handler`.

When arm64's unwinder encounter frames returning to `return_to_handler`,
it finds the associated original return address from the fgraph ret
stack, assuming the most recent `ret_to_hander` entry on the stack
corresponds to the most recent entry in the fgraph ret stack, and so on.

When arch_stack_walk() is used to dump the current task's stack, it
starts from the caller of arch_stack_walk(). However, arch_stack_walk()
can be traced, and so may push an entry on to the fgraph ret stack,
leaving the fgraph ret stack offset by one from the expected position.

This can be seen when dumping the stack via /proc/self/stack, where
enabling the graph tracer results in an unexpected
`stack_trace_save_tsk` entry at the start of the trace, and `el0_svc`
missing form the end of the trace.

This patch fixes this by marking arch_stack_walk() as notrace, as we do
for all other functions on the path to ftrace_graph_get_ret_stack().
While a few helper functions are not marked notrace, their calls/returns
are balanced, and will have no observable effect when examining the
fgraph ret stack.

It is possible for an exeption boundary to cause a similar offset if the
return address of the interrupted context was in the LR. Fixing those
cases will require some more substantial rework, and is left for
subsequent patches.

Before:

| # cat /proc/self/stack
| [&lt;0&gt;] proc_pid_stack+0xc4/0x140
| [&lt;0&gt;] proc_single_show+0x6c/0x120
| [&lt;0&gt;] seq_read_iter+0x240/0x4e0
| [&lt;0&gt;] seq_read+0xe8/0x140
| [&lt;0&gt;] vfs_read+0xb8/0x1e4
| [&lt;0&gt;] ksys_read+0x74/0x100
| [&lt;0&gt;] __arm64_sys_read+0x28/0x3c
| [&lt;0&gt;] invoke_syscall+0x50/0x120
| [&lt;0&gt;] el0_svc_common.constprop.0+0xc4/0xd4
| [&lt;0&gt;] do_el0_svc+0x30/0x9c
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0t_64_sync_handler+0x1a8/0x1b0
| [&lt;0&gt;] el0t_64_sync+0x198/0x19c
| # echo function_graph &gt; /sys/kernel/tracing/current_tracer
| # cat /proc/self/stack
| [&lt;0&gt;] stack_trace_save_tsk+0xa4/0x110
| [&lt;0&gt;] proc_pid_stack+0xc4/0x140
| [&lt;0&gt;] proc_single_show+0x6c/0x120
| [&lt;0&gt;] seq_read_iter+0x240/0x4e0
| [&lt;0&gt;] seq_read+0xe8/0x140
| [&lt;0&gt;] vfs_read+0xb8/0x1e4
| [&lt;0&gt;] ksys_read+0x74/0x100
| [&lt;0&gt;] __arm64_sys_read+0x28/0x3c
| [&lt;0&gt;] invoke_syscall+0x50/0x120
| [&lt;0&gt;] el0_svc_common.constprop.0+0xc4/0xd4
| [&lt;0&gt;] do_el0_svc+0x30/0x9c
| [&lt;0&gt;] el0t_64_sync_handler+0x1a8/0x1b0
| [&lt;0&gt;] el0t_64_sync+0x198/0x19c

After:

| # cat /proc/self/stack
| [&lt;0&gt;] proc_pid_stack+0xc4/0x140
| [&lt;0&gt;] proc_single_show+0x6c/0x120
| [&lt;0&gt;] seq_read_iter+0x240/0x4e0
| [&lt;0&gt;] seq_read+0xe8/0x140
| [&lt;0&gt;] vfs_read+0xb8/0x1e4
| [&lt;0&gt;] ksys_read+0x74/0x100
| [&lt;0&gt;] __arm64_sys_read+0x28/0x3c
| [&lt;0&gt;] invoke_syscall+0x50/0x120
| [&lt;0&gt;] el0_svc_common.constprop.0+0xc4/0xd4
| [&lt;0&gt;] do_el0_svc+0x30/0x9c
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0t_64_sync_handler+0x1a8/0x1b0
| [&lt;0&gt;] el0t_64_sync+0x198/0x19c
| # echo function_graph &gt; /sys/kernel/tracing/current_tracer
| # cat /proc/self/stack
| [&lt;0&gt;] proc_pid_stack+0xc4/0x140
| [&lt;0&gt;] proc_single_show+0x6c/0x120
| [&lt;0&gt;] seq_read_iter+0x240/0x4e0
| [&lt;0&gt;] seq_read+0xe8/0x140
| [&lt;0&gt;] vfs_read+0xb8/0x1e4
| [&lt;0&gt;] ksys_read+0x74/0x100
| [&lt;0&gt;] __arm64_sys_read+0x28/0x3c
| [&lt;0&gt;] invoke_syscall+0x50/0x120
| [&lt;0&gt;] el0_svc_common.constprop.0+0xc4/0xd4
| [&lt;0&gt;] do_el0_svc+0x30/0x9c
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0t_64_sync_handler+0x1a8/0x1b0
| [&lt;0&gt;] el0t_64_sync+0x198/0x19c

Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Cc: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Cc: Madhavan T. Venkataraman &lt;madvenka@linux.microsoft.com&gt;
Cc: Mark Brown &lt;broonie@kernel.org&gt;
Cc: Will Deacon &lt;will@kernel.org&gt;
Reviwed-by: Mark Brown &lt;broonie@kernel.org&gt;
Link: https://lore.kernel.org/r/20210802164845.45506-3-mark.rutland@arm.com
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 0c32706dac1b0a72713184246952ab0f54327c21 upstream.

When the function_graph tracer is in use, arch_stack_walk() may unwind
the stack incorrectly, erroneously reporting itself, missing the final
entry which is being traced, and reporting all traced entries between
these off-by-one from where they should be.

When ftrace hooks a function return, the original return address is
saved to the fgraph ret_stack, and the return address  in the LR (or the
function's frame record) is replaced with `return_to_handler`.

When arm64's unwinder encounter frames returning to `return_to_handler`,
it finds the associated original return address from the fgraph ret
stack, assuming the most recent `ret_to_hander` entry on the stack
corresponds to the most recent entry in the fgraph ret stack, and so on.

When arch_stack_walk() is used to dump the current task's stack, it
starts from the caller of arch_stack_walk(). However, arch_stack_walk()
can be traced, and so may push an entry on to the fgraph ret stack,
leaving the fgraph ret stack offset by one from the expected position.

This can be seen when dumping the stack via /proc/self/stack, where
enabling the graph tracer results in an unexpected
`stack_trace_save_tsk` entry at the start of the trace, and `el0_svc`
missing form the end of the trace.

This patch fixes this by marking arch_stack_walk() as notrace, as we do
for all other functions on the path to ftrace_graph_get_ret_stack().
While a few helper functions are not marked notrace, their calls/returns
are balanced, and will have no observable effect when examining the
fgraph ret stack.

It is possible for an exeption boundary to cause a similar offset if the
return address of the interrupted context was in the LR. Fixing those
cases will require some more substantial rework, and is left for
subsequent patches.

Before:

| # cat /proc/self/stack
| [&lt;0&gt;] proc_pid_stack+0xc4/0x140
| [&lt;0&gt;] proc_single_show+0x6c/0x120
| [&lt;0&gt;] seq_read_iter+0x240/0x4e0
| [&lt;0&gt;] seq_read+0xe8/0x140
| [&lt;0&gt;] vfs_read+0xb8/0x1e4
| [&lt;0&gt;] ksys_read+0x74/0x100
| [&lt;0&gt;] __arm64_sys_read+0x28/0x3c
| [&lt;0&gt;] invoke_syscall+0x50/0x120
| [&lt;0&gt;] el0_svc_common.constprop.0+0xc4/0xd4
| [&lt;0&gt;] do_el0_svc+0x30/0x9c
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0t_64_sync_handler+0x1a8/0x1b0
| [&lt;0&gt;] el0t_64_sync+0x198/0x19c
| # echo function_graph &gt; /sys/kernel/tracing/current_tracer
| # cat /proc/self/stack
| [&lt;0&gt;] stack_trace_save_tsk+0xa4/0x110
| [&lt;0&gt;] proc_pid_stack+0xc4/0x140
| [&lt;0&gt;] proc_single_show+0x6c/0x120
| [&lt;0&gt;] seq_read_iter+0x240/0x4e0
| [&lt;0&gt;] seq_read+0xe8/0x140
| [&lt;0&gt;] vfs_read+0xb8/0x1e4
| [&lt;0&gt;] ksys_read+0x74/0x100
| [&lt;0&gt;] __arm64_sys_read+0x28/0x3c
| [&lt;0&gt;] invoke_syscall+0x50/0x120
| [&lt;0&gt;] el0_svc_common.constprop.0+0xc4/0xd4
| [&lt;0&gt;] do_el0_svc+0x30/0x9c
| [&lt;0&gt;] el0t_64_sync_handler+0x1a8/0x1b0
| [&lt;0&gt;] el0t_64_sync+0x198/0x19c

After:

| # cat /proc/self/stack
| [&lt;0&gt;] proc_pid_stack+0xc4/0x140
| [&lt;0&gt;] proc_single_show+0x6c/0x120
| [&lt;0&gt;] seq_read_iter+0x240/0x4e0
| [&lt;0&gt;] seq_read+0xe8/0x140
| [&lt;0&gt;] vfs_read+0xb8/0x1e4
| [&lt;0&gt;] ksys_read+0x74/0x100
| [&lt;0&gt;] __arm64_sys_read+0x28/0x3c
| [&lt;0&gt;] invoke_syscall+0x50/0x120
| [&lt;0&gt;] el0_svc_common.constprop.0+0xc4/0xd4
| [&lt;0&gt;] do_el0_svc+0x30/0x9c
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0t_64_sync_handler+0x1a8/0x1b0
| [&lt;0&gt;] el0t_64_sync+0x198/0x19c
| # echo function_graph &gt; /sys/kernel/tracing/current_tracer
| # cat /proc/self/stack
| [&lt;0&gt;] proc_pid_stack+0xc4/0x140
| [&lt;0&gt;] proc_single_show+0x6c/0x120
| [&lt;0&gt;] seq_read_iter+0x240/0x4e0
| [&lt;0&gt;] seq_read+0xe8/0x140
| [&lt;0&gt;] vfs_read+0xb8/0x1e4
| [&lt;0&gt;] ksys_read+0x74/0x100
| [&lt;0&gt;] __arm64_sys_read+0x28/0x3c
| [&lt;0&gt;] invoke_syscall+0x50/0x120
| [&lt;0&gt;] el0_svc_common.constprop.0+0xc4/0xd4
| [&lt;0&gt;] do_el0_svc+0x30/0x9c
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0t_64_sync_handler+0x1a8/0x1b0
| [&lt;0&gt;] el0t_64_sync+0x198/0x19c

Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Cc: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Cc: Madhavan T. Venkataraman &lt;madvenka@linux.microsoft.com&gt;
Cc: Mark Brown &lt;broonie@kernel.org&gt;
Cc: Will Deacon &lt;will@kernel.org&gt;
Reviwed-by: Mark Brown &lt;broonie@kernel.org&gt;
Link: https://lore.kernel.org/r/20210802164845.45506-3-mark.rutland@arm.com
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: stacktrace: don't trace arch_stack_walk()</title>
<updated>2021-03-30T12:31:54+00:00</updated>
<author>
<name>Mark Rutland</name>
<email>mark.rutland@arm.com</email>
</author>
<published>2021-03-19T18:41:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=1ced45535d4bb8df3d84e41534dbe67c58c01955'/>
<id>1ced45535d4bb8df3d84e41534dbe67c58c01955</id>
<content type='text'>
commit c607ab4f916d4d5259072eca34055d3f5a795c21 upstream.

We recently converted arm64 to use arch_stack_walk() in commit:

  5fc57df2f6fd ("arm64: stacktrace: Convert to ARCH_STACKWALK")

The core stacktrace code expects that (when tracing the current task)
arch_stack_walk() starts a trace at its caller, and does not include
itself in the trace. However, arm64's arch_stack_walk() includes itself,
and so traces include one more entry than callers expect. The core
stacktrace code which calls arch_stack_walk() tries to skip a number of
entries to prevent itself appearing in a trace, and the additional entry
prevents skipping one of the core stacktrace functions, leaving this in
the trace unexpectedly.

We can fix this by having arm64's arch_stack_walk() begin the trace with
its caller. The first value returned by the trace will be
__builtin_return_address(0), i.e. the caller of arch_stack_walk(). The
first frame record to be unwound will be __builtin_frame_address(1),
i.e. the caller's frame record. To prevent surprises, arch_stack_walk()
is also marked noinline.

While __builtin_frame_address(1) is not safe in portable code, local GCC
developers have confirmed that it is safe on arm64. To find the caller's
frame record, the builtin can safely dereference the current function's
frame record or (in theory) could stash the original FP into another GPR
at function entry time, neither of which are problematic.

Prior to this patch, the tracing code would unexpectedly show up in
traces of the current task, e.g.

| # cat /proc/self/stack
| [&lt;0&gt;] stack_trace_save_tsk+0x98/0x100
| [&lt;0&gt;] proc_pid_stack+0xb4/0x130
| [&lt;0&gt;] proc_single_show+0x60/0x110
| [&lt;0&gt;] seq_read_iter+0x230/0x4d0
| [&lt;0&gt;] seq_read+0xdc/0x130
| [&lt;0&gt;] vfs_read+0xac/0x1e0
| [&lt;0&gt;] ksys_read+0x6c/0xfc
| [&lt;0&gt;] __arm64_sys_read+0x20/0x30
| [&lt;0&gt;] el0_svc_common.constprop.0+0x60/0x120
| [&lt;0&gt;] do_el0_svc+0x24/0x90
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0_sync_handler+0x1a4/0x1b0
| [&lt;0&gt;] el0_sync+0x170/0x180

After this patch, the tracing code will not show up in such traces:

| # cat /proc/self/stack
| [&lt;0&gt;] proc_pid_stack+0xb4/0x130
| [&lt;0&gt;] proc_single_show+0x60/0x110
| [&lt;0&gt;] seq_read_iter+0x230/0x4d0
| [&lt;0&gt;] seq_read+0xdc/0x130
| [&lt;0&gt;] vfs_read+0xac/0x1e0
| [&lt;0&gt;] ksys_read+0x6c/0xfc
| [&lt;0&gt;] __arm64_sys_read+0x20/0x30
| [&lt;0&gt;] el0_svc_common.constprop.0+0x60/0x120
| [&lt;0&gt;] do_el0_svc+0x24/0x90
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0_sync_handler+0x1a4/0x1b0
| [&lt;0&gt;] el0_sync+0x170/0x180

Erring on the side of caution, I've given this a spin with a bunch of
toolchains, verifying the output of /proc/self/stack and checking that
the assembly looked sound. For GCC (where we require version 5.1.0 or
later) I tested with the kernel.org crosstool binares for versions
5.5.0, 6.4.0, 6.5.0, 7.3.0, 7.5.0, 8.1.0, 8.3.0, 8.4.0, 9.2.0, and
10.1.0. For clang (where we require version 10.0.1 or later) I tested
with the llvm.org binary releases of 11.0.0, and 11.0.1.

Fixes: 5fc57df2f6fd ("arm64: stacktrace: Convert to ARCH_STACKWALK")
Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Cc: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Cc: Chen Jun &lt;chenjun102@huawei.com&gt;
Cc: Marco Elver &lt;elver@google.com&gt;
Cc: Mark Brown &lt;broonie@kernel.org&gt;
Cc: Will Deacon &lt;will@kernel.org&gt;
Cc: &lt;stable@vger.kernel.org&gt; # 5.10.x
Reviewed-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Reviewed-by: Mark Brown &lt;broonie@kernel.org&gt;
Link: https://lore.kernel.org/r/20210319184106.5688-1-mark.rutland@arm.com
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit c607ab4f916d4d5259072eca34055d3f5a795c21 upstream.

We recently converted arm64 to use arch_stack_walk() in commit:

  5fc57df2f6fd ("arm64: stacktrace: Convert to ARCH_STACKWALK")

The core stacktrace code expects that (when tracing the current task)
arch_stack_walk() starts a trace at its caller, and does not include
itself in the trace. However, arm64's arch_stack_walk() includes itself,
and so traces include one more entry than callers expect. The core
stacktrace code which calls arch_stack_walk() tries to skip a number of
entries to prevent itself appearing in a trace, and the additional entry
prevents skipping one of the core stacktrace functions, leaving this in
the trace unexpectedly.

We can fix this by having arm64's arch_stack_walk() begin the trace with
its caller. The first value returned by the trace will be
__builtin_return_address(0), i.e. the caller of arch_stack_walk(). The
first frame record to be unwound will be __builtin_frame_address(1),
i.e. the caller's frame record. To prevent surprises, arch_stack_walk()
is also marked noinline.

While __builtin_frame_address(1) is not safe in portable code, local GCC
developers have confirmed that it is safe on arm64. To find the caller's
frame record, the builtin can safely dereference the current function's
frame record or (in theory) could stash the original FP into another GPR
at function entry time, neither of which are problematic.

Prior to this patch, the tracing code would unexpectedly show up in
traces of the current task, e.g.

| # cat /proc/self/stack
| [&lt;0&gt;] stack_trace_save_tsk+0x98/0x100
| [&lt;0&gt;] proc_pid_stack+0xb4/0x130
| [&lt;0&gt;] proc_single_show+0x60/0x110
| [&lt;0&gt;] seq_read_iter+0x230/0x4d0
| [&lt;0&gt;] seq_read+0xdc/0x130
| [&lt;0&gt;] vfs_read+0xac/0x1e0
| [&lt;0&gt;] ksys_read+0x6c/0xfc
| [&lt;0&gt;] __arm64_sys_read+0x20/0x30
| [&lt;0&gt;] el0_svc_common.constprop.0+0x60/0x120
| [&lt;0&gt;] do_el0_svc+0x24/0x90
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0_sync_handler+0x1a4/0x1b0
| [&lt;0&gt;] el0_sync+0x170/0x180

After this patch, the tracing code will not show up in such traces:

| # cat /proc/self/stack
| [&lt;0&gt;] proc_pid_stack+0xb4/0x130
| [&lt;0&gt;] proc_single_show+0x60/0x110
| [&lt;0&gt;] seq_read_iter+0x230/0x4d0
| [&lt;0&gt;] seq_read+0xdc/0x130
| [&lt;0&gt;] vfs_read+0xac/0x1e0
| [&lt;0&gt;] ksys_read+0x6c/0xfc
| [&lt;0&gt;] __arm64_sys_read+0x20/0x30
| [&lt;0&gt;] el0_svc_common.constprop.0+0x60/0x120
| [&lt;0&gt;] do_el0_svc+0x24/0x90
| [&lt;0&gt;] el0_svc+0x2c/0x54
| [&lt;0&gt;] el0_sync_handler+0x1a4/0x1b0
| [&lt;0&gt;] el0_sync+0x170/0x180

Erring on the side of caution, I've given this a spin with a bunch of
toolchains, verifying the output of /proc/self/stack and checking that
the assembly looked sound. For GCC (where we require version 5.1.0 or
later) I tested with the kernel.org crosstool binares for versions
5.5.0, 6.4.0, 6.5.0, 7.3.0, 7.5.0, 8.1.0, 8.3.0, 8.4.0, 9.2.0, and
10.1.0. For clang (where we require version 10.0.1 or later) I tested
with the llvm.org binary releases of 11.0.0, and 11.0.1.

Fixes: 5fc57df2f6fd ("arm64: stacktrace: Convert to ARCH_STACKWALK")
Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Cc: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Cc: Chen Jun &lt;chenjun102@huawei.com&gt;
Cc: Marco Elver &lt;elver@google.com&gt;
Cc: Mark Brown &lt;broonie@kernel.org&gt;
Cc: Will Deacon &lt;will@kernel.org&gt;
Cc: &lt;stable@vger.kernel.org&gt; # 5.10.x
Reviewed-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Reviewed-by: Mark Brown &lt;broonie@kernel.org&gt;
Link: https://lore.kernel.org/r/20210319184106.5688-1-mark.rutland@arm.com
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: Move console stack display code to stacktrace.c</title>
<updated>2020-09-21T18:43:03+00:00</updated>
<author>
<name>Mark Brown</name>
<email>broonie@kernel.org</email>
</author>
<published>2020-09-21T12:23:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=9e0f085c2b33ebe13bcec53cbacce505fe78fde7'/>
<id>9e0f085c2b33ebe13bcec53cbacce505fe78fde7</id>
<content type='text'>
Currently the code for displaying a stack trace on the console is located
in traps.c rather than stacktrace.c, using the unwinding code that is in
stacktrace.c. This can be confusing and make the code hard to find since
such output is often referred to as a stack trace which might mislead the
unwary. Due to this and since traps.c doesn't interact with this code
except for via the public interfaces move the code to stacktrace.c to
make it easier to find.

Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Link: https://lore.kernel.org/r/20200921122341.11280-1-broonie@kernel.org
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Currently the code for displaying a stack trace on the console is located
in traps.c rather than stacktrace.c, using the unwinding code that is in
stacktrace.c. This can be confusing and make the code hard to find since
such output is often referred to as a stack trace which might mislead the
unwary. Due to this and since traps.c doesn't interact with this code
except for via the public interfaces move the code to stacktrace.c to
make it easier to find.

Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Link: https://lore.kernel.org/r/20200921122341.11280-1-broonie@kernel.org
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: stacktrace: Convert to ARCH_STACKWALK</title>
<updated>2020-09-18T13:24:16+00:00</updated>
<author>
<name>Mark Brown</name>
<email>broonie@kernel.org</email>
</author>
<published>2020-09-14T15:34:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=5fc57df2f6fdc18b9f9273f98318ff7919968c2c'/>
<id>5fc57df2f6fdc18b9f9273f98318ff7919968c2c</id>
<content type='text'>
Historically architectures have had duplicated code in their stack trace
implementations for filtering what gets traced. In order to avoid this
duplication some generic code has been provided using a new interface
arch_stack_walk(), enabled by selecting ARCH_STACKWALK in Kconfig, which
factors all this out into the generic stack trace code. Convert arm64
to use this common infrastructure.

Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Reviewed-by: Miroslav Benes &lt;mbenes@suse.cz&gt;
Link: https://lore.kernel.org/r/20200914153409.25097-4-broonie@kernel.org
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Historically architectures have had duplicated code in their stack trace
implementations for filtering what gets traced. In order to avoid this
duplication some generic code has been provided using a new interface
arch_stack_walk(), enabled by selecting ARCH_STACKWALK in Kconfig, which
factors all this out into the generic stack trace code. Convert arm64
to use this common infrastructure.

Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Reviewed-by: Miroslav Benes &lt;mbenes@suse.cz&gt;
Link: https://lore.kernel.org/r/20200914153409.25097-4-broonie@kernel.org
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: stacktrace: Make stack walk callback consistent with generic code</title>
<updated>2020-09-18T13:24:16+00:00</updated>
<author>
<name>Mark Brown</name>
<email>broonie@kernel.org</email>
</author>
<published>2020-09-14T15:34:08+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=baa2cd417053cb674deb90ee66b88afea0517335'/>
<id>baa2cd417053cb674deb90ee66b88afea0517335</id>
<content type='text'>
As with the generic arch_stack_walk() code the arm64 stack walk code takes
a callback that is called per stack frame. Currently the arm64 code always
passes a struct stackframe to the callback and the generic code just passes
the pc, however none of the users ever reference anything in the struct
other than the pc value. The arm64 code also uses a return type of int
while the generic code uses a return type of bool though in both cases the
return value is a boolean value and the sense is inverted between the two.

In order to reduce code duplication when arm64 is converted to use
arch_stack_walk() change the signature and return sense of the arm64
specific callback to match that of the generic code.

Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Reviewed-by: Miroslav Benes &lt;mbenes@suse.cz&gt;
Link: https://lore.kernel.org/r/20200914153409.25097-3-broonie@kernel.org
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As with the generic arch_stack_walk() code the arm64 stack walk code takes
a callback that is called per stack frame. Currently the arm64 code always
passes a struct stackframe to the callback and the generic code just passes
the pc, however none of the users ever reference anything in the struct
other than the pc value. The arm64 code also uses a return type of int
while the generic code uses a return type of bool though in both cases the
return value is a boolean value and the sense is inverted between the two.

In order to reduce code duplication when arm64 is converted to use
arch_stack_walk() change the signature and return sense of the arm64
specific callback to match that of the generic code.

Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Reviewed-by: Miroslav Benes &lt;mbenes@suse.cz&gt;
Link: https://lore.kernel.org/r/20200914153409.25097-3-broonie@kernel.org
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: stacktrace: Move export for save_stack_trace_tsk()</title>
<updated>2020-07-14T18:16:25+00:00</updated>
<author>
<name>Mark Brown</name>
<email>broonie@kernel.org</email>
</author>
<published>2020-07-10T18:24:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=0de674afe83cb23676ec391470251aaa9700f21a'/>
<id>0de674afe83cb23676ec391470251aaa9700f21a</id>
<content type='text'>
Due to refactoring way back in bb53c820c5b0f1 ("arm64: stacktrace: avoid
listing stacktrace functions in stacktrace") the EXPORT_SYMBOL_GPL() for
save_stack_trace_tsk() is at the end of __save_stack_trace() rather than
the function it exports. Move it to the expected location.

Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Acked-by: Will Deacon &lt;will@kernel.org&gt;
Link: https://lore.kernel.org/r/20200710182402.50473-1-broonie@kernel.org
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Due to refactoring way back in bb53c820c5b0f1 ("arm64: stacktrace: avoid
listing stacktrace functions in stacktrace") the EXPORT_SYMBOL_GPL() for
save_stack_trace_tsk() is at the end of __save_stack_trace() rather than
the function it exports. Move it to the expected location.

Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
Acked-by: Will Deacon &lt;will@kernel.org&gt;
Link: https://lore.kernel.org/r/20200710182402.50473-1-broonie@kernel.org
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: unwind: strip PAC from kernel addresses</title>
<updated>2020-03-18T09:50:20+00:00</updated>
<author>
<name>Mark Rutland</name>
<email>mark.rutland@arm.com</email>
</author>
<published>2020-03-13T09:04:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=04ad99a0b160450ae615e41b839e444eccb5c99b'/>
<id>04ad99a0b160450ae615e41b839e444eccb5c99b</id>
<content type='text'>
When we enable pointer authentication in the kernel, LR values saved to
the stack will have a PAC which we must strip in order to retrieve the
real return address.

Strip PACs when unwinding the stack in order to account for this.

When function graph tracer is used with patchable-function-entry then
return_to_handler will also have pac bits so strip it too.

Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Acked-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Reviewed-by: James Morse &lt;james.morse@arm.com&gt;
Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Signed-off-by: Kristina Martsenko &lt;kristina.martsenko@arm.com&gt;
[Amit: Re-position ptrauth_strip_insn_pac, comment]
Signed-off-by: Amit Daniel Kachhap &lt;amit.kachhap@arm.com&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When we enable pointer authentication in the kernel, LR values saved to
the stack will have a PAC which we must strip in order to retrieve the
real return address.

Strip PACs when unwinding the stack in order to account for this.

When function graph tracer is used with patchable-function-entry then
return_to_handler will also have pac bits so strip it too.

Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Acked-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Reviewed-by: James Morse &lt;james.morse@arm.com&gt;
Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Signed-off-by: Kristina Martsenko &lt;kristina.martsenko@arm.com&gt;
[Amit: Re-position ptrauth_strip_insn_pac, comment]
Signed-off-by: Amit Daniel Kachhap &lt;amit.kachhap@arm.com&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: unwind: Prohibit probing on return_address()</title>
<updated>2019-08-01T14:00:26+00:00</updated>
<author>
<name>Masami Hiramatsu</name>
<email>mhiramat@kernel.org</email>
</author>
<published>2019-07-25T08:16:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=ee07b93e7721ccd5d5b9fa6f0c10cb3fe2f1f4f9'/>
<id>ee07b93e7721ccd5d5b9fa6f0c10cb3fe2f1f4f9</id>
<content type='text'>
Prohibit probing on return_address() and subroutines which
is called from return_address(), since the it is invoked from
trace_hardirqs_off() which is also kprobe blacklisted.

Reported-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
Signed-off-by: Masami Hiramatsu &lt;mhiramat@kernel.org&gt;
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Prohibit probing on return_address() and subroutines which
is called from return_address(), since the it is invoked from
trace_hardirqs_off() which is also kprobe blacklisted.

Reported-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
Signed-off-by: Masami Hiramatsu &lt;mhiramat@kernel.org&gt;
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: stacktrace: Better handle corrupted stacks</title>
<updated>2019-07-22T10:44:15+00:00</updated>
<author>
<name>Mark Rutland</name>
<email>mark.rutland@arm.com</email>
</author>
<published>2019-07-02T13:07:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=592700f094be229b5c9cc1192d5cea46eb4c7afc'/>
<id>592700f094be229b5c9cc1192d5cea46eb4c7afc</id>
<content type='text'>
The arm64 stacktrace code is careful to only dereference frame records
in valid stack ranges, ensuring that a corrupted frame record won't
result in a faulting access.

However, it's still possible for corrupt frame records to result in
infinite loops in the stacktrace code, which is also undesirable.

This patch ensures that we complete a stacktrace in finite time, by
keeping track of which stacks we have already completed unwinding, and
verifying that if the next frame record is on the same stack, it is at a
higher address.

As this has turned out to be particularly subtle, comments are added to
explain the procedure.

Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Reviewed-by: James Morse &lt;james.morse@arm.com&gt;
Tested-by: James Morse &lt;james.morse@arm.com&gt;
Acked-by: Dave Martin &lt;Dave.Martin@arm.com&gt;
Acked-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Cc: Tengfei Fan &lt;tengfeif@codeaurora.org&gt;
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The arm64 stacktrace code is careful to only dereference frame records
in valid stack ranges, ensuring that a corrupted frame record won't
result in a faulting access.

However, it's still possible for corrupt frame records to result in
infinite loops in the stacktrace code, which is also undesirable.

This patch ensures that we complete a stacktrace in finite time, by
keeping track of which stacks we have already completed unwinding, and
verifying that if the next frame record is on the same stack, it is at a
higher address.

As this has turned out to be particularly subtle, comments are added to
explain the procedure.

Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Reviewed-by: James Morse &lt;james.morse@arm.com&gt;
Tested-by: James Morse &lt;james.morse@arm.com&gt;
Acked-by: Dave Martin &lt;Dave.Martin@arm.com&gt;
Acked-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Cc: Tengfei Fan &lt;tengfeif@codeaurora.org&gt;
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: stacktrace: Factor out backtrace initialisation</title>
<updated>2019-07-22T10:44:08+00:00</updated>
<author>
<name>Dave Martin</name>
<email>Dave.Martin@arm.com</email>
</author>
<published>2019-07-02T13:07:28+00:00</published>
<link rel='alternate' type='text/html' href='https://git.exis.tech/linux.git/commit/?id=f3dcbe67ed424f1cf92065f9ad0cc647f2b44eac'/>
<id>f3dcbe67ed424f1cf92065f9ad0cc647f2b44eac</id>
<content type='text'>
Some common code is required by each stacktrace user to initialise
struct stackframe before the first call to unwind_frame().

In preparation for adding to the common code, this patch factors it
out into a separate function start_backtrace(), and modifies the
stacktrace callers appropriately.

No functional change.

Signed-off-by: Dave Martin &lt;dave.martin@arm.com&gt;
[Mark: drop tsk argument, update more callsites]
Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Reviewed-by: James Morse &lt;james.morse@arm.com&gt;
Acked-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Some common code is required by each stacktrace user to initialise
struct stackframe before the first call to unwind_frame().

In preparation for adding to the common code, this patch factors it
out into a separate function start_backtrace(), and modifies the
stacktrace callers appropriately.

No functional change.

Signed-off-by: Dave Martin &lt;dave.martin@arm.com&gt;
[Mark: drop tsk argument, update more callsites]
Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Reviewed-by: James Morse &lt;james.morse@arm.com&gt;
Acked-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Signed-off-by: Will Deacon &lt;will@kernel.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
