Skip to content

Commit c41bf43

Browse files
AndybnACTpalmer-dabbelt
authored andcommitted
riscv: ftrace: align patchable functions to 4 Byte boundary
We are changing ftrace code patching in order to remove dependency from stop_machine() and enable kernel preemption. This requires us to align functions entry at a 4-B align address. However, -falign-functions on older versions of GCC alone was not strong enoungh to align all functions. In fact, cold functions are not aligned after turning on optimizations. We consider this is a bug in GCC and turn off guess-branch-probility as a workaround to align all functions. GCC bug id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88345 The option -fmin-function-alignment is able to align all functions properly on newer versions of gcc. So, we add a cc-option to test if the toolchain supports it. Suggested-by: Evgenii Shatokhin <e.shatokhin@yadro.com> Signed-off-by: Andy Chiu <andy.chiu@sifive.com> Reviewed-by: Björn Töpel <bjorn@rivosinc.com> Link: https://lore.kernel.org/r/20250407180838.42877-3-andybnac@gmail.com Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com>
1 parent 54ecbc8 commit c41bf43

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

arch/riscv/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ config RISCV
150150
select HAVE_DEBUG_KMEMLEAK
151151
select HAVE_DMA_CONTIGUOUS if MMU
152152
select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
153+
select FUNCTION_ALIGNMENT_4B if HAVE_DYNAMIC_FTRACE && RISCV_ISA_C
153154
select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
154155
select HAVE_DYNAMIC_FTRACE_WITH_ARGS if HAVE_DYNAMIC_FTRACE
155156
select HAVE_FTRACE_GRAPH_FUNC
@@ -236,6 +237,7 @@ config CLANG_SUPPORTS_DYNAMIC_FTRACE
236237
config GCC_SUPPORTS_DYNAMIC_FTRACE
237238
def_bool CC_IS_GCC
238239
depends on $(cc-option,-fpatchable-function-entry=8)
240+
depends on CC_HAS_MIN_FUNCTION_ALIGNMENT || !RISCV_ISA_C
239241

240242
config HAVE_SHADOW_CALL_STACK
241243
def_bool $(cc-option,-fsanitize=shadow-call-stack)

0 commit comments

Comments
 (0)