From: Qing Zhang <zhangqing@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>
Cc: WANG Xuerui <kernel@xen0n.name>,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org, Jiaxun Yang <jiaxun.yang@flygoat.com>,
hejinyang@loongson.cn, zhangqing@loongson.cn
Subject: [PATCH 0/9] LoongArch: Add ftrace support
Date: Fri, 19 Aug 2022 16:13:54 +0800 [thread overview]
Message-ID: <20220819081403.7143-1-zhangqing@loongson.cn> (raw)
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.
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: modules/ftrace: Initialize PLT at load time
Loongarch/ftrace: Add HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support
LoongArch: ftrace: Add CALLER_ADDRx macros
LoongArch: Enable CONFIG_KALLSYMS_ALL and CONFIG_DEBUG_FS
arch/loongarch/Kconfig | 6 +
arch/loongarch/Makefile | 5 +
arch/loongarch/configs/loongson3_defconfig | 60 ++---
arch/loongarch/include/asm/ftrace.h | 46 ++++
arch/loongarch/include/asm/inst.h | 35 +++
arch/loongarch/include/asm/module.h | 14 +-
arch/loongarch/include/asm/module.lds.h | 1 +
arch/loongarch/include/asm/processor.h | 2 -
arch/loongarch/include/asm/unwind.h | 1 +
arch/loongarch/kernel/Makefile | 17 +-
arch/loongarch/kernel/entry_dyn.S | 154 +++++++++++++
arch/loongarch/kernel/ftrace.c | 74 ++++++
arch/loongarch/kernel/ftrace_dyn.c | 252 +++++++++++++++++++++
arch/loongarch/kernel/inst.c | 129 +++++++++++
arch/loongarch/kernel/mcount.S | 94 ++++++++
arch/loongarch/kernel/module-sections.c | 11 +
arch/loongarch/kernel/module.c | 48 ++++
arch/loongarch/kernel/return_address.c | 45 ++++
arch/loongarch/kernel/unwind_guess.c | 4 +-
arch/loongarch/kernel/unwind_prologue.c | 10 +-
scripts/recordmcount.c | 23 ++
21 files changed, 973 insertions(+), 58 deletions(-)
create mode 100644 arch/loongarch/include/asm/ftrace.h
create mode 100644 arch/loongarch/kernel/entry_dyn.S
create mode 100644 arch/loongarch/kernel/ftrace.c
create mode 100644 arch/loongarch/kernel/ftrace_dyn.c
create mode 100644 arch/loongarch/kernel/mcount.S
create mode 100644 arch/loongarch/kernel/return_address.c
--
2.36.1
next reply other threads:[~2022-08-19 8:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-19 8:13 Qing Zhang [this message]
2022-08-19 8:13 ` [PATCH 1/9] LoongArch/ftrace: Add basic support Qing Zhang
2022-08-19 9:29 ` Jinyang He
2022-08-19 16:53 ` Steven Rostedt
2022-08-20 1:34 ` Qing Zhang
2022-08-20 2:16 ` Huacai Chen
2022-08-19 17:25 ` Steven Rostedt
2022-08-20 1:35 ` Qing Zhang
2022-08-20 1:38 ` Jinyang He
2022-08-20 1:52 ` Steven Rostedt
2022-08-20 3:16 ` Jinyang He
2022-08-19 8:13 ` [PATCH 2/9] LoongArch/ftrace: Add recordmcount support Qing Zhang
2022-08-19 8:13 ` [PATCH 3/9] LoongArch/ftrace: Add dynamic function tracer support Qing Zhang
2022-08-19 8:13 ` [PATCH 4/9] Loongarch/ftrace: Add dynamic function graph " Qing Zhang
2022-08-19 8:13 ` [PATCH 5/9] Loongarch/ftrace: Add DYNAMIC_FTRACE_WITH_REGS support Qing Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220819081403.7143-1-zhangqing@loongson.cn \
--to=zhangqing@loongson.cn \
--cc=chenhuacai@kernel.org \
--cc=hejinyang@loongson.cn \
--cc=jiaxun.yang@flygoat.com \
--cc=kernel@xen0n.name \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox