Skip to content

Commit f8693f6

Browse files
AndybnACTpalmer-dabbelt
authored andcommitted
riscv: ftrace: support fastcc in Clang for WITH_ARGS
Some caller-saved registers which are not defined as function arguments in the ABI can still be passed as arguments when the kernel is compiled with Clang. As a result, we must save and restore those registers to prevent ftrace from clobbering them. - [1]: https://reviews.llvm.org/D68559 Reported-by: Evgenii Shatokhin <e.shatokhin@yadro.com> Closes: https://lore.kernel.org/linux-riscv/7e7c7914-445d-426d-89a0-59a9199c45b1@yadro.com/ Fixes: 7caa976 ("ftrace: riscv: move from REGS to ARGS") Acked-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Björn Töpel <bjorn@rivosinc.com> Signed-off-by: Andy Chiu <andy.chiu@sifive.com> Tested-by: Björn Töpel <bjorn@rivosinc.com> Link: https://lore.kernel.org/r/20250407180838.42877-1-andybnac@gmail.com Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com>
1 parent 9c32cda commit f8693f6

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

arch/riscv/include/asm/ftrace.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ struct __arch_ftrace_regs {
146146
unsigned long a5;
147147
unsigned long a6;
148148
unsigned long a7;
149+
#ifdef CONFIG_CC_IS_CLANG
150+
unsigned long t2;
151+
unsigned long t3;
152+
unsigned long t4;
153+
unsigned long t5;
154+
unsigned long t6;
155+
#endif
149156
};
150157
};
151158
};

arch/riscv/kernel/asm-offsets.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,13 @@ void asm_offsets(void)
501501
DEFINE(FREGS_SP, offsetof(struct __arch_ftrace_regs, sp));
502502
DEFINE(FREGS_S0, offsetof(struct __arch_ftrace_regs, s0));
503503
DEFINE(FREGS_T1, offsetof(struct __arch_ftrace_regs, t1));
504+
#ifdef CONFIG_CC_IS_CLANG
505+
DEFINE(FREGS_T2, offsetof(struct __arch_ftrace_regs, t2));
506+
DEFINE(FREGS_T3, offsetof(struct __arch_ftrace_regs, t3));
507+
DEFINE(FREGS_T4, offsetof(struct __arch_ftrace_regs, t4));
508+
DEFINE(FREGS_T5, offsetof(struct __arch_ftrace_regs, t5));
509+
DEFINE(FREGS_T6, offsetof(struct __arch_ftrace_regs, t6));
510+
#endif
504511
DEFINE(FREGS_A0, offsetof(struct __arch_ftrace_regs, a0));
505512
DEFINE(FREGS_A1, offsetof(struct __arch_ftrace_regs, a1));
506513
DEFINE(FREGS_A2, offsetof(struct __arch_ftrace_regs, a2));

arch/riscv/kernel/mcount-dyn.S

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@
9696
REG_S x8, FREGS_S0(sp)
9797
#endif
9898
REG_S x6, FREGS_T1(sp)
99-
99+
#ifdef CONFIG_CC_IS_CLANG
100+
REG_S x7, FREGS_T2(sp)
101+
REG_S x28, FREGS_T3(sp)
102+
REG_S x29, FREGS_T4(sp)
103+
REG_S x30, FREGS_T5(sp)
104+
REG_S x31, FREGS_T6(sp)
105+
#endif
100106
// save the arguments
101107
REG_S x10, FREGS_A0(sp)
102108
REG_S x11, FREGS_A1(sp)
@@ -115,7 +121,13 @@
115121
REG_L x8, FREGS_S0(sp)
116122
#endif
117123
REG_L x6, FREGS_T1(sp)
118-
124+
#ifdef CONFIG_CC_IS_CLANG
125+
REG_L x7, FREGS_T2(sp)
126+
REG_L x28, FREGS_T3(sp)
127+
REG_L x29, FREGS_T4(sp)
128+
REG_L x30, FREGS_T5(sp)
129+
REG_L x31, FREGS_T6(sp)
130+
#endif
119131
// restore the arguments
120132
REG_L x10, FREGS_A0(sp)
121133
REG_L x11, FREGS_A1(sp)

0 commit comments

Comments
 (0)