mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v6 0/9] LoongArch: Add ftrace support
@ 2022-11-15  2:55 Qing Zhang
  2022-11-15  2:55 ` [PATCH v6 1/9] LoongArch/ftrace: Add basic support Qing Zhang
                   ` (8 more replies)
  0 siblings, 9 replies; 24+ messages in thread
From: Qing Zhang @ 2022-11-15  2:55 UTC (permalink / raw)
  To: Huacai Chen, Steven Rostedt, Ingo Molnar; +Cc: loongarch, linux-kernel

This patch series to support basic and dynamic ftrace.

1) -pg
Use `-pg` makes stub like a child function `void _mcount(void *ra)`.
Thus, it can be seen store RA and open stack before `call _mcount`.
Find `open stack` at first, and then find `store RA`.

2) -fpatchable-function-entry=2
The compiler has inserted 2 NOPs before the regular function prologue.
T series registers are available and safe because of LoongArch psABI.

At runtime, replace nop with bl to enable ftrace call and replace bl with
nop to disable ftrace call. The bl requires us to save the original RA value,
so here it saves RA at t0.
details are:

| Compiled   |       Disabled         |        Enabled         |
+------------+------------------------+------------------------+
| nop        | move     t0, ra        | move     t0, ra        |
| nop        | nop                    | bl      ftrace_caller  |
| func_body  | func_body              | func_body              |

The RA value will be recovered by ftrace_regs_entry, and restored into RA
before returning to the regular function prologue. When a function is not
being traced, the move t0, ra is not harmful.

performs a series of startup tests on ftrace and The test cases in selftests
has passed on LoongArch.

Changes in v2:
 - Remove patch "LoongArch: ftrace: Add CALLER_ADDRx macros" there are other
   better ways
 Suggested by Steve:
 - Add HAVE_DYNAMIC_FTRACE_WITH_ARGS support (6/10)
 Suggested by Jinyang:
 - Change addu16id to lu12iw and Adjust module_finalize return value (7/10)
 - Use the "jr" pseudo-instruction where applicable (1/10)
 - Use the "la.pcrel" instead of "la" (3/10)

Changes in v3:
 Reported by Jeff:
 - Fix unwind state when option func_stack_trace (10/10)

Changes in v4:
 - No comments. Just resend the series.
 - Rebased onto v6.0.0-rc4.

Changes in v5:
 - Modify the indentation of Kconfig and small changes

Changes in v6:
 Suggested by Huacai:
 - Adjusting the patch Sequence
 - renamed mcount-dyn.S for consistency

Qing Zhang (9):
  LoongArch/ftrace: Add basic support
  LoongArch/ftrace: Add recordmcount support
  LoongArch/ftrace: Add dynamic function tracer support
  LoongArch/ftrace: Add dynamic function graph tracer support
  LoongArch/ftrace: Add DYNAMIC_FTRACE_WITH_REGS support
  LoongArch/ftrace: Add HAVE_DYNAMIC_FTRACE_WITH_ARGS support
  LoongArch/ftrace: Add HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support
  LoongArch: modules/ftrace: Initialize PLT at load time
  LoongArch: Enable CONFIG_KALLSYMS_ALL and CONFIG_DEBUG_FS

 arch/loongarch/Kconfig                     |   7 +
 arch/loongarch/Makefile                    |   5 +
 arch/loongarch/configs/loongson3_defconfig |   2 +
 arch/loongarch/include/asm/ftrace.h        |  61 +++++
 arch/loongarch/include/asm/inst.h          |  18 ++
 arch/loongarch/include/asm/module.h        |   5 +-
 arch/loongarch/include/asm/module.lds.h    |   1 +
 arch/loongarch/include/asm/unwind.h        |   3 +-
 arch/loongarch/kernel/Makefile             |  13 +
 arch/loongarch/kernel/ftrace.c             |  74 ++++++
 arch/loongarch/kernel/ftrace_dyn.c         | 264 +++++++++++++++++++++
 arch/loongarch/kernel/inst.c               | 127 ++++++++++
 arch/loongarch/kernel/mcount-dyn.S         | 154 ++++++++++++
 arch/loongarch/kernel/mcount.S             |  94 ++++++++
 arch/loongarch/kernel/module-sections.c    |  11 +
 arch/loongarch/kernel/module.c             |  22 ++
 arch/loongarch/kernel/unwind_guess.c       |   4 +-
 arch/loongarch/kernel/unwind_prologue.c    |  46 +++-
 scripts/recordmcount.c                     |  23 ++
 19 files changed, 924 insertions(+), 10 deletions(-)
 create mode 100644 arch/loongarch/include/asm/ftrace.h
 create mode 100644 arch/loongarch/kernel/ftrace.c
 create mode 100644 arch/loongarch/kernel/ftrace_dyn.c
 create mode 100644 arch/loongarch/kernel/mcount-dyn.S
 create mode 100644 arch/loongarch/kernel/mcount.S

-- 
2.36.0


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2022-11-15 11:13 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15  2:55 [PATCH v6 0/9] LoongArch: Add ftrace support Qing Zhang
2022-11-15  2:55 ` [PATCH v6 1/9] LoongArch/ftrace: Add basic support Qing Zhang
2022-11-15  8:25   ` Huacai Chen
2022-11-15  8:50     ` Qing Zhang
2022-11-15  9:04       ` Huacai Chen
2022-11-15 11:06         ` Qing Zhang
2022-11-15  2:55 ` [PATCH v6 2/9] LoongArch/ftrace: Add recordmcount support Qing Zhang
2022-11-15  2:55 ` [PATCH v6 3/9] LoongArch/ftrace: Add dynamic function tracer support Qing Zhang
2022-11-15 10:54   ` Huacai Chen
2022-11-15 11:11     ` Qing Zhang
2022-11-15  2:55 ` [PATCH v6 4/9] LoongArch/ftrace: Add dynamic function graph " Qing Zhang
2022-11-15  2:55 ` [PATCH v6 5/9] LoongArch/ftrace: Add DYNAMIC_FTRACE_WITH_REGS support Qing Zhang
2022-11-15  8:41   ` Huacai Chen
2022-11-15  9:22     ` Qing Zhang
2022-11-15  9:24       ` Huacai Chen
2022-11-15 10:44         ` Qing Zhang
2022-11-15 10:55           ` Huacai Chen
2022-11-15  2:55 ` [PATCH v6 6/9] LoongArch/ftrace: Add HAVE_DYNAMIC_FTRACE_WITH_ARGS support Qing Zhang
2022-11-15  2:55 ` [PATCH v6 7/9] LoongArch/ftrace: Add HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support Qing Zhang
2022-11-15  2:55 ` [PATCH v6 8/9] LoongArch: modules/ftrace: Initialize PLT at load time Qing Zhang
2022-11-15  2:55 ` [PATCH v6 9/9] LoongArch: Enable CONFIG_KALLSYMS_ALL and CONFIG_DEBUG_FS Qing Zhang
2022-11-15  8:31   ` Huacai Chen
2022-11-15  8:47     ` Arnd Bergmann
2022-11-15 10:56       ` Huacai Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®