From: Julian Braha <julianbraha@gmail.com>
To: chenhuacai@kernel.org
Cc: kernel@xen0n.name, rostedt@goodmis.org, mhiramat@kernel.org,
mark.rutland@arm.com, guodongtai@kylinos.cn,
lianyangyang@kylinos.cn, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Julian Braha <julianbraha@gmail.com>
Subject: [PATCH] LoongArch: cleanup dead static ftrace files
Date: Thu, 3 Dec 2026 19:33:02 +0000 [thread overview]
Message-ID: <20261203193302.2572186-1-julianbraha@gmail.com> (raw)
Linux v6.17 removed static ftrace for architectures that support dynamic
ftrace in commit 9b4d5d330fcd ("ftrace: Make DYNAMIC_FTRACE always enabled
for architectures that support it"). Now, the DYNAMIC_FTRACE config option
can not be disabled when FUNCTION_TRACER=y, which makes ftrace.c and
mcount.S dead code.
Let's remove these dead files, and their impossible Makefile branch.
Signed-off-by: Julian Braha <julianbraha@gmail.com>
---
arch/loongarch/kernel/Makefile | 9 +--
arch/loongarch/kernel/ftrace.c | 73 ------------------------
arch/loongarch/kernel/mcount.S | 101 ---------------------------------
3 files changed, 2 insertions(+), 181 deletions(-)
delete mode 100644 arch/loongarch/kernel/ftrace.c
delete mode 100644 arch/loongarch/kernel/mcount.S
diff --git a/arch/loongarch/kernel/Makefile b/arch/loongarch/kernel/Makefile
index 6260c15adaba..afc2c3dc0f1e 100644
--- a/arch/loongarch/kernel/Makefile
+++ b/arch/loongarch/kernel/Makefile
@@ -27,13 +27,8 @@ CFLAGS_traps.o += $(call cc-disable-warning, override-init)
CFLAGS_perf_event.o += $(call cc-disable-warning, override-init)
ifdef CONFIG_FUNCTION_TRACER
- ifndef CONFIG_DYNAMIC_FTRACE
- obj-y += mcount.o ftrace.o
- CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
- else
- obj-y += mcount_dyn.o ftrace_dyn.o
- CFLAGS_REMOVE_ftrace_dyn.o = $(CC_FLAGS_FTRACE)
- endif
+ obj-y += mcount_dyn.o ftrace_dyn.o
+ CFLAGS_REMOVE_ftrace_dyn.o = $(CC_FLAGS_FTRACE)
CFLAGS_REMOVE_inst.o = $(CC_FLAGS_FTRACE)
CFLAGS_REMOVE_time.o = $(CC_FLAGS_FTRACE)
CFLAGS_REMOVE_perf_event.o = $(CC_FLAGS_FTRACE)
diff --git a/arch/loongarch/kernel/ftrace.c b/arch/loongarch/kernel/ftrace.c
deleted file mode 100644
index 8c3ec1bc7aad..000000000000
--- a/arch/loongarch/kernel/ftrace.c
+++ /dev/null
@@ -1,73 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (C) 2022 Loongson Technology Corporation Limited
- */
-
-#include <linux/init.h>
-#include <linux/ftrace.h>
-#include <linux/syscalls.h>
-#include <linux/uaccess.h>
-
-#include <asm/asm.h>
-#include <asm/asm-offsets.h>
-#include <asm/cacheflush.h>
-#include <asm/inst.h>
-#include <asm/loongarch.h>
-#include <asm/syscall.h>
-
-#include <asm-generic/sections.h>
-
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-
-/*
- * As `call _mcount` follows LoongArch psABI, ra-saved operation and
- * stack operation can be found before this insn.
- */
-
-static int ftrace_get_parent_ra_addr(unsigned long insn_addr, int *ra_off)
-{
- int limit = 32;
- union loongarch_instruction *insn;
-
- insn = (union loongarch_instruction *)insn_addr;
-
- do {
- insn--;
- limit--;
-
- if (is_ra_save_ins(insn))
- *ra_off = -((1 << 12) - insn->reg2i12_format.immediate);
-
- } while (!is_stack_alloc_ins(insn) && limit);
-
- if (!limit)
- return -EINVAL;
-
- return 0;
-}
-
-void prepare_ftrace_return(unsigned long self_addr,
- unsigned long callsite_sp, unsigned long old)
-{
- int ra_off;
- unsigned long return_hooker = (unsigned long)&return_to_handler;
-
- if (unlikely(ftrace_graph_is_dead()))
- return;
-
- if (unlikely(atomic_read(¤t->tracing_graph_pause)))
- return;
-
- if (ftrace_get_parent_ra_addr(self_addr, &ra_off))
- goto out;
-
- if (!function_graph_enter(old, self_addr, 0, NULL))
- *(unsigned long *)(callsite_sp + ra_off) = return_hooker;
-
- return;
-
-out:
- ftrace_graph_stop();
- WARN_ON(1);
-}
-#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
diff --git a/arch/loongarch/kernel/mcount.S b/arch/loongarch/kernel/mcount.S
deleted file mode 100644
index b6850503e061..000000000000
--- a/arch/loongarch/kernel/mcount.S
+++ /dev/null
@@ -1,101 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * LoongArch specific _mcount support
- *
- * Copyright (C) 2022 Loongson Technology Corporation Limited
- */
-
-#include <linux/export.h>
-#include <asm/ftrace.h>
-#include <asm/regdef.h>
-#include <asm/stackframe.h>
-
- .text
-
-#define MCOUNT_S0_OFFSET (0)
-#define MCOUNT_RA_OFFSET (SZREG)
-#define MCOUNT_STACK_SIZE (2 * SZREG)
-
- .macro MCOUNT_SAVE_REGS
- PTR_ADDI sp, sp, -MCOUNT_STACK_SIZE
- PTR_S s0, sp, MCOUNT_S0_OFFSET
- PTR_S ra, sp, MCOUNT_RA_OFFSET
- move s0, a0
- .endm
-
- .macro MCOUNT_RESTORE_REGS
- move a0, s0
- PTR_L ra, sp, MCOUNT_RA_OFFSET
- PTR_L s0, sp, MCOUNT_S0_OFFSET
- PTR_ADDI sp, sp, MCOUNT_STACK_SIZE
- .endm
-
-SYM_FUNC_START(_mcount)
- la.pcrel t1, ftrace_stub
- la.pcrel t2, ftrace_trace_function /* Prepare t2 for (1) */
- PTR_L t2, t2, 0
- beq t1, t2, fgraph_trace
-
- MCOUNT_SAVE_REGS
-
- move a0, ra /* arg0: self return address */
- move a1, s0 /* arg1: parent's return address */
- jirl ra, t2, 0 /* (1) call *ftrace_trace_function */
-
- MCOUNT_RESTORE_REGS
-
-fgraph_trace:
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
- la.pcrel t1, ftrace_stub
- la.pcrel t3, ftrace_graph_return
- PTR_L t3, t3, 0
- bne t1, t3, ftrace_graph_caller
- la.pcrel t1, ftrace_graph_entry_stub
- la.pcrel t3, ftrace_graph_entry
- PTR_L t3, t3, 0
- bne t1, t3, ftrace_graph_caller
-#endif
-
-SYM_INNER_LABEL(ftrace_stub, SYM_L_GLOBAL)
- jr ra
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-SYM_INNER_LABEL(ftrace_graph_func, SYM_L_GLOBAL)
- bl ftrace_stub
-#endif
-SYM_FUNC_END(_mcount)
-EXPORT_SYMBOL(_mcount)
-
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-SYM_FUNC_START(ftrace_graph_caller)
- MCOUNT_SAVE_REGS
-
- PTR_ADDI a0, ra, -4 /* arg0: Callsite self return addr */
- PTR_ADDI a1, sp, MCOUNT_STACK_SIZE /* arg1: Callsite sp */
- move a2, s0 /* arg2: Callsite parent ra */
- bl prepare_ftrace_return
-
- MCOUNT_RESTORE_REGS
- jr ra
-SYM_FUNC_END(ftrace_graph_caller)
-
-SYM_FUNC_START(return_to_handler)
- /* Save return value regs */
- PTR_ADDI sp, sp, -PT_SIZE
- PTR_S a0, sp, PT_R4
- PTR_S a1, sp, PT_R5
- PTR_S zero, sp, PT_R22
-
- move a0, sp
- bl ftrace_return_to_handler
-
- /* Restore the real parent address: a0 -> ra */
- move ra, a0
-
- /* Restore return value regs */
- PTR_L a0, sp, PT_R4
- PTR_L a1, sp, PT_R5
- PTR_ADDI sp, sp, PT_SIZE
-
- jr ra
-SYM_FUNC_END(return_to_handler)
-#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
--
2.56.1
reply other threads:[~2026-12-03 19:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261203193302.2572186-1-julianbraha@gmail.com \
--to=julianbraha@gmail.com \
--cc=chenhuacai@kernel.org \
--cc=guodongtai@kylinos.cn \
--cc=kernel@xen0n.name \
--cc=lianyangyang@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--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