ftrace: Add HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
authorPeter Zijlstra (Intel) <peterz@infradead.org>
Sat, 3 Sep 2022 13:11:53 +0000 (15:11 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 16 Sep 2022 20:16:48 +0000 (22:16 +0200)
x86 will shortly start using -fpatchable-function-entry for purposes
other than ftrace, make sure the __patchable_function_entry section
isn't merged in the mcount_loc section.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220903131154.420467-2-jolsa@kernel.org
include/asm-generic/vmlinux.lds.h
kernel/trace/Kconfig
tools/objtool/check.c

index 7515a46..13b197e 100644 (file)
 #define MEM_DISCARD(sec) *(.mem##sec)
 #endif
 
+#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
+#define KEEP_PATCHABLE         KEEP(*(__patchable_function_entries))
+#define PATCHABLE_DISCARDS
+#else
+#define KEEP_PATCHABLE
+#define PATCHABLE_DISCARDS     *(__patchable_function_entries)
+#endif
+
 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
 /*
  * The ftrace call sites are logged to a section whose name depends on the
 #define MCOUNT_REC()   . = ALIGN(8);                           \
                        __start_mcount_loc = .;                 \
                        KEEP(*(__mcount_loc))                   \
-                       KEEP(*(__patchable_function_entries))   \
+                       KEEP_PATCHABLE                          \
                        __stop_mcount_loc = .;                  \
                        ftrace_stub_graph = ftrace_stub;        \
                        ftrace_ops_list_func = arch_ftrace_ops_list_func;
 
 #define COMMON_DISCARDS                                                        \
        SANITIZER_DISCARDS                                              \
+       PATCHABLE_DISCARDS                                              \
        *(.discard)                                                     \
        *(.discard.*)                                                   \
        *(.modinfo)                                                     \
index 1052126..e9e95c7 100644 (file)
@@ -51,6 +51,12 @@ config HAVE_DYNAMIC_FTRACE_WITH_ARGS
         This allows for use of regs_get_kernel_argument() and
         kernel_stack_pointer().
 
+config HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
+       bool
+       help
+         If the architecture generates __patchable_function_entries sections
+         but does not want them included in the ftrace locations.
+
 config HAVE_FTRACE_MCOUNT_RECORD
        bool
        help
index e55fdf9..9216060 100644 (file)
@@ -4113,7 +4113,8 @@ static int validate_ibt(struct objtool_file *file)
                    !strcmp(sec->name, "__bug_table")                   ||
                    !strcmp(sec->name, "__ex_table")                    ||
                    !strcmp(sec->name, "__jump_table")                  ||
-                   !strcmp(sec->name, "__mcount_loc"))
+                   !strcmp(sec->name, "__mcount_loc")                  ||
+                   strstr(sec->name, "__patchable_function_entries"))
                        continue;
 
                list_for_each_entry(reloc, &sec->reloc->reloc_list, list)