Skip to contentSkip to conversation

riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

PATCH In review ChenMiao 3 participants 11 messages Jul 6, 2025 – Jul 16, 2025

Subsystems (3)
lore
Share & tools
lore

ChenMiao

author
#0 lore raw

PATCH v2 1/1 riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

From: chenmiao <[email protected]>

V1: The first version mainly involves modifications to the configuration of the dynamic ftracer.

Link https://lore.kernel.org/all/[email protected]/

V2: After a series of discussions, Steven concluded that only supporting the dynamic ftracer would suffice. Alex also pointed out that if only the dynamic ftracer needs to be supported, the code related to the static ftracer would become obsolete and turn into dead code. He had already done some preliminary work on this.

Based on this, the modifications to the configuration were made, and the dead code generated by the ftracer
(originally related to the static ftracer) was also removed.

Link https://lore.kernel.org/all/[email protected]/
Link https://github.com/linux-riscv/linux/pull/556/commits/0481092a5bec3818658981c11f629e06e66382b3

---
 arch/riscv/Kconfig              |  3 +-
 arch/riscv/include/asm/ftrace.h |  3 --
 arch/riscv/kernel/ftrace.c      | 11 +-----
 arch/riscv/kernel/mcount.S      | 64 ---------------------------------
 kernel/trace/Kconfig            |  2 +-
 5 files changed, 4 insertions(+), 79 deletions(-)
arch/riscv/Kconfig +2 -1
index 36061f4732b7..95d24b19c466 100644
@@ -97,8 +97,9 @@ config RISCV
 	select CLONE_BACKWARDS
 	select COMMON_CLK
 	select CPU_PM if CPU_IDLE || HIBERNATION || SUSPEND
+	select DYNAMIC_FTRACE if FUNCTION_TRACER
 	select EDAC_SUPPORT
-	select FRAME_POINTER if PERF_EVENTS || (FUNCTION_TRACER && !DYNAMIC_FTRACE)
+	select FRAME_POINTER if PERF_EVENTS
 	select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY if DYNAMIC_FTRACE
 	select FUNCTION_ALIGNMENT_8B if DYNAMIC_FTRACE_WITH_CALL_OPS
 	select GENERIC_ARCH_TOPOLOGY
arch/riscv/include/asm/ftrace.h +0 -3
index 22ebea3c2b26..77ddb6dce0a8 100644
@@ -49,7 +49,6 @@ struct dyn_arch_ftrace {
 };
 #endif
 
-#ifdef CONFIG_DYNAMIC_FTRACE
 /*
  * A general call in RISC-V is a pair of insts:
  * 1) auipc: setting high-20 pc-related bits to ra register
@@ -237,6 +236,4 @@ static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsi
 
 #endif /* __ASSEMBLY__ */
 
-#endif /* CONFIG_DYNAMIC_FTRACE */
-
 #endif /* _ASM_RISCV_FTRACE_H */
arch/riscv/kernel/ftrace.c +1 -10
index 4c6c24380cfd..93bad646d233 100644
@@ -13,7 +13,6 @@
 #include <asm/cacheflush.h>
 #include <asm/text-patching.h>
 
-#ifdef CONFIG_DYNAMIC_FTRACE
 unsigned long ftrace_call_adjust(unsigned long addr)
 {
 	if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS))
@@ -191,13 +190,6 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
 	return 0;
 }
 
-#else /* CONFIG_DYNAMIC_FTRACE */
-unsigned long ftrace_call_adjust(unsigned long addr)
-{
-	return addr;
-}
-#endif /* CONFIG_DYNAMIC_FTRACE */
-
 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
 int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
 		       unsigned long addr)
@@ -236,7 +228,6 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
 		*parent = return_hooker;
 }
 
-#ifdef CONFIG_DYNAMIC_FTRACE
 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
 		       struct ftrace_ops *op, struct ftrace_regs *fregs)
 {
@@ -257,5 +248,5 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
 	if (!function_graph_enter_regs(old, ip, frame_pointer, parent, fregs))
 		*parent = return_hooker;
 }
-#endif /* CONFIG_DYNAMIC_FTRACE */
+
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
arch/riscv/kernel/mcount.S +0 -64

88 lines not on this page · raw message

kernel/trace/Kconfig +1 -1
index a3f35c7d83b6..28afc6941e7a 100644
@@ -275,7 +275,7 @@ config FUNCTION_TRACE_ARGS
 	  funcgraph-args (for the function graph tracer)
 
 config DYNAMIC_FTRACE
-	bool "enable/disable function tracing dynamically"
+	bool
 	depends on FUNCTION_TRACER
 	depends on HAVE_DYNAMIC_FTRACE
 	default y

base-commit: fda589c286040d9ba2d72a0eaf0a13945fc48026

Signature · 1 line
2.45.2
#1 lore raw
kernel test robot noticed the following build errors:

Hi ChenMiao,

kernel test robot noticed the following build errors:

[auto build test ERROR on fda589c286040d9ba2d72a0eaf0a13945fc48026]

url:    https://github.com/intel-lab-lkp/linux/commits/ChenMiao/riscv-ftrace-Fix-the-logic-issue-in-DYNAMIC_FTRACE-selection/20250706-231907
base:   fda589c286040d9ba2d72a0eaf0a13945fc48026
patch link:    https://lore.kernel.org/r/20250706151830.25091-1-chenmiao.ku%40gmail.com
patch subject: [PATCH V2] riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: riscv-randconfig-r112-20250708 (attached as .config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce: (attached as reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> <instantiation>:1:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]
   addi sp, sp, -FREGS_SIZE_ON_STACK
                ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
>> <instantiation>:2:18: error: unexpected token
    sw t0, FREGS_EPC(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:3:17: error: unexpected token
    sw x1, FREGS_RA(sp)
                   ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:7:17: error: unexpected token
    sw x6, FREGS_T1(sp)
                   ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:9:17: error: unexpected token
    sw x7, FREGS_T2(sp)
                   ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:10:18: error: unexpected token
    sw x28, FREGS_T3(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:11:18: error: unexpected token
    sw x29, FREGS_T4(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:12:18: error: unexpected token
    sw x30, FREGS_T5(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:13:18: error: unexpected token
    sw x31, FREGS_T6(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:16:18: error: unexpected token
    sw x10, FREGS_A0(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:17:18: error: unexpected token
    sw x11, FREGS_A1(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:18:18: error: unexpected token
    sw x12, FREGS_A2(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:19:18: error: unexpected token
    sw x13, FREGS_A3(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:20:18: error: unexpected token
    sw x14, FREGS_A4(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:21:18: error: unexpected token
    sw x15, FREGS_A5(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:22:18: error: unexpected token
    sw x16, FREGS_A6(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^
   <instantiation>:23:18: error: unexpected token
    sw x17, FREGS_A7(sp)
                    ^
   arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
    SAVE_ABI_REGS
    ^

<instantiation>:25:15: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]
addi a0, a0, FREGS_SIZE_ON_STACK
^
arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
SAVE_ABI_REGS

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DYNAMIC_FTRACE Depends on [n]: FTRACE [=y] && FUNCTION_TRACER [=y] && HAVE_DYNAMIC_FTRACE [=n] Selected by [y]:
- RISCV [=y] && FUNCTION_TRACER [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

reproduce:
git clone https://github.com/intel/lkp-tests.git ~/lkp-tests
# apt-get install sparse
# sparse version: v0.6.4-66-g0196afe1
# https://github.com/intel-lab-lkp/linux/commit/554547cdd15477e2cedac28c966a87607e43bb99
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review ChenMiao/riscv-ftrace-Fix-the-logic-issue-in-DYNAMIC_FTRACE-selection/20250706-231907
git checkout 554547cdd15477e2cedac28c966a87607e43bb99
# save the config file
mkdir build_dir && cp config build_dir/.config
~/lkp-tests/kbuild/make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__ -fmax-errors=unlimited -fmax-warnings=unlimited' O=build_dir ARCH=riscv olddefconfig ~/lkp-tests/kbuild/make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__ -fmax-errors=unlimited -fmax-warnings=unlimited' O=build_dir ARCH=riscv SHELL=/bin/bash

#2 lore raw

Hi ChenMiao,

Quoted 131 lines · kernel test robot

Hi ChenMiao,

kernel test robot noticed the following build errors:

[auto build test ERROR on fda589c286040d9ba2d72a0eaf0a13945fc48026]

url:    https://github.com/intel-lab-lkp/linux/commits/ChenMiao/riscv-ftrace-Fix-the-logic-issue-in-DYNAMIC_FTRACE-selection/20250706-231907
base:   fda589c286040d9ba2d72a0eaf0a13945fc48026
patch link:    https://lore.kernel.org/r/20250706151830.25091-1-chenmiao.ku%40gmail.com
patch subject: [PATCH V2] riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: riscv-randconfig-r112-20250708 (attached as .config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce: (attached as reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

<instantiation>:1:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]

addi sp, sp, -FREGS_SIZE_ON_STACK
^
arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
SAVE_ABI_REGS
^

Quoted 1 line
Quoted 1 line

<instantiation>:2:18: error: unexpected token

     sw t0, FREGS_EPC(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:3:17: error: unexpected token
     sw x1, FREGS_RA(sp)
                    ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:7:17: error: unexpected token
     sw x6, FREGS_T1(sp)
                    ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:9:17: error: unexpected token
     sw x7, FREGS_T2(sp)
                    ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:10:18: error: unexpected token
     sw x28, FREGS_T3(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:11:18: error: unexpected token
     sw x29, FREGS_T4(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:12:18: error: unexpected token
     sw x30, FREGS_T5(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:13:18: error: unexpected token
     sw x31, FREGS_T6(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:16:18: error: unexpected token
     sw x10, FREGS_A0(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:17:18: error: unexpected token
     sw x11, FREGS_A1(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:18:18: error: unexpected token
     sw x12, FREGS_A2(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:19:18: error: unexpected token
     sw x13, FREGS_A3(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:20:18: error: unexpected token
     sw x14, FREGS_A4(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:21:18: error: unexpected token
     sw x15, FREGS_A5(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:22:18: error: unexpected token
     sw x16, FREGS_A6(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:23:18: error: unexpected token
     sw x17, FREGS_A7(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:25:15: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]
     addi a0, a0, FREGS_SIZE_ON_STACK
                  ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
Quoted 5 lines

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DYNAMIC_FTRACE Depends on [n]: FTRACE [=y] && FUNCTION_TRACER [=y] && HAVE_DYNAMIC_FTRACE [=n] Selected by [y]:
- RISCV [=y] && FUNCTION_TRACER [=y]

To avoid that, we should check HAVE_DYNAMIC_FTRACE too:

select DYNAMIC_FTRACE if FUNCTION_TRACER && HAVE_DYNAMIC_FTRACE

That fixes the build error for me. Can you send a v3 with this change?

Thanks,

Alex

Quoted 1 line
author
#3 lore raw

Hello Alex,

Sure, I'll checkout it. Btw, this is my first commit, so can u tell how to reproduce failed case? Using the reproduce and .config.gz gived by build-bot?

Thanks,

Chen Miao

Quoted 153 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 19:53写道:

Hi ChenMiao,

Quoted 131 lines · kernel test robot

Hi ChenMiao,

kernel test robot noticed the following build errors:

[auto build test ERROR on fda589c286040d9ba2d72a0eaf0a13945fc48026]

url:    https://github.com/intel-lab-lkp/linux/commits/ChenMiao/riscv-ftrace-Fix-the-logic-issue-in-DYNAMIC_FTRACE-selection/20250706-231907
base:   fda589c286040d9ba2d72a0eaf0a13945fc48026
patch link:    https://lore.kernel.org/r/20250706151830.25091-1-chenmiao.ku%40gmail.com
patch subject: [PATCH V2] riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: riscv-randconfig-r112-20250708 (attached as .config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce: (attached as reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

<instantiation>:1:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]

addi sp, sp, -FREGS_SIZE_ON_STACK
^
arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
SAVE_ABI_REGS
^

Quoted 1 line
Quoted 1 line

<instantiation>:2:18: error: unexpected token

     sw t0, FREGS_EPC(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:3:17: error: unexpected token
     sw x1, FREGS_RA(sp)
                    ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:7:17: error: unexpected token
     sw x6, FREGS_T1(sp)
                    ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:9:17: error: unexpected token
     sw x7, FREGS_T2(sp)
                    ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:10:18: error: unexpected token
     sw x28, FREGS_T3(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:11:18: error: unexpected token
     sw x29, FREGS_T4(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:12:18: error: unexpected token
     sw x30, FREGS_T5(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:13:18: error: unexpected token
     sw x31, FREGS_T6(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:16:18: error: unexpected token
     sw x10, FREGS_A0(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:17:18: error: unexpected token
     sw x11, FREGS_A1(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:18:18: error: unexpected token
     sw x12, FREGS_A2(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:19:18: error: unexpected token
     sw x13, FREGS_A3(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:20:18: error: unexpected token
     sw x14, FREGS_A4(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:21:18: error: unexpected token
     sw x15, FREGS_A5(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:22:18: error: unexpected token
     sw x16, FREGS_A6(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:23:18: error: unexpected token
     sw x17, FREGS_A7(sp)
                     ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
     ^
    <instantiation>:25:15: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]
     addi a0, a0, FREGS_SIZE_ON_STACK
                  ^
    arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
     SAVE_ABI_REGS
Quoted 5 lines

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DYNAMIC_FTRACE Depends on [n]: FTRACE [=y] && FUNCTION_TRACER [=y] && HAVE_DYNAMIC_FTRACE [=n] Selected by [y]:
- RISCV [=y] && FUNCTION_TRACER [=y]

To avoid that, we should check HAVE_DYNAMIC_FTRACE too:

select DYNAMIC_FTRACE if FUNCTION_TRACER && HAVE_DYNAMIC_FTRACE

That fixes the build error for me. Can you send a v3 with this change?

Thanks,

Alex

Quoted 1 line
#4 lore raw
Quoted 5 lines · Miao Chen

Hello Alex,

Sure, I'll checkout it. Btw, this is my first commit, so can u tell how to reproduce failed case? Using the reproduce and .config.gz gived by build-bot?

Yes exactly!

Quoted 160 lines

Thanks,

Chen Miao

Quoted 141 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 19:53写道:

Hi ChenMiao,

Quoted 131 lines · kernel test robot

Hi ChenMiao,

kernel test robot noticed the following build errors:

[auto build test ERROR on fda589c286040d9ba2d72a0eaf0a13945fc48026]

url:    https://github.com/intel-lab-lkp/linux/commits/ChenMiao/riscv-ftrace-Fix-the-logic-issue-in-DYNAMIC_FTRACE-selection/20250706-231907
base:   fda589c286040d9ba2d72a0eaf0a13945fc48026
patch link:    https://lore.kernel.org/r/20250706151830.25091-1-chenmiao.ku%40gmail.com
patch subject: [PATCH V2] riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: riscv-randconfig-r112-20250708 (attached as .config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce: (attached as reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

<instantiation>:1:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]

addi sp, sp, -FREGS_SIZE_ON_STACK
^
arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
SAVE_ABI_REGS
^

Quoted 1 line
Quoted 1 line

<instantiation>:2:18: error: unexpected token

      sw t0, FREGS_EPC(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:3:17: error: unexpected token
      sw x1, FREGS_RA(sp)
                     ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:7:17: error: unexpected token
      sw x6, FREGS_T1(sp)
                     ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:9:17: error: unexpected token
      sw x7, FREGS_T2(sp)
                     ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:10:18: error: unexpected token
      sw x28, FREGS_T3(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:11:18: error: unexpected token
      sw x29, FREGS_T4(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:12:18: error: unexpected token
      sw x30, FREGS_T5(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:13:18: error: unexpected token
      sw x31, FREGS_T6(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:16:18: error: unexpected token
      sw x10, FREGS_A0(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:17:18: error: unexpected token
      sw x11, FREGS_A1(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:18:18: error: unexpected token
      sw x12, FREGS_A2(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:19:18: error: unexpected token
      sw x13, FREGS_A3(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:20:18: error: unexpected token
      sw x14, FREGS_A4(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:21:18: error: unexpected token
      sw x15, FREGS_A5(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:22:18: error: unexpected token
      sw x16, FREGS_A6(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:23:18: error: unexpected token
      sw x17, FREGS_A7(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:25:15: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]
      addi a0, a0, FREGS_SIZE_ON_STACK
                   ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
Quoted 5 lines

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DYNAMIC_FTRACE Depends on [n]: FTRACE [=y] && FUNCTION_TRACER [=y] && HAVE_DYNAMIC_FTRACE [=n] Selected by [y]:
- RISCV [=y] && FUNCTION_TRACER [=y]

To avoid that, we should check HAVE_DYNAMIC_FTRACE too:

Quoted 9 lines

select DYNAMIC_FTRACE if FUNCTION_TRACER && HAVE_DYNAMIC_FTRACE

That fixes the build error for me. Can you send a v3 with this change?

Thanks,

Alex

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#5 lore raw

Hello Alex,

I found where the error is, but there's a problem here:

config PORTABLE
bool
default !NONPORTABLE
select EFI
select MMU
select OF

select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)

Because HAVE_DYNAMIC_FTRACE depends on the MMU—of course, it's reasonable for DYNAMIC_FTRACE to depend on the MMU—*but since NONPORTABLE is enabled by default, this causes PORTABLE to default to n, thereby preventing the MMU from being enabled*. So, should I change NONPORTABLE to default to n?

Thanks,

Alex

Quoted 173 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 22:33写道:
Quoted 5 lines · Miao Chen

Hello Alex,

Sure, I'll checkout it. Btw, this is my first commit, so can u tell how to reproduce failed case? Using the reproduce and .config.gz gived by build-bot?

Yes exactly!

Quoted 160 lines

Thanks,

Chen Miao

Quoted 141 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 19:53写道:

Hi ChenMiao,

Quoted 131 lines · kernel test robot

Hi ChenMiao,

kernel test robot noticed the following build errors:

[auto build test ERROR on fda589c286040d9ba2d72a0eaf0a13945fc48026]

url:    https://github.com/intel-lab-lkp/linux/commits/ChenMiao/riscv-ftrace-Fix-the-logic-issue-in-DYNAMIC_FTRACE-selection/20250706-231907
base:   fda589c286040d9ba2d72a0eaf0a13945fc48026
patch link:    https://lore.kernel.org/r/20250706151830.25091-1-chenmiao.ku%40gmail.com
patch subject: [PATCH V2] riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: riscv-randconfig-r112-20250708 (attached as .config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce: (attached as reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

<instantiation>:1:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]

addi sp, sp, -FREGS_SIZE_ON_STACK
^
arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
SAVE_ABI_REGS
^

Quoted 1 line
Quoted 1 line

<instantiation>:2:18: error: unexpected token

      sw t0, FREGS_EPC(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:3:17: error: unexpected token
      sw x1, FREGS_RA(sp)
                     ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:7:17: error: unexpected token
      sw x6, FREGS_T1(sp)
                     ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:9:17: error: unexpected token
      sw x7, FREGS_T2(sp)
                     ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:10:18: error: unexpected token
      sw x28, FREGS_T3(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:11:18: error: unexpected token
      sw x29, FREGS_T4(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:12:18: error: unexpected token
      sw x30, FREGS_T5(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:13:18: error: unexpected token
      sw x31, FREGS_T6(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:16:18: error: unexpected token
      sw x10, FREGS_A0(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:17:18: error: unexpected token
      sw x11, FREGS_A1(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:18:18: error: unexpected token
      sw x12, FREGS_A2(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:19:18: error: unexpected token
      sw x13, FREGS_A3(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:20:18: error: unexpected token
      sw x14, FREGS_A4(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:21:18: error: unexpected token
      sw x15, FREGS_A5(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:22:18: error: unexpected token
      sw x16, FREGS_A6(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:23:18: error: unexpected token
      sw x17, FREGS_A7(sp)
                      ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
      ^
     <instantiation>:25:15: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]
      addi a0, a0, FREGS_SIZE_ON_STACK
                   ^
     arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
      SAVE_ABI_REGS
Quoted 5 lines

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DYNAMIC_FTRACE Depends on [n]: FTRACE [=y] && FUNCTION_TRACER [=y] && HAVE_DYNAMIC_FTRACE [=n] Selected by [y]:
- RISCV [=y] && FUNCTION_TRACER [=y]

To avoid that, we should check HAVE_DYNAMIC_FTRACE too:

Quoted 9 lines

select DYNAMIC_FTRACE if FUNCTION_TRACER && HAVE_DYNAMIC_FTRACE

That fixes the build error for me. Can you send a v3 with this change?

Thanks,

Alex

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#6 lore raw

Hi,

Quoted 11 lines · Miao Chen

Hello Alex,

I found where the error is, but there's a problem here:

config PORTABLE
bool
default !NONPORTABLE
select EFI
select MMU
select OF

Quoted 8 lines

select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)

Because HAVE_DYNAMIC_FTRACE depends on the MMU—of course, it's reasonable for DYNAMIC_FTRACE to depend on the MMU—*but since NONPORTABLE is enabled by default, this causes PORTABLE to default to n, thereby preventing the MMU from being enabled*. So, should I change NONPORTABLE to default to n?

NONPORTABLE is not enabled by default and PORTABLE=n does not prevent MMU from being enabled.

IIUC, it seems like you don't have HAVE_DYNAMIC_FTRACE enabled but that's probably because of your toolchain, not !MMU, can you check that in your .config?

Thanks,

Alex

Quoted 180 lines

Thanks,

Alex

Quoted 170 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 22:33写道:
Quoted 5 lines · Miao Chen

Hello Alex,

Sure, I'll checkout it. Btw, this is my first commit, so can u tell how to reproduce failed case? Using the reproduce and .config.gz gived by build-bot?

Yes exactly!

Quoted 159 lines

Thanks,

Chen Miao

Quoted 141 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 19:53写道:

Hi ChenMiao,

Quoted 131 lines · kernel test robot

Hi ChenMiao,

kernel test robot noticed the following build errors:

[auto build test ERROR on fda589c286040d9ba2d72a0eaf0a13945fc48026]

url:    https://github.com/intel-lab-lkp/linux/commits/ChenMiao/riscv-ftrace-Fix-the-logic-issue-in-DYNAMIC_FTRACE-selection/20250706-231907
base:   fda589c286040d9ba2d72a0eaf0a13945fc48026
patch link:    https://lore.kernel.org/r/20250706151830.25091-1-chenmiao.ku%40gmail.com
patch subject: [PATCH V2] riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: riscv-randconfig-r112-20250708 (attached as .config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce: (attached as reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

<instantiation>:1:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]

addi sp, sp, -FREGS_SIZE_ON_STACK
^
arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
SAVE_ABI_REGS
^

Quoted 1 line
Quoted 1 line

<instantiation>:2:18: error: unexpected token

       sw t0, FREGS_EPC(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:3:17: error: unexpected token
       sw x1, FREGS_RA(sp)
                      ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:7:17: error: unexpected token
       sw x6, FREGS_T1(sp)
                      ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:9:17: error: unexpected token
       sw x7, FREGS_T2(sp)
                      ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:10:18: error: unexpected token
       sw x28, FREGS_T3(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:11:18: error: unexpected token
       sw x29, FREGS_T4(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:12:18: error: unexpected token
       sw x30, FREGS_T5(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:13:18: error: unexpected token
       sw x31, FREGS_T6(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:16:18: error: unexpected token
       sw x10, FREGS_A0(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:17:18: error: unexpected token
       sw x11, FREGS_A1(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:18:18: error: unexpected token
       sw x12, FREGS_A2(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:19:18: error: unexpected token
       sw x13, FREGS_A3(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:20:18: error: unexpected token
       sw x14, FREGS_A4(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:21:18: error: unexpected token
       sw x15, FREGS_A5(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:22:18: error: unexpected token
       sw x16, FREGS_A6(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:23:18: error: unexpected token
       sw x17, FREGS_A7(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:25:15: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]
       addi a0, a0, FREGS_SIZE_ON_STACK
                    ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
Quoted 5 lines

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DYNAMIC_FTRACE Depends on [n]: FTRACE [=y] && FUNCTION_TRACER [=y] && HAVE_DYNAMIC_FTRACE [=n] Selected by [y]:
- RISCV [=y] && FUNCTION_TRACER [=y]

To avoid that, we should check HAVE_DYNAMIC_FTRACE too:

Quoted 9 lines

select DYNAMIC_FTRACE if FUNCTION_TRACER && HAVE_DYNAMIC_FTRACE

That fixes the build error for me. Can you send a v3 with this change?

Thanks,

Alex

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#7 lore raw

Hi,

I rechecked the .config file. I configured it using

make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__ -fmax-errors=unlimited -fmax-warnings=unlimited' O=build_dir olddefconfig,

and obtained the following configuration. If NONPORTABLE is disabled, the MMU will be enabled. I did not find any other settings that would affect the enabling of NONPORTABLE—it is set to 'y' by default.

--------- CONFIG ---------------------

config NONPORTABLE
bool "Allow configurations that result in non-portable kernels"

Symbol: HAVE_DYNAMIC_FTRACE [=n]
Type : bool
Defined at kernel/trace/Kconfig:42
Selected by [n]:
- RISCV [=y] && !XIP_KERNEL [=n] && MMU [=n] &&
(CLANG_SUPPORTS_DYNAMIC_FTRACE [=n] || GCC_SUPPORTS_DYNAMIC_FTRACE [=y])

Symbol: MMU [=n]
Type : bool
Defined at arch/riscv/Kconfig:298
Prompt: MMU-based Paged Memory Management Support Location:
(1) -> MMU-based Paged Memory Management Support (MMU [=n]) Selected by [n]:
- PORTABLE [=n]

Symbol: PORTABLE [=n]
Type : bool
Defined at arch/riscv/Kconfig:1344
Selects: EFI [=n] && MMU [=n] && OF [=y]

Symbol: NONPORTABLE [=y]

  │ Type  : bool
  │ Defined at arch/riscv/Kconfig:389
  │   Prompt: Allow configurations that result in non-portable kernels
  │   Location:
  │     -> Platform type
  │ (1)   -> Allow configurations that result in non-portable kernels

(NONPORTABLE [=y])

Thanks,

Chen Miao

Quoted 217 lines · Alexandre Ghiti <[email protected]> 于2025年7月11日周五 15:55写道:

Hi,

Quoted 11 lines · Miao Chen

Hello Alex,

I found where the error is, but there's a problem here:

config PORTABLE
bool
default !NONPORTABLE
select EFI
select MMU
select OF

Quoted 8 lines

select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)

Because HAVE_DYNAMIC_FTRACE depends on the MMU—of course, it's reasonable for DYNAMIC_FTRACE to depend on the MMU—*but since NONPORTABLE is enabled by default, this causes PORTABLE to default to n, thereby preventing the MMU from being enabled*. So, should I change NONPORTABLE to default to n?

NONPORTABLE is not enabled by default and PORTABLE=n does not prevent MMU from being enabled.

IIUC, it seems like you don't have HAVE_DYNAMIC_FTRACE enabled but that's probably because of your toolchain, not !MMU, can you check that in your .config?

Thanks,

Alex

Quoted 180 lines

Thanks,

Alex

Quoted 170 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 22:33写道:
Quoted 5 lines · Miao Chen

Hello Alex,

Sure, I'll checkout it. Btw, this is my first commit, so can u tell how to reproduce failed case? Using the reproduce and .config.gz gived by build-bot?

Yes exactly!

Quoted 159 lines

Thanks,

Chen Miao

Quoted 141 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 19:53写道:

Hi ChenMiao,

Quoted 131 lines · kernel test robot

Hi ChenMiao,

kernel test robot noticed the following build errors:

[auto build test ERROR on fda589c286040d9ba2d72a0eaf0a13945fc48026]

url:    https://github.com/intel-lab-lkp/linux/commits/ChenMiao/riscv-ftrace-Fix-the-logic-issue-in-DYNAMIC_FTRACE-selection/20250706-231907
base:   fda589c286040d9ba2d72a0eaf0a13945fc48026
patch link:    https://lore.kernel.org/r/20250706151830.25091-1-chenmiao.ku%40gmail.com
patch subject: [PATCH V2] riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: riscv-randconfig-r112-20250708 (attached as .config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce: (attached as reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

<instantiation>:1:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]

addi sp, sp, -FREGS_SIZE_ON_STACK
^
arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
SAVE_ABI_REGS
^

Quoted 1 line
Quoted 1 line

<instantiation>:2:18: error: unexpected token

       sw t0, FREGS_EPC(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:3:17: error: unexpected token
       sw x1, FREGS_RA(sp)
                      ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:7:17: error: unexpected token
       sw x6, FREGS_T1(sp)
                      ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:9:17: error: unexpected token
       sw x7, FREGS_T2(sp)
                      ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:10:18: error: unexpected token
       sw x28, FREGS_T3(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:11:18: error: unexpected token
       sw x29, FREGS_T4(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:12:18: error: unexpected token
       sw x30, FREGS_T5(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:13:18: error: unexpected token
       sw x31, FREGS_T6(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:16:18: error: unexpected token
       sw x10, FREGS_A0(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:17:18: error: unexpected token
       sw x11, FREGS_A1(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:18:18: error: unexpected token
       sw x12, FREGS_A2(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:19:18: error: unexpected token
       sw x13, FREGS_A3(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:20:18: error: unexpected token
       sw x14, FREGS_A4(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:21:18: error: unexpected token
       sw x15, FREGS_A5(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:22:18: error: unexpected token
       sw x16, FREGS_A6(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:23:18: error: unexpected token
       sw x17, FREGS_A7(sp)
                       ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
       ^
      <instantiation>:25:15: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]
       addi a0, a0, FREGS_SIZE_ON_STACK
                    ^
      arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
       SAVE_ABI_REGS
Quoted 5 lines

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DYNAMIC_FTRACE Depends on [n]: FTRACE [=y] && FUNCTION_TRACER [=y] && HAVE_DYNAMIC_FTRACE [=n] Selected by [y]:
- RISCV [=y] && FUNCTION_TRACER [=y]

To avoid that, we should check HAVE_DYNAMIC_FTRACE too:

Quoted 9 lines

select DYNAMIC_FTRACE if FUNCTION_TRACER && HAVE_DYNAMIC_FTRACE

That fixes the build error for me. Can you send a v3 with this change?

Thanks,

Alex

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#8 lore raw

Hi,

Quoted 11 lines · Miao Chen

Hi,

I rechecked the .config file. I configured it using

make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__ -fmax-errors=unlimited -fmax-warnings=unlimited' O=build_dir olddefconfig,

and obtained the following configuration. If NONPORTABLE is disabled, the MMU will be enabled. I did not find any other settings that would affect the enabling of NONPORTABLE—it is set to 'y' by default.

NONPORTABLE being set does not prevent MMU to be enabled. I see that in your config MMU is disabled and then HAVE_DYNAMIC_FTRACE is disabled, I don't see anything wrong with this configuration so there is no need to try to enable MMU.

This configuration shows that we need to check that HAVE_DYNAMIC_FTRACE is set to enable DYNAMIC_FTRACE, otherwise we encounter the build errors reported by kernel test robot.

Can you send a v3 with this change?

Also, can you change the patch title and patch log to something like this:

    riscv: Stop supporting static ftrace

    Now that DYNAMIC_FTRACE was introduced, there is no need to support static ftrace as it is way less performant. This simplifies the code and prevents build failures as reported by kernel test robot when !DYNAMIC_FTRACE.

Thanks,

Alex

Quoted 259 lines

--------- CONFIG ---------------------

config NONPORTABLE
bool "Allow configurations that result in non-portable kernels"

Symbol: HAVE_DYNAMIC_FTRACE [=n]
Type : bool
Defined at kernel/trace/Kconfig:42
Selected by [n]:
- RISCV [=y] && !XIP_KERNEL [=n] && MMU [=n] &&
(CLANG_SUPPORTS_DYNAMIC_FTRACE [=n] || GCC_SUPPORTS_DYNAMIC_FTRACE [=y])

Symbol: MMU [=n]
Type : bool
Defined at arch/riscv/Kconfig:298
Prompt: MMU-based Paged Memory Management Support Location:
(1) -> MMU-based Paged Memory Management Support (MMU [=n]) Selected by [n]:
- PORTABLE [=n]

Symbol: PORTABLE [=n]
Type : bool
Defined at arch/riscv/Kconfig:1344
Selects: EFI [=n] && MMU [=n] && OF [=y]

Symbol: NONPORTABLE [=y]

   │ Type  : bool
   │ Defined at arch/riscv/Kconfig:389
   │   Prompt: Allow configurations that result in non-portable kernels
   │   Location:
   │     -> Platform type
   │ (1)   -> Allow configurations that result in non-portable kernels

(NONPORTABLE [=y])

Thanks,

Chen Miao

Quoted 26 lines · Alexandre Ghiti <[email protected]> 于2025年7月11日周五 15:55写道:

Hi,

Quoted 11 lines · Miao Chen

Hello Alex,

I found where the error is, but there's a problem here:

config PORTABLE
bool
default !NONPORTABLE
select EFI
select MMU
select OF

Quoted 8 lines

select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)

Because HAVE_DYNAMIC_FTRACE depends on the MMU—of course, it's reasonable for DYNAMIC_FTRACE to depend on the MMU—*but since NONPORTABLE is enabled by default, this causes PORTABLE to default to n, thereby preventing the MMU from being enabled*. So, should I change NONPORTABLE to default to n?

NONPORTABLE is not enabled by default and PORTABLE=n does not prevent MMU from being enabled.

Quoted 186 lines

IIUC, it seems like you don't have HAVE_DYNAMIC_FTRACE enabled but that's probably because of your toolchain, not !MMU, can you check that in your .config?

Thanks,

Alex

Quoted 177 lines

Thanks,

Alex

Quoted 168 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 22:33写道:
Quoted 5 lines · Miao Chen

Hello Alex,

Sure, I'll checkout it. Btw, this is my first commit, so can u tell how to reproduce failed case? Using the reproduce and .config.gz gived by build-bot?

Yes exactly!

Quoted 159 lines

Thanks,

Chen Miao

Quoted 141 lines · Alexandre Ghiti <[email protected]> 于2025年7月10日周四 19:53写道:

Hi ChenMiao,

Quoted 131 lines · kernel test robot

Hi ChenMiao,

kernel test robot noticed the following build errors:

[auto build test ERROR on fda589c286040d9ba2d72a0eaf0a13945fc48026]

url:    https://github.com/intel-lab-lkp/linux/commits/ChenMiao/riscv-ftrace-Fix-the-logic-issue-in-DYNAMIC_FTRACE-selection/20250706-231907
base:   fda589c286040d9ba2d72a0eaf0a13945fc48026
patch link:    https://lore.kernel.org/r/20250706151830.25091-1-chenmiao.ku%40gmail.com
patch subject: [PATCH V2] riscv: ftrace: Fix the logic issue in DYNAMIC_FTRACE selection

:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: riscv-randconfig-r112-20250708 (attached as .config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce: (attached as reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

<instantiation>:1:14: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]

addi sp, sp, -FREGS_SIZE_ON_STACK
^
arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
SAVE_ABI_REGS
^

Quoted 1 line
Quoted 1 line

<instantiation>:2:18: error: unexpected token

        sw t0, FREGS_EPC(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:3:17: error: unexpected token
        sw x1, FREGS_RA(sp)
                       ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:7:17: error: unexpected token
        sw x6, FREGS_T1(sp)
                       ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:9:17: error: unexpected token
        sw x7, FREGS_T2(sp)
                       ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:10:18: error: unexpected token
        sw x28, FREGS_T3(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:11:18: error: unexpected token
        sw x29, FREGS_T4(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:12:18: error: unexpected token
        sw x30, FREGS_T5(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:13:18: error: unexpected token
        sw x31, FREGS_T6(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:16:18: error: unexpected token
        sw x10, FREGS_A0(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:17:18: error: unexpected token
        sw x11, FREGS_A1(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:18:18: error: unexpected token
        sw x12, FREGS_A2(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:19:18: error: unexpected token
        sw x13, FREGS_A3(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:20:18: error: unexpected token
        sw x14, FREGS_A4(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:21:18: error: unexpected token
        sw x15, FREGS_A5(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:22:18: error: unexpected token
        sw x16, FREGS_A6(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:23:18: error: unexpected token
        sw x17, FREGS_A7(sp)
                        ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
        ^
       <instantiation>:25:15: error: operand must be a symbol with %lo/%pcrel_lo/%tprel_lo modifier or an integer in the range [-2048, 2047]
        addi a0, a0, FREGS_SIZE_ON_STACK
                     ^
       arch/riscv/kernel/mcount-dyn.S:185:2: note: while in macro instantiation
        SAVE_ABI_REGS
Quoted 5 lines

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DYNAMIC_FTRACE Depends on [n]: FTRACE [=y] && FUNCTION_TRACER [=y] && HAVE_DYNAMIC_FTRACE [=n] Selected by [y]:
- RISCV [=y] && FUNCTION_TRACER [=y]

To avoid that, we should check HAVE_DYNAMIC_FTRACE too:

Quoted 9 lines

select DYNAMIC_FTRACE if FUNCTION_TRACER && HAVE_DYNAMIC_FTRACE

That fixes the build error for me. Can you send a v3 with this change?

Thanks,

Alex

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#9 lore raw
In reply to ChenMiao
Quoted 214 lines · ChenMiao

From: chenmiao <[email protected]>

V1: The first version mainly involves modifications to the configuration of the dynamic ftracer.

Link https://lore.kernel.org/all/[email protected]/

V2: After a series of discussions, Steven concluded that only supporting the dynamic ftracer would suffice. Alex also pointed out that if only the dynamic ftracer needs to be supported, the code related to the static ftracer would become obsolete and turn into dead code. He had already done some preliminary work on this.

Based on this, the modifications to the configuration were made, and the dead code generated by the ftracer
(originally related to the static ftracer) was also removed.

Link https://lore.kernel.org/all/[email protected]/
Link https://github.com/linux-riscv/linux/pull/556/commits/0481092a5bec3818658981c11f629e06e66382b3

---
  arch/riscv/Kconfig              |  3 +-
  arch/riscv/include/asm/ftrace.h |  3 --
  arch/riscv/kernel/ftrace.c      | 11 +-----
  arch/riscv/kernel/mcount.S      | 64 ---------------------------------
  kernel/trace/Kconfig            |  2 +-
  5 files changed, 4 insertions(+), 79 deletions(-)
arch/riscv/Kconfig +2 -1
index 36061f4732b7..95d24b19c466 100644
@@ -97,8 +97,9 @@ config RISCV
  	select CLONE_BACKWARDS
  	select COMMON_CLK
  	select CPU_PM if CPU_IDLE || HIBERNATION || SUSPEND
+	select DYNAMIC_FTRACE if FUNCTION_TRACER
  	select EDAC_SUPPORT
-	select FRAME_POINTER if PERF_EVENTS || (FUNCTION_TRACER && !DYNAMIC_FTRACE)
+	select FRAME_POINTER if PERF_EVENTS
  	select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY if DYNAMIC_FTRACE
  	select FUNCTION_ALIGNMENT_8B if DYNAMIC_FTRACE_WITH_CALL_OPS
  	select GENERIC_ARCH_TOPOLOGY
arch/riscv/include/asm/ftrace.h +0 -3
index 22ebea3c2b26..77ddb6dce0a8 100644
@@ -49,7 +49,6 @@ struct dyn_arch_ftrace {
  };
  #endif
 
-#ifdef CONFIG_DYNAMIC_FTRACE
  /*
   * A general call in RISC-V is a pair of insts:
   * 1) auipc: setting high-20 pc-related bits to ra register
@@ -237,6 +236,4 @@ static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsi
 
  #endif /* __ASSEMBLY__ */
 
-#endif /* CONFIG_DYNAMIC_FTRACE */
-
  #endif /* _ASM_RISCV_FTRACE_H */
arch/riscv/kernel/ftrace.c +1 -10
index 4c6c24380cfd..93bad646d233 100644
@@ -13,7 +13,6 @@
  #include <asm/cacheflush.h>
  #include <asm/text-patching.h>
 
-#ifdef CONFIG_DYNAMIC_FTRACE
  unsigned long ftrace_call_adjust(unsigned long addr)
  {
  	if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS))
@@ -191,13 +190,6 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
  	return 0;
  }
 
-#else /* CONFIG_DYNAMIC_FTRACE */
-unsigned long ftrace_call_adjust(unsigned long addr)
-{
-	return addr;
-}
-#endif /* CONFIG_DYNAMIC_FTRACE */
-
  #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
  int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  		       unsigned long addr)
@@ -236,7 +228,6 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
  		*parent = return_hooker;
  }
 
-#ifdef CONFIG_DYNAMIC_FTRACE
  void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
  		       struct ftrace_ops *op, struct ftrace_regs *fregs)
  {
@@ -257,5 +248,5 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
  	if (!function_graph_enter_regs(old, ip, frame_pointer, parent, fregs))
  		*parent = return_hooker;
  }
-#endif /* CONFIG_DYNAMIC_FTRACE */
+
  #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
arch/riscv/kernel/mcount.S +0 -64
index da4a4000e57e..bb550c15f1c9 100644
@@ -14,13 +14,6 @@
 
  	.text
 
-	.macro SAVE_ABI_STATE
-	addi	sp, sp, -16
-	REG_S	s0, 0*SZREG(sp)
-	REG_S	ra, 1*SZREG(sp)
-	addi	s0, sp, 16
-	.endm
-
  	/*
  	 * The call to ftrace_return_to_handler would overwrite the return
  	 * register if a0 was not saved.
@@ -34,12 +27,6 @@
  	addi	s0, sp, FREGS_SIZE_ON_STACK
  	.endm
 
-	.macro RESTORE_ABI_STATE
-	REG_L	ra, 1*SZREG(sp)
-	REG_L	s0, 0*SZREG(sp)
-	addi	sp, sp, 16
-	.endm
-
  	.macro RESTORE_RET_ABI_STATE
  	REG_L	ra, FREGS_RA(sp)
  	REG_L	s0, FREGS_S0(sp)
@@ -49,10 +36,8 @@
  	.endm
 
  SYM_TYPED_FUNC_START(ftrace_stub)
-#ifdef CONFIG_DYNAMIC_FTRACE
         .global _mcount
         .set    _mcount, ftrace_stub
-#endif
  	ret
  SYM_FUNC_END(ftrace_stub)
 
@@ -79,53 +64,4 @@ SYM_FUNC_START(return_to_handler)
  SYM_FUNC_END(return_to_handler)
  #endif
 
-#ifndef CONFIG_DYNAMIC_FTRACE
-SYM_FUNC_START(_mcount)
-	la	t4, ftrace_stub
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-	la	t0, ftrace_graph_return
-	REG_L	t1, 0(t0)
-	bne	t1, t4, .Ldo_ftrace_graph_caller
-
-	la	t3, ftrace_graph_entry
-	REG_L	t2, 0(t3)
-	la	t6, ftrace_graph_entry_stub
-	bne	t2, t6, .Ldo_ftrace_graph_caller
-#endif
-	la	t3, ftrace_trace_function
-	REG_L	t5, 0(t3)
-	bne	t5, t4, .Ldo_trace
-	ret
-
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-/*
- * A pseudo representation for the function graph tracer:
- * prepare_to_return(&ra_to_caller_of_caller, ra_to_caller)
- */
-.Ldo_ftrace_graph_caller:
-	addi	a0, s0, -SZREG
-	mv	a1, ra
-#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
-	REG_L	a2, -2*SZREG(s0)
-#endif
-	SAVE_ABI_STATE
-	call	prepare_ftrace_return
-	RESTORE_ABI_STATE
-	ret
-#endif
-
-/*
- * A pseudo representation for the function tracer:
- * (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller)
- */
-.Ldo_trace:
-	REG_L	a1, -SZREG(s0)
-	mv	a0, ra
-
-	SAVE_ABI_STATE
-	jalr	t5
-	RESTORE_ABI_STATE
-	ret
-SYM_FUNC_END(_mcount)
-#endif
  EXPORT_SYMBOL(_mcount)
kernel/trace/Kconfig +1 -1
index a3f35c7d83b6..28afc6941e7a 100644
@@ -275,7 +275,7 @@ config FUNCTION_TRACE_ARGS
  	  funcgraph-args (for the function graph tracer)
 
  config DYNAMIC_FTRACE
-	bool "enable/disable function tracing dynamically"
+	bool
  	depends on FUNCTION_TRACER
  	depends on HAVE_DYNAMIC_FTRACE
  	default y
Quoted 1 line

base-commit: fda589c286040d9ba2d72a0eaf0a13945fc48026

I have just given it a try but I'm getting the following errors:

../arch/riscv/kernel/ftrace.c: In function 'arch_ftrace_update_code':
../arch/riscv/kernel/ftrace.c:44:9: error: implicit declaration of function 'ftrace_modify_all_code' [-Werror=implicit-function-declaration] 44 |         ftrace_modify_all_code(command);
      |         ^~~~~~~~~~~~~~~~~~~~~~
../arch/riscv/kernel/ftrace.c: At top level:
../arch/riscv/kernel/ftrace.c:116:5: warning: no previous prototype for 'ftrace_make_call' [-Wmissing-prototypes]
  116 | int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
      |     ^~~~~~~~~~~~~~~~
../arch/riscv/kernel/ftrace.c: In function 'ftrace_make_call':
../arch/riscv/kernel/ftrace.c:118:52: error: invalid use of undefined type 'struct dyn_ftrace'
  118 |         unsigned long distance, orig_addr, pc = rec->ip - MCOUNT_AUIPC_SIZE;
      |                                                    ^~
../arch/riscv/kernel/ftrace.c:125:37: error: 'ftrace_caller' undeclared (first use in this function); did you mean 'ftrace_kill'? 125 |         orig_addr = (unsigned long)&ftrace_caller;
      |                                     ^~~~~~~~~~~~~
      |                                     ftrace_kill
../arch/riscv/kernel/ftrace.c:125:37: note: each undeclared identifier is reported only once for each function it appears in ../arch/riscv/kernel/ftrace.c:128:24: error: 'FTRACE_ADDR' undeclared (first use in this function)
  128 |                 addr = FTRACE_ADDR;
      |                        ^~~~~~~~~~~
../arch/riscv/kernel/ftrace.c: At top level:
../arch/riscv/kernel/ftrace.c:133:5: warning: no previous prototype for 'ftrace_make_nop' [-Wmissing-prototypes]
  133 | int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long addr)
      |     ^~~~~~~~~~~~~~~
../arch/riscv/kernel/ftrace.c: In function 'ftrace_make_nop':
../arch/riscv/kernel/ftrace.c:142:41: error: invalid use of undefined type 'struct dyn_ftrace'
  142 |         if (patch_insn_write((void *)rec->ip, &nop4, MCOUNT_NOP4_SIZE))
      |                                         ^~
../arch/riscv/kernel/ftrace.c: In function 'ftrace_init_nop':
../arch/riscv/kernel/ftrace.c:157:31: error: invalid use of undefined type 'struct dyn_ftrace'
  157 |         unsigned long pc = rec->ip - MCOUNT_AUIPC_SIZE;
      |                               ^~
  CC      drivers/nvme/target/io-cmd-bdev.o
../arch/riscv/kernel/ftrace.c:167:35: error: 'ftrace_caller' undeclared (first use in this function); did you mean 'ftrace_kill'? 167 |         offset = (unsigned long) &ftrace_caller - pc;
      |                                   ^~~~~~~~~~~~~
      |                                   ftrace_kill
../arch/riscv/kernel/ftrace.c: At top level:
../arch/riscv/kernel/ftrace.c:177:5: warning: no previous prototype for 'ftrace_update_ftrace_func' [-Wmissing-prototypes] 177 | int ftrace_update_ftrace_func(ftrace_func_t func)

#10 lore raw
Quoted 243 lines · Alexandre Ghiti
Quoted 205 lines · ChenMiao

From: chenmiao <[email protected]>

V1: The first version mainly involves modifications to the configuration of the dynamic ftracer.

Link https://lore.kernel.org/all/[email protected]/

V2: After a series of discussions, Steven concluded that only supporting the dynamic ftracer would suffice. Alex also pointed out that if only the dynamic ftracer needs to be supported, the code related to the static ftracer would become obsolete and turn into dead code. He had already done some preliminary work on this.

Based on this, the modifications to the configuration were made, and the dead code generated by the ftracer
(originally related to the static ftracer) was also removed.

Link https://lore.kernel.org/all/[email protected]/
Link https://github.com/linux-riscv/linux/pull/556/commits/0481092a5bec3818658981c11f629e06e66382b3

---
  arch/riscv/Kconfig              |  3 +- arch/riscv/include/asm/ftrace.h |  3 -- arch/riscv/kernel/ftrace.c      | 11 +----- arch/riscv/kernel/mcount.S      | 64 --------------------------------- kernel/trace/Kconfig            |  2 +-

  5 files changed, 4 insertions(+), 79 deletions(-)
arch/riscv/Kconfig +0 -0
index 36061f4732b7..95d24b19c466 100644
@@ -97,8 +97,9 @@ config RISCV

      select CLONE_BACKWARDS
      select COMMON_CLK
      select CPU_PM if CPU_IDLE || HIBERNATION || SUSPEND
+    select DYNAMIC_FTRACE if FUNCTION_TRACER
      select EDAC_SUPPORT
-    select FRAME_POINTER if PERF_EVENTS || (FUNCTION_TRACER && !DYNAMIC_FTRACE)
+    select FRAME_POINTER if PERF_EVENTS
      select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY if DYNAMIC_FTRACE select FUNCTION_ALIGNMENT_8B if DYNAMIC_FTRACE_WITH_CALL_OPS select GENERIC_ARCH_TOPOLOGY

arch/riscv/include/asm/ftrace.h +0 -0
index 22ebea3c2b26..77ddb6dce0a8 100644
@@ -49,7 +49,6 @@ struct dyn_arch_ftrace {
   };
   #endif

  -#ifdef CONFIG_DYNAMIC_FTRACE
  /*
   * A general call in RISC-V is a pair of insts:
   * 1) auipc: setting high-20 pc-related bits to ra register

arch/riscv/include/asm/ftrace.h +0 -0
@@ -237,6 +236,4 @@ static inline void 

arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsi #endif /* __ASSEMBLY__ */
  -#endif /* CONFIG_DYNAMIC_FTRACE */
-
  #endif /* _ASM_RISCV_FTRACE_H */

arch/riscv/kernel/ftrace.c +0 -0
index 4c6c24380cfd..93bad646d233 100644
@@ -13,7 +13,6 @@
   #include <asm/cacheflush.h>
   #include <asm/text-patching.h>

  -#ifdef CONFIG_DYNAMIC_FTRACE
  unsigned long ftrace_call_adjust(unsigned long addr) {
      if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS))

arch/riscv/kernel/ftrace.c +0 -0
@@ -191,13 +190,6 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
       return 0;
   }

  -#else /* CONFIG_DYNAMIC_FTRACE */

arch/riscv/kernel/ftrace.c +0 -6
-unsigned long ftrace_call_adjust(unsigned long addr)
-{
-    return addr;
-}
-#endif /* CONFIG_DYNAMIC_FTRACE */
-

  #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
  int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, unsigned long addr)

arch/riscv/kernel/ftrace.c +0 -0
@@ -236,7 +228,6 @@ void prepare_ftrace_return(unsigned long *parent, 
 unsigned long self_addr,
           *parent = return_hooker;
   }

  -#ifdef CONFIG_DYNAMIC_FTRACE
  void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs) {

arch/riscv/kernel/ftrace.c +1 -1
@@ -257,5 +248,5 @@ void ftrace_graph_func(unsigned long ip, unsigned 
 long parent_ip,
       if (!function_graph_enter_regs(old, ip, frame_pointer, parent, fregs))
           *parent = return_hooker;
   }
-#endif /* CONFIG_DYNAMIC_FTRACE */
+

  #endif /* CONFIG_FUNCTION_GRAPH_TRACER */

arch/riscv/kernel/mcount.S +0 -0
index da4a4000e57e..bb550c15f1c9 100644
@@ -14,13 +14,6 @@

        .text
  -    .macro SAVE_ABI_STATE
-    addi    sp, sp, -16
-    REG_S    s0, 0*SZREG(sp)
-    REG_S    ra, 1*SZREG(sp)
-    addi    s0, sp, 16
-    .endm
-
      /*
       * The call to ftrace_return_to_handler would overwrite the return
       * register if a0 was not saved.

arch/riscv/kernel/mcount.S +0 -0
@@ -34,12 +27,6 @@

      addi    s0, sp, FREGS_SIZE_ON_STACK
      .endm
  -    .macro RESTORE_ABI_STATE
-    REG_L    ra, 1*SZREG(sp)
-    REG_L    s0, 0*SZREG(sp)
-    addi    sp, sp, 16
-    .endm
-
      .macro RESTORE_RET_ABI_STATE
      REG_L    ra, FREGS_RA(sp)
      REG_L    s0, FREGS_S0(sp)

arch/riscv/kernel/mcount.S +0 -0
@@ -49,10 +36,8 @@

      .endm
    SYM_TYPED_FUNC_START(ftrace_stub)
-#ifdef CONFIG_DYNAMIC_FTRACE
         .global _mcount
         .set    _mcount, ftrace_stub
-#endif
      ret
  SYM_FUNC_END(ftrace_stub)
  @@ -79,53 +64,4 @@ SYM_FUNC_START(return_to_handler) SYM_FUNC_END(return_to_handler)
  #endif
  -#ifndef CONFIG_DYNAMIC_FTRACE

arch/riscv/kernel/mcount.S +0 -48
-SYM_FUNC_START(_mcount)
-    la    t4, ftrace_stub
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-    la    t0, ftrace_graph_return
-    REG_L    t1, 0(t0)
-    bne    t1, t4, .Ldo_ftrace_graph_caller
-
-    la    t3, ftrace_graph_entry
-    REG_L    t2, 0(t3)
-    la    t6, ftrace_graph_entry_stub
-    bne    t2, t6, .Ldo_ftrace_graph_caller
-#endif
-    la    t3, ftrace_trace_function
-    REG_L    t5, 0(t3)
-    bne    t5, t4, .Ldo_trace
-    ret
-
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
-/*
- * A pseudo representation for the function graph tracer:
- * prepare_to_return(&ra_to_caller_of_caller, ra_to_caller)
- */
-.Ldo_ftrace_graph_caller:
-    addi    a0, s0, -SZREG
-    mv    a1, ra
-#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
-    REG_L    a2, -2*SZREG(s0)
-#endif
-    SAVE_ABI_STATE
-    call    prepare_ftrace_return
-    RESTORE_ABI_STATE
-    ret
-#endif
-
-/*
- * A pseudo representation for the function tracer:
- * (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller)
- */
-.Ldo_trace:
-    REG_L    a1, -SZREG(s0)
-    mv    a0, ra
-
-    SAVE_ABI_STATE
-    jalr    t5
-    RESTORE_ABI_STATE
-    ret
-SYM_FUNC_END(_mcount)
-#endif

  EXPORT_SYMBOL(_mcount)

kernel/trace/Kconfig +0 -0
index a3f35c7d83b6..28afc6941e7a 100644
@@ -275,7 +275,7 @@ config FUNCTION_TRACE_ARGS
         funcgraph-args (for the function graph tracer)

    config DYNAMIC_FTRACE
-    bool "enable/disable function tracing dynamically" +    bool
      depends on FUNCTION_TRACER
      depends on HAVE_DYNAMIC_FTRACE
      default y

Quoted 1 line

base-commit: fda589c286040d9ba2d72a0eaf0a13945fc48026

I have just given it a try but I'm getting the following errors:

../arch/riscv/kernel/ftrace.c: In function 'arch_ftrace_update_code':
../arch/riscv/kernel/ftrace.c:44:9: error: implicit declaration of function 'ftrace_modify_all_code' [-Werror=implicit-function-declaration] 44 |         ftrace_modify_all_code(command);
      |         ^~~~~~~~~~~~~~~~~~~~~~
../arch/riscv/kernel/ftrace.c: At top level:
../arch/riscv/kernel/ftrace.c:116:5: warning: no previous prototype for 'ftrace_make_call' [-Wmissing-prototypes]
  116 | int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
      |     ^~~~~~~~~~~~~~~~
../arch/riscv/kernel/ftrace.c: In function 'ftrace_make_call':
../arch/riscv/kernel/ftrace.c:118:52: error: invalid use of undefined type 'struct dyn_ftrace'
  118 |         unsigned long distance, orig_addr, pc = rec->ip - MCOUNT_AUIPC_SIZE;
      |                                                    ^~
../arch/riscv/kernel/ftrace.c:125:37: error: 'ftrace_caller' undeclared (first use in this function); did you mean 'ftrace_kill'? 125 |         orig_addr = (unsigned long)&ftrace_caller;
      |                                     ^~~~~~~~~~~~~
      |                                     ftrace_kill
../arch/riscv/kernel/ftrace.c:125:37: note: each undeclared identifier is reported only once for each function it appears in ../arch/riscv/kernel/ftrace.c:128:24: error: 'FTRACE_ADDR' undeclared (first use in this function)
  128 |                 addr = FTRACE_ADDR;
      |                        ^~~~~~~~~~~
../arch/riscv/kernel/ftrace.c: At top level:
../arch/riscv/kernel/ftrace.c:133:5: warning: no previous prototype for 'ftrace_make_nop' [-Wmissing-prototypes]
  133 | int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long addr)
      |     ^~~~~~~~~~~~~~~
../arch/riscv/kernel/ftrace.c: In function 'ftrace_make_nop':
../arch/riscv/kernel/ftrace.c:142:41: error: invalid use of undefined type 'struct dyn_ftrace'
  142 |         if (patch_insn_write((void *)rec->ip, &nop4, MCOUNT_NOP4_SIZE))
      |                                         ^~
../arch/riscv/kernel/ftrace.c: In function 'ftrace_init_nop':
../arch/riscv/kernel/ftrace.c:157:31: error: invalid use of undefined type 'struct dyn_ftrace'
  157 |         unsigned long pc = rec->ip - MCOUNT_AUIPC_SIZE;
      |                               ^~

Quoted 8 lines

  CC      drivers/nvme/target/io-cmd-bdev.o
../arch/riscv/kernel/ftrace.c:167:35: error: 'ftrace_caller' undeclared (first use in this function); did you mean 'ftrace_kill'? 167 |         offset = (unsigned long) &ftrace_caller - pc;
      |                                   ^~~~~~~~~~~~~
      |                                   ftrace_kill
../arch/riscv/kernel/ftrace.c: At top level:
../arch/riscv/kernel/ftrace.c:177:5: warning: no previous prototype for 'ftrace_update_ftrace_func' [-Wmissing-prototypes] 177 | int ftrace_update_ftrace_func(ftrace_func_t func)

I'll send a simple version this afternoon to fix the build error so that we can merge it in 6.16. That will be a simple version that does not remove the dead code.

I'll add your SoB, let me know if you want to work on removing the dead code in a follow-up patch targeting 6.17.

Thanks,

Alex

Quoted 6 lines

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv