Skip to content

Commit 6b9b641

Browse files
committed
ftrace: Fix assuming build time sort works for s390
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]>
1 parent 35140d3 commit 6b9b641

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

kernel/trace/Kconfig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ config HAVE_C_RECORDMCOUNT
7070
help
7171
C version of recordmcount available?
7272

73+
config BUILDTIME_MCOUNT_SORT
74+
bool
75+
default y
76+
depends on BUILDTIME_TABLE_SORT && !S390
77+
help
78+
Sort the mcount_loc section at build time.
79+
7380
config TRACER_MAX_TRACE
7481
bool
7582

@@ -918,7 +925,7 @@ config EVENT_TRACE_TEST_SYSCALLS
918925
config FTRACE_SORT_STARTUP_TEST
919926
bool "Verify compile time sorting of ftrace functions"
920927
depends on DYNAMIC_FTRACE
921-
depends on BUILDTIME_TABLE_SORT
928+
depends on BUILDTIME_MCOUNT_SORT
922929
help
923930
Sorting of the mcount_loc sections that is used to find the
924931
where the ftrace knows where to patch functions for tracing

kernel/trace/ftrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6429,10 +6429,10 @@ static int ftrace_process_locs(struct module *mod,
64296429

64306430
/*
64316431
* Sorting mcount in vmlinux at build time depend on
6432-
* CONFIG_BUILDTIME_TABLE_SORT, while mcount loc in
6432+
* CONFIG_BUILDTIME_MCOUNT_SORT, while mcount loc in
64336433
* modules can not be sorted at build time.
64346434
*/
6435-
if (!IS_ENABLED(CONFIG_BUILDTIME_TABLE_SORT) || mod) {
6435+
if (!IS_ENABLED(CONFIG_BUILDTIME_MCOUNT_SORT) || mod) {
64366436
sort(start, count, sizeof(*start),
64376437
ftrace_cmp_ips, NULL);
64386438
} else {

0 commit comments

Comments
 (0)