mbox series

[0/2] arm64: stacktrace: add kunwind_stack_walk()

Message ID 20231124110511.2795958-1-mark.rutland@arm.com (mailing list archive)
Headers show
Series arm64: stacktrace: add kunwind_stack_walk() | expand

Message

Mark Rutland Nov. 24, 2023, 11:05 a.m. UTC
Currently arm64 uses the generic arch_stack_walk() interface for all
stack walking code. This only passes a PC value and cookie to the unwind
callback, whereas we'd like to pass some additional information in some
cases. For example, the BPF exception unwinder wants the FP, for
reliable stacktrace we'll want to perform additional checks on other
portions of unwind state, and we'd like to expand the information
printed by dump_backtrace() to include provenance and reliability
information.

These patches refactor arm64's stacktrace code into a new
kunwind_stack_walk() function that provides the full unwind state to
callback functions. The existing arch_stack_walk() interface is
unchanged, and is implemented atop kunwind_stack_walk().

I had originally intended to send this with additional patches that
would have dump_backtrace() use this to identify and report exception
boundaries and fgraph/kretprobes PC recovery, but due to LPC and bug
hunting over the last few weeks I haven't managed to get all of that
ready just yet.

Puranjay has a need for this for BPF:

  https://lore.kernel.org/linux-arm-kernel/20230917000045.56377-1-puranjay12@gmail.com/

Hence I'm sending this as-is as preparatory rework.

Thanks,
Mark.

Mark Rutland (2):
  arm64: stacktrace: factor out kernel unwind state
  arm64: stacktrace: factor out kunwind_stack_walk()

 arch/arm64/include/asm/stacktrace/common.h |  19 +--
 arch/arm64/include/asm/stacktrace/nvhe.h   |   2 +-
 arch/arm64/kernel/stacktrace.c             | 146 ++++++++++++++-------
 3 files changed, 104 insertions(+), 63 deletions(-)

Comments

Mark Brown Nov. 24, 2023, 12:32 p.m. UTC | #1
On Fri, Nov 24, 2023 at 11:05:09AM +0000, Mark Rutland wrote:

> Puranjay has a need for this for BPF:

>   https://lore.kernel.org/linux-arm-kernel/20230917000045.56377-1-puranjay12@gmail.com/

> Hence I'm sending this as-is as preparatory rework.

This will also be useful for joining GCS up with the stacktrace
infrastructure (for reliability checks if nothing else):

Reviewed-by: Mark Brown <broonie@kernel.org>
Madhavan T. Venkataraman Nov. 27, 2023, 4:31 p.m. UTC | #2
On 11/24/23 05:05, Mark Rutland wrote:
> Currently arm64 uses the generic arch_stack_walk() interface for all
> stack walking code. This only passes a PC value and cookie to the unwind
> callback, whereas we'd like to pass some additional information in some
> cases. For example, the BPF exception unwinder wants the FP, for
> reliable stacktrace we'll want to perform additional checks on other
> portions of unwind state, and we'd like to expand the information
> printed by dump_backtrace() to include provenance and reliability
> information.
> 
> These patches refactor arm64's stacktrace code into a new
> kunwind_stack_walk() function that provides the full unwind state to
> callback functions. The existing arch_stack_walk() interface is
> unchanged, and is implemented atop kunwind_stack_walk().
> 
> I had originally intended to send this with additional patches that
> would have dump_backtrace() use this to identify and report exception
> boundaries and fgraph/kretprobes PC recovery, but due to LPC and bug
> hunting over the last few weeks I haven't managed to get all of that
> ready just yet.
> 
> Puranjay has a need for this for BPF:
> 
>   https://lore.kernel.org/linux-arm-kernel/20230917000045.56377-1-puranjay12@gmail.com/
> 
> Hence I'm sending this as-is as preparatory rework.
> 
> Thanks,
> Mark.
> 
> Mark Rutland (2):
>   arm64: stacktrace: factor out kernel unwind state
>   arm64: stacktrace: factor out kunwind_stack_walk()
> 
>  arch/arm64/include/asm/stacktrace/common.h |  19 +--
>  arch/arm64/include/asm/stacktrace/nvhe.h   |   2 +-
>  arch/arm64/kernel/stacktrace.c             | 146 ++++++++++++++-------
>  3 files changed, 104 insertions(+), 63 deletions(-)
> 

Reviewed-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
Will Deacon Dec. 11, 2023, 8:27 p.m. UTC | #3
On Fri, 24 Nov 2023 11:05:09 +0000, Mark Rutland wrote:
> Currently arm64 uses the generic arch_stack_walk() interface for all
> stack walking code. This only passes a PC value and cookie to the unwind
> callback, whereas we'd like to pass some additional information in some
> cases. For example, the BPF exception unwinder wants the FP, for
> reliable stacktrace we'll want to perform additional checks on other
> portions of unwind state, and we'd like to expand the information
> printed by dump_backtrace() to include provenance and reliability
> information.
> 
> [...]

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

[1/2] arm64: stacktrace: factor out kernel unwind state
      https://git.kernel.org/arm64/c/1beef60e7d6b
[2/2] arm64: stacktrace: factor out kunwind_stack_walk()
      https://git.kernel.org/arm64/c/1aba06e7b2b4

Cheers,