Skip to content

Commit

Permalink
ftrace: Fix assuming build time sort works for s390
Browse files Browse the repository at this point in the history
To speed up the boot process, as mcount_loc needs to be sorted for ftrace
to work properly, sorting it at build time is more efficient than boot up
and can save milliseconds of time. Unfortunately, this change broke s390
as it will modify the mcount_loc location after the sorting takes place
and will put back the unsorted locations. Since the sorting is skipped at
boot up if it is believed that it was sorted at run time, ftrace can crash
as its algorithms are dependent on the list being sorted.

Add a new config BUILDTIME_MCOUNT_SORT that is set when
BUILDTIME_TABLE_SORT but not if S390 is set. Use this config to determine
if sorting should take place at boot up.

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

Fixes: 72b3942 ("scripts: ftrace - move the sort-processing in ftrace_init")
Reported-by: Sven Schnelle <[email protected]>
Tested-by: Heiko Carstens <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
  • Loading branch information
rostedt committed Jan 23, 2022
1 parent 35140d3 commit 6b9b641
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ config HAVE_C_RECORDMCOUNT
help
C version of recordmcount available?

config BUILDTIME_MCOUNT_SORT
bool
default y
depends on BUILDTIME_TABLE_SORT && !S390
help
Sort the mcount_loc section at build time.

config TRACER_MAX_TRACE
bool

Expand Down Expand Up @@ -918,7 +925,7 @@ config EVENT_TRACE_TEST_SYSCALLS
config FTRACE_SORT_STARTUP_TEST
bool "Verify compile time sorting of ftrace functions"
depends on DYNAMIC_FTRACE
depends on BUILDTIME_TABLE_SORT
depends on BUILDTIME_MCOUNT_SORT
help
Sorting of the mcount_loc sections that is used to find the
where the ftrace knows where to patch functions for tracing
Expand Down
4 changes: 2 additions & 2 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6429,10 +6429,10 @@ static int ftrace_process_locs(struct module *mod,

/*
* Sorting mcount in vmlinux at build time depend on
* CONFIG_BUILDTIME_TABLE_SORT, while mcount loc in
* CONFIG_BUILDTIME_MCOUNT_SORT, while mcount loc in
* modules can not be sorted at build time.
*/
if (!IS_ENABLED(CONFIG_BUILDTIME_TABLE_SORT) || mod) {
if (!IS_ENABLED(CONFIG_BUILDTIME_MCOUNT_SORT) || mod) {
sort(start, count, sizeof(*start),
ftrace_cmp_ips, NULL);
} else {
Expand Down

0 comments on commit 6b9b641

Please sign in to comment.