Skip to content

Commit 406145c

Browse files
Yinan Liushiloong
authored andcommitted
ftrace: modify the scope of sorting mcount at compile
ANBZ: torvalds#434 commit 4ed308c upstream. First S390 complained that the sorting of the mcount sections at build time caused the kernel to crash on their architecture. Now PowerPC is complaining about it too. And also ARM64 appears to be having issues. It may be necessary to also update the relocation table for the values in the mcount table. Not only do we have to sort the table, but also update the relocations that may be applied to the items in the table. If the system is not relocatable, then it is fine to sort, but if it is, some architectures may have issues (although x86 does not as it shifts all addresses the same). Add a HAVE_BUILDTIME_MCOUNT_SORT that an architecture can set to say it is safe to do the sorting at build time. Also update the config to compile in build time sorting in the sorttable code in scripts/ to depend on CONFIG_BUILDTIME_MCOUNT_SORT. Fixes: 1cb7e9c ("anolis: scripts: ftrace_init optimization about sorting") Reported-by: Sachin Sant <[email protected]> Tested-by: Sachin Sant <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Yinan Liu <[email protected]> Reviewed-by: Shanpei Chen <[email protected]>
1 parent cfa5a28 commit 406145c

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ config ARM
6161
select HAVE_EBPF_JIT if !CPU_ENDIAN_BE32
6262
select HAVE_CONTEXT_TRACKING
6363
select HAVE_C_RECORDMCOUNT
64+
select HAVE_BUILDTIME_MCOUNT_SORT
6465
select HAVE_DEBUG_KMEMLEAK
6566
select HAVE_DMA_CONTIGUOUS if MMU
6667
select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) && !CPU_ENDIAN_BE32 && MMU

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ config X86
135135
select HAVE_CONTEXT_TRACKING if X86_64
136136
select HAVE_COPY_THREAD_TLS
137137
select HAVE_C_RECORDMCOUNT
138+
select HAVE_BUILDTIME_MCOUNT_SORT
138139
select HAVE_DEBUG_KMEMLEAK
139140
select HAVE_DEBUG_STACKOVERFLOW
140141
select HAVE_DMA_CONTIGUOUS

kernel/trace/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ config HAVE_C_RECORDMCOUNT
5757
help
5858
C version of recordmcount available?
5959

60+
config HAVE_BUILDTIME_MCOUNT_SORT
61+
bool
62+
help
63+
An architecture selects this if it sorts the mcount_loc section
64+
at build time.
65+
66+
config BUILDTIME_MCOUNT_SORT
67+
bool
68+
default y
69+
depends on HAVE_BUILDTIME_MCOUNT_SORT && DYNAMIC_FTRACE
70+
help
71+
Sort the mcount_loc section at build time.
72+
6073
config TRACER_MAX_TRACE
6174
bool
6275

kernel/trace/ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5554,7 +5554,7 @@ static int ftrace_process_locs(struct module *mod,
55545554
* CONFIG_BUILDTIME_TABLE_SORT, while mcount loc in
55555555
* modules can not be sorted at build time.
55565556
*/
5557-
if (!IS_ENABLED(CONFIG_BUILDTIME_TABLE_SORT) || mod) {
5557+
if (!IS_ENABLED(CONFIG_BUILDTIME_MCOUNT_SORT) || mod) {
55585558
sort(start, count, sizeof(*start),
55595559
ftrace_cmp_ips, NULL);
55605560
}

scripts/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ HOSTCFLAGS_sorttable.o += -DUNWINDER_ORC_ENABLED
3434
endif
3535
endif
3636

37-
ifdef CONFIG_FUNCTION_TRACER
37+
ifdef CONFIG_BUILDTIME_MCOUNT_SORT
3838
HOSTCFLAGS_sorttable.o += -DMCOUNT_SORT_ENABLED
3939
endif
4040

scripts/sorttable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static int do_sort(Elf_Ehdr *ehdr,
285285
unsigned int shnum;
286286
unsigned int shstrndx;
287287
#ifdef MCOUNT_SORT_ENABLED
288-
struct elf_mcount_loc mstruct;
288+
struct elf_mcount_loc mstruct = {0};
289289
uint_t _start_mcount_loc = 0;
290290
uint_t _stop_mcount_loc = 0;
291291
pthread_t mcount_sort_thread = 0;

0 commit comments

Comments
 (0)