linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: perf: Fix stacktraces for tracepoint events in THUMB2 kernels
@ 2022-09-20 23:07 Tomislav Novak
  2022-09-22  8:57 ` Linus Walleij
  0 siblings, 1 reply; 4+ messages in thread
From: Tomislav Novak @ 2022-09-20 23:07 UTC (permalink / raw)
  To: Will Deacon
  Cc: Russell King, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, linux-arm-kernel, linux-perf-users,
	linux-kernel, Tomislav Novak

Store the frame address where arm_get_current_stackframe() looks for it
(ARM_r7 instead of ARM_fp if CONFIG_THUMB2_KERNEL=y). Otherwise frame->fp
gets set to 0, causing unwind_frame() to fail.

  # bpftrace -e 't:sched:sched_switch { @[kstack] = count(); exit(); }'
  Attaching 1 probe...
  @[
      __schedule+1059
  ]: 1

A typical first unwind instruction is 0x97 (SP = R7), so after executing
it SP ends up being 0 and -URC_FAILURE is returned.

  unwind_frame(pc = ac9da7d7 lr = 00000000 sp = c69bdda0 fp = 00000000)
  unwind_find_idx(ac9da7d7)
  unwind_exec_insn: insn = 00000097
  unwind_exec_insn: fp = 00000000 sp = 00000000 lr = 00000000 pc = 00000000

With this patch:

  # bpftrace -e 't:sched:sched_switch { @[kstack] = count(); exit(); }'
  Attaching 1 probe...
  @[
      __schedule+1059
      __schedule+1059
      schedule+79
      schedule_hrtimeout_range_clock+163
      schedule_hrtimeout_range+17
      ep_poll+471
      SyS_epoll_wait+111
      sys_epoll_pwait+231
      __ret_fast_syscall+1
  ]: 1

Signed-off-by: Tomislav Novak <tnovak@fb.com>
---
 arch/arm/include/asm/perf_event.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/perf_event.h b/arch/arm/include/asm/perf_event.h
index 4f9dec489931..c5d27140834e 100644
--- a/arch/arm/include/asm/perf_event.h
+++ b/arch/arm/include/asm/perf_event.h
@@ -21,7 +21,7 @@ extern unsigned long perf_misc_flags(struct pt_regs *regs);
 
 #define perf_arch_fetch_caller_regs(regs, __ip) { \
 	(regs)->ARM_pc = (__ip); \
-	(regs)->ARM_fp = (unsigned long) __builtin_frame_address(0); \
+	frame_pointer((regs)) = (unsigned long) __builtin_frame_address(0); \
 	(regs)->ARM_sp = current_stack_pointer; \
 	(regs)->ARM_cpsr = SVC_MODE; \
 }
-- 
2.30.2


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

* Re: [PATCH] ARM: perf: Fix stacktraces for tracepoint events in THUMB2 kernels
  2022-09-20 23:07 [PATCH] ARM: perf: Fix stacktraces for tracepoint events in THUMB2 kernels Tomislav Novak
@ 2022-09-22  8:57 ` Linus Walleij
  2022-09-23 15:05   ` Tomislav Novak
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2022-09-22  8:57 UTC (permalink / raw)
  To: Tomislav Novak
  Cc: Will Deacon, Russell King, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, linux-arm-kernel, linux-perf-users,
	linux-kernel, Arnd Bergmann

On Wed, Sep 21, 2022 at 1:19 AM Tomislav Novak <tnovak@fb.com> wrote:

> Store the frame address where arm_get_current_stackframe() looks for it
> (ARM_r7 instead of ARM_fp if CONFIG_THUMB2_KERNEL=y). Otherwise frame->fp
> gets set to 0, causing unwind_frame() to fail.
>
>   # bpftrace -e 't:sched:sched_switch { @[kstack] = count(); exit(); }'
>   Attaching 1 probe...
>   @[
>       __schedule+1059
>   ]: 1
>
> A typical first unwind instruction is 0x97 (SP = R7), so after executing
> it SP ends up being 0 and -URC_FAILURE is returned.
>
>   unwind_frame(pc = ac9da7d7 lr = 00000000 sp = c69bdda0 fp = 00000000)
>   unwind_find_idx(ac9da7d7)
>   unwind_exec_insn: insn = 00000097
>   unwind_exec_insn: fp = 00000000 sp = 00000000 lr = 00000000 pc = 00000000
>
> With this patch:
>
>   # bpftrace -e 't:sched:sched_switch { @[kstack] = count(); exit(); }'
>   Attaching 1 probe...
>   @[
>       __schedule+1059
>       __schedule+1059
>       schedule+79
>       schedule_hrtimeout_range_clock+163
>       schedule_hrtimeout_range+17
>       ep_poll+471
>       SyS_epoll_wait+111
>       sys_epoll_pwait+231
>       __ret_fast_syscall+1
>   ]: 1
>
> Signed-off-by: Tomislav Novak <tnovak@fb.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Can you put this patch into Russell's patch tracker please?
https://www.armlinux.org.uk/developer/patches/

BTW: what is this interesting CONFIG_THUMB2_KERNEL target
that Facebook/Meta is working on? (It's OK if you can't tell, just
curious.)

Yours,
Linus Walleij

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

* Re: [PATCH] ARM: perf: Fix stacktraces for tracepoint events in THUMB2 kernels
  2022-09-22  8:57 ` Linus Walleij
@ 2022-09-23 15:05   ` Tomislav Novak
  2022-10-03 21:56     ` Linus Walleij
  0 siblings, 1 reply; 4+ messages in thread
From: Tomislav Novak @ 2022-09-23 15:05 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Will Deacon, Russell King, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, linux-arm-kernel, Arnd Bergmann

On Thu, Sep 22, 2022 at 10:57:11AM +0200, Linus Walleij wrote:
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> 
> Can you put this patch into Russell's patch tracker please?

Thanks! Done: https://www.armlinux.org.uk/developer/patches/viewpatch.php?id=9250/1

This bug came up while I was testing another patch[1] to make sure it doesn't
break stack unwinding in Thumb-2 builds.

[1] https://lore.kernel.org/r/20220921002446.3096120-1-tnovak@fb.com/

-- 
T.
_______________________________________________
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] 4+ messages in thread

* Re: [PATCH] ARM: perf: Fix stacktraces for tracepoint events in THUMB2 kernels
  2022-09-23 15:05   ` Tomislav Novak
@ 2022-10-03 21:56     ` Linus Walleij
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2022-10-03 21:56 UTC (permalink / raw)
  To: Tomislav Novak
  Cc: Will Deacon, Russell King, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, linux-arm-kernel, Arnd Bergmann

On Fri, Sep 23, 2022 at 5:06 PM Tomislav Novak <tnovak@meta.com> wrote:
> On Thu, Sep 22, 2022 at 10:57:11AM +0200, Linus Walleij wrote:
> > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> >
> > Can you put this patch into Russell's patch tracker please?
>
> Thanks! Done: https://www.armlinux.org.uk/developer/patches/viewpatch.php?id=9250/1
>
> This bug came up while I was testing another patch[1] to make sure it doesn't
> break stack unwinding in Thumb-2 builds.
>
> [1] https://lore.kernel.org/r/20220921002446.3096120-1-tnovak@fb.com/

That's what I call a job well done, and exactly the walking an extra mile
spirit that we value in developers!

Thanks!

Yours,
Linus Walleij

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

end of thread, other threads:[~2022-10-03 21:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 23:07 [PATCH] ARM: perf: Fix stacktraces for tracepoint events in THUMB2 kernels Tomislav Novak
2022-09-22  8:57 ` Linus Walleij
2022-09-23 15:05   ` Tomislav Novak
2022-10-03 21:56     ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).