All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] arm64: stacktrace: minor fixes
@ 2021-08-02 16:48 Mark Rutland
  2021-08-02 16:48 ` [PATCH 1/2] arm64: stacktrace: fix comment Mark Rutland
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mark Rutland @ 2021-08-02 16:48 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, catalin.marinas, madvenka, mark.rutland, will

These patches address a couple of minor issues I spotted while reviewing
arm64's stacktrace code. Patch 1 is a simple comment fix, and patch 2
addresses an imbalance across the main stack and the fgraph return
stack.

Thanks,
Mark

Mark Rutland (2):
  arm64: stacktrace: fix comment
  arm64: stacktrace: avoid tracing arch_stack_walk()

 arch/arm64/include/asm/stacktrace.h | 2 +-
 arch/arm64/kernel/stacktrace.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.11.0


_______________________________________________
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] 6+ messages in thread

* [PATCH 1/2] arm64: stacktrace: fix comment
  2021-08-02 16:48 [PATCH 0/2] arm64: stacktrace: minor fixes Mark Rutland
@ 2021-08-02 16:48 ` Mark Rutland
  2021-08-02 16:53   ` Mark Brown
  2021-08-02 16:48 ` [PATCH 2/2] arm64: stacktrace: avoid tracing arch_stack_walk() Mark Rutland
  2021-08-03 10:05 ` [PATCH 0/2] arm64: stacktrace: minor fixes Will Deacon
  2 siblings, 1 reply; 6+ messages in thread
From: Mark Rutland @ 2021-08-02 16:48 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, catalin.marinas, madvenka, mark.rutland, will

Due to a copy-paste error, we describe struct stackframe::pc as a
snapshot of the `fp` field rather than the `lr` field.

Fix the comment.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/include/asm/stacktrace.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h
index 1801399204d7..8aebc00c1718 100644
--- a/arch/arm64/include/asm/stacktrace.h
+++ b/arch/arm64/include/asm/stacktrace.h
@@ -35,7 +35,7 @@ struct stack_info {
  * accounting information necessary for robust unwinding.
  *
  * @fp:          The fp value in the frame record (or the real fp)
- * @pc:          The fp value in the frame record (or the real lr)
+ * @pc:          The lr value in the frame record (or the real lr)
  *
  * @stacks_done: Stacks which have been entirely unwound, for which it is no
  *               longer valid to unwind to.
-- 
2.11.0


_______________________________________________
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] 6+ messages in thread

* [PATCH 2/2] arm64: stacktrace: avoid tracing arch_stack_walk()
  2021-08-02 16:48 [PATCH 0/2] arm64: stacktrace: minor fixes Mark Rutland
  2021-08-02 16:48 ` [PATCH 1/2] arm64: stacktrace: fix comment Mark Rutland
@ 2021-08-02 16:48 ` Mark Rutland
  2021-08-02 17:18   ` Mark Brown
  2021-08-03 10:05 ` [PATCH 0/2] arm64: stacktrace: minor fixes Will Deacon
  2 siblings, 1 reply; 6+ messages in thread
From: Mark Rutland @ 2021-08-02 16:48 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, catalin.marinas, madvenka, mark.rutland, will

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 the an exeption boundary to cause a similar offset if
the return address of the interrupted context was in the LR. Fixing
those case will require some more substantial rework, and is left for
subsequent patches.

Before:

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

After:

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

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Will Deacon <will@kernel.org>
---
 arch/arm64/kernel/stacktrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index b83c8d911930..8982a2b78acf 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -218,7 +218,7 @@ void show_stack(struct task_struct *tsk, unsigned long *sp, const char *loglvl)
 
 #ifdef CONFIG_STACKTRACE
 
-noinline void arch_stack_walk(stack_trace_consume_fn consume_entry,
+noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry,
 			      void *cookie, struct task_struct *task,
 			      struct pt_regs *regs)
 {
-- 
2.11.0


_______________________________________________
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] 6+ messages in thread

* Re: [PATCH 1/2] arm64: stacktrace: fix comment
  2021-08-02 16:48 ` [PATCH 1/2] arm64: stacktrace: fix comment Mark Rutland
@ 2021-08-02 16:53   ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2021-08-02 16:53 UTC (permalink / raw)
  To: Mark Rutland; +Cc: linux-arm-kernel, catalin.marinas, madvenka, will


[-- Attachment #1.1: Type: text/plain, Size: 262 bytes --]

On Mon, Aug 02, 2021 at 05:48:44PM +0100, Mark Rutland wrote:
> Due to a copy-paste error, we describe struct stackframe::pc as a
> snapshot of the `fp` field rather than the `lr` field.
> 
> Fix the comment.

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
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] 6+ messages in thread

* Re: [PATCH 2/2] arm64: stacktrace: avoid tracing arch_stack_walk()
  2021-08-02 16:48 ` [PATCH 2/2] arm64: stacktrace: avoid tracing arch_stack_walk() Mark Rutland
@ 2021-08-02 17:18   ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2021-08-02 17:18 UTC (permalink / raw)
  To: Mark Rutland; +Cc: linux-arm-kernel, catalin.marinas, madvenka, will


[-- Attachment #1.1: Type: text/plain, Size: 371 bytes --]

On Mon, Aug 02, 2021 at 05:48:45PM +0100, Mark Rutland wrote:
> 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.

Reviwed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
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] 6+ messages in thread

* Re: [PATCH 0/2] arm64: stacktrace: minor fixes
  2021-08-02 16:48 [PATCH 0/2] arm64: stacktrace: minor fixes Mark Rutland
  2021-08-02 16:48 ` [PATCH 1/2] arm64: stacktrace: fix comment Mark Rutland
  2021-08-02 16:48 ` [PATCH 2/2] arm64: stacktrace: avoid tracing arch_stack_walk() Mark Rutland
@ 2021-08-03 10:05 ` Will Deacon
  2 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2021-08-03 10:05 UTC (permalink / raw)
  To: Mark Rutland, linux-arm-kernel
  Cc: catalin.marinas, kernel-team, Will Deacon, madvenka, broonie

On Mon, 2 Aug 2021 17:48:43 +0100, Mark Rutland wrote:
> These patches address a couple of minor issues I spotted while reviewing
> arm64's stacktrace code. Patch 1 is a simple comment fix, and patch 2
> addresses an imbalance across the main stack and the fgraph return
> stack.
> 
> Thanks,
> Mark
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/2] arm64: stacktrace: fix comment
      https://git.kernel.org/arm64/c/8d5903f45714
[2/2] arm64: stacktrace: avoid tracing arch_stack_walk()
      https://git.kernel.org/arm64/c/0c32706dac1b

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
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] 6+ messages in thread

end of thread, other threads:[~2021-08-03 10:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 16:48 [PATCH 0/2] arm64: stacktrace: minor fixes Mark Rutland
2021-08-02 16:48 ` [PATCH 1/2] arm64: stacktrace: fix comment Mark Rutland
2021-08-02 16:53   ` Mark Brown
2021-08-02 16:48 ` [PATCH 2/2] arm64: stacktrace: avoid tracing arch_stack_walk() Mark Rutland
2021-08-02 17:18   ` Mark Brown
2021-08-03 10:05 ` [PATCH 0/2] arm64: stacktrace: minor fixes Will Deacon

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.