Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples: ftrace: Include the nospec-branch.h only for x86

When other architectures without the nospec functionality write their
direct-call functions of samples/ftrace/*.c, the including of
asm/nospec-branch.h must be taken care to fix the no header file found
error in building process.

This commit (ee3e2469b346 "x86/ftrace: Make it call depth tracking aware")
file-globally includes asm/nospec-branch.h providing CALL_DEPTH_ACCOUNT
for only x86 direct-call functions.

It seems better to move the including to `#ifdef CONFIG_X86_64`.

Link: https://lore.kernel.org/linux-trace-kernel/20230130085954.647845-1-suagrfillet@gmail.com

Signed-off-by: Song Shuai <suagrfillet@gmail.com>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Song Shuai and committed by
Steven Rostedt (Google)
01678fbc a9c4bdd5

+5 -5
+1 -1
samples/ftrace/ftrace-direct-modify.c
··· 3 3 #include <linux/kthread.h> 4 4 #include <linux/ftrace.h> 5 5 #include <asm/asm-offsets.h> 6 - #include <asm/nospec-branch.h> 7 6 8 7 extern void my_direct_func1(void); 9 8 extern void my_direct_func2(void); ··· 25 26 #ifdef CONFIG_X86_64 26 27 27 28 #include <asm/ibt.h> 29 + #include <asm/nospec-branch.h> 28 30 29 31 asm ( 30 32 " .pushsection .text, \"ax\", @progbits\n"
+1 -1
samples/ftrace/ftrace-direct-multi-modify.c
··· 3 3 #include <linux/kthread.h> 4 4 #include <linux/ftrace.h> 5 5 #include <asm/asm-offsets.h> 6 - #include <asm/nospec-branch.h> 7 6 8 7 extern void my_direct_func1(unsigned long ip); 9 8 extern void my_direct_func2(unsigned long ip); ··· 23 24 #ifdef CONFIG_X86_64 24 25 25 26 #include <asm/ibt.h> 27 + #include <asm/nospec-branch.h> 26 28 27 29 asm ( 28 30 " .pushsection .text, \"ax\", @progbits\n"
+1 -1
samples/ftrace/ftrace-direct-multi.c
··· 5 5 #include <linux/ftrace.h> 6 6 #include <linux/sched/stat.h> 7 7 #include <asm/asm-offsets.h> 8 - #include <asm/nospec-branch.h> 9 8 10 9 extern void my_direct_func(unsigned long ip); 11 10 ··· 18 19 #ifdef CONFIG_X86_64 19 20 20 21 #include <asm/ibt.h> 22 + #include <asm/nospec-branch.h> 21 23 22 24 asm ( 23 25 " .pushsection .text, \"ax\", @progbits\n"
+1 -1
samples/ftrace/ftrace-direct-too.c
··· 4 4 #include <linux/mm.h> /* for handle_mm_fault() */ 5 5 #include <linux/ftrace.h> 6 6 #include <asm/asm-offsets.h> 7 - #include <asm/nospec-branch.h> 8 7 9 8 extern void my_direct_func(struct vm_area_struct *vma, 10 9 unsigned long address, unsigned int flags); ··· 20 21 #ifdef CONFIG_X86_64 21 22 22 23 #include <asm/ibt.h> 24 + #include <asm/nospec-branch.h> 23 25 24 26 asm ( 25 27 " .pushsection .text, \"ax\", @progbits\n"
+1 -1
samples/ftrace/ftrace-direct.c
··· 4 4 #include <linux/sched.h> /* for wake_up_process() */ 5 5 #include <linux/ftrace.h> 6 6 #include <asm/asm-offsets.h> 7 - #include <asm/nospec-branch.h> 8 7 9 8 extern void my_direct_func(struct task_struct *p); 10 9 ··· 17 18 #ifdef CONFIG_X86_64 18 19 19 20 #include <asm/ibt.h> 21 + #include <asm/nospec-branch.h> 20 22 21 23 asm ( 22 24 " .pushsection .text, \"ax\", @progbits\n"